emnapi 1.5.0 → 1.6.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/dist/library_napi.js
CHANGED
|
@@ -983,6 +983,10 @@ var emnapiExternalMemory = {
|
|
|
983
983
|
emnapiExternalMemory.table = new WeakMap();
|
|
984
984
|
emnapiExternalMemory.wasmMemoryViewTable = new WeakMap();
|
|
985
985
|
},
|
|
986
|
+
isSharedArrayBuffer: function (value) {
|
|
987
|
+
return ((typeof SharedArrayBuffer === 'function' && value instanceof SharedArrayBuffer) ||
|
|
988
|
+
(Object.prototype.toString.call(value) === '[object SharedArrayBuffer]'));
|
|
989
|
+
},
|
|
986
990
|
isDetachedArrayBuffer: function (arrayBuffer) {
|
|
987
991
|
if (arrayBuffer.byteLength === 0) {
|
|
988
992
|
try {
|
|
@@ -1124,7 +1128,7 @@ function _napi_get_arraybuffer_info(env, arraybuffer, data, byte_length) {
|
|
|
1124
1128
|
if (!arraybuffer)
|
|
1125
1129
|
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
1126
1130
|
var handle = emnapiCtx.handleStore.get(arraybuffer);
|
|
1127
|
-
if (!handle.isArrayBuffer()) {
|
|
1131
|
+
if (!handle.isArrayBuffer() && !emnapiExternalMemory.isSharedArrayBuffer(handle.value)) {
|
|
1128
1132
|
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
1129
1133
|
}
|
|
1130
1134
|
if (data) {
|
|
@@ -2627,7 +2631,7 @@ function emnapiSyncMemory(js_to_wasm, arrayBufferOrView, offset, len) {
|
|
|
2627
2631
|
offset = offset !== null && offset !== void 0 ? offset : 0;
|
|
2628
2632
|
offset = offset >>> 0;
|
|
2629
2633
|
var view;
|
|
2630
|
-
if (arrayBufferOrView instanceof ArrayBuffer) {
|
|
2634
|
+
if (arrayBufferOrView instanceof ArrayBuffer || emnapiExternalMemory.isSharedArrayBuffer(arrayBufferOrView)) {
|
|
2631
2635
|
var pointer = emnapiExternalMemory.getArrayBufferPointer(arrayBufferOrView, false).address;
|
|
2632
2636
|
if (!pointer)
|
|
2633
2637
|
throw new Error('Unknown ArrayBuffer address');
|
|
@@ -2695,7 +2699,7 @@ function _emnapi_sync_memory(env, js_to_wasm, arraybuffer_or_view, offset, len)
|
|
|
2695
2699
|
{{{ from64('len') }}};
|
|
2696
2700
|
var handleId = {{{ makeGetValue('arraybuffer_or_view', 0, '*') }}};
|
|
2697
2701
|
var handle = envObject.ctx.handleStore.get(handleId);
|
|
2698
|
-
if (!handle.isArrayBuffer() && !handle.isTypedArray() && !handle.isDataView()) {
|
|
2702
|
+
if (!handle.isArrayBuffer() && !handle.isTypedArray() && !handle.isDataView() && !emnapiExternalMemory.isSharedArrayBuffer(handle.value)) {
|
|
2699
2703
|
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
2700
2704
|
}
|
|
2701
2705
|
var ret = emnapiSyncMemory(Boolean(js_to_wasm), handle.value, offset, len);
|
|
@@ -2715,7 +2719,7 @@ function emnapiGetMemoryAddress(arrayBufferOrView) {
|
|
|
2715
2719
|
var isArrayBuffer = arrayBufferOrView instanceof ArrayBuffer;
|
|
2716
2720
|
var isDataView = arrayBufferOrView instanceof DataView;
|
|
2717
2721
|
var isTypedArray = ArrayBuffer.isView(arrayBufferOrView) && !isDataView;
|
|
2718
|
-
if (!isArrayBuffer && !isTypedArray && !isDataView) {
|
|
2722
|
+
if (!isArrayBuffer && !isTypedArray && !isDataView && !emnapiExternalMemory.isSharedArrayBuffer(arrayBufferOrView)) {
|
|
2719
2723
|
throw new TypeError('emnapiGetMemoryAddress expect ArrayBuffer or ArrayBufferView as first parameter');
|
|
2720
2724
|
}
|
|
2721
2725
|
var info;
|
|
@@ -2841,10 +2845,10 @@ function _napi_create_array_with_length(env, length, result) {
|
|
|
2841
2845
|
{{{ makeSetValue('result', 0, 'value', '*') }}};
|
|
2842
2846
|
return envObject.clearLastError();
|
|
2843
2847
|
}
|
|
2844
|
-
function emnapiCreateArrayBuffer(byte_length, data) {
|
|
2848
|
+
function emnapiCreateArrayBuffer(byte_length, data, shared) {
|
|
2845
2849
|
{{{ from64('byte_length') }}};
|
|
2846
2850
|
byte_length = byte_length >>> 0;
|
|
2847
|
-
var arrayBuffer = new ArrayBuffer(byte_length);
|
|
2851
|
+
var arrayBuffer = shared ? new SharedArrayBuffer(byte_length) : new ArrayBuffer(byte_length);
|
|
2848
2852
|
if (data) {
|
|
2849
2853
|
{{{ from64('data') }}};
|
|
2850
2854
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -2873,7 +2877,37 @@ function _napi_create_arraybuffer(env, byte_length, data, result) {
|
|
|
2873
2877
|
if (!result)
|
|
2874
2878
|
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
2875
2879
|
{{{ from64('result') }}};
|
|
2876
|
-
var arrayBuffer = emnapiCreateArrayBuffer(byte_length, data);
|
|
2880
|
+
var arrayBuffer = emnapiCreateArrayBuffer(byte_length, data, false);
|
|
2881
|
+
value = emnapiCtx.addToCurrentScope(arrayBuffer).id;
|
|
2882
|
+
{{{ makeSetValue('result', 0, 'value', '*') }}};
|
|
2883
|
+
return envObject.getReturnStatus();
|
|
2884
|
+
}
|
|
2885
|
+
catch (err) {
|
|
2886
|
+
envObject.tryCatch.setError(err);
|
|
2887
|
+
return envObject.setLastError(10 /* napi_status.napi_pending_exception */);
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
/**
|
|
2891
|
+
* @__sig ipppp
|
|
2892
|
+
*/
|
|
2893
|
+
function _node_api_create_sharedarraybuffer(env, byte_length, data, result) {
|
|
2894
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2895
|
+
var value;
|
|
2896
|
+
if (!env)
|
|
2897
|
+
return 1 /* napi_status.napi_invalid_arg */;
|
|
2898
|
+
// @ts-expect-error
|
|
2899
|
+
var envObject = emnapiCtx.envStore.get(env);
|
|
2900
|
+
envObject.checkGCAccess();
|
|
2901
|
+
if (!envObject.tryCatch.isEmpty())
|
|
2902
|
+
return envObject.setLastError(10 /* napi_status.napi_pending_exception */);
|
|
2903
|
+
if (!envObject.canCallIntoJs())
|
|
2904
|
+
return envObject.setLastError(envObject.moduleApiVersion >= 10 ? 23 /* napi_status.napi_cannot_run_js */ : 10 /* napi_status.napi_pending_exception */);
|
|
2905
|
+
envObject.clearLastError();
|
|
2906
|
+
try {
|
|
2907
|
+
if (!result)
|
|
2908
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
2909
|
+
{{{ from64('result') }}};
|
|
2910
|
+
var arrayBuffer = emnapiCreateArrayBuffer(byte_length, data, true);
|
|
2877
2911
|
value = emnapiCtx.addToCurrentScope(arrayBuffer).id;
|
|
2878
2912
|
{{{ makeSetValue('result', 0, 'value', '*') }}};
|
|
2879
2913
|
return envObject.getReturnStatus();
|
|
@@ -3246,7 +3280,7 @@ function _napi_create_buffer_copy(env, length, data, result_data, result) {
|
|
|
3246
3280
|
if (!Buffer) {
|
|
3247
3281
|
throw emnapiCtx.createNotSupportBufferError('napi_create_buffer_copy', '');
|
|
3248
3282
|
}
|
|
3249
|
-
var arrayBuffer = emnapiCreateArrayBuffer(length, result_data);
|
|
3283
|
+
var arrayBuffer = emnapiCreateArrayBuffer(length, result_data, false);
|
|
3250
3284
|
var buffer = Buffer.from(arrayBuffer);
|
|
3251
3285
|
{{{ from64('data') }}};
|
|
3252
3286
|
{{{ from64('length') }}};
|
|
@@ -6458,6 +6492,27 @@ function _napi_is_arraybuffer(env, value, result) {
|
|
|
6458
6492
|
return envObject.clearLastError();
|
|
6459
6493
|
}
|
|
6460
6494
|
/** @__sig ippp */
|
|
6495
|
+
function _node_api_is_sharedarraybuffer(env, value, result) {
|
|
6496
|
+
if (!env)
|
|
6497
|
+
return 1 /* napi_status.napi_invalid_arg */;
|
|
6498
|
+
// @ts-expect-error
|
|
6499
|
+
var envObject = emnapiCtx.envStore.get(env);
|
|
6500
|
+
envObject.checkGCAccess();
|
|
6501
|
+
if (!value)
|
|
6502
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
6503
|
+
if (!result)
|
|
6504
|
+
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
6505
|
+
var h = emnapiCtx.handleStore.get(value);
|
|
6506
|
+
{{{ from64('result') }}};
|
|
6507
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6508
|
+
var r = ((typeof SharedArrayBuffer === 'function' && h.value instanceof SharedArrayBuffer) ||
|
|
6509
|
+
(Object.prototype.toString.call(h.value) === '[object SharedArrayBuffer]'))
|
|
6510
|
+
? 1
|
|
6511
|
+
: 0;
|
|
6512
|
+
{{{ makeSetValue('result', 0, 'r', 'i8') }}};
|
|
6513
|
+
return envObject.clearLastError();
|
|
6514
|
+
}
|
|
6515
|
+
/** @__sig ippp */
|
|
6461
6516
|
function _napi_is_date(env, value, result) {
|
|
6462
6517
|
if (!env)
|
|
6463
6518
|
return 1 /* napi_status.napi_invalid_arg */;
|
|
@@ -6784,7 +6839,7 @@ function _napi_get_version(env, result) {
|
|
|
6784
6839
|
emnapi_is_support_weakref__deps: ["$emnapiCtx"],
|
|
6785
6840
|
emnapi_is_support_weakref__sig: "i",
|
|
6786
6841
|
emnapi_sync_memory: _emnapi_sync_memory,
|
|
6787
|
-
emnapi_sync_memory__deps: ["$emnapiCtx", "$emnapiSyncMemory"],
|
|
6842
|
+
emnapi_sync_memory__deps: ["$emnapiCtx", "$emnapiExternalMemory", "$emnapiSyncMemory"],
|
|
6788
6843
|
emnapi_sync_memory__sig: "ipippp",
|
|
6789
6844
|
$emnapiTSFN: emnapiTSFN,
|
|
6790
6845
|
$emnapiTSFN__deps: ["$emnapiCtx", "_emnapi_runtime_keepalive_pop", "$emnapiNodeBinding", "_emnapi_node_emit_async_destroy", "malloc", "free"],
|
|
@@ -7232,9 +7287,15 @@ function _napi_get_version(env, result) {
|
|
|
7232
7287
|
node_api_create_property_key_utf8: _node_api_create_property_key_utf8,
|
|
7233
7288
|
node_api_create_property_key_utf8__deps: ["napi_create_string_utf8"],
|
|
7234
7289
|
node_api_create_property_key_utf8__sig: "ipppp",
|
|
7290
|
+
node_api_create_sharedarraybuffer: _node_api_create_sharedarraybuffer,
|
|
7291
|
+
node_api_create_sharedarraybuffer__deps: ["$emnapiCtx", "$emnapiCreateArrayBuffer"],
|
|
7292
|
+
node_api_create_sharedarraybuffer__sig: "ipppp",
|
|
7235
7293
|
node_api_create_syntax_error: _node_api_create_syntax_error,
|
|
7236
7294
|
node_api_create_syntax_error__deps: ["$emnapiCtx"],
|
|
7237
7295
|
node_api_create_syntax_error__sig: "ipppp",
|
|
7296
|
+
node_api_is_sharedarraybuffer: _node_api_is_sharedarraybuffer,
|
|
7297
|
+
node_api_is_sharedarraybuffer__deps: ["$emnapiCtx"],
|
|
7298
|
+
node_api_is_sharedarraybuffer__sig: "ippp",
|
|
7238
7299
|
node_api_post_finalizer: _node_api_post_finalizer,
|
|
7239
7300
|
node_api_post_finalizer__deps: ["$emnapiCtx"],
|
|
7240
7301
|
node_api_post_finalizer__sig: "ipppp",
|
package/include/node/emnapi.h
CHANGED
|
@@ -358,7 +358,7 @@ napi_create_reference(napi_env env,
|
|
|
358
358
|
|
|
359
359
|
// Deletes a reference. The referenced value is released, and may
|
|
360
360
|
// be GC'd unless there are other references to it.
|
|
361
|
-
NAPI_EXTERN napi_status NAPI_CDECL napi_delete_reference(
|
|
361
|
+
NAPI_EXTERN napi_status NAPI_CDECL napi_delete_reference(node_api_basic_env env,
|
|
362
362
|
napi_ref ref);
|
|
363
363
|
|
|
364
364
|
// Increments the reference count, optionally returning the resulting count.
|
|
@@ -480,6 +480,14 @@ napi_get_dataview_info(napi_env env,
|
|
|
480
480
|
napi_value* arraybuffer,
|
|
481
481
|
size_t* byte_offset);
|
|
482
482
|
|
|
483
|
+
#ifdef NAPI_EXPERIMENTAL
|
|
484
|
+
#define NODE_API_EXPERIMENTAL_HAS_SHAREDARRAYBUFFER
|
|
485
|
+
NAPI_EXTERN napi_status NAPI_CDECL
|
|
486
|
+
node_api_is_sharedarraybuffer(napi_env env, napi_value value, bool* result);
|
|
487
|
+
NAPI_EXTERN napi_status NAPI_CDECL node_api_create_sharedarraybuffer(
|
|
488
|
+
napi_env env, size_t byte_length, void** data, napi_value* result);
|
|
489
|
+
#endif // NAPI_EXPERIMENTAL
|
|
490
|
+
|
|
483
491
|
// version management
|
|
484
492
|
NAPI_EXTERN napi_status NAPI_CDECL napi_get_version(node_api_basic_env env,
|
|
485
493
|
uint32_t* result);
|