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
@@ -0,0 +1,43 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to
5
+ * deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ * sell copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ * IN THE SOFTWARE.
20
+ */
21
+
22
+ #ifndef UV_VERSION_H
23
+ #define UV_VERSION_H
24
+
25
+ /*
26
+ * Versions with the same major number are ABI stable. API is allowed to
27
+ * evolve between minor releases, but only in a backwards compatible way.
28
+ * Make sure you update the -soname directives in configure.ac
29
+ * whenever you bump UV_VERSION_MAJOR or UV_VERSION_MINOR (but
30
+ * not UV_VERSION_PATCH.)
31
+ */
32
+
33
+ #define UV_VERSION_MAJOR 1
34
+ #define UV_VERSION_MINOR 48
35
+ #define UV_VERSION_PATCH 0
36
+ #define UV_VERSION_IS_RELEASE 1
37
+ #define UV_VERSION_SUFFIX ""
38
+
39
+ #define UV_VERSION_HEX ((UV_VERSION_MAJOR << 16) | \
40
+ (UV_VERSION_MINOR << 8) | \
41
+ (UV_VERSION_PATCH))
42
+
43
+ #endif /* UV_VERSION_H */
package/include/node/uv.h CHANGED
@@ -7,6 +7,7 @@
7
7
  extern "C" {
8
8
  #endif
9
9
 
10
+ #include "uv/version.h"
10
11
  #include <stddef.h>
11
12
  #include <stdint.h>
12
13
 
@@ -80,6 +81,11 @@ UV_EXTERN void uv_cond_destroy(uv_cond_t* cond);
80
81
 
81
82
  UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void));
82
83
 
84
+ UV_EXTERN int uv_key_create(uv_key_t* key);
85
+ UV_EXTERN void uv_key_delete(uv_key_t* key);
86
+ UV_EXTERN void* uv_key_get(uv_key_t* key);
87
+ UV_EXTERN void uv_key_set(uv_key_t* key, void* value);
88
+
83
89
  struct uv_work_s {
84
90
  UV_REQ_FIELDS
85
91
  uv_loop_t* loop;
package/index.js CHANGED
@@ -34,17 +34,21 @@ exports.requiredConfig = {
34
34
  settings: {
35
35
  WASM_BIGINT: '1',
36
36
  ALLOW_MEMORY_GROWTH: '1',
37
+ ALLOW_TABLE_GROWTH: '1',
37
38
  MIN_CHROME_VERSION: '85',
38
39
  EXPORTED_RUNTIME_METHODS: [
39
- 'emnapiInit'
40
+ 'emnapiInit',
40
41
  ],
41
42
  EXPORTED_FUNCTIONS: [
42
43
  '_malloc',
43
44
  '_free',
44
45
  '_napi_register_wasm_v1',
45
- '_node_api_module_get_api_version_v1'
46
- ]
47
- }
46
+ '_node_api_module_get_api_version_v1',
47
+ '_emnapi_create_env',
48
+ '_emnapi_delete_env',
49
+ '_uv_library_shutdown'
50
+ ],
51
+ },
48
52
  },
49
53
  clang: {
50
54
  target: 'wasm32-wasip1-threads',
@@ -54,13 +58,17 @@ exports.requiredConfig = {
54
58
  '--import-memory',
55
59
  '--shared-memory',
56
60
  '--export-table',
61
+ '--growable-table',
57
62
  '--export=malloc',
58
63
  '--export=free',
59
64
  '--export=napi_register_wasm_v1',
60
65
  '--export-if-defined=node_api_module_get_api_version_v1',
61
66
  '--export=emnapi_thread_crashed',
62
67
  '--export-if-defined=emnapi_async_worker_create',
63
- '--export-if-defined=emnapi_async_worker_init'
64
- ]
65
- }
68
+ '--export-if-defined=emnapi_async_worker_init',
69
+ '--export-if-defined=uv_library_shutdown',
70
+ '--export=emnapi_create_env',
71
+ '--export=emnapi_delete_env',
72
+ ],
73
+ },
66
74
  }
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emnapi",
3
- "version": "1.11.0",
3
+ "version": "2.0.0-alpha.2",
4
4
  "description": "Node-API implementation for Emscripten",
5
5
  "main": "index.js",
