emnapi 1.2.0 → 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 (41) hide show
  1. package/CMakeLists.txt +13 -3
  2. package/dist/library_napi.js +54 -33
  3. package/emnapi.gyp +3 -0
  4. package/include/node/emnapi.h +1 -1
  5. package/include/node/js_native_api.h +30 -25
  6. package/include/node/js_native_api_types.h +13 -9
  7. package/include/node/node_api.h +13 -13
  8. package/include/node/uv/threadpool.h +1 -1
  9. package/include/node/uv/unix.h +4 -0
  10. package/include/node/uv.h +49 -6
  11. package/lib/wasm32/libemnapi.a +0 -0
  12. package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
  13. package/lib/wasm32-emscripten/libemnapi.a +0 -0
  14. package/lib/wasm32-wasi/libemnapi.a +0 -0
  15. package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
  16. package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
  17. package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
  18. package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
  19. package/lib/wasm32-wasip1/libemnapi.a +0 -0
  20. package/lib/wasm32-wasip1-threads/libemnapi-basic-mt.a +0 -0
  21. package/lib/wasm32-wasip1-threads/libemnapi-basic.a +0 -0
  22. package/lib/wasm32-wasip1-threads/libemnapi-mt.a +0 -0
  23. package/lib/wasm32-wasip1-threads/libemnapi.a +0 -0
  24. package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
  25. package/lib/wasm64-emscripten/libemnapi.a +0 -0
  26. package/package.json +1 -1
  27. package/src/async_cleanup_hook.c +1 -1
  28. package/src/async_work.c +2 -2
  29. package/src/emnapi_internal.h +2 -2
  30. package/src/js_native_api.c +2 -1
  31. package/src/node_api.c +5 -5
  32. package/src/threadsafe_function.c +20 -21
  33. package/src/uv/queue.h +68 -86
  34. package/src/uv/threadpool.c +58 -40
  35. package/src/uv/unix/async.c +67 -64
  36. package/src/uv/unix/core.c +36 -1
  37. package/src/uv/unix/internal.h +54 -0
  38. package/src/uv/unix/loop.c +40 -4
  39. package/src/uv/unix/posix-hrtime.c +40 -0
  40. package/src/uv/uv-common.c +123 -7
  41. package/src/uv/uv-common.h +137 -9
