emnapi 1.1.1 → 1.3.0

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 (55) hide show
  1. package/CMakeLists.txt +27 -5
  2. package/README.md +39 -11
  3. package/common.gypi +4 -4
  4. package/dist/library_napi.js +56 -35
  5. package/emnapi.gyp +4 -1
  6. package/include/node/emnapi.h +2 -2
  7. package/include/node/js_native_api.h +30 -25
  8. package/include/node/js_native_api_types.h +13 -9
  9. package/include/node/node_api.h +13 -13
  10. package/include/node/uv/threadpool.h +1 -1
  11. package/include/node/uv/unix.h +4 -0
  12. package/include/node/uv.h +49 -6
  13. package/lib/wasm32/libdlmalloc-mt.a +0 -0
  14. package/lib/wasm32/libdlmalloc.a +0 -0
  15. package/lib/wasm32/libemmalloc-mt.a +0 -0
  16. package/lib/wasm32/libemmalloc.a +0 -0
  17. package/lib/wasm32/libemnapi-basic-mt.a +0 -0
  18. package/lib/wasm32/libemnapi-basic.a +0 -0
  19. package/lib/wasm32/libemnapi.a +0 -0
  20. package/lib/wasm32-emscripten/libemnapi-basic.a +0 -0
  21. package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
  22. package/lib/wasm32-emscripten/libemnapi.a +0 -0
  23. package/lib/wasm32-wasi/libemnapi-basic-mt.a +0 -0
  24. package/lib/wasm32-wasi/libemnapi-basic.a +0 -0
  25. package/lib/wasm32-wasi/libemnapi.a +0 -0
  26. package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
  27. package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
  28. package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
  29. package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
  30. package/lib/wasm32-wasip1/libemnapi-basic-mt.a +0 -0
  31. package/lib/wasm32-wasip1/libemnapi-basic.a +0 -0
  32. package/lib/wasm32-wasip1/libemnapi.a +0 -0
  33. package/lib/wasm32-wasip1-threads/libemnapi-basic-mt.a +0 -0
  34. package/lib/wasm32-wasip1-threads/libemnapi-basic.a +0 -0
  35. package/lib/wasm32-wasip1-threads/libemnapi-mt.a +0 -0
  36. package/lib/wasm32-wasip1-threads/libemnapi.a +0 -0
  37. package/lib/wasm64-emscripten/libemnapi-basic.a +0 -0
  38. package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
  39. package/lib/wasm64-emscripten/libemnapi.a +0 -0
  40. package/package.json +1 -1
  41. package/src/async_cleanup_hook.c +1 -1
  42. package/src/async_work.c +2 -2
  43. package/src/emnapi_internal.h +2 -2
  44. package/src/js_native_api.c +2 -1
  45. package/src/node_api.c +5 -5
  46. package/src/threadsafe_function.c +20 -21
  47. package/src/uv/queue.h +68 -86
  48. package/src/uv/threadpool.c +58 -40
  49. package/src/uv/unix/async.c +67 -64
  50. package/src/uv/unix/core.c +36 -1
  51. package/src/uv/unix/internal.h +54 -0
  52. package/src/uv/unix/loop.c +40 -4
  53. package/src/uv/unix/posix-hrtime.c +40 -0
  54. package/src/uv/uv-common.c +123 -7
  55. package/src/uv/uv-common.h +137 -9
package/CMakeLists.txt CHANGED
@@ -17,10 +17,23 @@ else()
17
17
  set(IS_WASM32 OFF)
18
18
  endif()
19
19
 