6
6
  "gypfile": false,
@@ -8,7 +8,7 @@ EXTERN_C_START
8
8
  typedef void (*async_cleanup_hook)(void* arg, void(*)(void*), void*);
9
9
 
10
10
  struct async_cleanup_hook_info {
11
- napi_env env;
11
+ node_api_basic_env env;
12
12
  async_cleanup_hook fun;
13
13
  void* arg;
14
14
  bool started;
@@ -16,7 +16,7 @@ struct async_cleanup_hook_info {
16
16
 
17
17
  struct napi_async_cleanup_hook_handle__ {
18
18
  struct async_cleanup_hook_info* handle_;
19
- napi_env env_;
19
+ node_api_basic_env env_;
20
20
  napi_async_cleanup_hook user_hook_;
21
21
  void* user_data_;
22
22
  void (*done_cb_)(void*);
@@ -46,7 +46,7 @@ static void _emnapi_run_async_cleanup_hook(void* arg) {
46
46
  }
47
47
 
48
48
  static struct async_cleanup_hook_info*
49
- _emnapi_add_async_environment_cleanup_hook(napi_env env,
49
+ _emnapi_add_async_environment_cleanup_hook(node_api_basic_env env,
50
50
  async_cleanup_hook fun,
51
51
  void* arg) {
52
52
  struct async_cleanup_hook_info* info =
@@ -68,7 +68,7 @@ static void _emnapi_remove_async_environment_cleanup_hook(
68
68
  }
69
69
 
70
70
  static napi_async_cleanup_hook_handle
71
- _emnapi_ach_handle_create(napi_env env,
71
+ _emnapi_ach_handle_create(node_api_basic_env env,
72
72
  napi_async_cleanup_hook user_hook,
73
73
  void* user_data) {
74
74
  napi_async_cleanup_hook_handle handle =
@@ -83,7 +83,7 @@ _emnapi_ach_handle_create(napi_env env,
83
83
  }
84
84
 
85
85
  static void _emnapi_ach_handle_env_unref(void* arg) {
86
- napi_env env = (napi_env) arg;
86
+ node_api_basic_env env = (node_api_basic_env) arg;
87
87
  _emnapi_env_unref(env);
88
88
  }
89
89
 
@@ -92,7 +92,7 @@ _emnapi_ach_handle_delete(napi_async_cleanup_hook_handle handle) {
92
92
  _emnapi_remove_async_environment_cleanup_hook(handle->handle_);
93
93
  if (handle->done_cb_ != NULL) handle->done_cb_(handle->done_data_);
94
94
 
95
- _emnapi_set_immediate(_emnapi_ach_handle_env_unref, handle->env_);
95
+ _emnapi_set_immediate(_emnapi_ach_handle_env_unref, (void*) handle->env_);
96
96
 
97
97
  free(handle->handle_);
98
98
  free(handle);
@@ -75,12 +75,6 @@ EXTERN_C_END
75
75
 
76
76
  EXTERN_C_START
77
77
 
78
- EMNAPI_INTERNAL_EXTERN napi_status napi_set_last_error(node_api_basic_env env,
79
- napi_status error_code,
80
- uint32_t engine_error_code,
81
- void* engine_reserved);
82
- EMNAPI_INTERNAL_EXTERN napi_status napi_clear_last_error(node_api_basic_env env);
83
-
84
78
  #ifdef __EMSCRIPTEN__
85
79
  #if __EMSCRIPTEN_major__ * 10000 + __EMSCRIPTEN_minor__ * 100 + __EMSCRIPTEN_tiny__ >= 30114 // NOLINT
86
80
  #define EMNAPI_KEEPALIVE_PUSH emscripten_runtime_keepalive_push
@@ -103,8 +97,8 @@ EMNAPI_INTERNAL_EXTERN void _emnapi_runtime_keepalive_pop();
103
97
 
104
98
  EMNAPI_INTERNAL_EXTERN napi_handle_scope _emnapi_open_handle_scope();
105
99
  EMNAPI_INTERNAL_EXTERN void _emnapi_close_handle_scope(napi_handle_scope scope);
106
- EMNAPI_INTERNAL_EXTERN void _emnapi_env_ref(napi_env env);
107
- EMNAPI_INTERNAL_EXTERN void _emnapi_env_unref(napi_env env);
100
+ EMNAPI_INTERNAL_EXTERN void _emnapi_env_ref(node_api_basic_env env);
101
+ EMNAPI_INTERNAL_EXTERN void _emnapi_env_unref(node_api_basic_env env);
108
102
  EMNAPI_INTERNAL_EXTERN void _emnapi_ctx_increase_waiting_request_counter();
109
103
  EMNAPI_INTERNAL_EXTERN void _emnapi_ctx_decrease_waiting_request_counter();
110
104
 
@@ -113,8 +107,7 @@ EMNAPI_INTERNAL_EXTERN int _emnapi_is_main_runtime_thread();
113
107
  EMNAPI_INTERNAL_EXTERN double _emnapi_get_now();
114
108
  EMNAPI_INTERNAL_EXTERN void _emnapi_unwind();
115
109
  EMNAPI_INTERNAL_EXTERN void _emnapi_set_immediate(void (*callback)(void*), void* data);
116
- EMNAPI_INTERNAL_EXTERN napi_status _emnapi_create_function(napi_env env,
117
- const char* utf8name,
110
+ EMNAPI_INTERNAL_EXTERN napi_status _emnapi_create_function(const char* utf8name,
118
111
  size_t length,
119
112
  napi_callback cb,
120
113
  void* data,
@@ -197,4 +190,6 @@ void _emnapi_env_check_gc_access(napi_env env);
197
190
 
198
191
  EXTERN_C_END
199
192
 
193
+ #include "js_native_api_internal.h"
194
+
200
195
  #endif
@@ -2,6 +2,34 @@
2
2
 
3
3
  EXTERN_C_START
4
4
 
5
+ struct node_api_base_env__vtable node_api_base_env__vtable_instance = {
6
+ .offset_to_top = offsetof(node_api_base_env__, vptr),
7
+ .type_info = NULL,
8
+ .cdtor = node_api_base_env__cdtor,
9
+ .ddtor = node_api_base_env__ddtor,
10
+ };
11
+
12
+ __attribute__((visibility("default")))
13
+ node_api_base_env__* emnapi_create_env() {
14
+ node_api_base_env__* env = (node_api_base_env__*) calloc(1, sizeof(node_api_base_env__));
15
+ node_api_base_env__ctor(env);
16
+ return env;
17
+ }
18
+
19
+ __attribute__((visibility("default")))
20
+ void emnapi_delete_env(node_api_base_env__* env) {
21
+ node_api_base_env__ddtor(env);
22
+ }
23
+
24
+ node_api_base_env__* node_api_base_env__cdtor(node_api_base_env__* self) {
25
+ return self;
26
+ }
27
+
28
+ void node_api_base_env__ddtor(node_api_base_env__* self) {
29
+ node_api_base_env__cdtor(self);
30
+ free(self);
31
+ }
32
+
5
33
  static const char* emnapi_error_messages[] = {
6
34
  NULL,
7
35
  "Invalid argument",
@@ -29,17 +57,12 @@ static const char* emnapi_error_messages[] = {
29
57
  "Cannot run JavaScript",
30
58
  };
31
59
 
32
- EMNAPI_INTERNAL_EXTERN void _emnapi_get_last_error_info(napi_env env,
33
- napi_status* error_code,
34
- uint32_t* engine_error_code,
35
- void** engine_reserved);
36
-
60
+ __attribute__((visibility("default")))
37
61
  napi_status napi_get_last_error_info(
38
62
  node_api_basic_env basic_env, const napi_extended_error_info** result) {
39
- static napi_extended_error_info last_error;
40
- napi_env env = (napi_env) basic_env;
41
- CHECK_ENV(env);
42
- CHECK_ARG(env, result);
63
+ CHECK_ENV(basic_env);
64
+ CHECK_ARG(basic_env, result);
65
+ node_api_base_env__* env = EMNAPI_AS_NODE_API_BASE_ENV(basic_env);
43
66
 
44
67
  const int last_status = napi_cannot_run_js;
45
68
 
@@ -48,21 +71,14 @@ napi_status napi_get_last_error_info(
48
71
  "Count of error messages must match count of error values");
49
72
  #endif
50
73
 
51
- _emnapi_get_last_error_info(env,
52
- &last_error.error_code,
53
- &last_error.engine_error_code,
54
- &last_error.engine_reserved);
55
-
56
- CHECK_LE(last_error.error_code, last_status);
74
+ CHECK_LE(env->last_error.error_code, last_status);
57
75
 
58
- last_error.error_message = emnapi_error_messages[last_error.error_code];
76
+ env->last_error.error_message = emnapi_error_messages[env->last_error.error_code];
59
77
 
60
- if (last_error.error_code == napi_ok) {
61
- napi_clear_last_error(env);
62
- last_error.engine_error_code = 0;
63
- last_error.engine_reserved = NULL;
78
+ if (env->last_error.error_code == napi_ok) {
79
+ napi_clear_last_error(basic_env);
64
80
  }
65
- *result = &last_error;
81
+ *result = &(env->last_error);
66
82
  return napi_ok;
67
83
  }
68
84
 
@@ -0,0 +1,66 @@
1
+ #ifndef SRC_JS_NATIVE_API_INTERNAL_H_
2
+ #define SRC_JS_NATIVE_API_INTERNAL_H_
3
+
4
+ #include "js_native_api_types.h"
5
+
6
+ typedef struct node_api_base_env__ {
7
+ void* vptr;
8
+ EMNAPI_NAPI_ENV_FIELDS;
9
+ uint32_t id;
10
+ napi_extended_error_info last_error;
11
+ } node_api_base_env__;
12
+
13
+ #define EMNAPI_AS_NODE_API_BASE_ENV(env) \
14
+ ((node_api_base_env__*)((char*)(env) - offsetof(node_api_base_env__, sentinel)))
15
+
16
+ struct node_api_base_env__vtable {
17
+ size_t offset_to_top;
18
+ void* type_info;
19
+ node_api_base_env__* (*cdtor)(node_api_base_env__* self);
20
+ void (*ddtor)(node_api_base_env__* self);
21
+ };
22
+
23
+ EXTERN_C_START
24
+
25
+ extern struct node_api_base_env__vtable node_api_base_env__vtable_instance;
26
+
27
+ // EMNAPI_INTERNAL_EXTERN
28
+ // const struct node_api_js_vtable* _emnapi_get_node_api_js_vtable();
29
+
30
+ // EMNAPI_INTERNAL_EXTERN
31
+ // const struct node_api_module_vtable* _emnapi_get_node_api_module_vtable();
32
+
33
+ node_api_base_env__* node_api_base_env__cdtor(node_api_base_env__* self);
34
+ void node_api_base_env__ddtor(node_api_base_env__* self);
35
+
36
+ static inline
37
+ node_api_base_env__* node_api_base_env__ctor(node_api_base_env__* self) {
38
+ self->vptr = &node_api_base_env__vtable_instance.cdtor;
39
+ self->sentinel = NODE_API_VT_SENTINEL;
40
+ return self;
41
+ }
42
+
43
+ static inline napi_status napi_clear_last_error(node_api_basic_env basic_env) {
44
+ node_api_base_env__* env = EMNAPI_AS_NODE_API_BASE_ENV(basic_env);
45
+ env->last_error.error_code = napi_ok;
46
+ env->last_error.engine_error_code = 0;
47
+ env->last_error.engine_reserved = NULL;
48
+ env->last_error.error_message = NULL;
49
+ return napi_ok;
50
+ }
51
+
52
+ static inline napi_status
53
+ napi_set_last_error(node_api_basic_env basic_env,
54
+ napi_status error_code,
55
+ uint32_t engine_error_code,
56
+ void* engine_reserved) {
57
+ node_api_base_env__* env = EMNAPI_AS_NODE_API_BASE_ENV(basic_env);
58
+ env->last_error.error_code = error_code;
59
+ env->last_error.engine_error_code = engine_error_code;
60
+ env->last_error.engine_reserved = engine_reserved;
61
+ return error_code;
62
+ }
63
+
64
+ EXTERN_C_END
65
+
66
+ #endif
package/src/node_api.c CHANGED
@@ -36,7 +36,7 @@ napi_status napi_get_uv_event_loop(node_api_basic_env env,
36
36
  return napi_clear_last_error(env);
37
37
  }
38
38
 
39
- EMNAPI_INTERNAL_EXTERN int _emnapi_get_filename(napi_env env, char* buf, int len);
39
+ EMNAPI_INTERNAL_EXTERN int _emnapi_get_filename(node_api_basic_env env, char* buf, int len);
40
40
 
41
41
  napi_status node_api_get_module_file_name(node_api_basic_env env,
42
42
  const char** result) {
@@ -215,7 +215,7 @@ static void _emnapi_tsfn_finalize(napi_threadsafe_function func) {
215
215
  if (emnapi_is_node_binding_available()) {
216
216
  napi_value resource, cb;
217
217
  EMNAPI_ASSERT_CALL(napi_get_reference_value(func->env, func->async_resource.resource_, &resource));
218
- EMNAPI_ASSERT_CALL(_emnapi_create_function(func->env, NULL, 0, _emnapi_tsfn_finalize_in_callback_scope, func, &cb));
218
+ EMNAPI_ASSERT_CALL(_emnapi_create_function(NULL, 0, _emnapi_tsfn_finalize_in_callback_scope, func, &cb));
219
219
  _emnapi_node_make_callback(func->env,
220
220
  resource,
221
221
  cb,
@@ -337,7 +337,7 @@ static bool _emnapi_tsfn_dispatch_one(napi_threadsafe_function func) {
337
337
  if (emnapi_is_node_binding_available()) {
338
338
  napi_value resource, cb;
339
339
  EMNAPI_ASSERT_CALL(napi_get_reference_value(func->env, func->async_resource.resource_, &resource));
340
- EMNAPI_ASSERT_CALL(_emnapi_create_function(func->env, NULL, 0, _emnapi_tsfn_call_js_cb_in_callback_scope, jscb_data, &cb));
340
+ EMNAPI_ASSERT_CALL(_emnapi_create_function(NULL, 0, _emnapi_tsfn_call_js_cb_in_callback_scope, jscb_data, &cb));
341
341
  _emnapi_node_make_callback(func->env,
342
342
  resource,
343
343
  cb,
@@ -188,4 +188,25 @@ int uv_thread_join(uv_thread_t *tid) {
188
188
  return pthread_join(*tid, NULL);
189
189
  }
190
190
 
191
+ int uv_key_create(uv_key_t* key) {
192
+ return pthread_key_create(key, NULL);
193
+ }
194
+
195
+
196
+ void uv_key_delete(uv_key_t* key) {
197
+ if (pthread_key_delete(*key))
198
+ abort();
199
+ }
200
+
201
+
202
+ void* uv_key_get(uv_key_t* key) {
203
+ return pthread_getspecific(*key);
204
+ }
205
+
206
+
207
+ void uv_key_set(uv_key_t* key, void* value) {
208
+ if (pthread_setspecific(*key, value))
209
+ abort();
210
+ }
211
+
191
212
  #endif
@@ -0,0 +1,19 @@
1
+ #include "v8_impl.h"
2
+
3
+ namespace v8 {
4
+
5
+ extern "C" {
6
+ V8_EXTERN internal::Address _v8_array_new(Isolate* isolate, int length);
7
+ V8_EXTERN uint32_t _v8_array_length(const Array* array);
8
+ }
9
+
10
+ Local<Array> Array::New(Isolate* isolate, int length) {
11
+ auto n = _v8_array_new(isolate, length);
12
+ return v8impl::V8LocalValueFromAddress(n).As<Array>();
13
+ }
14
+
15
+ uint32_t Array::Length() const {
16
+ return _v8_array_length(this);
17
+ }
18
+
19
+ }
@@ -0,0 +1,26 @@
1
+ #include "v8_impl.h"
2
+
3
+ namespace v8 {
4
+
5
+ extern "C" {
6
+ V8_EXTERN bool _v8_boolean_value(const Boolean*);
7
+ V8_EXTERN int _v8_boolean_object_value_of(const BooleanObject*);
8
+ V8_EXTERN internal::Address _v8_boolean_object_new(Isolate* isolate, int value);
9
+ }
10
+
11
+ void Boolean::CheckCast(v8::Data*) {}
12
+
13
+ bool Boolean::Value() const {
14
+ return _v8_boolean_value(this);
15
+ }
16
+
17
+ Local<Value> BooleanObject::New(Isolate* isolate, bool value) {
18
+ auto n = _v8_boolean_object_new(isolate, static_cast<int>(value));
19
+ return v8impl::V8LocalValueFromAddress(n);
20
+ }
21
+
22
+ bool BooleanObject::ValueOf() const {
23
+ return static_cast<bool>(_v8_boolean_object_value_of(this));
24
+ }
25
+
26
+ }
package/src/v8/date.cc ADDED
@@ -0,0 +1,15 @@
1
+ #include "v8_impl.h"
2
+
3
+ namespace v8 {
4
+
5
+ extern "C" {
6
+ V8_EXTERN internal::Address _v8_date_new(Context* context, double value);
7
+ }
8
+
9
+ MaybeLocal<Value> Date::New(Local<Context> context, double time) {
10
+ auto n = _v8_date_new(*context, time);
11
+ if (!n) return MaybeLocal<Value>();
12
+ return v8impl::V8LocalValueFromAddress(n);
13
+ }
14
+
15
+ }
@@ -0,0 +1,48 @@
1
+ #include "v8_impl.h"
2
+
3
+ namespace v8 {
4
+
5
+ extern "C" {
6
+ V8_EXTERN internal::Address _v8_exception_error(internal::Address message, internal::Address options);
7
+ V8_EXTERN internal::Address _v8_exception_type_error(internal::Address message, internal::Address options);
8
+ V8_EXTERN internal::Address _v8_exception_range_error(internal::Address message, internal::Address options);
9
+ V8_EXTERN internal::Address _v8_exception_reference_error(internal::Address message, internal::Address options);
10
+ V8_EXTERN internal::Address _v8_exception_syntax_error(internal::Address message, internal::Address options);
11
+ }
12
+
13
+ Local<Value> Exception::Error(Local<String> message, Local<Value> options) {
14
+ return v8impl::V8LocalValueFromAddress(
15
+ _v8_exception_error(
16
+ v8impl::AddressFromV8LocalValue(message),
17
+ v8impl::AddressFromV8LocalValue(options)));
18
+ }
19
+
20
+ Local<Value> Exception::TypeError(Local<String> message, Local<Value> options) {
21
+ return v8impl::V8LocalValueFromAddress(
22
+ _v8_exception_type_error(
23
+ v8impl::AddressFromV8LocalValue(message),
24
+ v8impl::AddressFromV8LocalValue(options)));
25
+ }
26
+
27
+ Local<Value> Exception::RangeError(Local<String> message, Local<Value> options) {
28
+ return v8impl::V8LocalValueFromAddress(
29
+ _v8_exception_range_error(
30
+ v8impl::AddressFromV8LocalValue(message),
31
+ v8impl::AddressFromV8LocalValue(options)));
32
+ }
33
+
34
+ Local<Value> Exception::ReferenceError(Local<String> message, Local<Value> options) {
35
+ return v8impl::V8LocalValueFromAddress(
36
+ _v8_exception_reference_error(
37
+ v8impl::AddressFromV8LocalValue(message),
38
+ v8impl::AddressFromV8LocalValue(options)));
39
+ }
40
+
41
+ Local<Value> Exception::SyntaxError(Local<String> message, Local<Value> options) {
42
+ return v8impl::V8LocalValueFromAddress(
43
+ _v8_exception_syntax_error(
44
+ v8impl::AddressFromV8LocalValue(message),
45
+ v8impl::AddressFromV8LocalValue(options)));
46
+ }
47
+
48
+ }
@@ -0,0 +1,23 @@
1
+ #include "v8_impl.h"
2
+
3
+ namespace v8 {
4
+
5
+ extern "C" {
6
+ V8_EXTERN internal::Address _v8_external_new(Isolate* isolate, void* data);
7
+ V8_EXTERN void* _v8_external_value(const External* obj);
8
+ }
9
+
10
+ void External::CheckCast(v8::Value* that) {}
11
+
12
+ Local<External> External::New(v8::Isolate* isolate, void* value) {
13
+ internal::Address obj_value = _v8_external_new(isolate, value);
14
+ if (!obj_value) return Local<External>();
15
+ auto obj = v8impl::V8LocalValueFromAddress(obj_value).As<External>();
16
+ return obj;
17
+ }
18
+
19
+ void* External::Value() const {
20
+ return _v8_external_value(this);
21
+ }
22
+
23
+ }
@@ -0,0 +1,35 @@
1
+ #include "v8_impl.h"
2
+
3
+ namespace v8 {
4
+
5
+ extern "C" {
6
+ V8_EXTERN void _v8_function_set_name(Function* func, internal::Address name);
7
+ V8_EXTERN internal::Address _v8_function_new_instance(
8
+ const Function* func, Context* context, int argc, internal::Address* argv);
9
+ V8_EXTERN internal::Address _v8_function_call(
10
+ Function* func, Context* context, internal::Address recv, int argc,
11
+ internal::Address* argv);
12
+ }
13
+
14
+ void Function::CheckCast(v8::Value*) {}
15
+
16
+ void Function::SetName(v8::Local<v8::String> name) {
17
+ _v8_function_set_name(this, v8impl::AddressFromV8LocalValue(name));
18
+ }
19
+
20
+ MaybeLocal<Object> Function::NewInstance(
21
+ Local<Context> context, int argc, Local<Value> argv[]) const {
22
+ return v8impl::V8LocalValueFromAddress(
23
+ _v8_function_new_instance(this, *context, argc, reinterpret_cast<internal::Address*>(argv))).As<Object>();
24
+ }
25
+
26
+ MaybeLocal<Value> Function::Call(Local<Context> context,
27
+ Local<Value> recv, int argc,
28
+ Local<Value> argv[]) {
29
+ internal::Address result = _v8_function_call(
30
+ this, *context, v8impl::AddressFromV8LocalValue(recv), argc,
31
+ reinterpret_cast<internal::Address*>(argv));
32
+ return v8impl::V8LocalValueFromAddress(result);
33
+ }
34
+
35
+ }
@@ -0,0 +1,46 @@
1
+ #include "v8_impl.h"
2
+ #include "internal.h"
3
+
4
+ namespace v8 {
5
+
6
+ extern "C" {
7
+ V8_EXTERN internal::Address _v8_open_handle_scope(Isolate* isolate);
8
+ V8_EXTERN internal::Address _v8_handle_scope_escape(internal::Address scope, internal::Address value);
9
+ V8_EXTERN void _v8_close_handle_scope(internal::Address scope);
10
+ }
11
+
12
+ HandleScope::HandleScope(Isolate* isolate)
13
+ : i_isolate_(reinterpret_cast<internal::Isolate*>(isolate)),
14
+ prev_next_(reinterpret_cast<internal::Address*>(_v8_open_handle_scope(isolate))),
15
+ prev_limit_(nullptr)
16
+ #ifdef V8_ENABLE_CHECKS
17
+ , scope_level_(0)
18
+ #endif
19
+ {
20
+ #ifdef V8_ENABLE_CHECKS
21
+ internal::HandleScopeData* current = i_isolate_->handle_scope_data();
22
+ current->level++;
23
+ scope_level_ = current->level;
24
+ #endif
25
+ }
26
+
27
+ HandleScope::~HandleScope() {
28
+ #ifdef V8_ENABLE_CHECKS
29
+ i_isolate_->handle_scope_data()->level--;
30
+ #endif
31
+ _v8_close_handle_scope(reinterpret_cast<internal::Address>(prev_next_));
32
+ }
33
+
34
+ EscapableHandleScopeBase::EscapableHandleScopeBase(Isolate* isolate): HandleScope(isolate), escape_slot_(nullptr) {}
35
+
36
+ internal::Address* EscapableHandleScopeBase::EscapeSlot(internal::Address* escape_value) {
37
+ if (escape_slot_ != nullptr) {
38
+ abort();
39
+ }
40
+ internal::Address* prev_next_ = *reinterpret_cast<internal::Address**>(reinterpret_cast<internal::Address>(this) + internal::kApiSystemPointerSize * 1);
41
+ escape_slot_ = reinterpret_cast<internal::Address*>(
42
+ _v8_handle_scope_escape(reinterpret_cast<internal::Address>(prev_next_), reinterpret_cast<internal::Address>(escape_value)));
43
+ return escape_slot_;
44
+ }
45
+
46
+ }