emnapi 1.0.0 → 1.1.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/README.md CHANGED
@@ -750,19 +750,19 @@ call set CXX_target=%%WASI_SDK_PATH:\=/%%/bin/clang++.exe
750
750
  emmake node-gyp rebuild \
751
751
  --arch=wasm32 \
752
752
  --nodedir=./node_modules/emnapi \
753
- -- -f make -DOS=emscripten # -Dwasm_threads=1
753
+ -- -f make-linux -DOS=emscripten # -Dwasm_threads=1
754
754
 
755
755
  # wasi
756
756
  node-gyp rebuild \
757
757
  --arch=wasm32 \
758
758
  --nodedir=./node_modules/emnapi \
759
- -- -f make -DOS=wasi # -Dwasm_threads=1
759
+ -- -f make-linux -DOS=wasi # -Dwasm_threads=1
760
760
 
761
761
  # bare wasm32
762
762
  node-gyp rebuild \
763
763
  --arch=wasm32 \
764
764
  --nodedir=./node_modules/emnapi \
765
- -- -f make -DOS=unknown # -Dwasm_threads=1
765
+ -- -f make-linux -DOS=unknown # -Dwasm_threads=1
766
766
  ```
767
767
 
768
768
  ```bat
@@ -770,15 +770,15 @@ node-gyp rebuild \
770
770
  @REM Run the bat file in POSIX-like environment (e.g. Cygwin)
771
771
 
772
772
  @REM emscripten
773
- call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make -DOS=emscripten
773
+ call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-linux -DOS=emscripten
774
774
  call emmake.bat make -C %~dp0build
775
775
 
776
776
  @REM wasi
777
- call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make -DOS=wasi
777
+ call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-linux -DOS=wasi
778
778
  make -C %~dp0build
779
779
 
780
780
  @REM bare wasm32
781
- call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make -DOS=unknown
781
+ call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-linux -DOS=unknown
782
782
  make -C %~dp0build