20
+ if((CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasi") OR (CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasip1"))
21
+ set(IS_WASM32_WASIP1 ON)
22
+ else()
23
+ set(IS_WASM32_WASIP1 OFF)
24
+ endif()
25
+
26
+ if((CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasi-threads") OR (CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasip1-threads"))
27
+ set(IS_WASM32_WASIP1_THREADS ON)
28
+ else()
29
+ set(IS_WASM32_WASIP1_THREADS OFF)
30
+ endif()
31
+
20
32
  set(UV_SRC
21
33
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/uv-common.c"
22
34
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/threadpool.c"
23
35
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/loop.c"
36
+ "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/posix-hrtime.c"
24
37
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/thread.c"
25
38
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/async.c"
26
39
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/core.c"
@@ -127,13 +140,16 @@ endif()
127
140
 
128
141
  add_library(${EMNAPI_BASIC_TARGET_NAME} STATIC ${ENAPI_BASIC_SRC})
129
142
  target_include_directories(${EMNAPI_BASIC_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
130
- target_compile_definitions(${EMNAPI_BASIC_TARGET_NAME} PUBLIC ${EMNAPI_DEFINES})
143
+ target_compile_definitions(${EMNAPI_BASIC_TARGET_NAME}
144
+ PUBLIC ${EMNAPI_DEFINES}
145
+ PRIVATE "EMNAPI_DISABLE_UV"
146
+ )
131
147
  if(IS_EMSCRIPTEN)
132
148
  set_target_properties(${EMNAPI_BASIC_TARGET_NAME} PROPERTIES INTERFACE_LINK_DEPENDS ${EMNAPI_JS_LIB})
133
149
  target_link_options(${EMNAPI_BASIC_TARGET_NAME} INTERFACE "--js-library=${EMNAPI_JS_LIB}")
134
150
  endif()
135
151
 
136
- if(IS_WASM32 OR (CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasi") OR (CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasi-threads"))
152
+ if(IS_WASM32 OR IS_WASM32_WASIP1 OR IS_WASM32_WASIP1_THREADS)
137
153
  set(EMNAPI_BUILD_BASIC_MT ON)
138
154
  else()
139
155
  set(EMNAPI_BUILD_BASIC_MT OFF)
@@ -147,7 +163,10 @@ if(EMNAPI_BUILD_BASIC_MT)
147
163
  )
148
164
  target_compile_options(${EMNAPI_BASIC_MT_TARGET_NAME} PUBLIC "-matomics" "-mbulk-memory")
149
165
  target_include_directories(${EMNAPI_BASIC_MT_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
150
- target_compile_definitions(${EMNAPI_BASIC_MT_TARGET_NAME} PUBLIC ${EMNAPI_DEFINES})
166
+ target_compile_definitions(${EMNAPI_BASIC_MT_TARGET_NAME}
167
+ PUBLIC ${EMNAPI_DEFINES}
168
+ PRIVATE "EMNAPI_DISABLE_UV"
169
+ )
151
170
 
152
171
  if(IS_EMSCRIPTEN)
153
172
  set_target_properties(${EMNAPI_BASIC_MT_TARGET_NAME} PROPERTIES INTERFACE_LINK_DEPENDS ${EMNAPI_JS_LIB})
@@ -155,7 +174,7 @@ if(EMNAPI_BUILD_BASIC_MT)
155
174
  endif()
156
175
  endif()
157
176
 
158
- if(IS_EMSCRIPTEN OR (CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasi-threads"))
177
+ if(IS_EMSCRIPTEN OR IS_WASM32_WASIP1_THREADS)
159
178
  set(EMNAPI_BUILD_MT ON)
160
179
  else()
161
180
  set(EMNAPI_BUILD_MT OFF)
@@ -163,7 +182,10 @@ endif()
163
182
 
164
183
  if(EMNAPI_BUILD_MT)
165
184
  add_library(${EMNAPI_MT_TARGET_NAME} STATIC ${EMNAPI_SRC} ${UV_SRC})
166
- target_compile_options(${EMNAPI_MT_TARGET_NAME} PRIVATE ${EMNAPI_MT_CFLAGS})
185
+ target_compile_options(${EMNAPI_MT_TARGET_NAME}
186
+ PUBLIC "-matomics" "-mbulk-memory"
187
+ PRIVATE ${EMNAPI_MT_CFLAGS}
188
+ )
167
189
  target_include_directories(${EMNAPI_MT_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
168
190
  target_compile_definitions(${EMNAPI_MT_TARGET_NAME} PUBLIC ${EMNAPI_DEFINES})
169
191
  if(IS_EMSCRIPTEN)
package/README.md CHANGED
@@ -23,6 +23,8 @@ This project aims to
23
23
 
24
24
  This project also powers the WebAssembly feature for [napi-rs](https://github.com/napi-rs/napi-rs), and enables many Node.js native addons to run on [StackBlitz](https://stackblitz.com)'s WebContainer.
25
25
 
26
+ [Node-API changes](https://github.com/nodejs/node/pulls?q=is%3Apr+label%3Anode-api+) will be synchronized into this repo.
27
+
26
28
  See documentation for more details:
27
29
  - [https://toyobayashi.github.io/emnapi-docs/guide/](https://toyobayashi.github.io/emnapi-docs/guide/)
28
30
  - [https://emnapi-docs.vercel.app/guide/](https://emnapi-docs.vercel.app/guide/)
@@ -628,9 +630,10 @@ Output code can run in recent version modern browsers and Node.js latest LTS. IE
628
630
  ### Using node-gyp (Experimental)
629
631
 
630
632
  Currently node-gyp works on Linux only and don't support static library linking in cross-compiling.
631
- There are opened PRs to try to make node-gyp work fine.
633
+ There are related PRs to try to make node-gyp work fine.
632
634
 
633
635
  - https://github.com/nodejs/gyp-next/pull/222
636
+ - https://github.com/nodejs/gyp-next/pull/240
634
637
  - https://github.com/nodejs/node-gyp/pull/2974
635
638
 
636
639
  If you experienced issues on Windows or macOS, please check the PRs for upstream changes detail and see
@@ -643,7 +646,7 @@ Arch: `node-gyp configure --arch=<wasm32 | wasm64>`
643
646
  ```ts
644
647
  // node-gyp configure -- -Dvariable_name=value
645
648
 
646
- declare var OS: 'emscripten' | 'wasi' | 'unknown' | ''
649
+ declare var OS: 'emscripten' | 'wasi' | 'unknown' | 'wasm' | ''
647
650
 
648
651
  /**
649
652
  * Enable async work and threadsafe-functions
@@ -699,7 +702,7 @@ declare var emnapi_manual_linking: 0 | 1
699
702
  ["OS == 'wasi'", {
700
703
  # ...
701
704
  }],
702
- ["OS == 'unknown' or OS == ''", {
705
+ ["OS in ' wasm unknown'", {
703
706
  # ...
704
707
  }]
705
708
  ]
@@ -750,19 +753,19 @@ call set CXX_target=%%WASI_SDK_PATH:\=/%%/bin/clang++.exe
750
753
  emmake node-gyp rebuild \
751
754
  --arch=wasm32 \
752
755
  --nodedir=./node_modules/emnapi \
753
- -- -f make-linux -DOS=emscripten # -Dwasm_threads=1
756
+ -- -f make-emscripten # -Dwasm_threads=1
754
757
 
755
758
  # wasi
756
759
  node-gyp rebuild \
757
760
  --arch=wasm32 \
758
761
  --nodedir=./node_modules/emnapi \
759
- -- -f make-linux -DOS=wasi # -Dwasm_threads=1
762
+ -- -f make-wasi # -Dwasm_threads=1
760
763
 
761
764
  # bare wasm32
762
765
  node-gyp rebuild \
763
766
  --arch=wasm32 \
764
767
  --nodedir=./node_modules/emnapi \
765
- -- -f make-linux -DOS=unknown # -Dwasm_threads=1
768
+ -- -f make-wasm # -Dwasm_threads=1
766
769
  ```
767
770
 
768
771
  ```bat
@@ -770,15 +773,15 @@ node-gyp rebuild \
770
773
  @REM Run the bat file in POSIX-like environment (e.g. Cygwin)
771
774
 
772
775
  @REM emscripten
773
- call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-linux -DOS=emscripten
776
+ call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-emscripten
774
777
  call emmake.bat make -C %~dp0build
775
778
 
776
779
  @REM wasi
777
- call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-linux -DOS=wasi
780
+ call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-wasi
778
781
  make -C %~dp0build
779
782
 
780
783
  @REM bare wasm32
781
- call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-linux -DOS=unknown
784
+ call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-wasm
782
785
  make -C %~dp0build
783
786
  ```
784
787
 
@@ -935,7 +938,32 @@ instantiateNapiModule(input, {
935
938
  */
936
939
  asyncWorkPoolSize: 4, // 0: single thread mock, > 0: schedule async work in web worker
937
940
  wasi: new WASI(/* ... */),
938
- // reuseWorker: true,
941
+
942
+ /**
943
+ * Setting this to `true` or a delay (ms) makes
944
+ * pthread_create() do not return until worker actually start.
945
+ * It will throw error if emnapi runs in browser main thread
946
+ * since browser disallow blocking the main thread (Atomics.wait).
947
+ * @defaultValue false
948
+ */
949
+ waitThreadStart: isNode || (isBrowser && !isBrowserMainThread),
950
+
951
+ /**
952
+ * Reuse the thread worker after thread exit to avoid re-creatation
953
+ * @defaultValue false
954
+ */
955
+ reuseWorker: {
956
+ /**
957
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
958
+ */
959
+ size: 0,
960
+
961
+ /**
962
+ * @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
963
+ */
964
+ strict: false
965
+ },
966
+
939
967
  onCreateWorker () {
940
968
  return new Worker('./worker.js')
941
969
  // Node.js
@@ -988,7 +1016,7 @@ instantiateNapiModule(input, {
988
1016
  }
989
1017
  })
990
1018
 
991
- WASI = require('./wasi').WASI
1019
+ WASI = require('wasi').WASI
992
1020
  emnapiCore = require('@emnapi/core')
993
1021
  } else {
994
1022
  importScripts('./node_modules/memfs-browser/dist/memfs.js')
package/common.gypi CHANGED
@@ -2,7 +2,7 @@
2
2
  # in https://github.com/lovell/sharp/pull/3522
3
3
  {
4
4
  'variables': {
5
- # OS: 'emscripten' | 'wasi' | 'unknown'
5
+ # OS: 'emscripten' | 'wasi' | 'unknown' | 'wasm'
6
6
  'clang': 1,
7
7
  'target_arch%': 'wasm32',
8
8
  'wasm_threads%': 0,
@@ -139,7 +139,7 @@
139
139
  }],
140
140
  ],
141
141
  }],
142
- ['OS in "wasi unknown "', {
142
+ ['OS in "wasi wasm unknown "', {
143
143
  'configurations': {
144
144
  'Release': {
145
145
  'ldflags': [ '-Wl,--strip-debug' ],
@@ -239,7 +239,7 @@
239
239
  'target_conditions': [
240
240
  ['_type=="executable"', {
241
241
  'conditions': [
242
- ['OS in "wasi unknown "', {
242
+ ['OS in "wasi wasm unknown "', {
243
243
  'product_extension': 'wasm',
244
244
 
245
245
  'ldflags': [
@@ -326,7 +326,7 @@
326
326
  }]
327
327
  ],
328
328
  }],
329
- ['OS in "wasi unknown "', {
329
+ ['OS in "wasi wasm unknown "', {
330
330
  'product_extension': 'wasm',
331
331
 
332
332
  'ldflags': [
@@ -958,7 +958,7 @@ var emnapiExternalMemory = {
958
958
  var _a;
959
959
  var info = {
960
960
  address: 0,
961
- ownership: 0 /* Ownership.kRuntime */,
961
+ ownership: 0 /* ReferenceOwnership.kRuntime */,
962
962
  runtimeAllocated: 0
963
963
  };
964
964
  if (arrayBuffer === wasmMemory.buffer) {
@@ -971,7 +971,7 @@ var emnapiExternalMemory = {
971
971
  cachedInfo.address = 0;
972
972
  return cachedInfo;
973
973
  }
974
- if (shouldCopy && cachedInfo.ownership === 0 /* Ownership.kRuntime */ && cachedInfo.runtimeAllocated === 1) {
974
+ if (shouldCopy && cachedInfo.ownership === 0 /* ReferenceOwnership.kRuntime */ && cachedInfo.runtimeAllocated === 1) {
975
975
  new Uint8Array(wasmMemory.buffer).set(new Uint8Array(arrayBuffer), cachedInfo.address);
976
976
  }
977
977
  return cachedInfo;
@@ -987,7 +987,7 @@ var emnapiExternalMemory = {
987
987
  throw new Error('Out of memory');
988
988
  new Uint8Array(wasmMemory.buffer).set(new Uint8Array(arrayBuffer), pointer);
989
989
  info.address = pointer;
990
- info.ownership = emnapiExternalMemory.registry ? 0 /* Ownership.kRuntime */ : 1 /* Ownership.kUserland */;
990
+ info.ownership = emnapiExternalMemory.registry ? 0 /* ReferenceOwnership.kRuntime */ : 1 /* ReferenceOwnership.kUserland */;
991
991
  info.runtimeAllocated = 1;
992
992
  emnapiExternalMemory.table.set(arrayBuffer, info);
993
993
  (_a = emnapiExternalMemory.registry) === null || _a === void 0 ? void 0 : _a.register(arrayBuffer, pointer);
@@ -1000,7 +1000,7 @@ var emnapiExternalMemory = {
1000
1000
  Ctor: view.constructor,
1001
1001
  address: view.byteOffset,
1002
1002
  length: view instanceof DataView ? view.byteLength : view.length,
1003
- ownership: 1 /* Ownership.kUserland */,
1003
+ ownership: 1 /* ReferenceOwnership.kUserland */,
1004
1004
  runtimeAllocated: 0
1005
1005
  });
1006
1006
  }
@@ -1031,7 +1031,7 @@ var emnapiExternalMemory = {
1031
1031
  var _a = emnapiExternalMemory.wasmMemoryViewTable.get(view), address_1 = _a.address, ownership_1 = _a.ownership, runtimeAllocated_1 = _a.runtimeAllocated;
1032
1032
  return { address: address_1, ownership: ownership_1, runtimeAllocated: runtimeAllocated_1, view: view };
1033
1033
  }
1034
- return { address: view.byteOffset, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0, view: view };
1034
+ return { address: view.byteOffset, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0, view: view };
1035
1035
  }
1036
1036
  var _b = emnapiExternalMemory.getArrayBufferPointer(view.buffer, shouldCopy), address = _b.address, ownership = _b.ownership, runtimeAllocated = _b.runtimeAllocated;
1037
1037
  return { address: address === 0 ? 0 : (address + view.byteOffset), ownership: ownership, runtimeAllocated: runtimeAllocated, view: view };
@@ -1235,7 +1235,7 @@ 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(emnapiCtx.feature.Buffer))
1239
1239
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
1240
1240
  return _napi_get_typedarray_info(env, buffer, 0, length, data, 0, 0);
1241
1241
  }
@@ -1867,6 +1867,18 @@ function _node_api_create_external_string_latin1(env, str, length, finalize_call
1867
1867
  function _node_api_create_external_string_utf16(env, str, length, finalize_callback, finalize_hint, result, copied) {
1868
1868
  return emnapiString.newExternalString(env, str, length, finalize_callback, finalize_hint, result, copied, _napi_create_string_utf16, undefined);
1869
1869
  }
1870
+ /**
1871
+ * @__sig ipppp
1872
+ */
1873
+ function _node_api_create_property_key_latin1(env, str, length, result) {
1874
+ return _napi_create_string_latin1(env, str, length, result);
1875
+ }
1876
+ /**
1877
+ * @__sig ipppp
1878
+ */
1879
+ function _node_api_create_property_key_utf8(env, str, length, result) {
1880
+ return _napi_create_string_utf8(env, str, length, result);
1881
+ }
1870
1882
  /**
1871
1883
  * @__sig ipppp
1872
1884
  */
@@ -2128,13 +2140,16 @@ function emnapiWrap(env, js_object, native_object, finalize_cb, finalize_hint, r
2128
2140
  if (result) {
2129
2141
  if (!finalize_cb)
2130
2142
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
2131
- reference = emnapiCtx.createReference(envObject, handle.id, 0, 1 /* Ownership.kUserland */, finalize_cb, native_object, finalize_hint);
2143
+ reference = emnapiCtx.createReferenceWithFinalizer(envObject, handle.id, 0, 1 /* ReferenceOwnership.kUserland */, finalize_cb, native_object, finalize_hint);
2132
2144
  {{{ from64('result') }}};
2133
2145
  referenceId = reference.id;
2134
2146
  {{{ makeSetValue('result', 0, 'referenceId', '*') }}};
2135
2147
  }
2148
+ else if (finalize_cb) {
2149
+ reference = emnapiCtx.createReferenceWithFinalizer(envObject, handle.id, 0, 0 /* ReferenceOwnership.kRuntime */, finalize_cb, native_object, finalize_hint);
2150
+ }
2136
2151
  else {
2137
- reference = emnapiCtx.createReference(envObject, handle.id, 0, 0 /* Ownership.kRuntime */, finalize_cb, native_object, !finalize_cb ? finalize_cb : finalize_hint);
2152
+ reference = emnapiCtx.createReferenceWithData(envObject, handle.id, 0, 0 /* ReferenceOwnership.kRuntime */, native_object);
2138
2153
  }
2139
2154
  envObject.getObjectBinding(handle.value).wrapped = reference.id;
2140
2155
  return envObject.getReturnStatus();
@@ -2181,7 +2196,7 @@ function emnapiUnwrap(env, js_object, result, action) {
2181
2196
  }
2182
2197
  if (action === 1 /* UnwrapAction.RemoveWrap */) {
2183
2198
  binding.wrapped = 0;
2184
- if (ref.ownership() === 1 /* Ownership.kUserland */) {
2199
+ if (ref.ownership() === 1 /* ReferenceOwnership.kUserland */) {
2185
2200
  // When the wrap is been removed, the finalizer should be reset.
2186
2201
  ref.resetFinalizer();
2187
2202
  }
@@ -2406,11 +2421,11 @@ function _napi_add_finalizer(env, js_object, finalize_data, finalize_cb, finaliz
2406
2421
  return envObject.setLastError(handleResult.status);
2407
2422
  }
2408
2423
  var handle = handleResult.handle;
2409
- var ownership = !result ? 0 /* Ownership.kRuntime */ : 1 /* Ownership.kUserland */;
2424
+ var ownership = !result ? 0 /* ReferenceOwnership.kRuntime */ : 1 /* ReferenceOwnership.kUserland */;
2410
2425
  {{{ from64('finalize_data') }}};
2411
2426
  {{{ from64('finalize_cb') }}};
2412
2427
  {{{ from64('finalize_hint') }}};
2413
- var reference = emnapiCtx.createReference(envObject, handle.id, 0, ownership, finalize_cb, finalize_data, finalize_hint);
2428
+ var reference = emnapiCtx.createReferenceWithFinalizer(envObject, handle.id, 0, ownership, finalize_cb, finalize_data, finalize_hint);
2414
2429
  if (result) {
2415
2430
  {{{ from64('result') }}};
2416
2431
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -2467,46 +2482,46 @@ function _emnapi_create_memory_view(env, typedarray_type, external_data, byte_le
2467
2482
  var viewDescriptor = void 0;
2468
2483
  switch (typedarray_type) {
2469
2484
  case 0 /* emnapi_memory_view_type.emnapi_int8_array */:
2470
- viewDescriptor = { Ctor: Int8Array, address: external_data, length: byte_length, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2485
+ viewDescriptor = { Ctor: Int8Array, address: external_data, length: byte_length, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2471
2486
  break;
2472
2487
  case 1 /* emnapi_memory_view_type.emnapi_uint8_array */:
2473
- viewDescriptor = { Ctor: Uint8Array, address: external_data, length: byte_length, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2488
+ viewDescriptor = { Ctor: Uint8Array, address: external_data, length: byte_length, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2474
2489
  break;
2475
2490
  case 2 /* emnapi_memory_view_type.emnapi_uint8_clamped_array */:
2476
- viewDescriptor = { Ctor: Uint8ClampedArray, address: external_data, length: byte_length, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2491
+ viewDescriptor = { Ctor: Uint8ClampedArray, address: external_data, length: byte_length, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2477
2492
  break;
2478
2493
  case 3 /* emnapi_memory_view_type.emnapi_int16_array */:
2479
- viewDescriptor = { Ctor: Int16Array, address: external_data, length: byte_length >> 1, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2494
+ viewDescriptor = { Ctor: Int16Array, address: external_data, length: byte_length >> 1, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2480
2495
  break;
2481
2496
  case 4 /* emnapi_memory_view_type.emnapi_uint16_array */:
2482
- viewDescriptor = { Ctor: Uint16Array, address: external_data, length: byte_length >> 1, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2497
+ viewDescriptor = { Ctor: Uint16Array, address: external_data, length: byte_length >> 1, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2483
2498
  break;
2484
2499
  case 5 /* emnapi_memory_view_type.emnapi_int32_array */:
2485
- viewDescriptor = { Ctor: Int32Array, address: external_data, length: byte_length >> 2, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2500
+ viewDescriptor = { Ctor: Int32Array, address: external_data, length: byte_length >> 2, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2486
2501
  break;
2487
2502
  case 6 /* emnapi_memory_view_type.emnapi_uint32_array */:
2488
- viewDescriptor = { Ctor: Uint32Array, address: external_data, length: byte_length >> 2, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2503
+ viewDescriptor = { Ctor: Uint32Array, address: external_data, length: byte_length >> 2, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2489
2504
  break;
2490
2505
  case 7 /* emnapi_memory_view_type.emnapi_float32_array */:
2491
- viewDescriptor = { Ctor: Float32Array, address: external_data, length: byte_length >> 2, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2506
+ viewDescriptor = { Ctor: Float32Array, address: external_data, length: byte_length >> 2, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2492
2507
  break;
2493
2508
  case 8 /* emnapi_memory_view_type.emnapi_float64_array */:
2494
- viewDescriptor = { Ctor: Float64Array, address: external_data, length: byte_length >> 3, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2509
+ viewDescriptor = { Ctor: Float64Array, address: external_data, length: byte_length >> 3, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2495
2510
  break;
2496
2511
  case 9 /* emnapi_memory_view_type.emnapi_bigint64_array */:
2497
- viewDescriptor = { Ctor: BigInt64Array, address: external_data, length: byte_length >> 3, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2512
+ viewDescriptor = { Ctor: BigInt64Array, address: external_data, length: byte_length >> 3, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2498
2513
  break;
2499
2514
  case 10 /* emnapi_memory_view_type.emnapi_biguint64_array */:
2500
- viewDescriptor = { Ctor: BigUint64Array, address: external_data, length: byte_length >> 3, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2515
+ viewDescriptor = { Ctor: BigUint64Array, address: external_data, length: byte_length >> 3, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2501
2516
  break;
2502
2517
  case -1 /* emnapi_memory_view_type.emnapi_data_view */:
2503
- viewDescriptor = { Ctor: DataView, address: external_data, length: byte_length, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2518
+ viewDescriptor = { Ctor: DataView, address: external_data, length: byte_length, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2504
2519
  break;
2505
2520
  case -2 /* emnapi_memory_view_type.emnapi_buffer */: {
2506
2521
  if (!emnapiCtx.feature.Buffer) {
2507
2522
  throw emnapiCtx.createNotSupportBufferError('emnapi_create_memory_view', '');
2508
2523
  }
2509
- viewDescriptor = { Ctor: emnapiCtx.feature.Buffer, address: external_data, length: byte_length, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
2524
+ viewDescriptor = { Ctor: emnapiCtx.feature.Buffer, address: external_data, length: byte_length, ownership: 1 /* ReferenceOwnership.kUserland */, runtimeAllocated: 0 };
2510
2525
  break;
2511
2526
  }
2512
2527
  default: return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
@@ -2869,7 +2884,7 @@ function _napi_create_external(env, data, finalize_cb, finalize_hint, result) {
2869
2884
  }
2870
2885
  var externalHandle = emnapiCtx.getCurrentScope().addExternal(envObject, data);
2871
2886
  if (finalize_cb) {
2872
- emnapiCtx.createReference(envObject, externalHandle.id, 0, 0 /* Ownership.kRuntime */, finalize_cb, data, finalize_hint);
2887
+ emnapiCtx.createReferenceWithFinalizer(envObject, externalHandle.id, 0, 0 /* ReferenceOwnership.kRuntime */, finalize_cb, data, finalize_hint);
2873
2888
  }
2874
2889
  {{{ from64('result') }}};
2875
2890
  value = externalHandle.id;
@@ -2927,7 +2942,7 @@ function _napi_create_external_arraybuffer(env, external_data, byte_length, fina
2927
2942
  u8arr.set(new Uint8Array(wasmMemory.buffer).subarray(external_data, external_data + byte_length));
2928
2943
  emnapiExternalMemory.table.set(arrayBuffer, {
2929
2944
  address: external_data,
2930
- ownership: 1 /* Ownership.kUserland */,
2945
+ ownership: 1 /* ReferenceOwnership.kUserland */,
2931
2946
  runtimeAllocated: 0
2932
2947
  });
2933
2948
  }
@@ -3051,7 +3066,7 @@ function _napi_create_typedarray(env, type, length, arraybuffer, byte_offset, re
3051
3066
  Ctor: Type,
3052
3067
  address: byte_offset,
3053
3068
  length: length,
3054
- ownership: 1 /* Ownership.kUserland */,
3069
+ ownership: 1 /* ReferenceOwnership.kUserland */,
3055
3070
  runtimeAllocated: 0
3056
3071
  });
3057
3072
  }
@@ -3138,7 +3153,7 @@ function _napi_create_buffer(env, size, data, result) {
3138
3153
  Ctor: Buffer,
3139
3154
  address: pointer,
3140
3155
  length: size,
3141
- ownership: emnapiExternalMemory.registry ? 0 /* Ownership.kRuntime */ : 1 /* Ownership.kUserland */,
3156
+ ownership: emnapiExternalMemory.registry ? 0 /* ReferenceOwnership.kRuntime */ : 1 /* ReferenceOwnership.kUserland */,
3142
3157
  runtimeAllocated: 1
3143
3158
  };
3144
3159
  emnapiExternalMemory.wasmMemoryViewTable.set(buffer_1, viewDescriptor);
@@ -3241,7 +3256,7 @@ function _napi_create_dataview(env, byte_length, arraybuffer, byte_offset, resul
3241
3256
  Ctor: DataView,
3242
3257
  address: byte_offset,
3243
3258
  length: byte_length,
3244
- ownership: 1 /* Ownership.kUserland */,
3259
+ ownership: 1 /* ReferenceOwnership.kUserland */,
3245
3260
  runtimeAllocated: 0
3246
3261
  });
3247
3262
  }
@@ -4032,7 +4047,7 @@ function _napi_create_reference(env, value, initial_refcount, result) {
4032
4047
  }
4033
4048
  }
4034
4049
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4035
- var ref = emnapiCtx.createReference(envObject, handle.id, initial_refcount >>> 0, 1 /* Ownership.kUserland */);
4050
+ var ref = emnapiCtx.createReference(envObject, handle.id, initial_refcount >>> 0, 1 /* ReferenceOwnership.kUserland */);
4036
4051
  {{{ from64('result') }}};
4037
4052
  {{{ makeSetValue('result', 0, 'ref.id', '*') }}};
4038
4053
  return envObject.clearLastError();
@@ -4076,7 +4091,7 @@ function _napi_reference_unref(env, ref, result) {
4076
4091
  if (!ref)
4077
4092
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
4078
4093
  var reference = emnapiCtx.refStore.get(ref);
4079
- var refcount = reference.refCount();
4094
+ var refcount = reference.refcount();
4080
4095
  if (refcount === 0) {
4081
4096
  return envObject.setLastError(9 /* napi_status.napi_generic_failure */);
4082
4097
  }
@@ -4101,7 +4116,7 @@ function _napi_get_reference_value(env, ref, result) {
4101
4116
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
4102
4117
  var reference = emnapiCtx.refStore.get(ref);
4103
4118
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4104
- var handleId = reference.get();
4119
+ var handleId = reference.get(envObject);
4105
4120
  {{{ from64('result') }}};
4106
4121
  {{{ makeSetValue('result', 0, 'handleId', '*') }}};
4107
4122
  return envObject.clearLastError();
@@ -5911,7 +5926,7 @@ function _napi_create_threadsafe_function(env, func, async_resource, async_resou
5911
5926
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
5912
5927
  }
5913
5928
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
5914
- ref = emnapiCtx.createReference(envObject, func, 1, 1 /* Ownership.kUserland */).id;
5929
+ ref = emnapiCtx.createReference(envObject, func, 1, 1 /* ReferenceOwnership.kUserland */).id;
5915
5930
  }
5916
5931
  var asyncResourceObject;
5917
5932
  if (async_resource) {
@@ -5937,7 +5952,7 @@ function _napi_create_threadsafe_function(env, func, async_resource, async_resou
5937
5952
  if (!tsfn)
5938
5953
  return envObject.setLastError(9 /* napi_status.napi_generic_failure */);
5939
5954
  new Uint8Array(wasmMemory.buffer).subarray(tsfn, tsfn + sizeofTSFN).fill(0);
5940
- var resourceRef = emnapiCtx.createReference(envObject, resource, 1, 1 /* Ownership.kUserland */);
5955
+ var resourceRef = emnapiCtx.createReference(envObject, resource, 1, 1 /* ReferenceOwnership.kUserland */);
5941
5956
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
5942
5957
  var resource_ = resourceRef.id;
5943
5958
  {{{ makeSetValue('tsfn', 0, 'resource_', '*') }}};
@@ -6393,7 +6408,7 @@ function _napi_is_buffer(env, value, result) {
6393
6408
  var h = emnapiCtx.handleStore.get(value);
6394
6409
  {{{ from64('result') }}};
6395
6410
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
6396
- var r = h.isBuffer() ? 1 : 0;
6411
+ var r = h.isBuffer(emnapiCtx.feature.Buffer) ? 1 : 0;
6397
6412
  {{{ makeSetValue('result', 0, 'r', 'i8') }}};
6398
6413
  return envObject.clearLastError();
6399
6414
  }
@@ -7074,9 +7089,15 @@ function _napi_get_version(env, result) {
7074
7089
  node_api_create_external_string_utf16: _node_api_create_external_string_utf16,
7075
7090
  node_api_create_external_string_utf16__deps: ["$emnapiString", "napi_create_string_utf16"],
7076
7091
  node_api_create_external_string_utf16__sig: "ippppppp",
7092
+ node_api_create_property_key_latin1: _node_api_create_property_key_latin1,
7093
+ node_api_create_property_key_latin1__deps: ["napi_create_string_latin1"],
7094
+ node_api_create_property_key_latin1__sig: "ipppp",
7077
7095
  node_api_create_property_key_utf16: _node_api_create_property_key_utf16,
7078
7096
  node_api_create_property_key_utf16__deps: ["napi_create_string_utf16"],
7079
7097
  node_api_create_property_key_utf16__sig: "ipppp",
7098
+ node_api_create_property_key_utf8: _node_api_create_property_key_utf8,
7099
+ node_api_create_property_key_utf8__deps: ["napi_create_string_utf8"],
7100
+ node_api_create_property_key_utf8__sig: "ipppp",
7080
7101
  node_api_create_syntax_error: _node_api_create_syntax_error,
7081
7102
  node_api_create_syntax_error__deps: ["$emnapiCtx"],
7082
7103
  node_api_create_syntax_error__sig: "ipppp",
package/emnapi.gyp CHANGED
@@ -47,6 +47,9 @@
47
47
  {
48
48
  'target_name': 'emnapi_basic',
49
49
  'type': 'static_library',
50
+ 'defines': [
51
+ 'EMNAPI_DISABLE_UV'
52
+ ],
50
53
  'sources': [
51
54
  'src/js_native_api.c',
52
55
  'src/node_api.c',
@@ -63,7 +66,7 @@
63
66
  ]
64
67
  },
65
68
  'conditions': [
66
- ['wasm_threads != 0 and OS in " unknown wasi"', {
69
+ ['wasm_threads != 0 and OS in " unknown wasm wasi"', {
67
70
  'sources': [
68
71
  'src/thread/async_worker_create.c',
69
72
  '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 1
10
- #define EMNAPI_PATCH_VERSION 1
9
+ #define EMNAPI_MINOR_VERSION 3
10
+ #define EMNAPI_PATCH_VERSION 0
11
11
 
12
12
  typedef enum {
13
13
  emnapi_runtime,