emnapi 1.9.2 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +127 -57
- package/README.md +164 -776
- package/cmake/wasm32.cmake +0 -3
- package/common.gypi +16 -14
- package/dist/library_async_work.js +390 -0
- package/dist/library_napi.js +1743 -2759
- package/dist/library_threadsafe_function.js +1178 -0
- package/dist/library_v8.js +1594 -0
- package/emnapi.gyp +37 -0
- package/include/node/emnapi.h +39 -3
- package/include/node/js_native_api.h +10 -0
- package/include/node/js_native_api_types.h +26 -0
- package/include/node/node.h +198 -0
- package/include/node/node_api.h +0 -10
- package/include/node/node_buffer.h +92 -0
- package/include/node/node_object_wrap.h +132 -0
- package/include/node/node_version.h +110 -0
- package/include/node/uv/unix.h +1 -0
- package/include/node/uv/version.h +43 -0
- package/include/node/uv.h +6 -0
- package/index.js +15 -7
- package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm32-emscripten/libemnapi.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm64-emscripten/libemnapi.a +0 -0
- package/package.json +1 -1
- package/src/async_cleanup_hook.c +6 -6
- package/src/emnapi_internal.h +5 -10
- package/src/js_native_api.c +37 -21
- package/src/js_native_api_internal.h +66 -0
- package/src/node_api.c +1 -1
- package/src/threadsafe_function.c +2 -2
- package/src/uv/unix/thread.c +21 -0
- package/src/v8/array.cc +19 -0
- package/src/v8/boolean.cc +26 -0
- package/src/v8/date.cc +15 -0
- package/src/v8/exception.cc +48 -0
- package/src/v8/external.cc +23 -0
- package/src/v8/function.cc +35 -0
- package/src/v8/handle_scope.cc +46 -0
- package/src/v8/internal.cc +126 -0
- package/src/v8/internal.h +41 -0
- package/src/v8/isolate.cc +35 -0
- package/src/v8/json.cc +25 -0
- package/src/v8/node.cc +24 -0
- package/src/v8/number.cc +62 -0
- package/src/v8/object.cc +106 -0
- package/src/v8/script.cc +75 -0
- package/src/v8/string.cc +104 -0
- package/src/v8/template.cc +234 -0
- package/src/v8/try_catch.cc +50 -0
- package/src/v8/v8_impl.h +42 -0
- package/src/v8/value.cc +138 -0
- package/lib/wasm32/libdlmalloc-mt.a +0 -0
- package/lib/wasm32/libdlmalloc.a +0 -0
- package/lib/wasm32/libemmalloc-mt.a +0 -0
- package/lib/wasm32/libemmalloc.a +0 -0
- package/lib/wasm32/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32/libemnapi-basic.a +0 -0
- package/lib/wasm32/libemnapi.a +0 -0
- package/lib/wasm32-emscripten/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi/libemnapi.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasip1/libemnapi.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-basic.a +0 -0
package/src/v8/string.cc
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#include "v8_impl.h"
|
|
2
|
+
|
|
3
|
+
namespace v8 {
|
|
4
|
+
|
|
5
|
+
extern "C" {
|
|
6
|
+
V8_EXTERN internal::Address _v8_string_new_from_utf8(Isolate* isolate, const char* data, v8::NewStringType type, int length);
|
|
7
|
+
V8_EXTERN internal::Address _v8_string_new_from_one_byte(Isolate* isolate, const uint8_t* data, v8::NewStringType type, int length);
|
|
8
|
+
V8_EXTERN internal::Address _v8_string_new_from_two_byte(Isolate* isolate, const uint16_t* data, v8::NewStringType type, int length);
|
|
9
|
+
V8_EXTERN internal::Address _v8_string_new_external_one_byte(Isolate* isolate, const char* data, int length);
|
|
10
|
+
V8_EXTERN internal::Address _v8_string_new_external_two_byte(Isolate* isolate, const uint16_t* data, int length);
|
|
11
|
+
V8_EXTERN int _v8_string_utf8_length(const String* self, Isolate* isolate);
|
|
12
|
+
V8_EXTERN int _v8_string_length(const String* self);
|
|
13
|
+
V8_EXTERN int _v8_string_write_utf8(const String* self, Isolate* isolate, char* buffer, int length, int* nchars_ref, int options);
|
|
14
|
+
V8_EXTERN internal::Address _v8_regex_new(Context* context, internal::Address pattern, int flags);
|
|
15
|
+
V8_EXTERN internal::Address _v8_string_object_new(Isolate* isolate, internal::Address value);
|
|
16
|
+
V8_EXTERN internal::Address _v8_string_object_value_of(const StringObject* self);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
void String::CheckCast(v8::Data*) {}
|
|
20
|
+
|
|
21
|
+
MaybeLocal<String> String::NewFromUtf8(v8::Isolate* isolate, char const* data, v8::NewStringType type, int length) {
|
|
22
|
+
auto str = _v8_string_new_from_utf8(isolate, data, type, length);
|
|
23
|
+
if (!str) return MaybeLocal<String>();
|
|
24
|
+
return v8impl::V8LocalValueFromAddress(str).As<String>();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
MaybeLocal<String> String::NewFromOneByte(Isolate* isolate, const uint8_t* data, NewStringType type, int length) {
|
|
28
|
+
auto str = _v8_string_new_from_one_byte(isolate, reinterpret_cast<const uint8_t*>(data), type, length);
|
|
29
|
+
if (!str) return MaybeLocal<String>();
|
|
30
|
+
return v8impl::V8LocalValueFromAddress(str).As<String>();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
MaybeLocal<String> String::NewFromTwoByte(Isolate* isolate, const uint16_t* data, NewStringType type, int length) {
|
|
34
|
+
auto str = _v8_string_new_from_two_byte(isolate, data, type, length);
|
|
35
|
+
if (!str) return MaybeLocal<String>();
|
|
36
|
+
return v8impl::V8LocalValueFromAddress(str).As<String>();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
MaybeLocal<String> String::NewExternalOneByte(Isolate* isolate, ExternalOneByteStringResource* resource) {
|
|
40
|
+
auto str = _v8_string_new_external_one_byte(isolate, resource->data(), static_cast<int>(resource->length()));
|
|
41
|
+
if (!str) return MaybeLocal<String>();
|
|
42
|
+
return v8impl::V8LocalValueFromAddress(str).As<String>();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
MaybeLocal<String> String::NewExternalTwoByte(Isolate* isolate, ExternalStringResource* resource) {
|
|
46
|
+
auto str = _v8_string_new_external_two_byte(isolate, resource->data(), static_cast<int>(resource->length()));
|
|
47
|
+
if (!str) return MaybeLocal<String>();
|
|
48
|
+
return v8impl::V8LocalValueFromAddress(str).As<String>();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
MaybeLocal<RegExp> RegExp::New(Local<Context> context,
|
|
52
|
+
Local<String> pattern,
|
|
53
|
+
Flags flags) {
|
|
54
|
+
auto regex = _v8_regex_new(*context, v8impl::AddressFromV8LocalValue(pattern), flags);
|
|
55
|
+
if (!regex) return MaybeLocal<RegExp>();
|
|
56
|
+
return v8impl::V8LocalValueFromAddress(regex).As<RegExp>();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Local<Value> StringObject::New(Isolate* isolate, Local<String> value) {
|
|
60
|
+
auto str = _v8_string_object_new(isolate, v8impl::AddressFromV8LocalValue(value));
|
|
61
|
+
return v8impl::V8LocalValueFromAddress(str);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Local<String> StringObject::ValueOf() const {
|
|
65
|
+
auto str = _v8_string_object_value_of(this);
|
|
66
|
+
return v8impl::V8LocalValueFromAddress(str).As<String>();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
int String::Utf8Length(v8::Isolate* isolate) const {
|
|
70
|
+
return _v8_string_utf8_length(this, isolate);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
int String::Length() const {
|
|
74
|
+
return _v8_string_length(this);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
int String::WriteUtf8(Isolate* isolate, char* buffer, int length,
|
|
78
|
+
int* nchars_ref, int options) const {
|
|
79
|
+
return _v8_string_write_utf8(
|
|
80
|
+
this, isolate, buffer, length, nchars_ref, options);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
String::Utf8Value::Utf8Value(Isolate* isolate, Local<v8::Value> obj) {
|
|
84
|
+
if (obj.IsEmpty() || !obj->IsString()) {
|
|
85
|
+
str_ = nullptr;
|
|
86
|
+
length_ = 0;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Local<String> str = obj.As<String>();
|
|
91
|
+
length_ = str->Utf8Length(isolate);
|
|
92
|
+
str_ = new char[length_ + 1];
|
|
93
|
+
str->WriteUtf8(isolate, str_, length_ + 1);
|
|
94
|
+
str_[length_] = '\0';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
String::Utf8Value::~Utf8Value() {
|
|
98
|
+
if (str_ == nullptr) return;
|
|
99
|
+
delete[] str_;
|
|
100
|
+
str_ = nullptr;
|
|
101
|
+
length_ = 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#include "v8_impl.h"
|
|
2
|
+
|
|
3
|
+
namespace v8 {
|
|
4
|
+
|
|
5
|
+
extern "C" {
|
|
6
|
+
V8_EXTERN Value* _v8_cbinfo_new_target(internal::Address info);
|
|
7
|
+
V8_EXTERN Value* _v8_cbinfo_holder(internal::Address info);
|
|
8
|
+
V8_EXTERN internal::Address _v8_function_template_new(
|
|
9
|
+
Isolate* isolate, internal::Address (*callback)(internal::Address info, v8::FunctionCallback cb),
|
|
10
|
+
v8::FunctionCallback cb,
|
|
11
|
+
internal::Address data, internal::Address signature,
|
|
12
|
+
int length, ConstructorBehavior behavior,
|
|
13
|
+
SideEffectType side_effect_type,
|
|
14
|
+
const CFunction* c_function, uint16_t instance_type,
|
|
15
|
+
uint16_t allowed_receiver_instance_type_range_start,
|
|
16
|
+
uint16_t allowed_receiver_instance_type_range_end);
|
|
17
|
+
V8_EXTERN internal::Address _v8_function_template_get_function(FunctionTemplate* tpl, Context* context);
|
|
18
|
+
V8_EXTERN void _v8_function_template_set_class_name(FunctionTemplate* tpl, internal::Address name);
|
|
19
|
+
V8_EXTERN int _v8_get_cb_info(internal::Address info, size_t* argc, internal::Address* argv, internal::Address* this_arg, void** data);
|
|
20
|
+
V8_EXTERN internal::Address _v8_object_template_new(Isolate* isolate, internal::Address constructor);
|
|
21
|
+
V8_EXTERN void _v8_object_template_set_internal_field_count(ObjectTemplate* obj_tpl, int value);
|
|
22
|
+
V8_EXTERN internal::Address _v8_object_template_new_instance(ObjectTemplate* obj_tpl, Context* context);
|
|
23
|
+
V8_EXTERN internal::Address _v8_signature_new(Isolate* isolate, internal::Address receiver);
|
|
24
|
+
V8_EXTERN void _v8_template_set(Template* tpl, internal::Address name, internal::Address value,
|
|
25
|
+
PropertyAttribute attributes);
|
|
26
|
+
V8_EXTERN internal::Address _v8_function_template_instance_template(FunctionTemplate* tpl);
|
|
27
|
+
V8_EXTERN internal::Address _v8_function_template_prototype_template(FunctionTemplate* tpl);
|
|
28
|
+
V8_EXTERN void _v8_get_property_cb_info(internal::Address info, internal::Address* args);
|
|
29
|
+
V8_EXTERN void _v8_object_template_set_accessor(
|
|
30
|
+
ObjectTemplate* obj_tpl, internal::Address name,
|
|
31
|
+
internal::Address (*getter_wrap)(internal::Address property, internal::Address info, AccessorNameGetterCallback getter),
|
|
32
|
+
internal::Address (*setter_wrap)(internal::Address property, internal::Address value, internal::Address info, AccessorNameSetterCallback setter),
|
|
33
|
+
AccessorNameGetterCallback getter, AccessorNameSetterCallback setter,
|
|
34
|
+
internal::Address data, PropertyAttribute attribute,
|
|
35
|
+
SideEffectType getter_side_effect_type,
|
|
36
|
+
SideEffectType setter_side_effect_type
|
|
37
|
+
);
|
|
38
|
+
V8_EXTERN internal::Address _v8_function_new(
|
|
39
|
+
Context* context,
|
|
40
|
+
internal::Address (*callback)(internal::Address info, v8::FunctionCallback cb),
|
|
41
|
+
v8::FunctionCallback cb,
|
|
42
|
+
internal::Address data,
|
|
43
|
+
int length,
|
|
44
|
+
int behavior,
|
|
45
|
+
int side_effect_type);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
namespace {
|
|
49
|
+
|
|
50
|
+
struct FunctionCallbackInfoImpl {
|
|
51
|
+
internal::Address* implicit_args_;
|
|
52
|
+
internal::Address* values_;
|
|
53
|
+
int length_;
|
|
54
|
+
|
|
55
|
+
FunctionCallbackInfoImpl(internal::Address info) {
|
|
56
|
+
size_t argc = 0;
|
|
57
|
+
_v8_get_cb_info(info, &argc, nullptr, nullptr, nullptr);
|
|
58
|
+
internal::Address* list = new internal::Address[7 + argc]{0};
|
|
59
|
+
implicit_args_ = list;
|
|
60
|
+
values_ = list + 7;
|
|
61
|
+
length_ = argc;
|
|
62
|
+
_v8_get_cb_info(info, &argc, values_, list, reinterpret_cast<void**>(list + 4));
|
|
63
|
+
// *(list) = reinterpret_cast<internal::Address>(_v8_cbinfo_this(info));
|
|
64
|
+
*(list + 1) = reinterpret_cast<internal::Address>(Isolate::GetCurrent());
|
|
65
|
+
*(list + 2) = 0;
|
|
66
|
+
// *(list + 3) = reinterpret_cast<internal::Address>(_v8_cbinfo_rv(info));
|
|
67
|
+
*(list + 3) = internal::ValueHelper::kEmpty;
|
|
68
|
+
// *(list + 4) = reinterpret_cast<internal::Address>(_v8_cbinfo_data(info));
|
|
69
|
+
*(list + 5) = reinterpret_cast<internal::Address>(_v8_cbinfo_new_target(info));
|
|
70
|
+
// *(list + 6) = argc;
|
|
71
|
+
*(list + 6) = *list;
|
|
72
|
+
*(list) = reinterpret_cast<internal::Address>(_v8_cbinfo_holder(info));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
FunctionCallbackInfoImpl(const FunctionCallbackInfoImpl&) = delete;
|
|
76
|
+
FunctionCallbackInfoImpl& operator=(const FunctionCallbackInfoImpl&) = delete;
|
|
77
|
+
FunctionCallbackInfoImpl(FunctionCallbackInfoImpl&&) = delete;
|
|
78
|
+
FunctionCallbackInfoImpl& operator=(FunctionCallbackInfoImpl&&) = delete;
|
|
79
|
+
|
|
80
|
+
~FunctionCallbackInfoImpl() {
|
|
81
|
+
delete[] implicit_args_;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
internal::Address CallbackWrap(internal::Address info, v8::FunctionCallback callback) {
|
|
86
|
+
const FunctionCallbackInfoImpl cbinfo{info};
|
|
87
|
+
const v8::FunctionCallbackInfo<Value>* args = reinterpret_cast<const v8::FunctionCallbackInfo<Value>*>(&cbinfo);
|
|
88
|
+
const v8::FunctionCallbackInfo<Value>& args_ref = *args;
|
|
89
|
+
callback(args_ref);
|
|
90
|
+
Local<Value> ret = args->GetReturnValue().Get();
|
|
91
|
+
return v8impl::AddressFromV8LocalValue(ret);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
struct PropertyCallbackInfoImpl {
|
|
95
|
+
internal::Address* args_;
|
|
96
|
+
|
|
97
|
+
PropertyCallbackInfoImpl(internal::Address info) {
|
|
98
|
+
internal::Address* list = new internal::Address[8]{0};
|
|
99
|
+
*(list + 2) = reinterpret_cast<internal::Address>(Isolate::GetCurrent());
|
|
100
|
+
*(list + 4) = internal::ValueHelper::kEmpty;
|
|
101
|
+
_v8_get_property_cb_info(info, list);
|
|
102
|
+
args_ = list;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
PropertyCallbackInfoImpl(const PropertyCallbackInfoImpl&) = delete;
|
|
106
|
+
PropertyCallbackInfoImpl& operator=(const PropertyCallbackInfoImpl&) = delete;
|
|
107
|
+
PropertyCallbackInfoImpl(PropertyCallbackInfoImpl&&) = delete;
|
|
108
|
+
PropertyCallbackInfoImpl& operator=(PropertyCallbackInfoImpl&&) = delete;
|
|
109
|
+
|
|
110
|
+
~PropertyCallbackInfoImpl() {
|
|
111
|
+
delete[] args_;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
internal::Address PropertyGetterWrap(internal::Address property, internal::Address info, AccessorNameGetterCallback getter) {
|
|
116
|
+
const PropertyCallbackInfoImpl cbinfo{info};
|
|
117
|
+
const v8::PropertyCallbackInfo<Value>* args = reinterpret_cast<const v8::PropertyCallbackInfo<Value>*>(&cbinfo);
|
|
118
|
+
const v8::PropertyCallbackInfo<Value>& args_ref = *args;
|
|
119
|
+
getter(v8impl::V8LocalValueFromAddress(property).As<Name>(), args_ref);
|
|
120
|
+
Local<Value> ret = args->GetReturnValue().Get();
|
|
121
|
+
return v8impl::AddressFromV8LocalValue(ret);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
internal::Address PropertySetterWrap(internal::Address property, internal::Address value, internal::Address info, AccessorNameSetterCallback setter) {
|
|
125
|
+
const PropertyCallbackInfoImpl cbinfo{info};
|
|
126
|
+
const v8::PropertyCallbackInfo<void>* args = reinterpret_cast<const v8::PropertyCallbackInfo<void>*>(&cbinfo);
|
|
127
|
+
const v8::PropertyCallbackInfo<void>& args_ref = *args;
|
|
128
|
+
setter(v8impl::V8LocalValueFromAddress(property).As<Name>(), v8impl::V8LocalValueFromAddress(value), args_ref);
|
|
129
|
+
Local<Value> ret = args->GetReturnValue().Get();
|
|
130
|
+
return v8impl::AddressFromV8LocalValue(ret);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
void FunctionTemplate::CheckCast(v8::Data*) {}
|
|
136
|
+
void ObjectTemplate::CheckCast(v8::Data*) {}
|
|
137
|
+
|
|
138
|
+
Local<FunctionTemplate> FunctionTemplate::New(
|
|
139
|
+
Isolate* isolate, v8::FunctionCallback callback,
|
|
140
|
+
Local<Value> data,
|
|
141
|
+
Local<Signature> signature, int length,
|
|
142
|
+
ConstructorBehavior behavior,
|
|
143
|
+
SideEffectType side_effect_type,
|
|
144
|
+
const CFunction* c_function, uint16_t instance_type,
|
|
145
|
+
uint16_t allowed_receiver_instance_type_range_start,
|
|
146
|
+
uint16_t allowed_receiver_instance_type_range_end) {
|
|
147
|
+
internal::Address tpl_value = _v8_function_template_new(isolate,
|
|
148
|
+
CallbackWrap, callback, reinterpret_cast<internal::Address>(*data),
|
|
149
|
+
reinterpret_cast<internal::Address>(*signature), length,
|
|
150
|
+
behavior, side_effect_type, c_function, instance_type,
|
|
151
|
+
allowed_receiver_instance_type_range_start,
|
|
152
|
+
allowed_receiver_instance_type_range_end);
|
|
153
|
+
return v8impl::V8LocalValueFromAddress(tpl_value).As<FunctionTemplate>();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
MaybeLocal<Function> FunctionTemplate::GetFunction(v8::Local<v8::Context> context) {
|
|
157
|
+
auto func = _v8_function_template_get_function(this, *context);
|
|
158
|
+
if (!func) return MaybeLocal<Function>();
|
|
159
|
+
return v8impl::V8LocalValueFromAddress(func).As<Function>();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
void FunctionTemplate::SetClassName(v8::Local<v8::String> name) {
|
|
163
|
+
_v8_function_template_set_class_name(this, v8impl::AddressFromV8LocalValue(name));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() {
|
|
167
|
+
internal::Address v = _v8_function_template_instance_template(this);
|
|
168
|
+
v8::Local<v8::ObjectTemplate> local;
|
|
169
|
+
memcpy(static_cast<void*>(&local), &v, sizeof(v));
|
|
170
|
+
return local;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
|
|
174
|
+
internal::Address v = _v8_function_template_prototype_template(this);
|
|
175
|
+
v8::Local<v8::ObjectTemplate> local;
|
|
176
|
+
memcpy(static_cast<void*>(&local), &v, sizeof(v));
|
|
177
|
+
return local;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
void Template::Set(Local<Name> name, Local<Data> value,
|
|
181
|
+
PropertyAttribute attributes) {
|
|
182
|
+
internal::Address name_value = v8impl::AddressFromV8LocalValue(name);
|
|
183
|
+
internal::Address value_value = reinterpret_cast<internal::Address>(*value);
|
|
184
|
+
_v8_template_set(this, name_value, value_value, attributes);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
void ObjectTemplate::SetAccessor(
|
|
188
|
+
Local<Name> name, AccessorNameGetterCallback getter,
|
|
189
|
+
AccessorNameSetterCallback setter,
|
|
190
|
+
Local<Value> data, PropertyAttribute attribute,
|
|
191
|
+
SideEffectType getter_side_effect_type,
|
|
192
|
+
SideEffectType setter_side_effect_type) {
|
|
193
|
+
_v8_object_template_set_accessor(
|
|
194
|
+
this, v8impl::AddressFromV8LocalValue(name),
|
|
195
|
+
PropertyGetterWrap, PropertySetterWrap,
|
|
196
|
+
getter, setter,
|
|
197
|
+
v8impl::AddressFromV8LocalValue(data), attribute,
|
|
198
|
+
getter_side_effect_type, setter_side_effect_type);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
Local<Signature> Signature::New(Isolate* isolate, Local<FunctionTemplate> receiver) {
|
|
202
|
+
internal::Address signature = _v8_signature_new(isolate, reinterpret_cast<internal::Address>(*receiver));
|
|
203
|
+
return v8impl::V8LocalValueFromAddress(signature).As<Signature>();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
Local<ObjectTemplate> ObjectTemplate::New(Isolate* isolate, Local<FunctionTemplate> constructor) {
|
|
207
|
+
internal::Address obj_tpl_value = _v8_object_template_new(isolate, reinterpret_cast<internal::Address>(*constructor));
|
|
208
|
+
if (!obj_tpl_value) return Local<ObjectTemplate>();
|
|
209
|
+
return v8impl::V8LocalValueFromAddress(obj_tpl_value).As<ObjectTemplate>();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
MaybeLocal<Object> ObjectTemplate::NewInstance(v8::Local<v8::Context> context) {
|
|
213
|
+
internal::Address obj_value = _v8_object_template_new_instance(this, *context);
|
|
214
|
+
if (!obj_value) return MaybeLocal<Object>();
|
|
215
|
+
return v8impl::V8LocalValueFromAddress(obj_value).As<Object>();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
void ObjectTemplate::SetInternalFieldCount(int value) {
|
|
219
|
+
_v8_object_template_set_internal_field_count(this, value);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
MaybeLocal<Function> Function::New(
|
|
223
|
+
Local<Context> context, FunctionCallback callback,
|
|
224
|
+
Local<Value> data, int length,
|
|
225
|
+
ConstructorBehavior behavior,
|
|
226
|
+
SideEffectType side_effect_type) {
|
|
227
|
+
internal::Address func_value = _v8_function_new(
|
|
228
|
+
*context, CallbackWrap, callback, reinterpret_cast<internal::Address>(*data),
|
|
229
|
+
length, static_cast<int>(behavior), static_cast<int>(side_effect_type));
|
|
230
|
+
if (!func_value) return MaybeLocal<Function>();
|
|
231
|
+
return v8impl::V8LocalValueFromAddress(func_value).As<Function>();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#include "v8_impl.h"
|
|
2
|
+
|
|
3
|
+
namespace v8 {
|
|
4
|
+
|
|
5
|
+
namespace {
|
|
6
|
+
|
|
7
|
+
TryCatch* current = nullptr;
|
|
8
|
+
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
extern "C" {
|
|
12
|
+
V8_EXTERN void _v8_trycatch_construct(TryCatch*);
|
|
13
|
+
V8_EXTERN void _v8_trycatch_destruct(TryCatch*);
|
|
14
|
+
V8_EXTERN bool _v8_trycatch_has_caught(const TryCatch*);
|
|
15
|
+
V8_EXTERN internal::Address _v8_trycatch_rethrow(TryCatch*);
|
|
16
|
+
V8_EXTERN internal::Address _v8_trycatch_exception(const TryCatch*);
|
|
17
|
+
V8_EXTERN void _v8_trycatch_reset(TryCatch*);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
TryCatch::TryCatch(Isolate* isolate) {
|
|
21
|
+
this->next_ = current;
|
|
22
|
+
current = this;
|
|
23
|
+
this->i_isolate_ = reinterpret_cast<internal::Isolate*>(isolate);
|
|
24
|
+
_v8_trycatch_construct(this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
TryCatch::~TryCatch() {
|
|
28
|
+
if (current) {
|
|
29
|
+
current = current->next_;
|
|
30
|
+
}
|
|
31
|
+
_v8_trycatch_destruct(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
bool TryCatch::HasCaught() const {
|
|
35
|
+
return _v8_trycatch_has_caught(this);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Local<Value> TryCatch::ReThrow() {
|
|
39
|
+
return v8impl::V8LocalValueFromAddress(_v8_trycatch_rethrow(this));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Local<Value> TryCatch::Exception() const {
|
|
43
|
+
return v8impl::V8LocalValueFromAddress(_v8_trycatch_exception(this));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void TryCatch::Reset() {
|
|
47
|
+
_v8_trycatch_reset(this);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
package/src/v8/v8_impl.h
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#ifndef EMNAPI_V8_IMPL_H_
|
|
2
|
+
#define EMNAPI_V8_IMPL_H_
|
|
3
|
+
|
|
4
|
+
#include "v8.h"
|
|
5
|
+
|
|
6
|
+
#if !defined(V8_EXTERN)
|
|
7
|
+
#define V8_EXTERN __attribute__((__import_module__("env")))
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
namespace v8 {
|
|
11
|
+
|
|
12
|
+
namespace v8impl {
|
|
13
|
+
|
|
14
|
+
enum class Constant : v8::internal::Address {
|
|
15
|
+
kHole,
|
|
16
|
+
kEmpty,
|
|
17
|
+
kUndefined,
|
|
18
|
+
kNull,
|
|
19
|
+
kFalse,
|
|
20
|
+
kTrue,
|
|
21
|
+
kGlobal,
|
|
22
|
+
kEmptyString,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
static_assert(sizeof(v8::Local<v8::Value>) == sizeof(internal::Address),
|
|
26
|
+
"Cannot convert between v8::Local<v8::Value> and internal::Address");
|
|
27
|
+
|
|
28
|
+
inline internal::Address AddressFromV8LocalValue(v8::Local<v8::Value> local) {
|
|
29
|
+
return reinterpret_cast<internal::Address>(*local);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
inline v8::Local<v8::Value> V8LocalValueFromAddress(internal::Address v) {
|
|
33
|
+
v8::Local<v8::Value> local;
|
|
34
|
+
memcpy(static_cast<void*>(&local), &v, sizeof(v));
|
|
35
|
+
return local;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#endif
|
package/src/v8/value.cc
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#include "v8_impl.h"
|
|
2
|
+
|
|
3
|
+
namespace v8 {
|
|
4
|
+
|
|
5
|
+
extern "C" {
|
|
6
|
+
V8_EXTERN bool _v8_value_strict_equals(const Value*, Value*);
|
|
7
|
+
V8_EXTERN internal::Address _v8_value_to_boolean(const Value*, Isolate*);
|
|
8
|
+
V8_EXTERN internal::Address _v8_value_to_number(const Value*, Context*);
|
|
9
|
+
V8_EXTERN internal::Address _v8_value_to_string(const Value*, Context*);
|
|
10
|
+
V8_EXTERN internal::Address _v8_value_to_object(const Value*, Context*);
|
|
11
|
+
V8_EXTERN internal::Address _v8_value_to_integer(const Value*, Context*);
|
|
12
|
+
V8_EXTERN internal::Address _v8_value_to_uint32(const Value*, Context*);
|
|
13
|
+
V8_EXTERN internal::Address _v8_value_to_int32(const Value*, Context*);
|
|
14
|
+
V8_EXTERN internal::Address _v8_value_to_array_index(const Value*, Context*);
|
|
15
|
+
V8_EXTERN bool _v8_value_is_function(const Value*);
|
|
16
|
+
V8_EXTERN bool _v8_value_is_undefined(const Value*);
|
|
17
|
+
V8_EXTERN bool _v8_value_is_null(const Value*);
|
|
18
|
+
V8_EXTERN bool _v8_value_is_true(const Value*);
|
|
19
|
+
V8_EXTERN bool _v8_value_is_false(const Value*);
|
|
20
|
+
V8_EXTERN bool _v8_value_is_string(const Value*);
|
|
21
|
+
V8_EXTERN bool _v8_value_is_number(const Value*);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void Value::CheckCast(Data*) {}
|
|
25
|
+
|
|
26
|
+
bool Value::StrictEquals(Local<Value> that) const {
|
|
27
|
+
return _v8_value_strict_equals(this, *that);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Local<Boolean> Value::ToBoolean(Isolate* isolate) const {
|
|
31
|
+
return v8impl::V8LocalValueFromAddress(_v8_value_to_boolean(this, isolate)).As<Boolean>();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
MaybeLocal<Number> Value::ToNumber(Local<Context> context) const {
|
|
35
|
+
internal::Address value = _v8_value_to_number(this, *context);
|
|
36
|
+
if (!value) return MaybeLocal<Number>();
|
|
37
|
+
return v8impl::V8LocalValueFromAddress(value).As<Number>();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
MaybeLocal<String> Value::ToString(Local<Context> context) const {
|
|
41
|
+
internal::Address value = _v8_value_to_string(this, *context);
|
|
42
|
+
if (!value) return MaybeLocal<String>();
|
|
43
|
+
return v8impl::V8LocalValueFromAddress(value).As<String>();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
MaybeLocal<String> Value::ToDetailString(Local<Context> context) const {
|
|
47
|
+
return ToString(context);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
bool Value::FullIsUndefined() const {
|
|
51
|
+
return _v8_value_is_undefined(this);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
bool Value::FullIsNull() const {
|
|
55
|
+
return _v8_value_is_null(this);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
bool Value::FullIsTrue() const {
|
|
59
|
+
return _v8_value_is_true(this);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
bool Value::FullIsFalse() const {
|
|
63
|
+
return _v8_value_is_false(this);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
bool Value::FullIsString() const {
|
|
67
|
+
return _v8_value_is_string(this);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
bool Value::IsFunction() const {
|
|
71
|
+
return _v8_value_is_function(this);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
bool Value::IsNumber() const {
|
|
75
|
+
return _v8_value_is_number(this);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
MaybeLocal<Object> Value::ToObject(Local<Context> context) const {
|
|
79
|
+
internal::Address value = _v8_value_to_object(this, *context);
|
|
80
|
+
if (!value) return MaybeLocal<Object>();
|
|
81
|
+
return v8impl::V8LocalValueFromAddress(value).As<Object>();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
MaybeLocal<Integer> Value::ToInteger(Local<Context> context) const {
|
|
85
|
+
internal::Address value = _v8_value_to_integer(this, *context);
|
|
86
|
+
if (!value) return MaybeLocal<Integer>();
|
|
87
|
+
return v8impl::V8LocalValueFromAddress(value).As<Integer>();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
MaybeLocal<Uint32> Value::ToUint32(Local<Context> context) const {
|
|
91
|
+
internal::Address value = _v8_value_to_uint32(this, *context);
|
|
92
|
+
if (!value) return MaybeLocal<Uint32>();
|
|
93
|
+
return v8impl::V8LocalValueFromAddress(value).As<Uint32>();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
MaybeLocal<Int32> Value::ToInt32(Local<Context> context) const {
|
|
97
|
+
internal::Address value = _v8_value_to_int32(this, *context);
|
|
98
|
+
if (!value) return MaybeLocal<Int32>();
|
|
99
|
+
return v8impl::V8LocalValueFromAddress(value).As<Int32>();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
|
|
103
|
+
internal::Address value = _v8_value_to_array_index(this, *context);
|
|
104
|
+
if (!value) return MaybeLocal<Uint32>();
|
|
105
|
+
return v8impl::V8LocalValueFromAddress(value).As<Uint32>();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
bool Value::BooleanValue(Isolate* isolate) const {
|
|
109
|
+
return ToBoolean(isolate)->Value();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Maybe<double> Value::NumberValue(Local<Context> context) const {
|
|
113
|
+
auto maybe = ToNumber(context);
|
|
114
|
+
if (maybe.IsEmpty()) return Nothing<double>();
|
|
115
|
+
return Just<double>(maybe.ToLocalChecked()->Value());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
|
|
119
|
+
auto maybe = ToInteger(context);
|
|
120
|
+
if (maybe.IsEmpty()) return Nothing<int64_t>();
|
|
121
|
+
return Just<int64_t>(maybe.ToLocalChecked()->Value());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
|
|
125
|
+
auto maybe = ToUint32(context);
|
|
126
|
+
if (maybe.IsEmpty()) return Nothing<uint32_t>();
|
|
127
|
+
return Just<uint32_t>(maybe.ToLocalChecked()->Value());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
|
|
131
|
+
auto maybe = ToInt32(context);
|
|
132
|
+
if (maybe.IsEmpty()) return Nothing<int32_t>();
|
|
133
|
+
return Just<int32_t>(maybe.ToLocalChecked()->Value());
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
}
|
|
Binary file
|
package/lib/wasm32/libdlmalloc.a
DELETED
|
Binary file
|
|
Binary file
|
package/lib/wasm32/libemmalloc.a
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/wasm32/libemnapi.a
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|