emnapi 1.11.0 → 2.0.0-alpha.2

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.
Files changed (79) hide show
  1. package/CMakeLists.txt +127 -57
  2. package/README.md +164 -776
  3. package/cmake/wasm32.cmake +0 -3
  4. package/common.gypi +16 -14
  5. package/dist/library_async_work.js +390 -0
  6. package/dist/library_napi.js +1476 -2802
  7. package/dist/library_threadsafe_function.js +1178 -0
  8. package/dist/library_v8.js +1594 -0
  9. package/emnapi.gyp +37 -0
  10. package/include/node/emnapi.h +13 -2
  11. package/include/node/js_native_api_types.h +22 -0
  12. package/include/node/node.h +198 -0
  13. package/include/node/node_api.h +0 -10
  14. package/include/node/node_buffer.h +92 -0
  15. package/include/node/node_object_wrap.h +132 -0
  16. package/include/node/node_version.h +110 -0
  17. package/include/node/uv/unix.h +1 -0
  18. package/include/node/uv/version.h +43 -0
  19. package/include/node/uv.h +6 -0
  20. package/index.js +15 -7
  21. package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
  22. package/lib/wasm32-emscripten/libemnapi.a +0 -0
  23. package/lib/wasm32-wasip1-threads/libemnapi-mt.a +0 -0
  24. package/lib/wasm32-wasip1-threads/libemnapi-napi-rs-mt.a +0 -0
  25. package/lib/wasm32-wasip1-threads/libemnapi.a +0 -0
  26. package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
  27. package/lib/wasm64-emscripten/libemnapi.a +0 -0
  28. package/package.json +1 -1
  29. package/src/async_cleanup_hook.c +6 -6
  30. package/src/emnapi_internal.h +5 -10
  31. package/src/js_native_api.c +37 -21
  32. package/src/js_native_api_internal.h +66 -0
  33. package/src/node_api.c +1 -1
  34. package/src/threadsafe_function.c +2 -2
  35. package/src/uv/unix/thread.c +21 -0
  36. package/src/v8/array.cc +19 -0
  37. package/src/v8/boolean.cc +26 -0
  38. package/src/v8/date.cc +15 -0
  39. package/src/v8/exception.cc +48 -0
  40. package/src/v8/external.cc +23 -0
  41. package/src/v8/function.cc +35 -0
  42. package/src/v8/handle_scope.cc +46 -0
  43. package/src/v8/internal.cc +126 -0
  44. package/src/v8/internal.h +41 -0
  45. package/src/v8/isolate.cc +35 -0
  46. package/src/v8/json.cc +25 -0
  47. package/src/v8/node.cc +24 -0
  48. package/src/v8/number.cc +62 -0
  49. package/src/v8/object.cc +106 -0
  50. package/src/v8/script.cc +75 -0
  51. package/src/v8/string.cc +104 -0
  52. package/src/v8/template.cc +234 -0
  53. package/src/v8/try_catch.cc +50 -0
  54. package/src/v8/v8_impl.h +42 -0
  55. package/src/v8/value.cc +138 -0
  56. package/lib/wasm32/libdlmalloc-mt.a +0 -0
  57. package/lib/wasm32/libdlmalloc.a +0 -0
  58. package/lib/wasm32/libemmalloc-mt.a +0 -0
  59. package/lib/wasm32/libemmalloc.a +0 -0
  60. package/lib/wasm32/libemnapi-basic-mt.a +0 -0
  61. package/lib/wasm32/libemnapi-basic.a +0 -0
  62. package/lib/wasm32/libemnapi.a +0 -0
  63. package/lib/wasm32-emscripten/libemnapi-basic.a +0 -0
  64. package/lib/wasm32-wasi/libemnapi-basic-mt.a +0 -0
  65. package/lib/wasm32-wasi/libemnapi-basic.a +0 -0
  66. package/lib/wasm32-wasi/libemnapi.a +0 -0
  67. package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
  68. package/lib/wasm32-wasi-threads/libemnapi-basic-napi-rs-mt.a +0 -0
  69. package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
  70. package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
  71. package/lib/wasm32-wasi-threads/libemnapi-napi-rs-mt.a +0 -0
  72. package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
  73. package/lib/wasm32-wasip1/libemnapi-basic-mt.a +0 -0
  74. package/lib/wasm32-wasip1/libemnapi-basic.a +0 -0
  75. package/lib/wasm32-wasip1/libemnapi.a +0 -0
  76. package/lib/wasm32-wasip1-threads/libemnapi-basic-mt.a +0 -0
  77. package/lib/wasm32-wasip1-threads/libemnapi-basic-napi-rs-mt.a +0 -0
  78. package/lib/wasm32-wasip1-threads/libemnapi-basic.a +0 -0
  79. 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
  }
@@ -5,8 +5,8 @@
5
5
  #include "js_native_api_types.h"
6
6
  #include "emnapi_common.h"
7
7
 
8
- #define EMNAPI_MAJOR_VERSION 1
9
- #define EMNAPI_MINOR_VERSION 11
8
+ #define EMNAPI_MAJOR_VERSION 2
9
+ #define EMNAPI_MINOR_VERSION 0
10
10
  #define EMNAPI_PATCH_VERSION 0
11
11
 