783
783
  ```
784
784
 
@@ -1235,9 +1235,8 @@ function _napi_get_buffer_info(env, buffer, data, length) {
1235
1235
  if (!buffer)
1236
1236
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
1237
1237
  var handle = emnapiCtx.handleStore.get(buffer);
1238
- if (!handle.isBuffer()) {
1238
+ if (!handle.isBuffer())
1239
1239
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
1240
- }
1241
1240
  return _napi_get_typedarray_info(env, buffer, 0, length, data, 0, 0);
1242
1241
  }
1243
1242
  /**
package/emnapi.gyp CHANGED
@@ -63,7 +63,7 @@
63
63
  ]
64
64
  },
65
65
  'conditions': [
66
- ['wasm_threads != 0 and OS in " unknown"', {
66
+ ['wasm_threads != 0 and OS in " unknown wasi"', {
67
67
  'sources': [
68
68
  'src/thread/async_worker_create.c',
69
69
  'src/thread/async_worker_init.S',
@@ -6,8 +6,8 @@
6
6
  #include "emnapi_common.h"
7
7
 
8
8
  #define EMNAPI_MAJOR_VERSION 1
9
- #define EMNAPI_MINOR_VERSION 0
10
- #define EMNAPI_PATCH_VERSION 0
9
+ #define EMNAPI_MINOR_VERSION 1
10
+ #define EMNAPI_PATCH_VERSION 1
11
11
 
12
12
  typedef enum {
13
13
  emnapi_runtime,
@@ -55,8 +55,8 @@
55
55
 
56
56
  EXTERN_C_START
57
57
 
58
- NAPI_EXTERN napi_status NAPI_CDECL
59
- napi_get_last_error_info(napi_env env, const napi_extended_error_info** result);
58
+ NAPI_EXTERN napi_status NAPI_CDECL napi_get_last_error_info(
59
+ node_api_nogc_env env, const napi_extended_error_info** result);
60
60
 
61
61
  // Getters for defined singletons
62
62
  NAPI_EXTERN napi_status NAPI_CDECL napi_get_undefined(napi_env env,
@@ -104,7 +104,7 @@ NAPI_EXTERN napi_status NAPI_CDECL
104
104
  node_api_create_external_string_latin1(napi_env env,
105
105
  char* str,
106
106
  size_t length,
107
- napi_finalize finalize_callback,
107
+ node_api_nogc_finalize finalize_callback,
108
108
  void* finalize_hint,
109
109
  napi_value* result,
110
110
  bool* copied);
@@ -112,7 +112,7 @@ NAPI_EXTERN napi_status NAPI_CDECL
112
112
  node_api_create_external_string_utf16(napi_env env,
113
113
  char16_t* str,
114
114
  size_t length,
115
- napi_finalize finalize_callback,
115
+ node_api_nogc_finalize finalize_callback,
116
116
  void* finalize_hint,
117
117
  napi_value* result,
118
118
  bool* copied);
@@ -303,7 +303,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_instanceof(napi_env env,
303
303
 
304
304
  // Gets all callback info in a single call. (Ugly, but faster.)
305
305
  NAPI_EXTERN napi_status NAPI_CDECL napi_get_cb_info(
306
- napi_env env, // [in] NAPI environment handle
306
+ napi_env env, // [in] Node-API environment handle
307
307
  napi_callback_info cbinfo, // [in] Opaque callback-info handle
308
308
  size_t* argc, // [in-out] Specifies the size of the provided argv array
309
309
  // and receives the actual count of args.
@@ -327,7 +327,7 @@ napi_define_class(napi_env env,
327
327
  NAPI_EXTERN napi_status NAPI_CDECL napi_wrap(napi_env env,
328
328
  napi_value js_object,
329
329
  void* native_object,
330
- napi_finalize finalize_cb,
330
+ node_api_nogc_finalize finalize_cb,
331
331
  void* finalize_hint,
332
332
  napi_ref* result);
333
333
  NAPI_EXTERN napi_status NAPI_CDECL napi_unwrap(napi_env env,
@@ -339,7 +339,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_remove_wrap(napi_env env,
339
339
  NAPI_EXTERN napi_status NAPI_CDECL
340
340
  napi_create_external(napi_env env,
341
341
  void* data,
342
- napi_finalize finalize_cb,
342
+ node_api_nogc_finalize finalize_cb,
343
343
  void* finalize_hint,
344
344
  napi_value* result);
345
345
  NAPI_EXTERN napi_status NAPI_CDECL napi_get_value_external(napi_env env,
@@ -438,7 +438,7 @@ NAPI_EXTERN napi_status NAPI_CDECL
438
438
  napi_create_external_arraybuffer(napi_env env,
439
439
  void* external_data,
440
440
  size_t byte_length,
441
- napi_finalize finalize_cb,
441
+ node_api_nogc_finalize finalize_cb,
442
442
  void* finalize_hint,
443
443
  napi_value* result);
444
444
  #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
@@ -480,7 +480,7 @@ napi_get_dataview_info(napi_env env,
480
480
  size_t* byte_offset);
481
481
 
482
482
  // version management
483
- NAPI_EXTERN napi_status NAPI_CDECL napi_get_version(napi_env env,
483
+ NAPI_EXTERN napi_status NAPI_CDECL napi_get_version(node_api_nogc_env env,
484
484
  uint32_t* result);
485
485
 
486
486
  // Promises
@@ -504,7 +504,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_run_script(napi_env env,
504
504
 
505
505
  // Memory management
506
506
  NAPI_EXTERN napi_status NAPI_CDECL napi_adjust_external_memory(
507
- napi_env env, int64_t change_in_bytes, int64_t* adjusted_value);
507
+ node_api_nogc_env env, int64_t change_in_bytes, int64_t* adjusted_value);
508
508
 
509
509
  #if NAPI_VERSION >= 5
510
510
 
@@ -522,12 +522,13 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_get_date_value(napi_env env,
522
522
  double* result);
523
523
 
524
524
  // Add finalizer for pointer
525
- NAPI_EXTERN napi_status NAPI_CDECL napi_add_finalizer(napi_env env,
526
- napi_value js_object,
527
- void* finalize_data,
528
- napi_finalize finalize_cb,
529
- void* finalize_hint,
530
- napi_ref* result);
525
+ NAPI_EXTERN napi_status NAPI_CDECL
526
+ napi_add_finalizer(napi_env env,
527
+ napi_value js_object,
528
+ void* finalize_data,
529
+ node_api_nogc_finalize finalize_cb,
530
+ void* finalize_hint,
531
+ napi_ref* result);
531
532
 
532
533
  #endif // NAPI_VERSION >= 5
533
534
 
@@ -535,7 +536,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_add_finalizer(napi_env env,
535
536
  #define NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
536
537
 
537
538
  NAPI_EXTERN napi_status NAPI_CDECL
538
- node_api_post_finalizer(napi_env env,
539
+ node_api_post_finalizer(node_api_nogc_env env,
539
540
  napi_finalize finalize_cb,
540
541
  void* finalize_data,
541
542
  void* finalize_hint);
@@ -579,10 +580,13 @@ napi_get_all_property_names(napi_env env,
579
580
  napi_value* result);
580
581
 
581
582
  // Instance data
582
- NAPI_EXTERN napi_status NAPI_CDECL napi_set_instance_data(
583
- napi_env env, void* data, napi_finalize finalize_cb, void* finalize_hint);
583
+ NAPI_EXTERN napi_status NAPI_CDECL
584
+ napi_set_instance_data(node_api_nogc_env env,
585
+ void* data,
586
+ napi_finalize finalize_cb,
587
+ void* finalize_hint);
584
588
 
585
- NAPI_EXTERN napi_status NAPI_CDECL napi_get_instance_data(napi_env env,
589
+ NAPI_EXTERN napi_status NAPI_CDECL napi_get_instance_data(node_api_nogc_env env,
586
590
  void** data);
587
591
  #endif // NAPI_VERSION >= 6
588
592
 
@@ -22,6 +22,35 @@ typedef uint16_t char16_t;
22
22
  // JSVM API types are all opaque pointers for ABI stability
23
23
  // typedef undefined structs instead of void* for compile time type safety
24
24
  typedef struct napi_env__* napi_env;
25
+
26
+ // We need to mark APIs which can be called during garbage collection (GC),
27
+ // meaning that they do not affect the state of the JS engine, and can
28
+ // therefore be called synchronously from a finalizer that itself runs
29
+ // synchronously during GC. Such APIs can receive either a `napi_env` or a
30
+ // `node_api_nogc_env` as their first parameter, because we should be able to
31
+ // also call them during normal, non-garbage-collecting operations, whereas
32
+ // APIs that affect the state of the JS engine can only receive a `napi_env` as
33
+ // their first parameter, because we must not call them during GC. In lieu of
34
+ // inheritance, we use the properties of the const qualifier to accomplish
35
+ // this, because both a const and a non-const value can be passed to an API
36
+ // expecting a const value, but only a non-const value can be passed to an API
37
+ // expecting a non-const value.
38
+ //
39
+ // In conjunction with appropriate CFLAGS to warn us if we're passing a const
40
+ // (nogc) environment into an API that expects a non-const environment, and the
41
+ // definition of nogc finalizer function pointer types below, which receive a
42
+ // nogc environment as their first parameter, and can thus only call nogc APIs
43
+ // (unless the user explicitly casts the environment), we achieve the ability
44
+ // to ensure at compile time that we do not call APIs that affect the state of
45
+ // the JS engine from a synchronous (nogc) finalizer.
46
+ #if !defined(NAPI_EXPERIMENTAL) || \
47
+ (defined(NAPI_EXPERIMENTAL) && \
48
+ defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT))
49
+ typedef struct napi_env__* node_api_nogc_env;
50
+ #else
51
+ typedef const struct napi_env__* node_api_nogc_env;
52
+ #endif
53
+
25
54
  typedef struct napi_value__* napi_value;
26
55
  typedef struct napi_ref__* napi_ref;
27
56
  typedef struct napi_handle_scope__* napi_handle_scope;
@@ -116,6 +145,16 @@ typedef void(NAPI_CDECL* napi_finalize)(napi_env env,
116
145
  void* finalize_data,
117
146
  void* finalize_hint);
118
147
 
148
+ #if !defined(NAPI_EXPERIMENTAL) || \
149
+ (defined(NAPI_EXPERIMENTAL) && \
150
+ defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT))
151
+ typedef napi_finalize node_api_nogc_finalize;
152
+ #else
153
+ typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env,
154
+ void* finalize_data,
155
+ void* finalize_hint);
156
+ #endif
157
+
119
158
  typedef struct {
120
159
  // One of utf8name or name should be NULL.
121
160
  const char* utf8name;
@@ -141,7 +141,7 @@ NAPI_EXTERN napi_status NAPI_CDECL
141
141
  napi_create_external_buffer(napi_env env,
142
142
  size_t length,
143
143
  void* data,
144
- napi_finalize finalize_cb,
144
+ node_api_nogc_finalize finalize_cb,
145
145
  void* finalize_hint,
146
146
  napi_value* result);
147
147
  #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
@@ -169,20 +169,20 @@ napi_create_async_work(napi_env env,
169
169
  napi_async_work* result);
170
170
  NAPI_EXTERN napi_status NAPI_CDECL napi_delete_async_work(napi_env env,
171
171
  napi_async_work work);
172
- NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(napi_env env,
172
+ NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(node_api_nogc_env env,
173
173
  napi_async_work work);
174
- NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(napi_env env,
174
+ NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(node_api_nogc_env env,
175
175
  napi_async_work work);
176
176
 
177
177
  // version management
178
178
  NAPI_EXTERN napi_status NAPI_CDECL
179
- napi_get_node_version(napi_env env, const napi_node_version** version);
179
+ napi_get_node_version(node_api_nogc_env env, const napi_node_version** version);
180
180
 
181
181
  #if NAPI_VERSION >= 2
182
182
 
183
183
  // Return the current libuv event loop for a given environment
184
184
  NAPI_EXTERN napi_status NAPI_CDECL
185
- napi_get_uv_event_loop(napi_env env, struct uv_loop_s** loop);
185
+ napi_get_uv_event_loop(node_api_nogc_env env, struct uv_loop_s** loop);
186
186
 
187
187
  #endif // NAPI_VERSION >= 2
188
188
 
@@ -191,11 +191,11 @@ napi_get_uv_event_loop(napi_env env, struct uv_loop_s** loop);
191
191
  NAPI_EXTERN napi_status NAPI_CDECL napi_fatal_exception(napi_env env,
192
192
  napi_value err);
193
193
 
194
- NAPI_EXTERN napi_status NAPI_CDECL
195
- napi_add_env_cleanup_hook(napi_env env, napi_cleanup_hook fun, void* arg);
194
+ NAPI_EXTERN napi_status NAPI_CDECL napi_add_env_cleanup_hook(
195
+ node_api_nogc_env env, napi_cleanup_hook fun, void* arg);
196
196
 
197
- NAPI_EXTERN napi_status NAPI_CDECL
198
- napi_remove_env_cleanup_hook(napi_env env, napi_cleanup_hook fun, void* arg);
197
+ NAPI_EXTERN napi_status NAPI_CDECL napi_remove_env_cleanup_hook(
198
+ node_api_nogc_env env, napi_cleanup_hook fun, void* arg);
199
199
 
200
200
  NAPI_EXTERN napi_status NAPI_CDECL
201
201
  napi_open_callback_scope(napi_env env,
@@ -238,18 +238,18 @@ napi_acquire_threadsafe_function(napi_threadsafe_function func);
238
238
  NAPI_EXTERN napi_status NAPI_CDECL napi_release_threadsafe_function(
239
239
  napi_threadsafe_function func, napi_threadsafe_function_release_mode mode);
240
240
 
241
- NAPI_EXTERN napi_status NAPI_CDECL
242
- napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);
241
+ NAPI_EXTERN napi_status NAPI_CDECL napi_unref_threadsafe_function(
242
+ node_api_nogc_env env, napi_threadsafe_function func);
243
243
 
244
- NAPI_EXTERN napi_status NAPI_CDECL
245
- napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
244
+ NAPI_EXTERN napi_status NAPI_CDECL napi_ref_threadsafe_function(
245
+ node_api_nogc_env env, napi_threadsafe_function func);
246
246
 
247
247
  #endif // NAPI_VERSION >= 4
248
248
 
249
249
  #if NAPI_VERSION >= 8
250
250
 
251
251
  NAPI_EXTERN napi_status NAPI_CDECL
252
- napi_add_async_cleanup_hook(napi_env env,
252
+ napi_add_async_cleanup_hook(node_api_nogc_env env,
253
253
  napi_async_cleanup_hook hook,
254
254
  void* arg,
255
255
  napi_async_cleanup_hook_handle* remove_handle);
@@ -262,7 +262,7 @@ napi_remove_async_cleanup_hook(napi_async_cleanup_hook_handle remove_handle);
262
262
  #if NAPI_VERSION >= 9
263
263
 
264
264
  NAPI_EXTERN napi_status NAPI_CDECL
265
- node_api_get_module_file_name(napi_env env, const char** result);
265
+ node_api_get_module_file_name(node_api_nogc_env env, const char** result);
266
266
 
267
267
  #endif // NAPI_VERSION >= 9
268
268
 
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "emnapi",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Node-API implementation for Emscripten",
5
5
  "main": "index.js",
6
+ "gypfile": false,
6
7
  "peerDependencies": {
7
8
  "node-addon-api": ">= 6.1.0"
8
9
  },
@@ -72,11 +72,11 @@ EXTERN_C_END
72
72
 
73
73
  EXTERN_C_START
74
74
 
75
- EMNAPI_INTERNAL_EXTERN napi_status napi_set_last_error(napi_env env,
75
+ EMNAPI_INTERNAL_EXTERN napi_status napi_set_last_error(node_api_nogc_env env,
76
76
  napi_status error_code,
77
77
  uint32_t engine_error_code,
78
78
  void* engine_reserved);
79
- EMNAPI_INTERNAL_EXTERN napi_status napi_clear_last_error(napi_env env);
79
+ EMNAPI_INTERNAL_EXTERN napi_status napi_clear_last_error(node_api_nogc_env env);
80
80
 
81
81
  #ifdef __EMSCRIPTEN__
82
82
  #if __EMSCRIPTEN_major__ * 10000 + __EMSCRIPTEN_minor__ * 100 + __EMSCRIPTEN_tiny__ >= 30114 // NOLINT