forked from nodejs/node-v8
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WASM API and Embedder Builtins to V8 #1
Open
OhadRau
wants to merge
2
commits into
canary
Choose a base branch
from
feat/v8-embedder-builtins
base: canary
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright 2019 the V8 project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef INCLUDE_V8_WASM_H_ | ||
#define INCLUDE_V8_WASM_H_ | ||
|
||
#include <cassert> | ||
#include <cstdint> | ||
#include <cstddef> | ||
#include "v8.h" | ||
|
||
namespace v8 { | ||
namespace wasm { | ||
|
||
#define PAGE_SIZE 0x10000 | ||
|
||
class V8_EXPORT Memory { | ||
private: | ||
size_t pages_; | ||
uint8_t* data_; | ||
public: | ||
Memory(size_t pages, uint8_t* data); | ||
Memory(const Memory& memory); | ||
size_t size(); | ||
size_t pages(); | ||
uint8_t* data(); | ||
}; | ||
|
||
class V8_EXPORT Table { | ||
private: | ||
void* tableObject_; | ||
public: | ||
Table(void* tableObject); | ||
Table(const Table& table); | ||
~Table(); | ||
MaybeLocal<Function> get(int index) const; | ||
}; | ||
|
||
class V8_EXPORT Context { | ||
public: | ||
Context(Memory* memory, Table* table); | ||
Context(Memory* memory, Table* table, v8::Isolate* isolate); | ||
Context(const Context& context); | ||
~Context(); | ||
Memory* memory; | ||
Table* table; | ||
v8::Isolate* isolate; | ||
}; | ||
|
||
enum V8_EXPORT ValKind : uint8_t { | ||
I32, | ||
I64, | ||
F32, | ||
F64, | ||
ANYREF = 128, | ||
FUNCREF | ||
}; | ||
|
||
// TODO(ohadrau): Should we enforce Ref ownership like the C API? | ||
class V8_EXPORT Val { | ||
private: | ||
ValKind kind_; | ||
union value { | ||
int32_t i32; | ||
int64_t i64; | ||
float f32; | ||
double f64; | ||
void* ref; | ||
} value_; | ||
|
||
Val(ValKind kind, value value); | ||
|
||
public: | ||
Val(); | ||
Val(Val&& val); | ||
explicit Val(int32_t i); | ||
explicit Val(int64_t i); | ||
explicit Val(float i); | ||
explicit Val(double i); | ||
explicit Val(void* r); | ||
|
||
Val& operator=(Val&&); | ||
|
||
ValKind kind() const; | ||
int32_t i32() const; | ||
int64_t i64() const; | ||
float f32() const; | ||
double f64() const; | ||
void* ref() const; | ||
}; | ||
|
||
class V8_EXPORT FuncType { | ||
private: | ||
std::vector<ValKind> params_, results_; | ||
public: | ||
FuncType(std::vector<ValKind> params, std::vector<ValKind> results); | ||
|
||
std::vector<ValKind> params() const; | ||
std::vector<ValKind> results() const; | ||
}; | ||
|
||
class V8_EXPORT Func { | ||
public: | ||
using callbackType = void (*)(const Context*, const Val[], Val[]); | ||
Func(const FuncType, callbackType); | ||
|
||
const FuncType type(); | ||
callbackType callback(); | ||
private: | ||
const FuncType type_; | ||
callbackType callback_; | ||
}; | ||
|
||
void RegisterEmbedderBuiltin(Isolate* isolate, | ||
const char* module_name, | ||
const char* name, | ||
Func import); | ||
|
||
} // namespace wasm | ||
} // namespace v8 | ||
|
||
#endif // INCLUDE_V8_WASM_H_ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggstion: use a different name for this macro, or better, make this a const static field of Memory. This avoids potential confusion with the PAGE_SIZE of host memory pages. (it is possible that you're following this pattern from elsewhere in V8 source code, in which case, you can ignore this suggestion)