12
12
  typedef enum {
@@ -82,6 +82,14 @@ 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
+
85
93
  /**
86
94
  * Get the handle for an external SharedArrayBuffer.
87
95
  * This function must be called on the emnapi main thread.
@@ -107,6 +115,9 @@ void emnapi_acquire_external_sharedarraybuffer(void* handle);
107
115
  EMNAPI_EXTERN
108
116
  void emnapi_release_external_sharedarraybuffer(void* handle);
109
117
 
118
+ #define DEBUGGER_LOG(str, value, type) \
119
+ emnapi_debug(__FILE__, __LINE__, str, value, type)
120
+
110
121
  EXTERN_C_END
111
122
 
112
123
  #endif
@@ -241,4 +241,26 @@ typedef struct {
241
241
  } napi_type_tag;
242
242
  #endif // NAPI_VERSION >= 8
243
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
+
244
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
@@ -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_
@@ -0,0 +1,110 @@
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_VERSION_H_
23
+ #define SRC_NODE_VERSION_H_
24
+
25
+ #define NODE_MAJOR_VERSION 22
26
+ #define NODE_MINOR_VERSION 15
27
+ #define NODE_PATCH_VERSION 0
28
+
29
+ #define NODE_VERSION_IS_LTS 1
30
+ #define NODE_VERSION_LTS_CODENAME "Jod"
31
+
32
+ #define NODE_VERSION_IS_RELEASE 1
33
+
34
+ #ifndef NODE_STRINGIFY
35
+ #define NODE_STRINGIFY(n) NODE_STRINGIFY_HELPER(n)
36
+ #define NODE_STRINGIFY_HELPER(n) #n
37
+ #endif
38
+
39
+ #ifndef NODE_RELEASE
40
+ #define NODE_RELEASE "node"
41
+ #endif
42
+
43
+ #ifndef NODE_TAG
44
+ # if NODE_VERSION_IS_RELEASE
45
+ # define NODE_TAG ""
46
+ # else
47
+ # define NODE_TAG "-pre"
48
+ # endif
49
+ #else
50
+ // NODE_TAG is passed without quotes when rc.exe is run from msbuild
51
+ # define NODE_EXE_VERSION NODE_STRINGIFY(NODE_MAJOR_VERSION) "." \
52
+ NODE_STRINGIFY(NODE_MINOR_VERSION) "." \
53
+ NODE_STRINGIFY(NODE_PATCH_VERSION) \
54
+ NODE_STRINGIFY(NODE_TAG)
55
+ #endif
56
+
57
+ # define NODE_VERSION_STRING NODE_STRINGIFY(NODE_MAJOR_VERSION) "." \
58
+ NODE_STRINGIFY(NODE_MINOR_VERSION) "." \
59
+ NODE_STRINGIFY(NODE_PATCH_VERSION) \
60
+ NODE_TAG
61
+ #ifndef NODE_EXE_VERSION
62
+ # define NODE_EXE_VERSION NODE_VERSION_STRING
63
+ #endif
64
+
65
+ #define NODE_VERSION "v" NODE_VERSION_STRING
66
+
67
+
68
+ #define NODE_VERSION_AT_LEAST(major, minor, patch) \
69
+ (( (major) < NODE_MAJOR_VERSION) \
70
+ || ((major) == NODE_MAJOR_VERSION && (minor) < NODE_MINOR_VERSION) \
71
+ || ((major) == NODE_MAJOR_VERSION && \
72
+ (minor) == NODE_MINOR_VERSION && (patch) <= NODE_PATCH_VERSION))
73
+
74
+ /**
75
+ * Node.js will refuse to load modules that weren't compiled against its own
76
+ * module ABI number, exposed as the process.versions.modules property.
77
+ *
78
+ * Node.js will refuse to load modules with a non-matching ABI version. The
79
+ * version number here should be changed whenever an ABI-incompatible API change
80
+ * is made in the C++ side, including in V8 or other dependencies.
81
+ *
82
+ * Node.js will not change the module version during a Major release line
83
+ * We will, at times update the version of V8 shipped in the release line
84
+ * if it can be made ABI compatible with the previous version.
85
+ *
86
+ * Embedders building Node.js can define NODE_EMBEDDER_MODULE_VERSION to
87
+ * override the default value of NODE_MODULE_VERSION.
88
+ *
89
+ * The registry of used NODE_MODULE_VERSION numbers is located at
90
+ * https://github.com/nodejs/node/blob/HEAD/doc/abi_version_registry.json
91
+ * Extenders, embedders and other consumers of Node.js that require ABI
92
+ * version matching should open a pull request to reserve a number in this
93
+ * registry.
94
+ */
95
+ #if defined(NODE_EMBEDDER_MODULE_VERSION)
96
+ #define NODE_MODULE_VERSION NODE_EMBEDDER_MODULE_VERSION
97
+ #else
98
+ #define NODE_MODULE_VERSION 127
99
+ #endif
100
+
101
+ // The NAPI_VERSION supported by the runtime. This is the inclusive range of
102
+ // versions which the Node.js binary being built supports.
103
+ #define NODE_API_SUPPORTED_VERSION_MAX 10
104
+ #define NODE_API_SUPPORTED_VERSION_MIN 1
105
+
106
+ // Node API modules use NAPI_VERSION 8 by default if it is not explicitly
107
+ // specified. It must be always 8.
108
+ #define NODE_API_DEFAULT_MODULE_API_VERSION 8
109
+
110
+ #endif // SRC_NODE_VERSION_H_
@@ -15,6 +15,7 @@ typedef pthread_t uv_thread_t;
15
15
  typedef pthread_mutex_t uv_mutex_t;
16
16
  typedef sem_t uv_sem_t;
17
17
  typedef pthread_cond_t uv_cond_t;
18
+ typedef pthread_key_t uv_key_t;
18
19
 
19
20
  #endif
20
21