emnapi 0.36.3 → 0.38.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.
package/CMakeLists.txt CHANGED
@@ -70,7 +70,7 @@ if(EMNAPI_FIND_NODE_ADDON_API)
70
70
  else()
71
71
  string(REGEX REPLACE "(\r?\n)|\"" "" OUTPUT_NAA_INCLUDE_DIR "${OUTPUT_NAA_INCLUDE_DIR}")
72
72
  string(REPLACE "\\" "/" OUTPUT_NAA_INCLUDE_DIR "${OUTPUT_NAA_INCLUDE_DIR}")
73
- list(PREPEND EMNAPI_INCLUDE "${OUTPUT_NAA_INCLUDE_DIR}")
73
+ list(APPEND EMNAPI_INCLUDE "${OUTPUT_NAA_INCLUDE_DIR}")
74
74
  endif()
75
75
  endif()
76
76
 
@@ -191,8 +191,6 @@ install(FILES
191
191
  ${CMAKE_CURRENT_SOURCE_DIR}/include/emnapi.h
192
192
  ${CMAKE_CURRENT_SOURCE_DIR}/include/js_native_api_types.h
193
193
  ${CMAKE_CURRENT_SOURCE_DIR}/include/js_native_api.h
194
- ${CMAKE_CURRENT_SOURCE_DIR}/include/napi-inl.h
195
- ${CMAKE_CURRENT_SOURCE_DIR}/include/napi.h
196
194
  ${CMAKE_CURRENT_SOURCE_DIR}/include/node_api_types.h
197
195
  ${CMAKE_CURRENT_SOURCE_DIR}/include/node_api.h
198
196
  ${CMAKE_CURRENT_SOURCE_DIR}/include/uv.h
package/README.md CHANGED
@@ -35,6 +35,7 @@ You will need to install:
35
35
  - (Optional) CMake `>= v3.13`
36
36
  - (Optional) ninja
37
37
  - (Optional) make
38
+ - (Optional) [node-addon-api](https://github.com/nodejs/node-addon-api) `>= 6.1.0`
38
39
 
39
40
  There are several choices to get `make` for Windows user
40
41
 
@@ -94,6 +95,9 @@ npm install @emnapi/runtime
94
95
 
95
96
  # for non-emscripten
96
97
  npm install @emnapi/core
98
+
99
+ # if you use node-addon-api
100
+ npm install node-addon-api
97
101
  ```
98
102
 
99
103
  Each package should match the same version.
@@ -404,9 +408,13 @@ instantiateNapiModule(fetch('./hello.wasm'), {
404
408
 
405
409
  </details>
406
410
 
407
- ### Using C++
411
+ ### Using C++ and node-addon-api
408
412
 
409
- Alternatively, you can also use [`node-addon-api`](https://github.com/nodejs/node-addon-api) which is official Node-API C++ wrapper, already shipped ([v6.0.0](https://github.com/nodejs/node-addon-api/releases/tag/v6.0.0)) in this package but without Node.js specific API such as `CallbackScope`.
413
+ Require [`node-addon-api`](https://github.com/nodejs/node-addon-api) `>= 6.1.0`
414
+
415
+ ```bash
416
+ npm install node-addon-api
417
+ ```
410
418
 
411
419
  **Note: C++ wrapper can only be used to target Node.js v14.6.0+ and modern browsers those support `FinalizationRegistry` and `WeakRef` ([v8 engine v8.4+](https://v8.dev/blog/v8-release-84))!**
412
420
 
@@ -441,6 +449,7 @@ em++ -O3 \
441
449
  -DNAPI_DISABLE_CPP_EXCEPTIONS \
442
450
  -DNODE_ADDON_API_ENABLE_MAYBE \
443
451
  -I./node_modules/emnapi/include \
452
+ -I./node_modules/node-addon-api \
444
453
  -L./node_modules/emnapi/lib/wasm32-emscripten \
445
454
  --js-library=./node_modules/emnapi/dist/library_napi.js \
446
455
  -sEXPORTED_FUNCTIONS="['_napi_register_wasm_v1','_malloc','_free']" \
@@ -459,6 +468,7 @@ clang++ -O3 \
459
468
  -DNAPI_DISABLE_CPP_EXCEPTIONS \
460
469
  -DNODE_ADDON_API_ENABLE_MAYBE \
461
470
  -I./node_modules/emnapi/include \
471
+ -I./node_modules/node-addon-api \
462
472
  -L./node_modules/emnapi/lib/wasm32-wasi \
463
473
  --target=wasm32-wasi \
464
474
  --sysroot=$WASI_SDK_PATH/share/wasi-sysroot \
@@ -563,15 +573,20 @@ elseif((CMAKE_C_COMPILER_TARGET STREQUAL "wasm32") OR (CMAKE_C_COMPILER_TARGET S
563
573
  endif()
564
574
  ```
565
575
 
576
+ If you use node-addon-api, you can use `-DEMNAPI_FIND_NODE_ADDON_API=ON` or manually add node-addon-api directory to the include dir via `include_directories()` or `target_include_directories()`.
577
+
566
578
  ```bash
567
579
  mkdir build
568
580
 
569
581
  # emscripten
570
- emcmake cmake -DCMAKE_BUILD_TYPE=Release -G Ninja -H. -Bbuild
582
+ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
583
+ -DEMNAPI_FIND_NODE_ADDON_API=ON \
584
+ -G Ninja -H. -Bbuild
571
585
 
572
586
  # wasi-sdk
573
587
  cmake -DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk.cmake \
574
588
  -DWASI_SDK_PREFIX=$WASI_SDK_PATH \
589
+ -DEMNAPI_FIND_NODE_ADDON_API=ON \
575
590
  -DCMAKE_BUILD_TYPE=Release \
576
591
  -G Ninja -H. -Bbuild
577
592
 
@@ -848,11 +863,15 @@ endif()
848
863
 
849
864
  ```bash
850
865
  # emscripten
851
- emcmake cmake -DCMAKE_BUILD_TYPE=Release -DEMNAPI_WORKER_POOL_SIZE=4 -G Ninja -H. -Bbuild
866
+ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
867
+ -DEMNAPI_FIND_NODE_ADDON_API=ON \
868
+ -DEMNAPI_WORKER_POOL_SIZE=4 \
869
+ -G Ninja -H. -Bbuild
852
870
 
853
871
  # wasi-sdk with thread support (Experimental)
854
872
  cmake -DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk-pthread.cmake \
855
873
  -DWASI_SDK_PREFIX=$WASI_SDK_PATH \
874
+ -DEMNAPI_FIND_NODE_ADDON_API=ON \
856
875
  -DCMAKE_BUILD_TYPE=Release \
857
876
  -G Ninja -H. -Bbuild
858
877
 
@@ -1043,47 +1062,48 @@ This option only has effect if you use emscripten `-pthread`. Default is `1` if
1043
1062
 
1044
1063
  See source code [here](https://github.com/toyobayashi/emnapi/tree/main/packages/bench)
1045
1064
 
1046
- - OS: Windows_NT x64 10.0.22621.963
1047
- - CPU: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz 2.30 GHz
1048
- - Memory: 16.0 GB
1049
- - Chrome: 108.0.5359.125
1050
- - Emscripten: 3.1.28
1051
- - emnapi: 0.22.0
1065
+ - OS: macOS 13.3.1 22E261 arm64
1066
+ - CPU: Apple M2 Pro
1067
+ - Memory: 32.0 GB
1068
+ - Chrome: 112.0.5615.137
1069
+ - Emscripten: 3.1.36
1070
+ - emnapi: 0.38.0
1071
+ - node-addon-api 6.1.0
1052
1072
 
1053
1073
  ```
1054
1074
  binding: function () {}
1055
- embind #emptyFunction x 37,148,158 ops/sec ±0.39% (67 runs sampled)
1056
- emnapi #emptyFunction x 40,207,668 ops/sec ±0.79% (67 runs sampled)
1057
- node-addon-api + emnapi #emptyFunction x 13,871,523 ops/sec ±0.35% (67 runs sampled)
1075
+ embind #emptyFunction x 49,956,250 ops/sec ±0.32% (68 runs sampled)
1076
+ emnapi #emptyFunction x 57,543,501 ops/sec ±0.76% (67 runs sampled)
1077
+ node-addon-api + emnapi #emptyFunction x 21,352,147 ops/sec ±0.62% (66 runs sampled)
1058
1078
  Fastest is emnapi #emptyFunction
1059
1079
 
1060
1080
  binding: function (obj) { return obj }
1061
- embind #returnParam x 19,230,099 ops/sec ±0.59% (68 runs sampled)
1062
- emnapi #returnParam x 14,930,264 ops/sec ±0.68% (64 runs sampled)
1063
- node-addon-api + emnapi #returnParam x 11,402,133 ops/sec ±0.47% (67 runs sampled)
1064
- Fastest is embind #returnParam
1081
+ embind #returnParam x 21,426,261 ops/sec ±0.67% (67 runs sampled)
1082
+ emnapi #returnParam x 25,111,317 ops/sec ±0.40% (68 runs sampled)
1083
+ node-addon-api + emnapi #returnParam x 17,811,804 ops/sec ±0.24% (68 runs sampled)
1084
+ Fastest is emnapi #returnParam
1065
1085
 
1066
1086
  binding: function (int) { return copy(int) }
1067
- embind #convertInteger x 9,178,287 ops/sec ±0.67% (67 runs sampled)
1068
- emnapi #convertInteger x 9,898,681 ops/sec ±0.56% (66 runs sampled)
1069
- node-addon-api + emnapi #convertInteger x 7,888,491 ops/sec ±0.79% (67 runs sampled)
1087
+ embind #convertInteger x 9,748,310 ops/sec ±0.52% (68 runs sampled)
1088
+ emnapi #convertInteger x 16,128,395 ops/sec ±0.38% (70 runs sampled)
1089
+ node-addon-api + emnapi #convertInteger x 11,692,687 ops/sec ±0.41% (67 runs sampled)
1070
1090
  Fastest is emnapi #convertInteger
1071
1091
 
1072
1092
  binding: function (str) { return copy(str) }
1073
- embind #convertString x 2,574,960 ops/sec ±0.46% (66 runs sampled)
1074
- emnapi #convertString x 3,412,941 ops/sec ±0.66% (68 runs sampled)
1075
- node-addon-api + emnapi #convertString x 2,913,797 ops/sec ±0.62% (67 runs sampled)
1093
+ embind #convertString x 3,681,066 ops/sec ±0.24% (69 runs sampled)
1094
+ emnapi #convertString x 4,555,446 ops/sec ±0.40% (69 runs sampled)
1095
+ node-addon-api + emnapi #convertString x 3,826,496 ops/sec ±0.24% (68 runs sampled)
1076
1096
  Fastest is emnapi #convertString
1077
1097
 
1078
1098
  binding: function (param) { return param.length }
1079
- embind #ObjectGet x 6,192,531 ops/sec ±0.73% (67 runs sampled)
1080
- emnapi #ObjectGet x 5,268,653 ops/sec ±0.59% (66 runs sampled)
1081
- node-addon-api + emnapi #ObjectGet x 4,828,204 ops/sec ±0.57% (67 runs sampled)
1082
- Fastest is embind #ObjectGet
1099
+ embind #ObjectGet x 6,874,783 ops/sec ±0.39% (68 runs sampled)
1100
+ emnapi #ObjectGet x 6,926,130 ops/sec ±0.34% (69 runs sampled)
1101
+ node-addon-api + emnapi #ObjectGet x 6,075,822 ops/sec ±0.41% (68 runs sampled)
1102
+ Fastest is emnapi #ObjectGet
1083
1103
 
1084
1104
  binding: function (obj, key, value) { obj[key] = value }
1085
- embind #ObjectSet x 11,467,433 ops/sec ±0.55% (67 runs sampled)
1086
- emnapi #ObjectSet x 9,476,512 ops/sec ±0.91% (66 runs sampled)
1087
- node-addon-api + emnapi #ObjectSet x 7,647,341 ops/sec ±0.36% (66 runs sampled)
1088
- Fastest is embind #ObjectSet
1105
+ embind #ObjectSet x 11,184,221 ops/sec ±0.35% (66 runs sampled)
1106
+ emnapi #ObjectSet x 15,812,566 ops/sec ±0.64% (66 runs sampled)
1107
+ node-addon-api + emnapi #ObjectSet x 12,022,909 ops/sec ±0.51% (66 runs sampled)
1108
+ Fastest is emnapi #ObjectSet
1089
1109
  ```
@@ -212,9 +212,13 @@ function _emnapi_create_memory_view(env, typedarray_type, external_data, byte_le
212
212
  case -1 /* emnapi_memory_view_type.emnapi_data_view */:
213
213
  viewDescriptor_1 = { Ctor: DataView, address: external_data, length: byte_length, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
214
214
  break;
215
- case -2 /* emnapi_memory_view_type.emnapi_buffer */:
215
+ case -2 /* emnapi_memory_view_type.emnapi_buffer */: {
216
+ if (!emnapiCtx.feature.Buffer) {
217
+ throw emnapiCtx.createNotSupportBufferError("emnapi_create_memory_view", "");
218
+ }
216
219
  viewDescriptor_1 = { Ctor: emnapiCtx.feature.Buffer, address: external_data, length: byte_length, ownership: 1 /* Ownership.kUserland */, runtimeAllocated: 0 };
217
220
  break;
221
+ }
218
222
  default: return envObject_1.setLastError(1 /* napi_status.napi_invalid_arg */);
219
223
  }
220
224
  var Ctor_1 = viewDescriptor_1.Ctor;
@@ -399,7 +403,7 @@ emnapiImplement2('emnapi_is_support_weakref', 'i', emnapi_is_support_weakref);
399
403
  emnapiImplement2('emnapi_is_support_bigint', 'i', emnapi_is_support_bigint);
400
404
  emnapiImplement2('emnapi_is_node_binding_available', 'i', emnapi_is_node_binding_available);
401
405
  emnapiImplement2('emnapi_create_memory_view', 'ipippppp', _emnapi_create_memory_view, ['napi_add_finalizer', '$emnapiExternalMemory']);
402
- emnapiImplement2('emnapi_sync_memory', 'ipppppi', emnapi_sync_memory, ['$emnapiSyncMemory']);
406
+ emnapiImplement2('emnapi_sync_memory', 'ipippp', emnapi_sync_memory, ['$emnapiSyncMemory']);
403
407
  emnapiImplement2('emnapi_get_memory_address', 'ipppp', emnapi_get_memory_address, ['$emnapiGetMemoryAddress']);
404
408
  function napi_set_instance_data(env, data, finalize_cb, finalize_hint) {
405
409
  if (env == 0)
@@ -1380,7 +1384,7 @@ var emnapiExternalMemory = {
1380
1384
  if (!shouldCopy) {
1381
1385
  return info;
1382
1386
  }
1383
- var pointer = {{{ makeMalloc('$emnapiExternalMemory.getArrayBufferPointer', 'arrayBuffer.byteLength') }}};
1387
+ var pointer = _malloc({{{ to64('arrayBuffer.byteLength') }}});
1384
1388
  if (!pointer)
1385
1389
  throw new Error('Out of memory');
1386
1390
  new Uint8Array(wasmMemory.buffer).set(new Uint8Array(arrayBuffer), pointer);
@@ -2461,22 +2465,15 @@ function napi_run_script(env, script, result) {
2461
2465
  return status;
2462
2466
  }
2463
2467
  emnapiImplement('napi_run_script', 'ippp', napi_run_script, ['napi_set_last_error']);
2464
- /* eslint-disable @typescript-eslint/indent */
2465
2468
  var emnapiString = {
2466
2469
  utf8Decoder: undefined,
2467
2470
  utf16Decoder: undefined,
2468
2471
  init: function () {
2469
2472
  #if !TEXTDECODER || TEXTDECODER == 1
2470
2473
  var fallbackDecoder = {
2471
- decode: function (input) {
2472
- var isArrayBuffer = input instanceof ArrayBuffer;
2473
- var isView = ArrayBuffer.isView(input);
2474
- if (!isArrayBuffer && !isView) {
2475
- throw new TypeError('The "input" argument must be an instance of ArrayBuffer or ArrayBufferView');
2476
- }
2477
- var bytes = isArrayBuffer ? new Uint8Array(input) : new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
2474
+ decode: function (bytes) {
2478
2475
  var inputIndex = 0;
2479
- var pendingSize = Math.min(256 * 256, bytes.length + 1);
2476
+ var pendingSize = Math.min(0x1000, bytes.length + 1);
2480
2477
  var pending = new Uint16Array(pendingSize);
2481
2478
  var chunks = [];
2482
2479
  var pendingIndex = 0;
@@ -2536,17 +2533,18 @@ var emnapiString = {
2536
2533
  #if !TEXTDECODER || TEXTDECODER == 1
2537
2534
  var fallbackDecoder2 = {
2538
2535
  decode: function (input) {
2539
- var isArrayBuffer = input instanceof ArrayBuffer;
2540
- var isView = ArrayBuffer.isView(input);
2541
- if (!isArrayBuffer && !isView) {
2542
- throw new TypeError('The "input" argument must be an instance of ArrayBuffer or ArrayBufferView');
2536
+ var bytes = new Uint16Array(input.buffer, input.byteOffset, input.byteLength / 2);
2537
+ if (bytes.length <= 0x1000) {
2538
+ return String.fromCharCode.apply(null, bytes);
2543
2539
  }
2544
- var bytes = isArrayBuffer ? new Uint16Array(input) : new Uint16Array(input.buffer, input.byteOffset, input.byteLength / 2);
2545
- var wcharArray = Array(bytes.length);
2546
- for (var i = 0; i < bytes.length; ++i) {
2547
- wcharArray[i] = String.fromCharCode(bytes[i]);
2540
+ var chunks = [];
2541
+ var i = 0;
2542
+ var len = 0;
2543
+ for (; i < bytes.length; i += len) {
2544
+ len = Math.min(0x1000, bytes.length - i);
2545
+ chunks.push(String.fromCharCode.apply(null, bytes.subarray(i, i + len)));
2548
2546
  }
2549
- return wcharArray.join('');
2547
+ return chunks.join('');
2550
2548
  }
2551
2549
  };
2552
2550
  #endif
@@ -2582,9 +2580,9 @@ var emnapiString = {
2582
2580
  return len;
2583
2581
  },
2584
2582
  UTF8ToString: function (ptr, length) {
2585
- ptr >>>= 0;
2586
2583
  if (!ptr || !length)
2587
2584
  return '';
2585
+ ptr >>>= 0;
2588
2586
  var HEAPU8 = new Uint8Array(wasmMemory.buffer);
2589
2587
  var end = ptr;
2590
2588
  if (length === -1) {
@@ -2594,6 +2592,40 @@ var emnapiString = {
2594
2592
  else {
2595
2593
  end = ptr + (length >>> 0);
2596
2594
  }
2595
+ #if TEXTDECODER != 2
2596
+ length = end - ptr;
2597
+ if (length <= 16) {
2598
+ var idx = ptr;
2599
+ var str = '';
2600
+ while (idx < end) {
2601
+ var u0 = HEAPU8[idx++];
2602
+ if (!(u0 & 0x80)) {
2603
+ str += String.fromCharCode(u0);
2604
+ continue;
2605
+ }
2606
+ var u1 = HEAPU8[idx++] & 63;
2607
+ if ((u0 & 0xE0) === 0xC0) {
2608
+ str += String.fromCharCode(((u0 & 31) << 6) | u1);
2609
+ continue;
2610
+ }
2611
+ var u2 = HEAPU8[idx++] & 63;
2612
+ if ((u0 & 0xF0) === 0xE0) {
2613
+ u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
2614
+ }
2615
+ else {
2616
+ u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (HEAPU8[idx++] & 63);
2617
+ }
2618
+ if (u0 < 0x10000) {
2619
+ str += String.fromCharCode(u0);
2620
+ }
2621
+ else {
2622
+ var ch = u0 - 0x10000;
2623
+ str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
2624
+ }
2625
+ }
2626
+ return str;
2627
+ }
2628
+ #endif
2597
2629
  return emnapiString.utf8Decoder.decode({{{ getUnsharedTextDecoderView('HEAPU8', 'ptr', 'end') }}});
2598
2630
  },
2599
2631
  stringToUTF8: function (str, outPtr, maxBytesToWrite) {
@@ -2642,9 +2674,9 @@ var emnapiString = {
2642
2674
  return outIdx - startIdx;
2643
2675
  },
2644
2676
  UTF16ToString: function (ptr, length) {
2645
- ptr >>>= 0;
2646
2677
  if (!ptr || !length)
2647
2678
  return '';
2679
+ ptr >>>= 0;
2648
2680
  var end = ptr;
2649
2681
  if (length === -1) {
2650
2682
  var idx = end >> 1;
@@ -2656,6 +2688,12 @@ var emnapiString = {
2656
2688
  else {
2657
2689
  end = ptr + (length >>> 0) * 2;
2658
2690
  }
2691
+ #if TEXTDECODER != 2
2692
+ length = end - ptr;
2693
+ if (length <= 32) {
2694
+ return String.fromCharCode.apply(null, new Uint16Array(wasmMemory.buffer, ptr, length / 2));
2695
+ }
2696
+ #endif
2659
2697
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2660
2698
  var HEAPU8 = new Uint8Array(wasmMemory.buffer);
2661
2699
  return emnapiString.utf16Decoder.decode({{{ getUnsharedTextDecoderView('HEAPU8', 'ptr', 'end') }}});
@@ -2752,7 +2790,7 @@ var emnapiTSFN = {
2752
2790
  },
2753
2791
  initQueue: function (func) {
2754
2792
  var size = 2 * {{{ POINTER_SIZE }}};
2755
- var queue = {{{ makeMalloc('emnapiTSFN.initQueue', 'size') }}};
2793
+ var queue = _malloc({{{ to64('size') }}});
2756
2794
  if (!queue)
2757
2795
  return false;
2758
2796
  new Uint8Array(wasmMemory.buffer, queue, size).fill(0);
@@ -2771,7 +2809,7 @@ var emnapiTSFN = {
2771
2809
  var tail = emnapiTSFN.loadSizeTypeValue(queue + {{{ POINTER_SIZE }}}, false);
2772
2810
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2773
2811
  var size = 2 * {{{ POINTER_SIZE }}};
2774
- var node = {{{ makeMalloc('emnapiTSFN.pushQueue', 'size') }}};
2812
+ var node = _malloc({{{ to64('size') }}});
2775
2813
  if (!node)
2776
2814
  throw new Error('OOM');
2777
2815
  emnapiTSFN.storeSizeTypeValue(node, data, false);
@@ -3361,7 +3399,7 @@ function _napi_create_threadsafe_function(env, func, async_resource, async_resou
3361
3399
  var resource_name = envObject.ensureHandleId(asyncResourceName);
3362
3400
  // tsfn create
3363
3401
  var sizeofTSFN = emnapiTSFN.offset.end;
3364
- var tsfn = {{{ makeMalloc('napi_create_threadsafe_function', 'sizeofTSFN') }}};
3402
+ var tsfn = _malloc({{{ to64('sizeofTSFN') }}});
3365
3403
  if (!tsfn)
3366
3404
  return envObject.setLastError(9 /* napi_status.napi_generic_failure */);
3367
3405
  new Uint8Array(wasmMemory.buffer).subarray(tsfn, tsfn + sizeofTSFN).fill(0);
@@ -3488,6 +3526,8 @@ function _napi_ref_threadsafe_function(env, func) {
3488
3526
  emnapiDefineVar('$emnapiTSFN', emnapiTSFN, [
3489
3527
  '$emnapiInit',
3490
3528
  '$PThread',
3529
+ 'malloc',
3530
+ 'free',
3491
3531
  '_emnapi_node_emit_async_init',
3492
3532
  '_emnapi_node_emit_async_destroy',
3493
3533
  '_emnapi_runtime_keepalive_pop',
@@ -5429,8 +5469,11 @@ function napi_create_buffer(env, size, data, result
5429
5469
  try {
5430
5470
  if (result == 0)
5431
5471
  return envObject_56.setLastError(1 /* napi_status.napi_invalid_arg */);
5432
- {{{ from64("result") }}};
5433
5472
  var Buffer_1 = emnapiCtx.feature.Buffer;
5473
+ if (!Buffer_1) {
5474
+ throw emnapiCtx.createNotSupportBufferError("napi_create_buffer", "");
5475
+ }
5476
+ {{{ from64("result") }}};
5434
5477
  var buffer_2 = void 0;
5435
5478
  {{{ from64("size") }}};
5436
5479
  size = size >>> 0;
@@ -5440,7 +5483,7 @@ function napi_create_buffer(env, size, data, result
5440
5483
  {{{ makeSetValue("result", 0, "value", "*") }}};
5441
5484
  }
5442
5485
  else {
5443
- pointer = {{{ makeMalloc("napi_create_buffer", "size") }}};
5486
+ pointer = _malloc({{{ to64("size") }}});
5444
5487
  if (!pointer)
5445
5488
  throw new Error("Out of memory");
5446
5489
  new Uint8Array(wasmMemory.buffer).subarray(pointer, pointer + size).fill(0);
@@ -5483,8 +5526,8 @@ function napi_create_buffer_copy(env, length, data, result_data, result
5483
5526
  try {
5484
5527
  if (result == 0)
5485
5528
  return envObject_57.setLastError(1 /* napi_status.napi_invalid_arg */);
5486
- var arrayBuffer_3 = emnapiCreateArrayBuffer(length, result_data);
5487
5529
  var Buffer_2 = emnapiCtx.feature.Buffer;
5530
+ var arrayBuffer_3 = emnapiCreateArrayBuffer(length, result_data);
5488
5531
  var buffer_4 = Buffer_2.from(arrayBuffer_3);
5489
5532
  {{{ from64("data") }}};
5490
5533
  {{{ from64("length") }}};
@@ -2,11 +2,9 @@
2
2
  #define EMNAPI_INCLUDE_COMMON_H_
3
3
 
4
4
  #ifdef __EMSCRIPTEN__
5
- #define NAPI_EXTERN __attribute__((visibility("default"))) \
6
- __attribute__((__import_module__("env")))
5
+ #define NAPI_EXTERN __attribute__((__import_module__("env")))
7
6
 
8
- #define EMNAPI_EXTERN __attribute__((visibility("default"))) \
9
- __attribute__((__import_module__("env")))
7
+ #define EMNAPI_EXTERN __attribute__((__import_module__("env")))
10
8
  #else
11
9
  #define NAPI_EXTERN __attribute__((__import_module__("napi")))
12
10