package/CMakeLists.txt CHANGED
@@ -33,6 +33,7 @@ set(UV_SRC
33
33
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/uv-common.c"
34
34
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/threadpool.c"
35
35
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/loop.c"
36
+ "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/posix-hrtime.c"
36
37
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/thread.c"
37
38
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/async.c"
38
39
  "${CMAKE_CURRENT_SOURCE_DIR}/src/uv/unix/core.c"
@@ -139,7 +140,10 @@ endif()
139
140
 
140
141
  add_library(${EMNAPI_BASIC_TARGET_NAME} STATIC ${ENAPI_BASIC_SRC})
141
142
  target_include_directories(${EMNAPI_BASIC_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
142
- 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
+ )
143
147
  if(IS_EMSCRIPTEN)
144
148
  set_target_properties(${EMNAPI_BASIC_TARGET_NAME} PROPERTIES INTERFACE_LINK_DEPENDS ${EMNAPI_JS_LIB})
145
149
  target_link_options(${EMNAPI_BASIC_TARGET_NAME} INTERFACE "--js-library=${EMNAPI_JS_LIB}")
@@ -159,7 +163,10 @@ if(EMNAPI_BUILD_BASIC_MT)
159
163
  )
160
164
  target_compile_options(${EMNAPI_BASIC_MT_TARGET_NAME} PUBLIC "-matomics" "-mbulk-memory")
161
165
  target_include_directories(${EMNAPI_BASIC_MT_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
162
- 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
+ )
163
170
 
164
171
  if(IS_EMSCRIPTEN)
165
172
  set_target_properties(${EMNAPI_BASIC_MT_TARGET_NAME} PROPERTIES INTERFACE_LINK_DEPENDS ${EMNAPI_JS_LIB})
@@ -175,7 +182,10 @@ endif()
175
182
 
176
183
  if(EMNAPI_BUILD_MT)
177
184
  add_library(${EMNAPI_MT_TARGET_NAME} STATIC ${EMNAPI_SRC} ${UV_SRC})
178
- 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
+ )
179
189
  target_include_directories(${EMNAPI_MT_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
180
190
  target_compile_definitions(${EMNAPI_MT_TARGET_NAME} PUBLIC ${EMNAPI_DEFINES})
181
191
  if(IS_EMSCRIPTEN)
@@ -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 };
@@ -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_', '*') }}};
@@ -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',
@@ -6,7 +6,7 @@
6
6
  #include "emnapi_common.h"
7
7
 
8
8
  #define EMNAPI_MAJOR_VERSION 1
9
- #define EMNAPI_MINOR_VERSION 2
9
+ #define EMNAPI_MINOR_VERSION 3
10
10
  #define EMNAPI_PATCH_VERSION 0
11
11
 
12
12
  typedef enum {
@@ -56,7 +56,7 @@
56
56
  EXTERN_C_START
57
57
 
58
58
  NAPI_EXTERN napi_status NAPI_CDECL napi_get_last_error_info(
59
- node_api_nogc_env env, const napi_extended_error_info** result);
59
+ node_api_basic_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,
@@ -100,19 +100,19 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_create_string_utf16(napi_env env,
100
100
  napi_value* result);
101
101
  #ifdef NAPI_EXPERIMENTAL
102
102
  #define NODE_API_EXPERIMENTAL_HAS_EXTERNAL_STRINGS
103
- NAPI_EXTERN napi_status NAPI_CDECL
104
- node_api_create_external_string_latin1(napi_env env,
105
- char* str,
106
- size_t length,
107
- node_api_nogc_finalize finalize_callback,
108
- void* finalize_hint,
109
- napi_value* result,
110
- bool* copied);
103
+ NAPI_EXTERN napi_status NAPI_CDECL node_api_create_external_string_latin1(
104
+ napi_env env,
105
+ char* str,
106
+ size_t length,
107
+ node_api_basic_finalize finalize_callback,
108
+ void* finalize_hint,
109
+ napi_value* result,
110
+ bool* copied);
111
111
  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
- node_api_nogc_finalize finalize_callback,
115
+ node_api_basic_finalize finalize_callback,
116
116
  void* finalize_hint,
117
117
  napi_value* result,
118
118
  bool* copied);
@@ -120,6 +120,10 @@ node_api_create_external_string_utf16(napi_env env,
120
120
 
121
121
  #ifdef NAPI_EXPERIMENTAL
122
122
  #define NODE_API_EXPERIMENTAL_HAS_PROPERTY_KEYS
123
+ NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_latin1(
124
+ napi_env env, const char* str, size_t length, napi_value* result);
125
+ NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_utf8(
126
+ napi_env env, const char* str, size_t length, napi_value* result);
123
127
  NAPI_EXTERN napi_status NAPI_CDECL node_api_create_property_key_utf16(
124
128
  napi_env env, const char16_t* str, size_t length, napi_value* result);
125
129
  #endif // NAPI_EXPERIMENTAL
@@ -324,12 +328,13 @@ napi_define_class(napi_env env,
324
328
  napi_value* result);
325
329
 
326
330
  // Methods to work with external data objects
327
- NAPI_EXTERN napi_status NAPI_CDECL napi_wrap(napi_env env,
328
- napi_value js_object,
329
- void* native_object,
330
- node_api_nogc_finalize finalize_cb,
331
- void* finalize_hint,
332
- napi_ref* result);
331
+ NAPI_EXTERN napi_status NAPI_CDECL
332
+ napi_wrap(napi_env env,
333
+ napi_value js_object,
334
+ void* native_object,
335
+ node_api_basic_finalize finalize_cb,
336
+ void* finalize_hint,
337
+ napi_ref* result);
333
338
  NAPI_EXTERN napi_status NAPI_CDECL napi_unwrap(napi_env env,
334
339
  napi_value js_object,
335
340
  void** result);
@@ -339,7 +344,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_remove_wrap(napi_env env,
339
344
  NAPI_EXTERN napi_status NAPI_CDECL
340
345
  napi_create_external(napi_env env,
341
346
  void* data,
342
- node_api_nogc_finalize finalize_cb,
347
+ node_api_basic_finalize finalize_cb,
343
348
  void* finalize_hint,
344
349
  napi_value* result);
345
350
  NAPI_EXTERN napi_status NAPI_CDECL napi_get_value_external(napi_env env,
@@ -438,7 +443,7 @@ NAPI_EXTERN napi_status NAPI_CDECL
438
443
  napi_create_external_arraybuffer(napi_env env,
439
444
  void* external_data,
440
445
  size_t byte_length,
441
- node_api_nogc_finalize finalize_cb,
446
+ node_api_basic_finalize finalize_cb,
442
447
  void* finalize_hint,
443
448
  napi_value* result);
444
449
  #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
@@ -480,7 +485,7 @@ napi_get_dataview_info(napi_env env,
480
485
  size_t* byte_offset);
481
486
 
482
487
  // version management
483
- NAPI_EXTERN napi_status NAPI_CDECL napi_get_version(node_api_nogc_env env,
488
+ NAPI_EXTERN napi_status NAPI_CDECL napi_get_version(node_api_basic_env env,
484
489
  uint32_t* result);
485
490
 
486
491
  // Promises
@@ -504,7 +509,7 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_run_script(napi_env env,
504
509
 
505
510
  // Memory management
506
511
  NAPI_EXTERN napi_status NAPI_CDECL napi_adjust_external_memory(
507
- node_api_nogc_env env, int64_t change_in_bytes, int64_t* adjusted_value);
512
+ node_api_basic_env env, int64_t change_in_bytes, int64_t* adjusted_value);
508
513
 
509
514
  #if NAPI_VERSION >= 5
510
515
 
@@ -526,7 +531,7 @@ NAPI_EXTERN napi_status NAPI_CDECL
526
531
  napi_add_finalizer(napi_env env,
527
532
  napi_value js_object,
528
533
  void* finalize_data,
529
- node_api_nogc_finalize finalize_cb,
534
+ node_api_basic_finalize finalize_cb,
530
535
  void* finalize_hint,
531
536
  napi_ref* result);
532
537
 
@@ -536,7 +541,7 @@ napi_add_finalizer(napi_env env,
536
541
  #define NODE_API_EXPERIMENTAL_HAS_POST_FINALIZER
537
542
 
538
543
  NAPI_EXTERN napi_status NAPI_CDECL
539
- node_api_post_finalizer(node_api_nogc_env env,
544
+ node_api_post_finalizer(node_api_basic_env env,
540
545
  napi_finalize finalize_cb,
541
546
  void* finalize_data,
542
547
  void* finalize_hint);
@@ -581,13 +586,13 @@ napi_get_all_property_names(napi_env env,
581
586
 
582
587
  // Instance data
583
588
  NAPI_EXTERN napi_status NAPI_CDECL
584
- napi_set_instance_data(node_api_nogc_env env,
589
+ napi_set_instance_data(node_api_basic_env env,
585
590
  void* data,
586
591
  napi_finalize finalize_cb,
587
592
  void* finalize_hint);
588
593
 
589
- NAPI_EXTERN napi_status NAPI_CDECL napi_get_instance_data(node_api_nogc_env env,
590
- void** data);
594
+ NAPI_EXTERN napi_status NAPI_CDECL
595
+ napi_get_instance_data(node_api_basic_env env, void** data);
591
596
  #endif // NAPI_VERSION >= 6
592
597
 
593
598
  #if NAPI_VERSION >= 7
@@ -27,7 +27,7 @@ typedef struct napi_env__* napi_env;
27
27
  // meaning that they do not affect the state of the JS engine, and can
28
28
  // therefore be called synchronously from a finalizer that itself runs
29
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
30
+ // `node_api_basic_env` as their first parameter, because we should be able to
31
31
  // also call them during normal, non-garbage-collecting operations, whereas
32
32
  // APIs that affect the state of the JS engine can only receive a `napi_env` as
33
33
  // their first parameter, because we must not call them during GC. In lieu of
@@ -37,19 +37,21 @@ typedef struct napi_env__* napi_env;
37
37
  // expecting a non-const value.
38
38
  //
39
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.
40
+ // (basic) environment into an API that expects a non-const environment, and
41
+ // the definition of basic finalizer function pointer types below, which
42
+ // receive a basic environment as their first parameter, and can thus only call
43
+ // basic APIs (unless the user explicitly casts the environment), we achieve
44
+ // the ability to ensure at compile time that we do not call APIs that affect
45
+ // the state of the JS engine from a synchronous (basic) finalizer.
46
46
  #if !defined(NAPI_EXPERIMENTAL) || \
47
47
  (defined(NAPI_EXPERIMENTAL) && \
48
- defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT))
48
+ (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \
49
+ defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
49
50
  typedef struct napi_env__* node_api_nogc_env;
50
51
  #else
51
52
  typedef const struct napi_env__* node_api_nogc_env;
52
53
  #endif
54
+ typedef node_api_nogc_env node_api_basic_env;
53
55
 
54
56
  typedef struct napi_value__* napi_value;
55
57
  typedef struct napi_ref__* napi_ref;
@@ -147,13 +149,15 @@ typedef void(NAPI_CDECL* napi_finalize)(napi_env env,
147
149
 
148
150
  #if !defined(NAPI_EXPERIMENTAL) || \
149
151
  (defined(NAPI_EXPERIMENTAL) && \
150
- defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT))
152
+ (defined(NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT) || \
153
+ defined(NODE_API_EXPERIMENTAL_BASIC_ENV_OPT_OUT)))
151
154
  typedef napi_finalize node_api_nogc_finalize;
152
155
  #else
153
156
  typedef void(NAPI_CDECL* node_api_nogc_finalize)(node_api_nogc_env env,
154
157
  void* finalize_data,
155
158
  void* finalize_hint);
156
159
  #endif
160
+ typedef node_api_nogc_finalize node_api_basic_finalize;
157
161
 
158
162
  typedef struct {
159
163
  // One of utf8name or name should be NULL.
@@ -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
- node_api_nogc_finalize finalize_cb,
144
+ node_api_basic_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(node_api_nogc_env env,
172
+ NAPI_EXTERN napi_status NAPI_CDECL napi_queue_async_work(node_api_basic_env env,
173
173
  napi_async_work work);
174
- NAPI_EXTERN napi_status NAPI_CDECL napi_cancel_async_work(node_api_nogc_env env,
175
- napi_async_work work);
174
+ NAPI_EXTERN napi_status NAPI_CDECL
175
+ napi_cancel_async_work(node_api_basic_env env, napi_async_work work);
176
176
 
177
177
  // version management
178
- NAPI_EXTERN napi_status NAPI_CDECL
179
- napi_get_node_version(node_api_nogc_env env, const napi_node_version** version);
178
+ NAPI_EXTERN napi_status NAPI_CDECL napi_get_node_version(
179
+ node_api_basic_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(node_api_nogc_env env, struct uv_loop_s** loop);
185
+ napi_get_uv_event_loop(node_api_basic_env env, struct uv_loop_s** loop);
186
186
 
187
187
  #endif // NAPI_VERSION >= 2
188
188
 
@@ -192,10 +192,10 @@ NAPI_EXTERN napi_status NAPI_CDECL napi_fatal_exception(napi_env env,
192
192
  napi_value err);
193
193
 
194
194
  NAPI_EXTERN napi_status NAPI_CDECL napi_add_env_cleanup_hook(
195
- node_api_nogc_env env, napi_cleanup_hook fun, void* arg);
195
+ node_api_basic_env env, napi_cleanup_hook fun, void* arg);
196
196
 
197
197
  NAPI_EXTERN napi_status NAPI_CDECL napi_remove_env_cleanup_hook(
198
- node_api_nogc_env env, napi_cleanup_hook fun, void* arg);
198
+ node_api_basic_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,
@@ -239,17 +239,17 @@ 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
241
  NAPI_EXTERN napi_status NAPI_CDECL napi_unref_threadsafe_function(
242
- node_api_nogc_env env, napi_threadsafe_function func);
242
+ node_api_basic_env env, napi_threadsafe_function func);
243
243
 
244
244
  NAPI_EXTERN napi_status NAPI_CDECL napi_ref_threadsafe_function(
245
- node_api_nogc_env env, napi_threadsafe_function func);
245
+ node_api_basic_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(node_api_nogc_env env,
252
+ napi_add_async_cleanup_hook(node_api_basic_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(node_api_nogc_env env, const char** result);
265
+ node_api_get_module_file_name(node_api_basic_env env, const char** result);
266
266
 
267
267
  #endif // NAPI_VERSION >= 9
268
268
 
@@ -33,7 +33,7 @@ struct uv__work {
33
33
  void (*work)(struct uv__work *w);
34
34
  void (*done)(struct uv__work *w, int status);
35
35
  struct uv_loop_s* loop;
36
- void* wq[2];
36
+ struct uv__queue wq;
37
37
  };
38
38
 
39
39
  #endif
@@ -18,4 +18,8 @@ typedef pthread_cond_t uv_cond_t;
18
18
 
19
19
  #endif
20
20
 
21
+ #define UV_HANDLE_PRIVATE_FIELDS \
22
+ uv_handle_t* next_closing; \
23
+ unsigned int flags; \
24
+
21
25
  #endif /* UV_UNIX_H */