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/emnapi.gyp
CHANGED
|
@@ -144,6 +144,43 @@
|
|
|
144
144
|
}],
|
|
145
145
|
]
|
|
146
146
|
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
'target_name': 'v8',
|
|
150
|
+
'type': 'static_library',
|
|
151
|
+
'sources': [
|
|
152
|
+
'array.cc',
|
|
153
|
+
'external.cc',
|
|
154
|
+
'exception.cc',
|
|
155
|
+
'date.cc',
|
|
156
|
+
'function.cc',
|
|
157
|
+
'handle_scope.cc',
|
|
158
|
+
'internal.cc',
|
|
159
|
+
'isolate.cc',
|
|
160
|
+
'json.cc',
|
|
161
|
+
'object.cc',
|
|
162
|
+
'string.cc',
|
|
163
|
+
'value.cc',
|
|
164
|
+
'boolean.cc',
|
|
165
|
+
'number.cc',
|
|
166
|
+
'template.cc',
|
|
167
|
+
'try_catch.cc',
|
|
168
|
+
'node.cc',
|
|
169
|
+
'script.cc'
|
|
170
|
+
],
|
|
171
|
+
'defines': [
|
|
172
|
+
'V8_ENABLE_DIRECT_LOCAL'
|
|
173
|
+
],
|
|
174
|
+
'link_settings': {
|
|
175
|
+
'target_conditions': [
|
|
176
|
+
['_type == "executable" and OS == "emscripten"', {
|
|
177
|
+
'libraries': [
|
|
178
|
+
'--js-library=<(emnapi_js_library)',
|
|
179
|
+
'--js-library=<(v8_js_library)',
|
|
180
|
+
]
|
|
181
|
+
}],
|
|
182
|
+
]
|
|
183
|
+
},
|
|
147
184
|
}
|
|
148
185
|
]
|
|
149
186
|
}
|
package/include/node/emnapi.h
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
#include "js_native_api_types.h"
|
|
6
6
|
#include "emnapi_common.h"
|
|
7
7
|
|
|
8
|
-
#define EMNAPI_MAJOR_VERSION
|
|
9
|
-
#define EMNAPI_MINOR_VERSION
|
|
10
|
-
#define EMNAPI_PATCH_VERSION
|
|
8
|
+
#define EMNAPI_MAJOR_VERSION 2
|
|
9
|
+
#define EMNAPI_MINOR_VERSION 0
|
|
10
|
+
#define EMNAPI_PATCH_VERSION 0
|
|
11
11
|
|
|
12
12
|
typedef enum {
|
|
13
13
|
emnapi_runtime,
|
|
@@ -82,6 +82,42 @@ napi_status emnapi_get_memory_address(napi_env env,
|
|
|
82
82
|
emnapi_ownership* ownership,
|
|
83
83
|
bool* runtime_allocated);
|
|
84
84
|
|
|
85
|
+
EMNAPI_EXTERN void emnapi_debug(
|
|
86
|
+
const char* file,
|
|
87
|
+
int lineno,
|
|
88
|
+
const char* str,
|
|
89
|
+
void* value,
|
|
90
|
+
int type
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get the handle for an external SharedArrayBuffer.
|
|
95
|
+
* This function must be called on the emnapi main thread.
|
|
96
|
+
*/
|
|
97
|
+
EMNAPI_EXTERN
|
|
98
|
+
napi_status emnapi_get_external_sharedarraybuffer_handle(
|
|
99
|
+
napi_env env,
|
|
100
|
+
napi_value sharedarraybuffer,
|
|
101
|
+
void** handle);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Acquire a reference to an external SharedArrayBuffer handle.
|
|
105
|
+
* This function may be called from any thread.
|
|
106
|
+
*/
|
|
107
|
+
EMNAPI_EXTERN
|
|
108
|
+
void emnapi_acquire_external_sharedarraybuffer(void* handle);
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Release a reference to an external SharedArrayBuffer handle.
|
|
112
|
+
* When the refcount reaches zero, finalize_cb is invoked.
|
|
113
|
+
* This function may be called from any thread.
|
|
114
|
+
*/
|
|
115
|
+
EMNAPI_EXTERN
|
|
116
|
+
void emnapi_release_external_sharedarraybuffer(void* handle);
|
|
117
|
+
|
|
118
|
+
#define DEBUGGER_LOG(str, value, type) \
|
|
119
|
+
emnapi_debug(__FILE__, __LINE__, str, value, type)
|
|
120
|
+
|
|
85
121
|
EXTERN_C_END
|
|
86
122
|
|
|
87
123
|
#endif
|
|
@@ -443,6 +443,16 @@ napi_create_external_arraybuffer(napi_env env,
|
|
|
443
443
|
node_api_basic_finalize finalize_cb,
|
|
444
444
|
void* finalize_hint,
|
|
445
445
|
napi_value* result);
|
|
446
|
+
#ifdef NAPI_EXPERIMENTAL
|
|
447
|
+
#define NODE_API_EXPERIMENTAL_HAS_CREATE_EXTERNAL_SHAREDARRAYBUFFER
|
|
448
|
+
NAPI_EXTERN napi_status NAPI_CDECL
|
|
449
|
+
node_api_create_external_sharedarraybuffer(napi_env env,
|
|
450
|
+
void* external_data,
|
|
451
|
+
size_t byte_length,
|
|
452
|
+
node_api_noenv_finalize finalize_cb,
|
|
453
|
+
void* finalize_hint,
|
|
454
|
+
napi_value* result);
|
|
455
|
+
#endif // NAPI_EXPERIMENTAL
|
|
446
456
|
#endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
|
|
447
457
|
NAPI_EXTERN napi_status NAPI_CDECL napi_get_arraybuffer_info(
|
|
448
458
|
napi_env env, napi_value arraybuffer, void** data, size_t* byte_length);
|
|
@@ -188,6 +188,10 @@ typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env,
|
|
|
188
188
|
#endif
|
|
189
189
|
typedef node_api_nogc_finalize node_api_basic_finalize;
|
|
190
190
|
|
|
191
|
+
// A finalizer that can be called from any thread and at any time.
|
|
192
|
+
typedef void(NAPI_CDECL* node_api_noenv_finalize)(void* finalize_data,
|
|
193
|
+
void* finalize_hint);
|
|
194
|
+
|
|
191
195
|
typedef struct {
|
|
192
196
|
// One of utf8name or name should be NULL.
|
|
193
197
|
const char* utf8name;
|
|
@@ -237,4 +241,26 @@ typedef struct {
|
|
|
237
241
|
} napi_type_tag;
|
|
238
242
|
#endif // NAPI_VERSION >= 8
|
|
239
243
|
|
|
244
|
+
#ifndef EMNAPI_UNMODIFIED_UPSTREAM
|
|
245
|
+
// Sentinel format: "NODE_VT" (7 bytes) + marker byte.
|
|
246
|
+
// Marker byte = (version << 1) | 1
|
|
247
|
+
// - Bit 0 is always 1: ensures the sentinel can never match a C++ vtable
|
|
248
|
+
// pointer (which is always pointer-aligned, thus bit 0 = 0).
|
|
249
|
+
// - Bits 1-7: struct version number (0-127).
|
|
250
|
+
#define NODE_API_VT_SENTINEL_VERSION 0
|
|
251
|
+
#define NODE_API_VT_SENTINEL_MAKE(version) \
|
|
252
|
+
(0x4E4F44455F565400ULL | (((version) << 1) | 1))
|
|
253
|
+
#define NODE_API_VT_SENTINEL \
|
|
254
|
+
NODE_API_VT_SENTINEL_MAKE(NODE_API_VT_SENTINEL_VERSION)
|
|
255
|
+
|
|
256
|
+
#define EMNAPI_NAPI_ENV_FIELDS \
|
|
257
|
+
uint64_t sentinel; \
|
|
258
|
+
const struct node_api_js_vtable* js_vtable; \
|
|
259
|
+
const struct node_api_module_vtable* module_vtable;
|
|
260
|
+
|
|
261
|
+
struct napi_env__ {
|
|
262
|
+
EMNAPI_NAPI_ENV_FIELDS
|
|
263
|
+
};
|
|
264
|
+
#endif
|
|
265
|
+
|
|
240
266
|
#endif // SRC_JS_NATIVE_API_TYPES_H_
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
#ifndef SRC_NODE_H_
|
|
2
|
+
#define SRC_NODE_H_
|
|
3
|
+
|
|
4
|
+
#if !defined(NODE_EXTERN)
|
|
5
|
+
#define NODE_EXTERN __attribute__((__import_module__("env")))
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
#include "v8.h"
|
|
9
|
+
#include "v8-platform.h"
|
|
10
|
+
#include "node_version.h"
|
|
11
|
+
#include "node_api_types.h"
|
|
12
|
+
|
|
13
|
+
// Forward-declare libuv loop
|
|
14
|
+
struct uv_loop_s;
|
|
15
|
+
struct napi_module;
|
|
16
|
+
|
|
17
|
+
namespace node {
|
|
18
|
+
|
|
19
|
+
inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
|
|
20
|
+
const char* name,
|
|
21
|
+
v8::FunctionCallback callback) {
|
|
22
|
+
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
23
|
+
v8::HandleScope handle_scope(isolate);
|
|
24
|
+
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
25
|
+
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
|
|
26
|
+
callback);
|
|
27
|
+
v8::Local<v8::Function> fn = t->GetFunction(context).ToLocalChecked();
|
|
28
|
+
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name,
|
|
29
|
+
v8::NewStringType::kInternalized).ToLocalChecked();
|
|
30
|
+
fn->SetName(fn_name);
|
|
31
|
+
recv->Set(context, fn_name, fn).Check();
|
|
32
|
+
}
|
|
33
|
+
#define NODE_SET_METHOD node::NODE_SET_METHOD
|
|
34
|
+
|
|
35
|
+
#ifdef _WIN32
|
|
36
|
+
# define NODE_MODULE_EXPORT __declspec(dllexport)
|
|
37
|
+
#else
|
|
38
|
+
#ifdef __EMSCRIPTEN__
|
|
39
|
+
#define NODE_MODULE_EXPORT \
|
|
40
|
+
__attribute__((visibility("default"))) __attribute__((used))
|
|
41
|
+
#else
|
|
42
|
+
# define NODE_MODULE_EXPORT __attribute__((visibility("default")))
|
|
43
|
+
#endif
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
#define NODE_DEPRECATED(message, declarator) declarator
|
|
47
|
+
|
|
48
|
+
typedef void (*addon_register_func)(
|
|
49
|
+
v8::Local<v8::Object> exports,
|
|
50
|
+
v8::Local<v8::Value> module,
|
|
51
|
+
void* priv);
|
|
52
|
+
|
|
53
|
+
// BINARY is a deprecated alias of LATIN1.
|
|
54
|
+
// BASE64URL is not currently exposed to the JavaScript side.
|
|
55
|
+
enum encoding {
|
|
56
|
+
ASCII,
|
|
57
|
+
UTF8,
|
|
58
|
+
BASE64,
|
|
59
|
+
UCS2,
|
|
60
|
+
BINARY,
|
|
61
|
+
HEX,
|
|
62
|
+
BUFFER,
|
|
63
|
+
BASE64URL,
|
|
64
|
+
LATIN1 = BINARY
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
NODE_EXTERN v8::Local<v8::Value> ErrnoException(v8::Isolate* isolate,
|
|
68
|
+
int errorno,
|
|
69
|
+
const char* syscall = nullptr,
|
|
70
|
+
const char* message = nullptr,
|
|
71
|
+
const char* path = nullptr);
|
|
72
|
+
NODE_EXTERN v8::Local<v8::Value> UVException(v8::Isolate* isolate,
|
|
73
|
+
int errorno,
|
|
74
|
+
const char* syscall = nullptr,
|
|
75
|
+
const char* message = nullptr,
|
|
76
|
+
const char* path = nullptr,
|
|
77
|
+
const char* dest = nullptr);
|
|
78
|
+
|
|
79
|
+
NODE_DEPRECATED("Use ErrnoException(isolate, ...)",
|
|
80
|
+
inline v8::Local<v8::Value> ErrnoException(
|
|
81
|
+
int errorno,
|
|
82
|
+
const char* syscall = nullptr,
|
|
83
|
+
const char* message = nullptr,
|
|
84
|
+
const char* path = nullptr) {
|
|
85
|
+
return ErrnoException(v8::Isolate::GetCurrent(),
|
|
86
|
+
errorno,
|
|
87
|
+
syscall,
|
|
88
|
+
message,
|
|
89
|
+
path);
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
NODE_DEPRECATED("Use UVException(isolate, ...)",
|
|
93
|
+
inline v8::Local<v8::Value> UVException(int errorno,
|
|
94
|
+
const char* syscall = nullptr,
|
|
95
|
+
const char* message = nullptr,
|
|
96
|
+
const char* path = nullptr) {
|
|
97
|
+
return UVException(v8::Isolate::GetCurrent(),
|
|
98
|
+
errorno,
|
|
99
|
+
syscall,
|
|
100
|
+
message,
|
|
101
|
+
path);
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
NODE_EXTERN struct uv_loop_s* GetCurrentEventLoop(v8::Isolate* isolate);
|
|
105
|
+
|
|
106
|
+
typedef double async_id;
|
|
107
|
+
struct async_context {
|
|
108
|
+
::node::async_id async_id;
|
|
109
|
+
::node::async_id trigger_async_id;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate,
|
|
113
|
+
v8::Local<v8::Object> resource,
|
|
114
|
+
const char* name,
|
|
115
|
+
async_id trigger_async_id = -1);
|
|
116
|
+
|
|
117
|
+
NODE_EXTERN async_context EmitAsyncInit(v8::Isolate* isolate,
|
|
118
|
+
v8::Local<v8::Object> resource,
|
|
119
|
+
v8::Local<v8::String> name,
|
|
120
|
+
async_id trigger_async_id = -1);
|
|
121
|
+
|
|
122
|
+
NODE_EXTERN void EmitAsyncDestroy(v8::Isolate* isolate,
|
|
123
|
+
async_context asyncContext);
|
|
124
|
+
|
|
125
|
+
NODE_EXTERN void FatalException(v8::Isolate* isolate,
|
|
126
|
+
const v8::TryCatch& try_catch);
|
|
127
|
+
|
|
128
|
+
NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate,
|
|
129
|
+
const char* buf,
|
|
130
|
+
size_t len,
|
|
131
|
+
enum encoding encoding = LATIN1);
|
|
132
|
+
|
|
133
|
+
// Warning: This reverses endianness on Big Endian platforms, even though the
|
|
134
|
+
// signature using uint16_t implies that it should not.
|
|
135
|
+
NODE_EXTERN v8::Local<v8::Value> Encode(v8::Isolate* isolate,
|
|
136
|
+
const uint16_t* buf,
|
|
137
|
+
size_t len);
|
|
138
|
+
|
|
139
|
+
// Returns -1 if the handle was not valid for decoding
|
|
140
|
+
NODE_EXTERN ssize_t DecodeBytes(v8::Isolate* isolate,
|
|
141
|
+
v8::Local<v8::Value>,
|
|
142
|
+
enum encoding encoding = LATIN1);
|
|
143
|
+
// returns bytes written.
|
|
144
|
+
NODE_EXTERN ssize_t DecodeWrite(v8::Isolate* isolate,
|
|
145
|
+
char* buf,
|
|
146
|
+
size_t buflen,
|
|
147
|
+
v8::Local<v8::Value>,
|
|
148
|
+
enum encoding encoding = LATIN1);
|
|
149
|
+
|
|
150
|
+
#define NODE_MODULE(modname, regfunc) \
|
|
151
|
+
NODE_MODULE_INIT() { ((node::addon_register_func)regfunc)(exports, module, NULL); }
|
|
152
|
+
|
|
153
|
+
#define NODE_MODULE_VERSION 127
|
|
154
|
+
|
|
155
|
+
#define NODE_MODULE_INITIALIZER_BASE node_register_module_v
|
|
156
|
+
|
|
157
|
+
#define NODE_MODULE_INITIALIZER_X(base, version) \
|
|
158
|
+
NODE_MODULE_INITIALIZER_X_HELPER(base, version)
|
|
159
|
+
|
|
160
|
+
#define NODE_MODULE_INITIALIZER_X_HELPER(base, version) base##version
|
|
161
|
+
|
|
162
|
+
#define NODE_MODULE_INITIALIZER \
|
|
163
|
+
NODE_MODULE_INITIALIZER_X(NODE_MODULE_INITIALIZER_BASE, \
|
|
164
|
+
NODE_MODULE_VERSION)
|
|
165
|
+
|
|
166
|
+
#define NODE_MODULE_INIT() \
|
|
167
|
+
extern "C" NODE_MODULE_EXPORT void \
|
|
168
|
+
NODE_MODULE_INITIALIZER(v8::Local<v8::Object> exports, \
|
|
169
|
+
v8::Local<v8::Value> module, \
|
|
170
|
+
v8::Local<v8::Context> context); \
|
|
171
|
+
void NODE_MODULE_INITIALIZER(v8::Local<v8::Object> exports, \
|
|
172
|
+
v8::Local<v8::Value> module, \
|
|
173
|
+
v8::Local<v8::Context> context)
|
|
174
|
+
|
|
175
|
+
NODE_EXTERN
|
|
176
|
+
v8::MaybeLocal<v8::Value> MakeCallback(v8::Isolate* isolate,
|
|
177
|
+
v8::Local<v8::Object> recv,
|
|
178
|
+
v8::Local<v8::Function> callback,
|
|
179
|
+
int argc,
|
|
180
|
+
v8::Local<v8::Value>* argv,
|
|
181
|
+
async_context asyncContext);
|
|
182
|
+
NODE_EXTERN
|
|
183
|
+
v8::MaybeLocal<v8::Value> MakeCallback(v8::Isolate* isolate,
|
|
184
|
+
v8::Local<v8::Object> recv,
|
|
185
|
+
const char* method,
|
|
186
|
+
int argc,
|
|
187
|
+
v8::Local<v8::Value>* argv,
|
|
188
|
+
async_context asyncContext);
|
|
189
|
+
NODE_EXTERN
|
|
190
|
+
v8::MaybeLocal<v8::Value> MakeCallback(v8::Isolate* isolate,
|
|
191
|
+
v8::Local<v8::Object> recv,
|
|
192
|
+
v8::Local<v8::String> symbol,
|
|
193
|
+
int argc,
|
|
194
|
+
v8::Local<v8::Value>* argv,
|
|
195
|
+
async_context asyncContext);
|
|
196
|
+
} // namespace node
|
|
197
|
+
|
|
198
|
+
#endif
|
package/include/node/node_api.h
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
#ifndef SRC_NODE_API_H_
|
|
2
2
|
#define SRC_NODE_API_H_
|
|
3
3
|
|
|
4
|
-
#ifndef EMNAPI_UNMODIFIED_UPSTREAM
|
|
5
|
-
#ifndef BUILDING_NODE_EXTENSION
|
|
6
|
-
#define BUILDING_NODE_EXTENSION
|
|
7
|
-
#endif
|
|
8
|
-
|
|
9
|
-
#if !defined(NAPI_EXTERN) && defined(__EMSCRIPTEN__)
|
|
10
|
-
#define NAPI_EXTERN __attribute__((__import_module__("env")))
|
|
11
|
-
#endif
|
|
12
|
-
#endif
|
|
13
|
-
|
|
14
4
|
#if defined(BUILDING_NODE_EXTENSION) && !defined(NAPI_EXTERN)
|
|
15
5
|
#ifdef _WIN32
|
|
16
6
|
// Building native addon against node
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
// copy of this software and associated documentation files (the
|
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
// following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
|
12
|
+
// in all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
#ifndef SRC_NODE_BUFFER_H_
|
|
23
|
+
#define SRC_NODE_BUFFER_H_
|
|
24
|
+
|
|
25
|
+
#include "node.h"
|
|
26
|
+
#include "v8.h"
|
|
27
|
+
|
|
28
|
+
namespace node {
|
|
29
|
+
|
|
30
|
+
namespace Buffer {
|
|
31
|
+
|
|
32
|
+
static const size_t kMaxLength = v8::Uint8Array::kMaxLength;
|
|
33
|
+
|
|
34
|
+
typedef void (*FreeCallback)(char* data, void* hint);
|
|
35
|
+
|
|
36
|
+
NODE_EXTERN bool HasInstance(v8::Local<v8::Value> val);
|
|
37
|
+
NODE_EXTERN bool HasInstance(v8::Local<v8::Object> val);
|
|
38
|
+
NODE_EXTERN char* Data(v8::Local<v8::Value> val);
|
|
39
|
+
NODE_EXTERN char* Data(v8::Local<v8::Object> val);
|
|
40
|
+
NODE_EXTERN size_t Length(v8::Local<v8::Value> val);
|
|
41
|
+
NODE_EXTERN size_t Length(v8::Local<v8::Object> val);
|
|
42
|
+
|
|
43
|
+
// public constructor - data is copied
|
|
44
|
+
NODE_EXTERN v8::MaybeLocal<v8::Object> Copy(v8::Isolate* isolate,
|
|
45
|
+
const char* data,
|
|
46
|
+
size_t len);
|
|
47
|
+
|
|
48
|
+
// public constructor
|
|
49
|
+
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
|
|
50
|
+
|
|
51
|
+
// public constructor from string
|
|
52
|
+
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
|
|
53
|
+
v8::Local<v8::String> string,
|
|
54
|
+
enum encoding enc = UTF8);
|
|
55
|
+
|
|
56
|
+
// public constructor - data is used, callback is passed data on object gc
|
|
57
|
+
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
|
|
58
|
+
char* data,
|
|
59
|
+
size_t length,
|
|
60
|
+
FreeCallback callback,
|
|
61
|
+
void* hint);
|
|
62
|
+
|
|
63
|
+
// public constructor - data is used.
|
|
64
|
+
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
|
|
65
|
+
char* data,
|
|
66
|
+
size_t len);
|
|
67
|
+
|
|
68
|
+
// Creates a Buffer instance over an existing ArrayBuffer.
|
|
69
|
+
NODE_EXTERN v8::MaybeLocal<v8::Uint8Array> New(v8::Isolate* isolate,
|
|
70
|
+
v8::Local<v8::ArrayBuffer> ab,
|
|
71
|
+
size_t byte_offset,
|
|
72
|
+
size_t length);
|
|
73
|
+
|
|
74
|
+
// This is verbose to be explicit with inline commenting
|
|
75
|
+
static inline bool IsWithinBounds(size_t off, size_t len, size_t max) {
|
|
76
|
+
// Asking to seek too far into the buffer
|
|
77
|
+
// check to avoid wrapping in subsequent subtraction
|
|
78
|
+
if (off > max)
|
|
79
|
+
return false;
|
|
80
|
+
|
|
81
|
+
// Asking for more than is left over in the buffer
|
|
82
|
+
if (max - off < len)
|
|
83
|
+
return false;
|
|
84
|
+
|
|
85
|
+
// Otherwise we're in bounds
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
} // namespace Buffer
|
|
90
|
+
} // namespace node
|
|
91
|
+
|
|
92
|
+
#endif // SRC_NODE_BUFFER_H_
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
// copy of this software and associated documentation files (the
|
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
// following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
|
12
|
+
// in all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
#ifndef SRC_NODE_OBJECT_WRAP_H_
|
|
23
|
+
#define SRC_NODE_OBJECT_WRAP_H_
|
|
24
|
+
|
|
25
|
+
#include "v8.h"
|
|
26
|
+
#include <cassert>
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
namespace node {
|
|
30
|
+
|
|
31
|
+
class ObjectWrap {
|
|
32
|
+
public:
|
|
33
|
+
ObjectWrap() {
|
|
34
|
+
refs_ = 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
virtual ~ObjectWrap() {
|
|
39
|
+
if (persistent().IsEmpty())
|
|
40
|
+
return;
|
|
41
|
+
persistent().ClearWeak();
|
|
42
|
+
persistent().Reset();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
template <class T>
|
|
47
|
+
static inline T* Unwrap(v8::Local<v8::Object> handle) {
|
|
48
|
+
assert(!handle.IsEmpty());
|
|
49
|
+
assert(handle->InternalFieldCount() > 0);
|
|
50
|
+
// Cast to ObjectWrap before casting to T. A direct cast from void
|
|
51
|
+
// to T won't work right when T has more than one base class.
|
|
52
|
+
void* ptr = handle->GetAlignedPointerFromInternalField(0);
|
|
53
|
+
ObjectWrap* wrap = static_cast<ObjectWrap*>(ptr);
|
|
54
|
+
return static_cast<T*>(wrap);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
inline v8::Local<v8::Object> handle() {
|
|
59
|
+
return handle(v8::Isolate::GetCurrent());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
inline v8::Local<v8::Object> handle(v8::Isolate* isolate) {
|
|
64
|
+
return v8::Local<v8::Object>::New(isolate, persistent());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
// NOLINTNEXTLINE(runtime/v8_persistent)
|
|
69
|
+
inline v8::Persistent<v8::Object>& persistent() {
|
|
70
|
+
return handle_;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
protected:
|
|
75
|
+
inline void Wrap(v8::Local<v8::Object> handle) {
|
|
76
|
+
assert(persistent().IsEmpty());
|
|
77
|
+
assert(handle->InternalFieldCount() > 0);
|
|
78
|
+
handle->SetAlignedPointerInInternalField(0, this);
|
|
79
|
+
persistent().Reset(v8::Isolate::GetCurrent(), handle);
|
|
80
|
+
MakeWeak();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
inline void MakeWeak() {
|
|
85
|
+
persistent().SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* Ref() marks the object as being attached to an event loop.
|
|
89
|
+
* Refed objects will not be garbage collected, even if
|
|
90
|
+
* all references are lost.
|
|
91
|
+
*/
|
|
92
|
+
virtual void Ref() {
|
|
93
|
+
assert(!persistent().IsEmpty());
|
|
94
|
+
persistent().ClearWeak();
|
|
95
|
+
refs_++;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Unref() marks an object as detached from the event loop. This is its
|
|
99
|
+
* default state. When an object with a "weak" reference changes from
|
|
100
|
+
* attached to detached state it will be freed. Be careful not to access
|
|
101
|
+
* the object after making this call as it might be gone!
|
|
102
|
+
* (A "weak reference" means an object that only has a
|
|
103
|
+
* persistent handle.)
|
|
104
|
+
*
|
|
105
|
+
* DO NOT CALL THIS FROM DESTRUCTOR
|
|
106
|
+
*/
|
|
107
|
+
virtual void Unref() {
|
|
108
|
+
assert(!persistent().IsEmpty());
|
|
109
|
+
assert(!persistent().IsWeak());
|
|
110
|
+
assert(refs_ > 0);
|
|
111
|
+
if (--refs_ == 0)
|
|
112
|
+
MakeWeak();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
int refs_; // ro
|
|
116
|
+
|
|
117
|
+
private:
|
|
118
|
+
static void WeakCallback(
|
|
119
|
+
const v8::WeakCallbackInfo<ObjectWrap>& data) {
|
|
120
|
+
ObjectWrap* wrap = data.GetParameter();
|
|
121
|
+
assert(wrap->refs_ == 0);
|
|
122
|
+
wrap->handle_.Reset();
|
|
123
|
+
delete wrap;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// NOLINTNEXTLINE(runtime/v8_persistent)
|
|
127
|
+
v8::Persistent<v8::Object> handle_;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
} // namespace node
|
|
131
|
+
|
|
132
|
+
#endif // SRC_NODE_OBJECT_WRAP_H_
|