@d0paminedriven/xlsxdown-wasm 0.7.0 → 0.9.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/worker.js
CHANGED
|
@@ -35,7 +35,7 @@ if (!("Buffer" in globalThis)) Object.defineProperty(globalThis, "Buffer", {
|
|
|
35
35
|
configurable: true,
|
|
36
36
|
writable: true
|
|
37
37
|
});
|
|
38
|
-
//
|
|
38
|
+
// ../../../node_modules/.store/@emnapi-wasi-threads-npm-2.2.0-6f3dce3920/package/dist/wasi-threads.js
|
|
39
39
|
const _WebAssembly$2 = typeof WebAssembly !== "undefined" ? WebAssembly : typeof WXWebAssembly !== "undefined" ? WXWebAssembly : void 0;
|
|
40
40
|
const ENVIRONMENT_IS_NODE = typeof process === "object" && process !== null && typeof process.versions === "object" && process.versions !== null && typeof process.versions.node === "string";
|
|
41
41
|
function getPostMessage(options) {
|
|
@@ -207,13 +207,7 @@ var ThreadManager = class {
|
|
|
207
207
|
if (this._reuseWorker) {
|
|
208
208
|
if (this._reuseWorker.size) {
|
|
209
209
|
let pthreadPoolSize = this._reuseWorker.size;
|
|
210
|
-
while (pthreadPoolSize--)
|
|
211
|
-
const worker = this.allocateUnusedWorker();
|
|
212
|
-
if (ENVIRONMENT_IS_NODE) {
|
|
213
|
-
worker.once("message", () => {});
|
|
214
|
-
worker.unref();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
210
|
+
while (pthreadPoolSize--) this.allocatePoolWorker();
|
|
217
211
|
}
|
|
218
212
|
}
|
|
219
213
|
}
|
|
@@ -297,8 +291,7 @@ var ThreadManager = class {
|
|
|
297
291
|
else err(message);
|
|
298
292
|
if (!worker.loaded) {
|
|
299
293
|
reject(error);
|
|
300
|
-
_this.
|
|
301
|
-
_this.terminateWorker(worker);
|
|
294
|
+
_this.dropFailedLoad(worker);
|
|
302
295
|
return;
|
|
303
296
|
}
|
|
304
297
|
_this.fail(error, !ENVIRONMENT_IS_NODE);
|
|
@@ -322,8 +315,7 @@ var ThreadManager = class {
|
|
|
322
315
|
const error = deserializeError(threadError.error);
|
|
323
316
|
if (!worker.loaded && threadError.phase === "load") {
|
|
324
317
|
reject(error);
|
|
325
|
-
this.
|
|
326
|
-
this.terminateWorker(worker);
|
|
318
|
+
this.dropFailedLoad(worker);
|
|
327
319
|
} else this.fail(error, true);
|
|
328
320
|
}
|
|
329
321
|
}
|
|
@@ -367,8 +359,7 @@ var ThreadManager = class {
|
|
|
367
359
|
error = memoryError;
|
|
368
360
|
}
|
|
369
361
|
reject(error);
|
|
370
|
-
this.
|
|
371
|
-
this.terminateWorker(worker);
|
|
362
|
+
this.dropFailedLoad(worker);
|
|
372
363
|
}
|
|
373
364
|
});
|
|
374
365
|
return worker.whenLoaded;
|
|
@@ -385,6 +376,20 @@ var ThreadManager = class {
|
|
|
385
376
|
this.unusedWorkers.push(worker);
|
|
386
377
|
return worker;
|
|
387
378
|
}
|
|
379
|
+
allocatePoolWorker() {
|
|
380
|
+
const worker = this.allocateUnusedWorker();
|
|
381
|
+
if (ENVIRONMENT_IS_NODE) {
|
|
382
|
+
worker.once("message", () => {});
|
|
383
|
+
worker.unref();
|
|
384
|
+
}
|
|
385
|
+
return worker;
|
|
386
|
+
}
|
|
387
|
+
dropFailedLoad(worker) {
|
|
388
|
+
const idle = this.unusedWorkers.indexOf(worker) !== -1;
|
|
389
|
+
this.loadRejects.delete(worker);
|
|
390
|
+
this.terminateWorker(worker);
|
|
391
|
+
if (idle && !this._fatalError) this.allocatePoolWorker();
|
|
392
|
+
}
|
|
388
393
|
getNewWorker(sab) {
|
|
389
394
|
this.assertRunning();
|
|
390
395
|
if (this._reuseWorker) {
|
|
@@ -395,14 +400,19 @@ var ThreadManager = class {
|
|
|
395
400
|
return;
|
|
396
401
|
}
|
|
397
402
|
}
|
|
398
|
-
|
|
399
|
-
this.loadWasmModuleToWorker(worker, sab);
|
|
403
|
+
return this.allocateAndLoadWorker(sab);
|
|
400
404
|
}
|
|
401
|
-
|
|
405
|
+
const worker = this.unusedWorkers.pop();
|
|
406
|
+
if (!worker.whenLoaded) this.loadWasmModuleToWorker(worker, sab);
|
|
407
|
+
return worker;
|
|
402
408
|
}
|
|
409
|
+
return this.allocateAndLoadWorker(sab);
|
|
410
|
+
}
|
|
411
|
+
allocateAndLoadWorker(sab) {
|
|
403
412
|
const worker = this.allocateUnusedWorker();
|
|
413
|
+
this.unusedWorkers.pop();
|
|
404
414
|
this.loadWasmModuleToWorker(worker, sab);
|
|
405
|
-
return this.
|
|
415
|
+
return this.expectedTerminations.has(worker) ? void 0 : worker;
|
|
406
416
|
}
|
|
407
417
|
cleanThread(worker, tid, force) {
|
|
408
418
|
if (!force && this._reuseWorker) this.returnWorkerToPool(worker);
|
|
@@ -416,12 +426,18 @@ var ThreadManager = class {
|
|
|
416
426
|
const tid = worker.__emnapi_tid;
|
|
417
427
|
this.expectedTerminations.add(worker);
|
|
418
428
|
this.registeredWorkers.delete(worker);
|
|
429
|
+
const index = this.unusedWorkers.indexOf(worker);
|
|
430
|
+
if (index !== -1) this.unusedWorkers.splice(index, 1);
|
|
419
431
|
this.loadRejects.delete(worker);
|
|
420
432
|
worker.terminate();
|
|
421
433
|
this.messageEvents.get(worker)?.clear();
|
|
422
434
|
this.messageEvents.delete(worker);
|
|
423
435
|
worker.onmessage = (e) => {
|
|
424
|
-
if (e.data.__emnapi__)
|
|
436
|
+
if (e.data.__emnapi__) {
|
|
437
|
+
const type = e.data.__emnapi__.type;
|
|
438
|
+
if (type === "loaded") return;
|
|
439
|
+
(0, this.printErr)("received \"" + type + "\" command from terminated worker: " + tid);
|
|
440
|
+
}
|
|
425
441
|
};
|
|
426
442
|
}
|
|
427
443
|
terminateAllThreads() {
|
|
@@ -643,7 +659,7 @@ var WASIThreads = class {
|
|
|
643
659
|
if (!shouldWait) worker.whenLoaded.catch((err) => {
|
|
644
660
|
delete worker.whenLoaded;
|
|
645
661
|
PThread.cleanThread(worker, tid, true);
|
|
646
|
-
|
|
662
|
+
PThread.printErr("failed to load the worker of thread " + tid + ": " + (err && err.stack || err));
|
|
647
663
|
});
|
|
648
664
|
if (isNewABI) return 0;
|
|
649
665
|
free(errorOrTid);
|
|
@@ -810,17 +826,20 @@ var ThreadMessageHandler = class {
|
|
|
810
826
|
_loaded(err, source, payload) {
|
|
811
827
|
if (err) {
|
|
812
828
|
notifyPthreadCreateResult(payload.sab, 2, err);
|
|
829
|
+
this._failQueuedStarts(err);
|
|
813
830
|
throw err;
|
|
814
831
|
}
|
|
815
832
|
if (source == null) {
|
|
816
833
|
const err = /* @__PURE__ */ new TypeError("onLoad should return an object");
|
|
817
834
|
notifyPthreadCreateResult(payload.sab, 2, err);
|
|
835
|
+
this._failQueuedStarts(err);
|
|
818
836
|
throw err;
|
|
819
837
|
}
|
|
820
838
|
const instance = source.instance;
|
|
821
839
|
if (!instance) {
|
|
822
840
|
const err = /* @__PURE__ */ new TypeError("onLoad should return an object which includes \"instance\"");
|
|
823
841
|
notifyPthreadCreateResult(payload.sab, 2, err);
|
|
842
|
+
this._failQueuedStarts(err);
|
|
824
843
|
throw err;
|
|
825
844
|
}
|
|
826
845
|
this.instance = instance;
|
|
@@ -832,6 +851,13 @@ var ThreadMessageHandler = class {
|
|
|
832
851
|
this.handle({ data });
|
|
833
852
|
}
|
|
834
853
|
}
|
|
854
|
+
_failQueuedStarts(err) {
|
|
855
|
+
this.messagesBeforeLoad = this.messagesBeforeLoad.filter((data) => {
|
|
856
|
+
if (data?.__emnapi__?.type !== "start") return true;
|
|
857
|
+
notifyPthreadCreateResult(data.__emnapi__.payload.sab, 2, err);
|
|
858
|
+
return false;
|
|
859
|
+
});
|
|
860
|
+
}
|
|
835
861
|
handleAfterLoad(e, f) {
|
|
836
862
|
if (this.instance !== void 0) f.call(this, e);
|
|
837
863
|
else this.messagesBeforeLoad.push(e.data);
|
|
@@ -865,18 +891,23 @@ function notifyPthreadCreateResult(sab, result, error) {
|
|
|
865
891
|
Atomics.notify(sab, 0);
|
|
866
892
|
}
|
|
867
893
|
}
|
|
868
|
-
//
|
|
894
|
+
// ../../../node_modules/.store/@emnapi-core-npm-2.0.0-beta.3-e70ba04e16/package/dist/emnapi-core.js
|
|
869
895
|
var emnapi_core_exports = /* @__PURE__ */ __exportAll({
|
|
870
896
|
MessageHandler: () => MessageHandler$1,
|
|
871
897
|
ThreadManager: () => ThreadManager,
|
|
872
898
|
ThreadMessageHandler: () => ThreadMessageHandler,
|
|
873
899
|
WASIThreads: () => WASIThreads,
|
|
900
|
+
createAddonModule: () => createAddonModule,
|
|
874
901
|
createInstanceProxy: () => createInstanceProxy,
|
|
875
902
|
createNapiModule: () => createNapiModule,
|
|
903
|
+
instantiateAddon: () => instantiateAddon,
|
|
904
|
+
instantiateAddonSync: () => instantiateAddonSync,
|
|
876
905
|
instantiateNapiModule: () => instantiateNapiModule$1,
|
|
877
906
|
instantiateNapiModuleSync: () => instantiateNapiModuleSync$1,
|
|
878
907
|
isSharedArrayBuffer: () => isSharedArrayBuffer,
|
|
879
908
|
isTrapError: () => isTrapError,
|
|
909
|
+
loadAddon: () => loadAddon,
|
|
910
|
+
loadAddonSync: () => loadAddonSync,
|
|
880
911
|
loadNapiModule: () => loadNapiModule,
|
|
881
912
|
loadNapiModuleSync: () => loadNapiModuleSync,
|
|
882
913
|
version: () => version$1
|
|
@@ -932,7 +963,7 @@ function loadSync(wasmInput, imports) {
|
|
|
932
963
|
module
|
|
933
964
|
};
|
|
934
965
|
}
|
|
935
|
-
function
|
|
966
|
+
function createAddonModule(options) {
|
|
936
967
|
return (function() {
|
|
937
968
|
function uleb128EncodeWithLen(arr) {
|
|
938
969
|
const n = arr.length;
|
|
@@ -1067,7 +1098,7 @@ function createNapiModule(options) {
|
|
|
1067
1098
|
GET_HEAP_DATA_VIEW().setUint32(env + 32, engine_reserved, true);
|
|
1068
1099
|
return error_code;
|
|
1069
1100
|
}
|
|
1070
|
-
var
|
|
1101
|
+
var addonModule = {
|
|
1071
1102
|
imports: {
|
|
1072
1103
|
env: {},
|
|
1073
1104
|
napi: {},
|
|
@@ -1082,7 +1113,7 @@ function createNapiModule(options) {
|
|
|
1082
1113
|
waitThreadStart,
|
|
1083
1114
|
PThread: void 0,
|
|
1084
1115
|
init(options) {
|
|
1085
|
-
if (
|
|
1116
|
+
if (addonModule.loaded) return addonModule.exports;
|
|
1086
1117
|
if (!options) throw new TypeError("Invalid napi init options");
|
|
1087
1118
|
const instance = options.instance;
|
|
1088
1119
|
if (!instance?.exports) throw new TypeError("Invalid wasm instance");
|
|
@@ -1103,39 +1134,60 @@ function createNapiModule(options) {
|
|
|
1103
1134
|
_free = exports.free;
|
|
1104
1135
|
_emnapi_create_env = exports.emnapi_create_env;
|
|
1105
1136
|
_emnapi_delete_env = exports.emnapi_delete_env;
|
|
1106
|
-
if (!
|
|
1107
|
-
const NODE_MODULE_VERSION =
|
|
1137
|
+
if (!addonModule.childThread) {
|
|
1138
|
+
const NODE_MODULE_VERSION = 137;
|
|
1108
1139
|
const nodeRegisterModuleSymbol = `node_register_module_v${NODE_MODULE_VERSION}`;
|
|
1140
|
+
var HEAP_DATA_VIEW = new DataView(wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(wasmMemory.buffer);
|
|
1109
1141
|
if (typeof instance.exports[nodeRegisterModuleSymbol] === "function") {
|
|
1110
1142
|
const scope = emnapiCtx.isolate.openScope();
|
|
1143
|
+
const malloc = instance.exports.malloc;
|
|
1144
|
+
const free = instance.exports.free;
|
|
1145
|
+
let exportsSlot = 0;
|
|
1146
|
+
let moduleSlot = 0;
|
|
1111
1147
|
try {
|
|
1112
|
-
const exports =
|
|
1148
|
+
const exports = addonModule.exports;
|
|
1113
1149
|
const exportsHandle = scope.add(exports);
|
|
1114
|
-
const moduleHandle = scope.add(
|
|
1115
|
-
|
|
1150
|
+
const moduleHandle = scope.add(addonModule);
|
|
1151
|
+
const size = 4;
|
|
1152
|
+
exportsSlot = malloc(size);
|
|
1153
|
+
moduleSlot = malloc(size);
|
|
1154
|
+
exportsSlot >>>= 0;
|
|
1155
|
+
moduleSlot >>>= 0;
|
|
1156
|
+
try {
|
|
1157
|
+
if (!exportsSlot || !moduleSlot) throw new Error("Failed to allocate V8 local handle slots");
|
|
1158
|
+
GET_HEAP_DATA_VIEW().setUint32(exportsSlot, exportsHandle, true);
|
|
1159
|
+
GET_HEAP_DATA_VIEW().setUint32(moduleSlot, moduleHandle, true);
|
|
1160
|
+
instance.exports[nodeRegisterModuleSymbol](exportsSlot, moduleSlot, 5);
|
|
1161
|
+
} finally {
|
|
1162
|
+
if (moduleSlot) free(moduleSlot);
|
|
1163
|
+
if (exportsSlot) free(exportsSlot);
|
|
1164
|
+
}
|
|
1116
1165
|
} catch (err) {
|
|
1117
1166
|
if (err !== "unwind") throw err;
|
|
1118
1167
|
} finally {
|
|
1119
1168
|
emnapiCtx.isolate.closeScope(scope);
|
|
1120
1169
|
}
|
|
1121
|
-
|
|
1122
|
-
delete
|
|
1123
|
-
return
|
|
1170
|
+
addonModule.loaded = true;
|
|
1171
|
+
delete addonModule.envObject;
|
|
1172
|
+
return addonModule.exports;
|
|
1124
1173
|
}
|
|
1125
1174
|
const find = Object.keys(instance.exports).filter((k) => k.startsWith("node_register_module_v"));
|
|
1126
|
-
if (find.length > 0) throw new Error(`The module${
|
|
1175
|
+
if (find.length > 0) throw new Error(`The module${addonModule.filename ? ` '${addonModule.filename}'` : ""}
|
|
1127
1176
|
was compiled against a different Node.js version using
|
|
1128
1177
|
NODE_MODULE_VERSION ${find[0].slice(22)}. This version of Node.js requires
|
|
1129
1178
|
NODE_MODULE_VERSION ${NODE_MODULE_VERSION}.`);
|
|
1130
1179
|
let moduleApiVersion = 8;
|
|
1131
1180
|
const node_api_module_get_api_version_v1 = instance.exports.node_api_module_get_api_version_v1;
|
|
1132
1181
|
if (typeof node_api_module_get_api_version_v1 === "function") moduleApiVersion = node_api_module_get_api_version_v1();
|
|
1133
|
-
const envObject =
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1182
|
+
const envObject = addonModule.envObject || (() => {
|
|
1183
|
+
const envObject = addonModule.envObject = emnapiEnv = emnapiCtx.createEnv(addonModule.filename, moduleApiVersion, {
|
|
1184
|
+
address: () => {
|
|
1185
|
+
let address = _emnapi_create_env();
|
|
1186
|
+
address >>>= 0;
|
|
1187
|
+
if (!address) throw new Error("Failed to create env");
|
|
1188
|
+
address += 8;
|
|
1189
|
+
return address;
|
|
1190
|
+
},
|
|
1139
1191
|
deleteEnv: (ptr) => {
|
|
1140
1192
|
_emnapi_delete_env(ptr - 8);
|
|
1141
1193
|
},
|
|
@@ -1144,27 +1196,27 @@ function createNapiModule(options) {
|
|
|
1144
1196
|
makeDynCall_vp: (cb) => wasmTable.get(cb),
|
|
1145
1197
|
abort
|
|
1146
1198
|
}, emnapiNodeBinding);
|
|
1147
|
-
|
|
1199
|
+
let address = envObject.address;
|
|
1148
1200
|
GET_HEAP_DATA_VIEW().setUint32(address - 8 + 24, envObject.id, true);
|
|
1149
1201
|
return envObject;
|
|
1150
1202
|
})();
|
|
1151
1203
|
const scope = emnapiCtx.openScope(envObject);
|
|
1152
1204
|
try {
|
|
1153
1205
|
envObject.callIntoModule((_envObject) => {
|
|
1154
|
-
const exports =
|
|
1155
|
-
const env = envObject.
|
|
1206
|
+
const exports = addonModule.exports;
|
|
1207
|
+
const env = envObject.address;
|
|
1156
1208
|
const exportsHandle = scope.add(exports);
|
|
1157
1209
|
const napiValue = (0, instance.exports.napi_register_wasm_v1)(env, exportsHandle);
|
|
1158
|
-
|
|
1210
|
+
addonModule.exports = !napiValue ? exports : emnapiCtx.jsValueFromNapiValue(napiValue);
|
|
1159
1211
|
});
|
|
1160
1212
|
} catch (e) {
|
|
1161
1213
|
if (e !== "unwind") throw e;
|
|
1162
1214
|
} finally {
|
|
1163
1215
|
emnapiCtx.closeScope(envObject, scope);
|
|
1164
1216
|
}
|
|
1165
|
-
|
|
1166
|
-
delete
|
|
1167
|
-
return
|
|
1217
|
+
addonModule.loaded = true;
|
|
1218
|
+
delete addonModule.envObject;
|
|
1219
|
+
return addonModule.exports;
|
|
1168
1220
|
}
|
|
1169
1221
|
}
|
|
1170
1222
|
};
|
|
@@ -1182,9 +1234,9 @@ function createNapiModule(options) {
|
|
|
1182
1234
|
emnapiCtx = options?.context;
|
|
1183
1235
|
const postMsg = typeof options.postMessage === "function" ? options.postMessage : typeof postMessage === "function" ? postMessage : void 0;
|
|
1184
1236
|
if (typeof postMsg !== "function") throw new TypeError("No postMessage found");
|
|
1185
|
-
|
|
1237
|
+
addonModule.postMessage = postMsg;
|
|
1186
1238
|
}
|
|
1187
|
-
if (typeof options.filename === "string")
|
|
1239
|
+
if (typeof options.filename === "string") addonModule.filename = options.filename;
|
|
1188
1240
|
if (typeof options.onCreateWorker === "function") onCreateWorker = options.onCreateWorker;
|
|
1189
1241
|
if (typeof options.print === "function") out = options.print;
|
|
1190
1242
|
else out = console.log.bind(console);
|
|
@@ -1206,14 +1258,14 @@ function createNapiModule(options) {
|
|
|
1206
1258
|
function _emnapi_async_work_pool_size() {
|
|
1207
1259
|
return Math.abs(emnapiAsyncWorkPoolSize);
|
|
1208
1260
|
}
|
|
1209
|
-
|
|
1261
|
+
addonModule.imports.env._emnapi_async_work_pool_size = _emnapi_async_work_pool_size;
|
|
1210
1262
|
function emnapiAddSendListener(worker) {
|
|
1211
1263
|
if (!worker) return false;
|
|
1212
1264
|
if (worker._emnapiSendListener) return true;
|
|
1213
1265
|
const handler = function(e) {
|
|
1214
1266
|
const __emnapi__ = (ENVIRONMENT_IS_NODE ? e : e.data).__emnapi__;
|
|
1215
1267
|
if (__emnapi__ && __emnapi__.type === "async-send") {
|
|
1216
|
-
if (ENVIRONMENT_IS_PTHREAD) (0,
|
|
1268
|
+
if (ENVIRONMENT_IS_PTHREAD) (0, addonModule.postMessage)({ __emnapi__ });
|
|
1217
1269
|
else {
|
|
1218
1270
|
const { type, callback, data } = __emnapi__.payload;
|
|
1219
1271
|
const call = () => wasmTable.get(callback)(data);
|
|
@@ -1239,7 +1291,7 @@ function createNapiModule(options) {
|
|
|
1239
1291
|
else worker.addEventListener("message", handler, false);
|
|
1240
1292
|
return true;
|
|
1241
1293
|
}
|
|
1242
|
-
|
|
1294
|
+
addonModule.emnapi.addSendListener = emnapiAddSendListener;
|
|
1243
1295
|
var PThread = new ThreadManager(ENVIRONMENT_IS_PTHREAD ? {
|
|
1244
1296
|
printErr: err,
|
|
1245
1297
|
childThread: true
|
|
@@ -1251,7 +1303,7 @@ function createNapiModule(options) {
|
|
|
1251
1303
|
reuseWorker: options.reuseWorker,
|
|
1252
1304
|
onCreateWorker
|
|
1253
1305
|
});
|
|
1254
|
-
|
|
1306
|
+
addonModule.PThread = PThread;
|
|
1255
1307
|
var initMod = /*#__PURE__*/ Object.freeze({
|
|
1256
1308
|
__proto__: null,
|
|
1257
1309
|
ENVIRONMENT_IS_NODE,
|
|
@@ -1272,6 +1324,7 @@ function createNapiModule(options) {
|
|
|
1272
1324
|
},
|
|
1273
1325
|
abort,
|
|
1274
1326
|
addFunction,
|
|
1327
|
+
addonModule,
|
|
1275
1328
|
get emnapiAsyncWorkPoolSize() {
|
|
1276
1329
|
return emnapiAsyncWorkPoolSize;
|
|
1277
1330
|
},
|
|
@@ -1288,7 +1341,6 @@ function createNapiModule(options) {
|
|
|
1288
1341
|
return err;
|
|
1289
1342
|
},
|
|
1290
1343
|
getWasmTableEntry,
|
|
1291
|
-
napiModule,
|
|
1292
1344
|
get onCreateWorker() {
|
|
1293
1345
|
return onCreateWorker;
|
|
1294
1346
|
},
|
|
@@ -1488,7 +1540,7 @@ function createNapiModule(options) {
|
|
|
1488
1540
|
}
|
|
1489
1541
|
/** @__sig vipp */
|
|
1490
1542
|
function _emnapi_async_send_js(type, callback, data) {
|
|
1491
|
-
if (ENVIRONMENT_IS_PTHREAD) (0,
|
|
1543
|
+
if (ENVIRONMENT_IS_PTHREAD) (0, addonModule.postMessage)({ __emnapi__: {
|
|
1492
1544
|
type: "async-send",
|
|
1493
1545
|
payload: {
|
|
1494
1546
|
type,
|
|
@@ -1543,7 +1595,7 @@ function createNapiModule(options) {
|
|
|
1543
1595
|
/** @__sig v */
|
|
1544
1596
|
function _emnapi_emit_async_thread_ready() {
|
|
1545
1597
|
if (!ENVIRONMENT_IS_PTHREAD) return;
|
|
1546
|
-
(0,
|
|
1598
|
+
(0, addonModule.postMessage)({ __emnapi__: {
|
|
1547
1599
|
type: "async-thread-ready",
|
|
1548
1600
|
payload: {}
|
|
1549
1601
|
} });
|
|
@@ -1587,6 +1639,7 @@ function createNapiModule(options) {
|
|
|
1587
1639
|
_free(_pointer);
|
|
1588
1640
|
}) : void 0,
|
|
1589
1641
|
table: /* @__PURE__ */ new WeakMap(),
|
|
1642
|
+
backingStoreTable: /* @__PURE__ */ new Map(),
|
|
1590
1643
|
wasmMemoryViewTable: /* @__PURE__ */ new WeakMap(),
|
|
1591
1644
|
cachedMemoryBuffer: void 0,
|
|
1592
1645
|
cachedHEAPU8: void 0,
|
|
@@ -1596,10 +1649,12 @@ function createNapiModule(options) {
|
|
|
1596
1649
|
_free(_pointer);
|
|
1597
1650
|
}) : void 0;
|
|
1598
1651
|
emnapiExternalMemory.table = /* @__PURE__ */ new WeakMap();
|
|
1652
|
+
emnapiExternalMemory.backingStoreTable = /* @__PURE__ */ new Map();
|
|
1599
1653
|
emnapiExternalMemory.wasmMemoryViewTable = /* @__PURE__ */ new WeakMap();
|
|
1600
1654
|
emnapiExternalMemory.cachedMemoryBuffer = void 0;
|
|
1601
1655
|
emnapiExternalMemory.cachedHEAPU8 = void 0;
|
|
1602
1656
|
const sharedArrayBufferByteLength = typeof SharedArrayBuffer === "function" ? Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength")?.get : void 0;
|
|
1657
|
+
const sharedArrayBufferMaxByteLength = typeof SharedArrayBuffer === "function" ? Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "maxByteLength")?.get : void 0;
|
|
1603
1658
|
emnapiExternalMemory.intrinsics = {
|
|
1604
1659
|
isView: ArrayBuffer.isView,
|
|
1605
1660
|
typedArray: {
|
|
@@ -1613,8 +1668,14 @@ function createNapiModule(options) {
|
|
|
1613
1668
|
byteOffset: Object.getOwnPropertyDescriptor(DataView.prototype, "byteOffset").get,
|
|
1614
1669
|
byteLength: Object.getOwnPropertyDescriptor(DataView.prototype, "byteLength").get
|
|
1615
1670
|
},
|
|
1616
|
-
arrayBuffer: {
|
|
1617
|
-
|
|
1671
|
+
arrayBuffer: {
|
|
1672
|
+
byteLength: Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get,
|
|
1673
|
+
maxByteLength: Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "maxByteLength")?.get
|
|
1674
|
+
},
|
|
1675
|
+
sharedArrayBuffer: sharedArrayBufferByteLength !== void 0 ? {
|
|
1676
|
+
byteLength: sharedArrayBufferByteLength,
|
|
1677
|
+
maxByteLength: sharedArrayBufferMaxByteLength
|
|
1678
|
+
} : void 0,
|
|
1618
1679
|
ctors: {
|
|
1619
1680
|
Int8Array,
|
|
1620
1681
|
Uint8Array,
|
|
@@ -1678,6 +1739,14 @@ function createNapiModule(options) {
|
|
|
1678
1739
|
return get.call(buffer);
|
|
1679
1740
|
}
|
|
1680
1741
|
},
|
|
1742
|
+
bufferMaxByteLength: function(buffer) {
|
|
1743
|
+
const intrinsics = emnapiExternalMemory.intrinsics;
|
|
1744
|
+
try {
|
|
1745
|
+
return intrinsics.arrayBuffer.maxByteLength?.call(buffer);
|
|
1746
|
+
} catch (_) {
|
|
1747
|
+
return intrinsics.sharedArrayBuffer?.maxByteLength?.call(buffer);
|
|
1748
|
+
}
|
|
1749
|
+
},
|
|
1681
1750
|
viewBuffer: function(view) {
|
|
1682
1751
|
const intrinsics = emnapiExternalMemory.intrinsics;
|
|
1683
1752
|
return intrinsics.typedArray.tag.call(view) === void 0 ? intrinsics.dataView.buffer.call(view) : intrinsics.typedArray.buffer.call(view);
|
|
@@ -1693,6 +1762,33 @@ function createNapiModule(options) {
|
|
|
1693
1762
|
getBufferFrom: function() {
|
|
1694
1763
|
return emnapiExternalMemory.intrinsics.bufferFrom ?? (emnapiExternalMemory.intrinsics.bufferFrom = emnapiCtx.features.Buffer.from);
|
|
1695
1764
|
},
|
|
1765
|
+
setBackingStore: function(backingStore, data, byteLength, arrayBuffer) {
|
|
1766
|
+
emnapiExternalMemory.backingStoreTable.set(backingStore, {
|
|
1767
|
+
data,
|
|
1768
|
+
byteLength,
|
|
1769
|
+
arrayBuffer
|
|
1770
|
+
});
|
|
1771
|
+
},
|
|
1772
|
+
getBackingStoreData: function(backingStore) {
|
|
1773
|
+
return emnapiExternalMemory.backingStoreTable.get(backingStore)?.data ?? 0;
|
|
1774
|
+
},
|
|
1775
|
+
getBackingStoreByteLength: function(backingStore) {
|
|
1776
|
+
return emnapiExternalMemory.backingStoreTable.get(backingStore)?.byteLength ?? 0;
|
|
1777
|
+
},
|
|
1778
|
+
deleteBackingStore: function(backingStore) {
|
|
1779
|
+
emnapiExternalMemory.backingStoreTable.delete(backingStore);
|
|
1780
|
+
},
|
|
1781
|
+
registerBufferAllocation: function(buffer, address, length) {
|
|
1782
|
+
const viewDescriptor = {
|
|
1783
|
+
Ctor: emnapiCtx.features.Buffer,
|
|
1784
|
+
address,
|
|
1785
|
+
length,
|
|
1786
|
+
ownership: emnapiExternalMemory.registry ? 0 : 1,
|
|
1787
|
+
runtimeAllocated: 1
|
|
1788
|
+
};
|
|
1789
|
+
emnapiExternalMemory.wasmMemoryViewTable.set(buffer, viewDescriptor);
|
|
1790
|
+
emnapiExternalMemory.registry?.register(viewDescriptor, address);
|
|
1791
|
+
},
|
|
1696
1792
|
getArrayBufferPointer: function(arrayBuffer, shouldCopy) {
|
|
1697
1793
|
const info = {
|
|
1698
1794
|
address: 0,
|
|
@@ -1707,7 +1803,29 @@ function createNapiModule(options) {
|
|
|
1707
1803
|
cachedInfo.address = 0;
|
|
1708
1804
|
return cachedInfo;
|
|
1709
1805
|
}
|
|
1710
|
-
if (shouldCopy && cachedInfo.
|
|
1806
|
+
if (shouldCopy && cachedInfo.runtimeAllocated === 1) {
|
|
1807
|
+
const byteLength = emnapiExternalMemory.bufferByteLength(arrayBuffer);
|
|
1808
|
+
const userland = cachedInfo.ownership === 1;
|
|
1809
|
+
if (byteLength > (userland ? cachedInfo.copied : cachedInfo.capacity)) {
|
|
1810
|
+
let capacity = userland ? byteLength : cachedInfo.capacity * 2;
|
|
1811
|
+
const maxByteLength = emnapiExternalMemory.bufferMaxByteLength(arrayBuffer);
|
|
1812
|
+
if (maxByteLength !== void 0 && capacity > maxByteLength) capacity = maxByteLength;
|
|
1813
|
+
if (capacity > 0x7f000000) capacity = 0x7f000000;
|
|
1814
|
+
if (capacity < byteLength) capacity = byteLength;
|
|
1815
|
+
let pointer = _malloc(capacity);
|
|
1816
|
+
if (!pointer && capacity !== byteLength) {
|
|
1817
|
+
capacity = byteLength;
|
|
1818
|
+
pointer = _malloc(capacity);
|
|
1819
|
+
}
|
|
1820
|
+
if (!pointer) throw new Error("Out of memory");
|
|
1821
|
+
pointer >>>= 0;
|
|
1822
|
+
cachedInfo.address = pointer;
|
|
1823
|
+
cachedInfo.capacity = capacity;
|
|
1824
|
+
emnapiExternalMemory.registry?.register(arrayBuffer, pointer);
|
|
1825
|
+
emnapiExternalMemory.getHEAPU8().set(new Uint8Array(arrayBuffer, 0, byteLength), cachedInfo.address);
|
|
1826
|
+
} else if (!userland) emnapiExternalMemory.getHEAPU8().set(new Uint8Array(arrayBuffer, 0, byteLength), cachedInfo.address);
|
|
1827
|
+
cachedInfo.copied = byteLength;
|
|
1828
|
+
}
|
|
1711
1829
|
return cachedInfo;
|
|
1712
1830
|
}
|
|
1713
1831
|
const byteLength = emnapiExternalMemory.bufferByteLength(arrayBuffer);
|
|
@@ -1716,10 +1834,12 @@ function createNapiModule(options) {
|
|
|
1716
1834
|
let pointer = _malloc(byteLength);
|
|
1717
1835
|
if (!pointer) throw new Error("Out of memory");
|
|
1718
1836
|
pointer >>>= 0;
|
|
1719
|
-
emnapiExternalMemory.getHEAPU8().set(new Uint8Array(arrayBuffer), pointer);
|
|
1837
|
+
emnapiExternalMemory.getHEAPU8().set(new Uint8Array(arrayBuffer, 0, byteLength), pointer);
|
|
1720
1838
|
info.address = pointer;
|
|
1721
1839
|
info.ownership = emnapiExternalMemory.registry ? 0 : 1;
|
|
1722
1840
|
info.runtimeAllocated = 1;
|
|
1841
|
+
info.capacity = byteLength;
|
|
1842
|
+
info.copied = byteLength;
|
|
1723
1843
|
emnapiExternalMemory.table.set(arrayBuffer, info);
|
|
1724
1844
|
emnapiExternalMemory.registry?.register(arrayBuffer, pointer);
|
|
1725
1845
|
return info;
|
|
@@ -1754,25 +1874,23 @@ function createNapiModule(options) {
|
|
|
1754
1874
|
},
|
|
1755
1875
|
getViewPointer: function(view, shouldCopy) {
|
|
1756
1876
|
view = emnapiExternalMemory.getOrUpdateMemoryView(view);
|
|
1757
|
-
const
|
|
1758
|
-
if (
|
|
1759
|
-
const
|
|
1760
|
-
if (info !== void 0) {
|
|
1761
|
-
const { address, ownership, runtimeAllocated } = info;
|
|
1762
|
-
return {
|
|
1763
|
-
address,
|
|
1764
|
-
ownership,
|
|
1765
|
-
runtimeAllocated,
|
|
1766
|
-
view
|
|
1767
|
-
};
|
|
1768
|
-
}
|
|
1877
|
+
const info = emnapiExternalMemory.wasmMemoryViewTable.get(view);
|
|
1878
|
+
if (info !== void 0) {
|
|
1879
|
+
const { address, ownership, runtimeAllocated } = info;
|
|
1769
1880
|
return {
|
|
1770
|
-
address
|
|
1771
|
-
ownership
|
|
1772
|
-
runtimeAllocated
|
|
1881
|
+
address,
|
|
1882
|
+
ownership,
|
|
1883
|
+
runtimeAllocated,
|
|
1773
1884
|
view
|
|
1774
1885
|
};
|
|
1775
1886
|
}
|
|
1887
|
+
const buffer = emnapiExternalMemory.viewBuffer(view);
|
|
1888
|
+
if (buffer === wasmMemory.buffer) return {
|
|
1889
|
+
address: emnapiExternalMemory.viewByteOffset(view),
|
|
1890
|
+
ownership: 1,
|
|
1891
|
+
runtimeAllocated: 0,
|
|
1892
|
+
view
|
|
1893
|
+
};
|
|
1776
1894
|
const { address, ownership, runtimeAllocated } = emnapiExternalMemory.getArrayBufferPointer(buffer, shouldCopy);
|
|
1777
1895
|
return {
|
|
1778
1896
|
address: address === 0 ? 0 : address + emnapiExternalMemory.viewByteOffset(view),
|
|
@@ -1780,6 +1898,10 @@ function createNapiModule(options) {
|
|
|
1780
1898
|
runtimeAllocated,
|
|
1781
1899
|
view
|
|
1782
1900
|
};
|
|
1901
|
+
},
|
|
1902
|
+
copyBytesFrom: function(arrayBuffer, byteOffset) {
|
|
1903
|
+
const copied = emnapiExternalMemory.table.get(arrayBuffer)?.copied;
|
|
1904
|
+
return copied === void 0 ? 1e400 : copied > byteOffset ? copied - byteOffset : 0;
|
|
1783
1905
|
}
|
|
1784
1906
|
};
|
|
1785
1907
|
/**
|
|
@@ -2149,6 +2271,7 @@ function createNapiModule(options) {
|
|
|
2149
2271
|
if (!arraybuffer) return envObject.setLastError(1);
|
|
2150
2272
|
const jsValue = emnapiCtx.jsValueFromNapiValue(arraybuffer);
|
|
2151
2273
|
if (!(jsValue instanceof ArrayBuffer) && !emnapiExternalMemory.isSharedArrayBuffer(jsValue)) return envObject.setLastError(1);
|
|
2274
|
+
const len = emnapiExternalMemory.bufferByteLength(jsValue);
|
|
2152
2275
|
var HEAP_DATA_VIEW = new DataView(wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(wasmMemory.buffer);
|
|
2153
2276
|
if (data) {
|
|
2154
2277
|
data >>>= 0;
|
|
@@ -2157,7 +2280,6 @@ function createNapiModule(options) {
|
|
|
2157
2280
|
}
|
|
2158
2281
|
if (byte_length) {
|
|
2159
2282
|
byte_length >>>= 0;
|
|
2160
|
-
const len = emnapiExternalMemory.bufferByteLength(jsValue);
|
|
2161
2283
|
GET_HEAP_DATA_VIEW().setUint32(byte_length, len, true);
|
|
2162
2284
|
}
|
|
2163
2285
|
return envObject.clearLastError();
|
|
@@ -3435,10 +3557,12 @@ function createNapiModule(options) {
|
|
|
3435
3557
|
if (arrayBufferOrView instanceof ArrayBuffer || emnapiExternalMemory.isSharedArrayBuffer(arrayBufferOrView)) {
|
|
3436
3558
|
const pointer = emnapiExternalMemory.getArrayBufferPointer(arrayBufferOrView, false).address;
|
|
3437
3559
|
if (!pointer) throw new Error("Unknown ArrayBuffer address");
|
|
3438
|
-
|
|
3560
|
+
const copyBytes = emnapiExternalMemory.copyBytesFrom(arrayBufferOrView, 0);
|
|
3561
|
+
if (typeof len !== "number" || len === -1 || len === 0xffffffff) len = Math.min(arrayBufferOrView.byteLength - offset, copyBytes);
|
|
3439
3562
|
len = len >>> 0;
|
|
3440
3563
|
if (len === 0) return arrayBufferOrView;
|
|
3441
3564
|
view = new Uint8Array(arrayBufferOrView, offset, len);
|
|
3565
|
+
if (len > copyBytes) throw new RangeError("The range is larger than the wasm copy of the buffer");
|
|
3442
3566
|
const wasmMemoryU8 = emnapiExternalMemory.getHEAPU8();
|
|
3443
3567
|
if (!js_to_wasm) view.set(wasmMemoryU8.subarray(pointer, pointer + len));
|
|
3444
3568
|
else wasmMemoryU8.set(view, pointer);
|
|
@@ -3449,10 +3573,12 @@ function createNapiModule(options) {
|
|
|
3449
3573
|
const latestView = viewPointerInfo.view;
|
|
3450
3574
|
const pointer = viewPointerInfo.address;
|
|
3451
3575
|
if (!pointer) throw new Error("Unknown ArrayBuffer address");
|
|
3452
|
-
|
|
3576
|
+
const copyBytes = emnapiExternalMemory.copyBytesFrom(emnapiExternalMemory.viewBuffer(latestView), emnapiExternalMemory.viewByteOffset(latestView));
|
|
3577
|
+
if (typeof len !== "number" || len === -1 || len === 0xffffffff) len = Math.min(latestView.byteLength - offset, copyBytes);
|
|
3453
3578
|
len = len >>> 0;
|
|
3454
3579
|
if (len === 0) return latestView;
|
|
3455
3580
|
view = new Uint8Array(latestView.buffer, latestView.byteOffset + offset, len);
|
|
3581
|
+
if (len > copyBytes) throw new RangeError("The range is larger than the wasm copy of the buffer");
|
|
3456
3582
|
const wasmMemoryU8 = emnapiExternalMemory.getHEAPU8();
|
|
3457
3583
|
if (!js_to_wasm) view.set(wasmMemoryU8.subarray(pointer, pointer + len));
|
|
3458
3584
|
else wasmMemoryU8.set(view, pointer);
|
|
@@ -3618,7 +3744,7 @@ function createNapiModule(options) {
|
|
|
3618
3744
|
* Can be called on any thread. Increments refcount and registers in
|
|
3619
3745
|
* the current thread's FinalizationRegistry.
|
|
3620
3746
|
* Exposed as Module.emnapiAcquireExternalSharedArrayBuffer (emscripten) or
|
|
3621
|
-
*
|
|
3747
|
+
* addonModule.emnapi.acquireExternalSharedArrayBuffer (core).
|
|
3622
3748
|
*/
|
|
3623
3749
|
function $emnapiAcquireExternalSharedArrayBuffer(handle, sab) {
|
|
3624
3750
|
if (sab != null && !emnapiExternalMemory.isSharedArrayBuffer(sab)) throw new TypeError("Expected a SharedArrayBuffer");
|
|
@@ -4774,7 +4900,7 @@ function createNapiModule(options) {
|
|
|
4774
4900
|
if (!result) return envObject.setLastError(1);
|
|
4775
4901
|
result >>>= 0;
|
|
4776
4902
|
const { thiz, fn } = emnapiCtx.getCallbackInfo(cbinfo);
|
|
4777
|
-
const value = thiz == null ||
|
|
4903
|
+
const value = thiz == null || typeof fn !== "function" ? 0 : thiz instanceof fn ? emnapiCtx.napiValueFromJsValue(fn) : 0;
|
|
4778
4904
|
var HEAP_DATA_VIEW = new DataView(wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(wasmMemory.buffer);
|
|
4779
4905
|
GET_HEAP_DATA_VIEW().setUint32(result, value, true);
|
|
4780
4906
|
return envObject.clearLastError();
|
|
@@ -4978,7 +5104,15 @@ function createNapiModule(options) {
|
|
|
4978
5104
|
});
|
|
4979
5105
|
/** @__sig vppdp */
|
|
4980
5106
|
function _emnapi_node_emit_async_init(async_resource, async_resource_name, trigger_async_id, result) {
|
|
4981
|
-
|
|
5107
|
+
var HEAP_DATA_VIEW = new DataView(wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(wasmMemory.buffer);
|
|
5108
|
+
if (!emnapiNodeBinding) {
|
|
5109
|
+
if (result) {
|
|
5110
|
+
result >>>= 0;
|
|
5111
|
+
GET_HEAP_DATA_VIEW().setFloat64(result, 0, true);
|
|
5112
|
+
GET_HEAP_DATA_VIEW().setFloat64(result + 8, trigger_async_id, true);
|
|
5113
|
+
}
|
|
5114
|
+
return;
|
|
5115
|
+
}
|
|
4982
5116
|
const resource = emnapiCtx.jsValueFromNapiValue(async_resource);
|
|
4983
5117
|
const resource_name = emnapiCtx.jsValueFromNapiValue(async_resource_name);
|
|
4984
5118
|
const asyncContext = emnapiNodeBinding.node.emitAsyncInit(resource, resource_name, trigger_async_id);
|
|
@@ -4986,7 +5120,6 @@ function createNapiModule(options) {
|
|
|
4986
5120
|
const triggerAsyncId = asyncContext.triggerAsyncId;
|
|
4987
5121
|
if (result) {
|
|
4988
5122
|
result >>>= 0;
|
|
4989
|
-
var HEAP_DATA_VIEW = new DataView(wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(wasmMemory.buffer);
|
|
4990
5123
|
GET_HEAP_DATA_VIEW().setFloat64(result, asyncId, true);
|
|
4991
5124
|
GET_HEAP_DATA_VIEW().setFloat64(result + 8, triggerAsyncId, true);
|
|
4992
5125
|
}
|
|
@@ -5003,7 +5136,6 @@ function createNapiModule(options) {
|
|
|
5003
5136
|
function _emnapi_node_make_callback(env, async_resource, cb, argv, size, async_id, trigger_async_id, result) {
|
|
5004
5137
|
let i = 0;
|
|
5005
5138
|
let v;
|
|
5006
|
-
if (!emnapiNodeBinding) return;
|
|
5007
5139
|
const resource = emnapiCtx.jsValueFromNapiValue(async_resource);
|
|
5008
5140
|
const callback = emnapiCtx.jsValueFromNapiValue(cb);
|
|
5009
5141
|
argv >>>= 0;
|
|
@@ -5015,6 +5147,18 @@ function createNapiModule(options) {
|
|
|
5015
5147
|
const argVal = GET_HEAP_DATA_VIEW().getUint32(argv + i * 4, true);
|
|
5016
5148
|
arr[i] = emnapiCtx.jsValueFromNapiValue(argVal);
|
|
5017
5149
|
}
|
|
5150
|
+
if (!emnapiNodeBinding) try {
|
|
5151
|
+
const ret = callback.apply(resource, arr);
|
|
5152
|
+
if (result) {
|
|
5153
|
+
result >>>= 0;
|
|
5154
|
+
const v = emnapiCtx.napiValueFromJsValue(ret);
|
|
5155
|
+
GET_HEAP_DATA_VIEW().setUint32(result, v, true);
|
|
5156
|
+
}
|
|
5157
|
+
return 0;
|
|
5158
|
+
} catch (err) {
|
|
5159
|
+
emnapiCtx.isolate.throwException(err);
|
|
5160
|
+
return 9;
|
|
5161
|
+
}
|
|
5018
5162
|
const ret = emnapiNodeBinding.node.makeCallback(resource, callback, arr, {
|
|
5019
5163
|
asyncId: async_id,
|
|
5020
5164
|
triggerAsyncId: trigger_async_id
|
|
@@ -5024,6 +5168,7 @@ function createNapiModule(options) {
|
|
|
5024
5168
|
v = emnapiCtx.napiValueFromJsValue(ret);
|
|
5025
5169
|
GET_HEAP_DATA_VIEW().setUint32(result, v, true);
|
|
5026
5170
|
}
|
|
5171
|
+
return 0;
|
|
5027
5172
|
}
|
|
5028
5173
|
/** @__sig ippp */
|
|
5029
5174
|
function _emnapi_async_init_js(async_resource, async_resource_name, result) {
|
|
@@ -6183,17 +6328,17 @@ function createNapiModule(options) {
|
|
|
6183
6328
|
emnapiExternalSAB.init();
|
|
6184
6329
|
emnapiString.init();
|
|
6185
6330
|
PThread.init();
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6331
|
+
addonModule.emnapi.syncMemory = $emnapiSyncMemory;
|
|
6332
|
+
addonModule.emnapi.getMemoryAddress = $emnapiGetMemoryAddress;
|
|
6333
|
+
addonModule.emnapi.acquireExternalSharedArrayBuffer = $emnapiAcquireExternalSharedArrayBuffer;
|
|
6189
6334
|
function addImports(mod) {
|
|
6190
6335
|
const keys = Object.keys(mod);
|
|
6191
6336
|
for (let i = 0; i < keys.length; ++i) {
|
|
6192
6337
|
const k = keys[i];
|
|
6193
6338
|
if (k.indexOf("$") === 0) continue;
|
|
6194
|
-
if (k.indexOf("emnapi_") === 0)
|
|
6195
|
-
else if (k.indexOf("_emnapi_") === 0 || k.indexOf("_v8_") === 0 || k === "napi_set_last_error" || k === "napi_clear_last_error")
|
|
6196
|
-
else
|
|
6339
|
+
if (k.indexOf("emnapi_") === 0) addonModule.imports.emnapi[k] = mod[k];
|
|
6340
|
+
else if (k.indexOf("_emnapi_") === 0 || k.indexOf("_v8_") === 0 || k === "napi_set_last_error" || k === "napi_clear_last_error") addonModule.imports.env[k] = mod[k];
|
|
6341
|
+
else addonModule.imports.napi[k] = mod[k];
|
|
6197
6342
|
}
|
|
6198
6343
|
}
|
|
6199
6344
|
addImports(asyncMod);
|
|
@@ -6216,7 +6361,10 @@ function createNapiModule(options) {
|
|
|
6216
6361
|
addImports(scriptMod);
|
|
6217
6362
|
addImports(valueOperationMod);
|
|
6218
6363
|
addImports(versionMod);
|
|
6219
|
-
const pluginCtx = {
|
|
6364
|
+
const pluginCtx = {
|
|
6365
|
+
emnapiString,
|
|
6366
|
+
emnapiExternalMemory
|
|
6367
|
+
};
|
|
6220
6368
|
Object.keys(initMod).forEach((k) => {
|
|
6221
6369
|
Object.defineProperty(pluginCtx, k, {
|
|
6222
6370
|
get: () => initMod[k],
|
|
@@ -6238,21 +6386,22 @@ function createNapiModule(options) {
|
|
|
6238
6386
|
configurable: true
|
|
6239
6387
|
});
|
|
6240
6388
|
});
|
|
6241
|
-
|
|
6389
|
+
addonModule.plugins = (options.plugins ?? []).map((plugin) => {
|
|
6242
6390
|
if (typeof plugin === "function") return plugin(pluginCtx);
|
|
6243
6391
|
if (typeof plugin === "object" && plugin !== null) return plugin;
|
|
6244
6392
|
throw new TypeError("Invalid plugin");
|
|
6245
6393
|
});
|
|
6246
|
-
|
|
6394
|
+
addonModule.plugins.forEach((plugin) => {
|
|
6247
6395
|
if (typeof plugin.importObject === "function") {
|
|
6248
|
-
const importObject = plugin.importObject(
|
|
6249
|
-
if (importObject)
|
|
6396
|
+
const importObject = plugin.importObject(addonModule.imports);
|
|
6397
|
+
if (importObject) addonModule.imports = importObject;
|
|
6250
6398
|
}
|
|
6251
6399
|
});
|
|
6252
|
-
return
|
|
6400
|
+
return addonModule;
|
|
6253
6401
|
})();
|
|
6254
6402
|
}
|
|
6255
|
-
|
|
6403
|
+
const createNapiModule = createAddonModule;
|
|
6404
|
+
function loadAddonModuleImpl(loadFn, userAddonModule, wasmInput, options, useLegacyPropertyName = false) {
|
|
6256
6405
|
options = options ?? {};
|
|
6257
6406
|
const getMemory = options.getMemory;
|
|
6258
6407
|
const getTable = options.getTable;
|
|
@@ -6260,28 +6409,28 @@ function loadNapiModuleImpl(loadFn, userNapiModule, wasmInput, options) {
|
|
|
6260
6409
|
if (getMemory != null && typeof getMemory !== "function") throw new TypeError("options.getMemory is not a function");
|
|
6261
6410
|
if (getTable != null && typeof getTable !== "function") throw new TypeError("options.getTable is not a function");
|
|
6262
6411
|
if (beforeInit != null && typeof beforeInit !== "function") throw new TypeError("options.beforeInit is not a function");
|
|
6263
|
-
let
|
|
6264
|
-
const isLoad = typeof
|
|
6412
|
+
let addonModule;
|
|
6413
|
+
const isLoad = typeof userAddonModule === "object" && userAddonModule !== null;
|
|
6265
6414
|
if (isLoad) {
|
|
6266
|
-
if (
|
|
6267
|
-
|
|
6268
|
-
} else
|
|
6415
|
+
if (userAddonModule.loaded) throw new Error(`${useLegacyPropertyName ? "napiModule" : "addonModule"} has already loaded`);
|
|
6416
|
+
addonModule = userAddonModule;
|
|
6417
|
+
} else addonModule = createAddonModule(options);
|
|
6269
6418
|
const wasi = options.wasi;
|
|
6270
6419
|
let wasiThreads;
|
|
6271
6420
|
let importObject = {
|
|
6272
|
-
env:
|
|
6273
|
-
napi:
|
|
6274
|
-
emnapi:
|
|
6421
|
+
env: addonModule.imports.env,
|
|
6422
|
+
napi: addonModule.imports.napi,
|
|
6423
|
+
emnapi: addonModule.imports.emnapi
|
|
6275
6424
|
};
|
|
6276
6425
|
if (wasi) {
|
|
6277
|
-
wasiThreads = new WASIThreads(
|
|
6426
|
+
wasiThreads = new WASIThreads(addonModule.childThread ? {
|
|
6278
6427
|
wasi,
|
|
6279
6428
|
childThread: true,
|
|
6280
|
-
postMessage:
|
|
6429
|
+
postMessage: addonModule.postMessage
|
|
6281
6430
|
} : {
|
|
6282
6431
|
wasi,
|
|
6283
|
-
threadManager:
|
|
6284
|
-
waitThreadStart:
|
|
6432
|
+
threadManager: addonModule.PThread,
|
|
6433
|
+
waitThreadStart: addonModule.waitThreadStart
|
|
6285
6434
|
});
|
|
6286
6435
|
Object.assign(importObject, typeof wasi.getImportObject === "function" ? wasi.getImportObject() : { wasi_snapshot_preview1: wasi.wasiImport });
|
|
6287
6436
|
Object.assign(importObject, wasiThreads.getImportObject());
|
|
@@ -6308,13 +6457,13 @@ function loadNapiModuleImpl(loadFn, userNapiModule, wasmInput, options) {
|
|
|
6308
6457
|
}
|
|
6309
6458
|
const module = source.module;
|
|
6310
6459
|
if (wasi) instance = wasiThreads.initialize(instance, module, memory);
|
|
6311
|
-
else
|
|
6460
|
+
else addonModule.PThread.setup(module, memory);
|
|
6312
6461
|
const emnapiInit = () => {
|
|
6313
6462
|
if (beforeInit) beforeInit({
|
|
6314
6463
|
instance: originalInstance,
|
|
6315
6464
|
module
|
|
6316
6465
|
});
|
|
6317
|
-
|
|
6466
|
+
addonModule.init({
|
|
6318
6467
|
instance,
|
|
6319
6468
|
module,
|
|
6320
6469
|
memory,
|
|
@@ -6325,13 +6474,20 @@ function loadNapiModuleImpl(loadFn, userNapiModule, wasmInput, options) {
|
|
|
6325
6474
|
module,
|
|
6326
6475
|
usedInstance: instance
|
|
6327
6476
|
};
|
|
6328
|
-
if (!isLoad)
|
|
6477
|
+
if (!isLoad) {
|
|
6478
|
+
if (useLegacyPropertyName) ret.napiModule = addonModule;
|
|
6479
|
+
else ret.addonModule = addonModule;
|
|
6480
|
+
}
|
|
6329
6481
|
return ret;
|
|
6330
6482
|
};
|
|
6331
|
-
if (
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6483
|
+
if (addonModule.PThread.shouldPreloadWorkers()) {
|
|
6484
|
+
if (loadFn === loadCallback) return addonModule.PThread.loadWasmModuleToAllWorkers().then(emnapiInit);
|
|
6485
|
+
const PThread = addonModule.PThread;
|
|
6486
|
+
const workers = PThread.unusedWorkers.slice();
|
|
6487
|
+
for (let i = 0; i < workers.length; ++i) {
|
|
6488
|
+
const worker = workers[i];
|
|
6489
|
+
if (!worker.whenLoaded) PThread.loadWasmModuleToWorker(worker).then(void 0, () => {});
|
|
6490
|
+
}
|
|
6335
6491
|
}
|
|
6336
6492
|
return emnapiInit();
|
|
6337
6493
|
});
|
|
@@ -6352,20 +6508,55 @@ function loadSyncCallback(wasmInput, importObject, callback) {
|
|
|
6352
6508
|
}
|
|
6353
6509
|
return callback(null, source);
|
|
6354
6510
|
}
|
|
6511
|
+
/** @public */
|
|
6512
|
+
function loadAddon(addonModule, wasmInput, options) {
|
|
6513
|
+
if (typeof addonModule !== "object" || addonModule === null) throw new TypeError("Invalid addonModule");
|
|
6514
|
+
return loadAddonModuleImpl(loadCallback, addonModule, wasmInput, options);
|
|
6515
|
+
}
|
|
6516
|
+
/** @public */
|
|
6517
|
+
function loadAddonSync(addonModule, wasmInput, options) {
|
|
6518
|
+
if (typeof addonModule !== "object" || addonModule === null) throw new TypeError("Invalid addonModule");
|
|
6519
|
+
return loadAddonModuleImpl(loadSyncCallback, addonModule, wasmInput, options);
|
|
6520
|
+
}
|
|
6521
|
+
/**
|
|
6522
|
+
* @public
|
|
6523
|
+
* @deprecated Use loadAddon instead. This API will be removed in 2.0.0-rc.
|
|
6524
|
+
*/
|
|
6355
6525
|
function loadNapiModule(napiModule, wasmInput, options) {
|
|
6356
6526
|
if (typeof napiModule !== "object" || napiModule === null) throw new TypeError("Invalid napiModule");
|
|
6357
|
-
return
|
|
6527
|
+
return loadAddonModuleImpl(loadCallback, napiModule, wasmInput, options, true);
|
|
6358
6528
|
}
|
|
6529
|
+
/**
|
|
6530
|
+
* @public
|
|
6531
|
+
* @deprecated Use loadAddonSync instead. This API will be removed in 2.0.0-rc.
|
|
6532
|
+
*/
|
|
6359
6533
|
function loadNapiModuleSync(napiModule, wasmInput, options) {
|
|
6360
6534
|
if (typeof napiModule !== "object" || napiModule === null) throw new TypeError("Invalid napiModule");
|
|
6361
|
-
return
|
|
6535
|
+
return loadAddonModuleImpl(loadSyncCallback, napiModule, wasmInput, options, true);
|
|
6362
6536
|
}
|
|
6537
|
+
/** @public */
|
|
6538
|
+
function instantiateAddon(wasmInput, options) {
|
|
6539
|
+
return loadAddonModuleImpl(loadCallback, void 0, wasmInput, options);
|
|
6540
|
+
}
|
|
6541
|
+
/** @public */
|
|
6542
|
+
function instantiateAddonSync(wasmInput, options) {
|
|
6543
|
+
return loadAddonModuleImpl(loadSyncCallback, void 0, wasmInput, options);
|
|
6544
|
+
}
|
|
6545
|
+
/**
|
|
6546
|
+
* @public
|
|
6547
|
+
* @deprecated Use instantiateAddon instead. This API will be removed in 2.0.0-rc.
|
|
6548
|
+
*/
|
|
6363
6549
|
function instantiateNapiModule$1(wasmInput, options) {
|
|
6364
|
-
return
|
|
6550
|
+
return loadAddonModuleImpl(loadCallback, void 0, wasmInput, options, true);
|
|
6365
6551
|
}
|
|
6552
|
+
/**
|
|
6553
|
+
* @public
|
|
6554
|
+
* @deprecated Use instantiateAddonSync instead. This API will be removed in 2.0.0-rc.
|
|
6555
|
+
*/
|
|
6366
6556
|
function instantiateNapiModuleSync$1(wasmInput, options) {
|
|
6367
|
-
return
|
|
6557
|
+
return loadAddonModuleImpl(loadSyncCallback, void 0, wasmInput, options, true);
|
|
6368
6558
|
}
|
|
6559
|
+
/** @public */
|
|
6369
6560
|
var MessageHandler$1 = class extends ThreadMessageHandler {
|
|
6370
6561
|
constructor(options) {
|
|
6371
6562
|
if (typeof options.onLoad !== "function") throw new TypeError("options.onLoad is not a function");
|
|
@@ -6377,6 +6568,7 @@ var MessageHandler$1 = class extends ThreadMessageHandler {
|
|
|
6377
6568
|
else throw err;
|
|
6378
6569
|
}
|
|
6379
6570
|
});
|
|
6571
|
+
this.addonModule = void 0;
|
|
6380
6572
|
this.napiModule = void 0;
|
|
6381
6573
|
}
|
|
6382
6574
|
beforeReportError(_error, _type) {
|
|
@@ -6386,12 +6578,17 @@ var MessageHandler$1 = class extends ThreadMessageHandler {
|
|
|
6386
6578
|
instantiate(data) {
|
|
6387
6579
|
const source = this.onLoad(data);
|
|
6388
6580
|
if (typeof source.then === "function") return source.then((result) => {
|
|
6389
|
-
this.
|
|
6581
|
+
this.setAddonModule(result);
|
|
6390
6582
|
return result;
|
|
6391
6583
|
});
|
|
6392
|
-
this.
|
|
6584
|
+
this.setAddonModule(source);
|
|
6393
6585
|
return source;
|
|
6394
6586
|
}
|
|
6587
|
+
setAddonModule(source) {
|
|
6588
|
+
const addonModule = "addonModule" in source ? source.addonModule : source.napiModule;
|
|
6589
|
+
this.addonModule = addonModule;
|
|
6590
|
+
this.napiModule = addonModule;
|
|
6591
|
+
}
|
|
6395
6592
|
handle(e) {
|
|
6396
6593
|
super.handle(e);
|
|
6397
6594
|
if (e?.data?.__emnapi__) {
|
|
@@ -6399,7 +6596,7 @@ var MessageHandler$1 = class extends ThreadMessageHandler {
|
|
|
6399
6596
|
const payload = e.data.__emnapi__.payload;
|
|
6400
6597
|
try {
|
|
6401
6598
|
if (type === "async-worker-init") this.handleAfterLoad(e, () => {
|
|
6402
|
-
this.
|
|
6599
|
+
this.addonModule.initWorker(payload.arg, payload.func);
|
|
6403
6600
|
});
|
|
6404
6601
|
} catch (err) {
|
|
6405
6602
|
this.reportError(err, "async-worker-init");
|
|
@@ -6407,8 +6604,8 @@ var MessageHandler$1 = class extends ThreadMessageHandler {
|
|
|
6407
6604
|
}
|
|
6408
6605
|
}
|
|
6409
6606
|
};
|
|
6410
|
-
const version$1 = "2.0.0-
|
|
6411
|
-
//
|
|
6607
|
+
const version$1 = "2.0.0-beta.3";
|
|
6608
|
+
// ../../../node_modules/.store/@emnapi-runtime-npm-2.0.0-beta.3-c2baf0f649/package/dist/emnapi.js
|
|
6412
6609
|
var emnapi_exports = /* @__PURE__ */ __exportAll({
|
|
6413
6610
|
ArrayStore: () => ArrayStore,
|
|
6414
6611
|
BaseArrayStore: () => BaseArrayStore,
|
|
@@ -6670,9 +6867,9 @@ function getDylinkMetadata(binary) {
|
|
|
6670
6867
|
failIf(offset !== end);
|
|
6671
6868
|
return customSection;
|
|
6672
6869
|
}
|
|
6673
|
-
const version = "2.0.0-
|
|
6870
|
+
const version = "2.0.0-beta.3";
|
|
6674
6871
|
const NAPI_VERSION_EXPERIMENTAL = 0x7fffffff;
|
|
6675
|
-
const NODE_MODULE_VERSION =
|
|
6872
|
+
const NODE_MODULE_VERSION = 137;
|
|
6676
6873
|
var Disposable = class {};
|
|
6677
6874
|
if (typeof Symbol.dispose === "symbol") Object.defineProperty(Disposable.prototype, Symbol.dispose, {
|
|
6678
6875
|
value() {
|
|
@@ -6901,6 +7098,57 @@ var PersistentStore = class extends ArrayStore {
|
|
|
6901
7098
|
}
|
|
6902
7099
|
}
|
|
6903
7100
|
};
|
|
7101
|
+
var GlobalIdentityStore = class {
|
|
7102
|
+
constructor(isolate) {
|
|
7103
|
+
this._objects = /* @__PURE__ */ new WeakMap();
|
|
7104
|
+
this._primitives = /* @__PURE__ */ new Map();
|
|
7105
|
+
this._bySlot = /* @__PURE__ */ new Map();
|
|
7106
|
+
this._isolate = isolate;
|
|
7107
|
+
}
|
|
7108
|
+
acquire(value) {
|
|
7109
|
+
const objectLike = value !== null && (typeof value === "object" || typeof value === "function");
|
|
7110
|
+
const table = objectLike ? this._objects : this._primitives;
|
|
7111
|
+
let identity = table.get(value);
|
|
7112
|
+
if (identity?.retired) identity = void 0;
|
|
7113
|
+
if (!identity) {
|
|
7114
|
+
const reference = new Persistent(this._isolate, value);
|
|
7115
|
+
if (objectLike) reference.setWeak(void 0, () => {});
|
|
7116
|
+
identity = {
|
|
7117
|
+
reference,
|
|
7118
|
+
count: 0,
|
|
7119
|
+
pending: false,
|
|
7120
|
+
retired: false,
|
|
7121
|
+
objectLike,
|
|
7122
|
+
primitiveValue: objectLike ? void 0 : value
|
|
7123
|
+
};
|
|
7124
|
+
table.set(value, identity);
|
|
7125
|
+
this._bySlot.set(reference.slot(), identity);
|
|
7126
|
+
}
|
|
7127
|
+
identity.count++;
|
|
7128
|
+
identity.pending = false;
|
|
7129
|
+
return identity.reference.slot();
|
|
7130
|
+
}
|
|
7131
|
+
retain(slot) {
|
|
7132
|
+
const identity = this._bySlot.get(Number(slot));
|
|
7133
|
+
if (!identity || identity.retired) return;
|
|
7134
|
+
identity.count++;
|
|
7135
|
+
identity.pending = false;
|
|
7136
|
+
}
|
|
7137
|
+
release(slot) {
|
|
7138
|
+
const identity = this._bySlot.get(Number(slot));
|
|
7139
|
+
if (!identity || identity.retired || identity.count === 0) return;
|
|
7140
|
+
if (--identity.count !== 0 || identity.pending) return;
|
|
7141
|
+
identity.pending = true;
|
|
7142
|
+
Promise.resolve().then(() => {
|
|
7143
|
+
identity.pending = false;
|
|
7144
|
+
if (identity.count !== 0 || identity.retired) return;
|
|
7145
|
+
identity.retired = true;
|
|
7146
|
+
this._bySlot.delete(identity.reference.slot());
|
|
7147
|
+
if (!identity.objectLike) this._primitives.delete(identity.primitiveValue);
|
|
7148
|
+
identity.reference.dispose();
|
|
7149
|
+
});
|
|
7150
|
+
}
|
|
7151
|
+
};
|
|
6904
7152
|
var StrongRef = class extends Disposable {
|
|
6905
7153
|
constructor(value) {
|
|
6906
7154
|
super();
|
|
@@ -7049,6 +7297,7 @@ var Env = class extends Disposable {
|
|
|
7049
7297
|
this.store.insert(this);
|
|
7050
7298
|
this.lastException = new Persistent(ctx.isolate);
|
|
7051
7299
|
this.bridge = bridge;
|
|
7300
|
+
this.address = typeof bridge.address === "function" ? bridge.address() : bridge.address;
|
|
7052
7301
|
}
|
|
7053
7302
|
canCallIntoJs() {
|
|
7054
7303
|
return true;
|
|
@@ -7064,11 +7313,11 @@ var Env = class extends Disposable {
|
|
|
7064
7313
|
if (this.refs === 0) this.dispose();
|
|
7065
7314
|
}
|
|
7066
7315
|
clearLastError() {
|
|
7067
|
-
this.bridge.setLastError(this.
|
|
7316
|
+
this.bridge.setLastError(this.address, 0, 0, 0);
|
|
7068
7317
|
return 0;
|
|
7069
7318
|
}
|
|
7070
7319
|
setLastError(error_code, engine_error_code = 0, engine_reserved = 0) {
|
|
7071
|
-
this.bridge.setLastError(this.
|
|
7320
|
+
this.bridge.setLastError(this.address, error_code, engine_error_code, engine_reserved);
|
|
7072
7321
|
return error_code;
|
|
7073
7322
|
}
|
|
7074
7323
|
callIntoModule(fn, handleException = handleThrow) {
|
|
@@ -7109,7 +7358,7 @@ var Env = class extends Disposable {
|
|
|
7109
7358
|
RefTracker.finalizeAll(this.reflist);
|
|
7110
7359
|
this.lastException.reset();
|
|
7111
7360
|
this.store.dealloc(this.id);
|
|
7112
|
-
this.bridge.deleteEnv(this.
|
|
7361
|
+
this.bridge.deleteEnv(this.address);
|
|
7113
7362
|
}
|
|
7114
7363
|
dispose() {
|
|
7115
7364
|
if (this.id === 0) return;
|
|
@@ -7185,7 +7434,7 @@ var NodeEnv = class extends Env {
|
|
|
7185
7434
|
}
|
|
7186
7435
|
callFinalizerInternal(forceUncaught, cb, data, hint) {
|
|
7187
7436
|
const f = this.bridge.makeDynCall_vppp(cb);
|
|
7188
|
-
const env = this.
|
|
7437
|
+
const env = this.address;
|
|
7189
7438
|
const scope = this.ctx.openScope(this);
|
|
7190
7439
|
try {
|
|
7191
7440
|
this.callbackIntoModule(Boolean(forceUncaught), () => {
|
|
@@ -7198,13 +7447,19 @@ var NodeEnv = class extends Env {
|
|
|
7198
7447
|
enqueueFinalizer(finalizer) {
|
|
7199
7448
|
super.enqueueFinalizer(finalizer);
|
|
7200
7449
|
if (!this.finalizationScheduled && !this.destructing) {
|
|
7201
|
-
|
|
7202
|
-
this.ref();
|
|
7203
|
-
this.ctx.features.setImmediate(() => {
|
|
7450
|
+
const drain = () => {
|
|
7204
7451
|
this.finalizationScheduled = false;
|
|
7205
7452
|
this.unref();
|
|
7206
7453
|
this.drainFinalizerQueue();
|
|
7207
|
-
}
|
|
7454
|
+
};
|
|
7455
|
+
try {
|
|
7456
|
+
this.ctx.features.setImmediate(drain);
|
|
7457
|
+
} catch (_) {
|
|
7458
|
+
if (typeof queueMicrotask === "function") queueMicrotask(drain);
|
|
7459
|
+
else Promise.resolve().then(drain);
|
|
7460
|
+
}
|
|
7461
|
+
this.finalizationScheduled = true;
|
|
7462
|
+
this.ref();
|
|
7208
7463
|
}
|
|
7209
7464
|
}
|
|
7210
7465
|
drainFinalizerQueue() {
|
|
@@ -7668,7 +7923,17 @@ var Template = class Template {
|
|
|
7668
7923
|
});
|
|
7669
7924
|
}
|
|
7670
7925
|
};
|
|
7671
|
-
function findHolder(obj,
|
|
7926
|
+
function findHolder(obj, target) {
|
|
7927
|
+
let value = obj;
|
|
7928
|
+
while (value != null) {
|
|
7929
|
+
const keys = Reflect.ownKeys(value);
|
|
7930
|
+
for (let i = 0; i < keys.length; i++) {
|
|
7931
|
+
const key = keys[i];
|
|
7932
|
+
const desc = Object.getOwnPropertyDescriptor(value, key);
|
|
7933
|
+
if (desc && (desc.value === target || desc.get === target || desc.set === target)) return value;
|
|
7934
|
+
}
|
|
7935
|
+
value = Object.getPrototypeOf(value);
|
|
7936
|
+
}
|
|
7672
7937
|
return obj;
|
|
7673
7938
|
}
|
|
7674
7939
|
const internalField = /* @__PURE__ */ new WeakMap();
|
|
@@ -7695,27 +7960,27 @@ var ObjectTemplate = class extends Template {
|
|
|
7695
7960
|
this._instances = /* @__PURE__ */ new WeakSet();
|
|
7696
7961
|
this.Ctor = Ctor ?? Object;
|
|
7697
7962
|
}
|
|
7698
|
-
|
|
7699
|
-
const config =
|
|
7700
|
-
name,
|
|
7701
|
-
getterWrap,
|
|
7702
|
-
setterWrap,
|
|
7703
|
-
getter,
|
|
7704
|
-
setter,
|
|
7705
|
-
data,
|
|
7706
|
-
attribute,
|
|
7707
|
-
getterSideEffectType,
|
|
7708
|
-
setterSideEffectType,
|
|
7709
|
-
getterFunction: void 0,
|
|
7710
|
-
setterFunction: void 0
|
|
7711
|
-
};
|
|
7712
|
-
config.getterFunction = getter ? this._createAccessorWrapper("getter", config) : void 0;
|
|
7713
|
-
config.setterFunction = setter ? this._createAccessorWrapper("setter", config) : void 0;
|
|
7963
|
+
setNativeDataProperty(name, getterWrap, setterWrap, getter, setter, data, attribute, getterSideEffectType, setterSideEffectType) {
|
|
7964
|
+
const config = this._createAccessorConfig(name, getterWrap, setterWrap, getter, setter, data, attribute, getterSideEffectType, setterSideEffectType);
|
|
7714
7965
|
this._accessors.set(name, config);
|
|
7715
7966
|
}
|
|
7967
|
+
setNativeDataPropertyOnInstance(instance, name, getterWrap, setterWrap, getter, setter, data, attribute, getterSideEffectType, setterSideEffectType) {
|
|
7968
|
+
const config = this._createAccessorConfig(name, getterWrap, setterWrap, getter, setter, data, attribute, getterSideEffectType, setterSideEffectType);
|
|
7969
|
+
this._instances.add(instance);
|
|
7970
|
+
this._defineAccessor(instance, config);
|
|
7971
|
+
}
|
|
7716
7972
|
setInternalFieldCount(value) {
|
|
7717
7973
|
this.internalFieldCount = value;
|
|
7718
7974
|
}
|
|
7975
|
+
setNamedPropertyHandler(config) {
|
|
7976
|
+
this._namedPropertyHandler = config;
|
|
7977
|
+
}
|
|
7978
|
+
setIndexedPropertyHandler(config) {
|
|
7979
|
+
this._indexedPropertyHandler = config;
|
|
7980
|
+
}
|
|
7981
|
+
setCallAsFunctionHandler(config) {
|
|
7982
|
+
this._callAsFunctionHandler = config;
|
|
7983
|
+
}
|
|
7719
7984
|
_createAccessorWrapper(type, config) {
|
|
7720
7985
|
const { ctx } = this;
|
|
7721
7986
|
const instances = this._instances;
|
|
@@ -7725,6 +7990,15 @@ var ObjectTemplate = class extends Template {
|
|
|
7725
7990
|
return holder || receiver;
|
|
7726
7991
|
};
|
|
7727
7992
|
function accessor(value) {
|
|
7993
|
+
if (type === "setter" && !instances.has(this)) {
|
|
7994
|
+
Object.defineProperty(this, config.name, {
|
|
7995
|
+
value,
|
|
7996
|
+
writable: !(config.attribute & 1),
|
|
7997
|
+
enumerable: !(config.attribute & 2),
|
|
7998
|
+
configurable: !(config.attribute & 4)
|
|
7999
|
+
});
|
|
8000
|
+
return;
|
|
8001
|
+
}
|
|
7728
8002
|
const scope = ctx.openScope();
|
|
7729
8003
|
const callbackInfo = scope.callbackInfo;
|
|
7730
8004
|
let returnValue;
|
|
@@ -7750,21 +8024,178 @@ var ObjectTemplate = class extends Template {
|
|
|
7750
8024
|
}
|
|
7751
8025
|
applyToInstance(instance) {
|
|
7752
8026
|
this._instances.add(instance);
|
|
7753
|
-
|
|
8027
|
+
const fields = Array(this.internalFieldCount);
|
|
8028
|
+
internalField.set(instance, fields);
|
|
7754
8029
|
this._addPropertiesToInstance(instance);
|
|
7755
|
-
this._accessors.forEach((config
|
|
7756
|
-
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7760
|
-
|
|
7761
|
-
|
|
8030
|
+
this._accessors.forEach((config) => this._defineAccessor(instance, config));
|
|
8031
|
+
if (this._namedPropertyHandler || this._indexedPropertyHandler) {
|
|
8032
|
+
const proxy = this._createPropertyHandlerProxy(instance);
|
|
8033
|
+
this._instances.add(proxy);
|
|
8034
|
+
internalField.set(proxy, fields);
|
|
8035
|
+
return proxy;
|
|
8036
|
+
}
|
|
8037
|
+
return instance;
|
|
8038
|
+
}
|
|
8039
|
+
_createPropertyHandlerProxy(target) {
|
|
8040
|
+
const { ctx } = this;
|
|
8041
|
+
const configuredHandler = this._namedPropertyHandler || this._indexedPropertyHandler;
|
|
8042
|
+
const resolveHandler = (property) => {
|
|
8043
|
+
const index = typeof property === "string" && /^(?:0|[1-9]\d*)$/.test(property) ? Number(property) : void 0;
|
|
8044
|
+
if (index !== void 0 && index <= 0xfffffffe && this._indexedPropertyHandler) return {
|
|
8045
|
+
config: this._indexedPropertyHandler,
|
|
8046
|
+
index
|
|
8047
|
+
};
|
|
8048
|
+
if (typeof property === "string" && this._namedPropertyHandler) return { config: this._namedPropertyHandler };
|
|
8049
|
+
};
|
|
8050
|
+
const invoke = (config, property, receiver, holder, kind, value) => {
|
|
8051
|
+
const wrap = kind === "getter" ? config.getterWrap : kind === "setter" ? config.setterWrap : kind === "query" ? config.queryWrap : kind === "deleter" ? config.deleterWrap : config.enumeratorWrap;
|
|
8052
|
+
if (!wrap) return {
|
|
8053
|
+
intercepted: false,
|
|
8054
|
+
value: void 0
|
|
8055
|
+
};
|
|
8056
|
+
const scope = ctx.openScope();
|
|
8057
|
+
const callbackInfo = scope.callbackInfo;
|
|
8058
|
+
const trap = function() {};
|
|
8059
|
+
callbackInfo.data = config.data;
|
|
8060
|
+
callbackInfo.args = kind === "setter" ? [value] : [];
|
|
8061
|
+
callbackInfo.thiz = receiver;
|
|
8062
|
+
callbackInfo.holder = holder;
|
|
8063
|
+
callbackInfo.fn = trap;
|
|
8064
|
+
let result = 0;
|
|
8065
|
+
try {
|
|
8066
|
+
const propertyValue = typeof property === "number" ? property : ctx.napiValueFromJsValue(property);
|
|
8067
|
+
if (kind === "getter") result = wrap(propertyValue, scope.id, config.getter);
|
|
8068
|
+
else if (kind === "setter") result = wrap(propertyValue, ctx.napiValueFromJsValue(value), scope.id, config.setter);
|
|
8069
|
+
else if (kind === "query") result = wrap(propertyValue, scope.id, config.query);
|
|
8070
|
+
else if (kind === "deleter") result = wrap(propertyValue, scope.id, config.deleter);
|
|
8071
|
+
else result = wrap(scope.id, config.enumerator);
|
|
8072
|
+
} catch (err) {
|
|
8073
|
+
ctx.throwException(err);
|
|
8074
|
+
}
|
|
8075
|
+
const returnValue = result ? ctx.jsValueFromNapiValue(result) : void 0;
|
|
8076
|
+
ctx.closeScope(scope);
|
|
8077
|
+
if (ctx.hasPendingException()) {
|
|
8078
|
+
if (TryCatch.top) TryCatch.top.setError(ctx.getAndClearLastException());
|
|
8079
|
+
else throw ctx.getAndClearLastException();
|
|
8080
|
+
}
|
|
8081
|
+
return {
|
|
8082
|
+
intercepted: Number(result) !== 0,
|
|
8083
|
+
value: returnValue
|
|
8084
|
+
};
|
|
8085
|
+
};
|
|
8086
|
+
const getOwnPropertyDescriptor = (_target, property) => {
|
|
8087
|
+
const handler = resolveHandler(property);
|
|
8088
|
+
if (!handler || !handler.config.queryWrap) return Reflect.getOwnPropertyDescriptor(target, property);
|
|
8089
|
+
const result = invoke(handler.config, handler.index === void 0 ? String(property) : handler.index, target, target, "query");
|
|
8090
|
+
if (!result.intercepted) return Reflect.getOwnPropertyDescriptor(target, property);
|
|
8091
|
+
if (result.value === void 0) return void 0;
|
|
8092
|
+
const attr = Number(result.value);
|
|
8093
|
+
return {
|
|
8094
|
+
value: Reflect.get(target, property, target),
|
|
8095
|
+
writable: !(attr & 1),
|
|
8096
|
+
enumerable: !(attr & 2),
|
|
8097
|
+
configurable: !(attr & 4)
|
|
8098
|
+
};
|
|
8099
|
+
};
|
|
8100
|
+
let proxy;
|
|
8101
|
+
proxy = new Proxy(target, {
|
|
8102
|
+
get(_target, property, receiver) {
|
|
8103
|
+
const handler = resolveHandler(property);
|
|
8104
|
+
if (!handler || !handler.config.getterWrap) return Reflect.get(target, property, receiver);
|
|
8105
|
+
const result = invoke(handler.config, handler.index === void 0 ? String(property) : handler.index, receiver, target, "getter");
|
|
8106
|
+
return result.intercepted ? result.value : Reflect.get(target, property, receiver);
|
|
8107
|
+
},
|
|
8108
|
+
set(_target, property, value, receiver) {
|
|
8109
|
+
const handler = resolveHandler(property);
|
|
8110
|
+
if (!handler || !handler.config.setterWrap) return Reflect.set(target, property, value, receiver);
|
|
8111
|
+
return invoke(handler.config, handler.index === void 0 ? String(property) : handler.index, receiver, target, "setter", value).intercepted ? true : Reflect.set(target, property, value, receiver);
|
|
8112
|
+
},
|
|
8113
|
+
has(_target, property) {
|
|
8114
|
+
const handler = resolveHandler(property);
|
|
8115
|
+
if (!handler || !handler.config.queryWrap) return Reflect.has(target, property);
|
|
8116
|
+
const result = invoke(handler.config, handler.index === void 0 ? String(property) : handler.index, proxy, target, "query");
|
|
8117
|
+
return result.intercepted ? result.value !== void 0 : Reflect.has(target, property);
|
|
8118
|
+
},
|
|
8119
|
+
deleteProperty(_target, property) {
|
|
8120
|
+
const handler = resolveHandler(property);
|
|
8121
|
+
if (!handler || !handler.config.deleterWrap) return Reflect.deleteProperty(target, property);
|
|
8122
|
+
const result = invoke(handler.config, handler.index === void 0 ? String(property) : handler.index, proxy, target, "deleter");
|
|
8123
|
+
return result.intercepted ? Boolean(result.value) : Reflect.deleteProperty(target, property);
|
|
8124
|
+
},
|
|
8125
|
+
ownKeys(_target) {
|
|
8126
|
+
const handler = configuredHandler;
|
|
8127
|
+
if (!handler || !handler.enumeratorWrap) return Reflect.ownKeys(target);
|
|
8128
|
+
const result = invoke(handler, "", proxy, target, "enumerator");
|
|
8129
|
+
if (!Array.isArray(result.value)) return Reflect.ownKeys(target);
|
|
8130
|
+
const keys = result.value.map((key) => typeof key === "number" ? String(key) : key);
|
|
8131
|
+
for (const key of Reflect.ownKeys(target)) {
|
|
8132
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
|
|
8133
|
+
if (descriptor && !descriptor.configurable && !keys.includes(key)) keys.push(key);
|
|
8134
|
+
}
|
|
8135
|
+
return keys;
|
|
8136
|
+
},
|
|
8137
|
+
getOwnPropertyDescriptor,
|
|
8138
|
+
defineProperty(_target, property, descriptor) {
|
|
8139
|
+
return Reflect.defineProperty(target, property, descriptor);
|
|
8140
|
+
}
|
|
8141
|
+
});
|
|
8142
|
+
return proxy;
|
|
8143
|
+
}
|
|
8144
|
+
_createAccessorConfig(name, getterWrap, setterWrap, getter, setter, data, attribute, getterSideEffectType, setterSideEffectType) {
|
|
8145
|
+
const config = {
|
|
8146
|
+
name,
|
|
8147
|
+
getterWrap,
|
|
8148
|
+
setterWrap,
|
|
8149
|
+
getter,
|
|
8150
|
+
setter,
|
|
8151
|
+
data,
|
|
8152
|
+
attribute,
|
|
8153
|
+
getterSideEffectType,
|
|
8154
|
+
setterSideEffectType,
|
|
8155
|
+
getterFunction: void 0,
|
|
8156
|
+
setterFunction: void 0
|
|
8157
|
+
};
|
|
8158
|
+
config.getterFunction = getter ? this._createAccessorWrapper("getter", config) : void 0;
|
|
8159
|
+
config.setterFunction = setter ? this._createAccessorWrapper("setter", config) : void 0;
|
|
8160
|
+
return config;
|
|
8161
|
+
}
|
|
8162
|
+
_defineAccessor(instance, config) {
|
|
8163
|
+
Object.defineProperty(instance, config.name, {
|
|
8164
|
+
get: config.getterFunction,
|
|
8165
|
+
set: config.setterFunction,
|
|
8166
|
+
enumerable: !(config.attribute & 2),
|
|
8167
|
+
configurable: !(config.attribute & 4)
|
|
7762
8168
|
});
|
|
7763
8169
|
}
|
|
7764
8170
|
newInstance(_context) {
|
|
7765
8171
|
const { ctx, Ctor } = this;
|
|
7766
8172
|
let instance;
|
|
7767
|
-
|
|
8173
|
+
if (this._callAsFunctionHandler) {
|
|
8174
|
+
const template = this;
|
|
8175
|
+
instance = function(...args) {
|
|
8176
|
+
const scope = ctx.openScope();
|
|
8177
|
+
const callbackInfo = scope.callbackInfo;
|
|
8178
|
+
callbackInfo.data = template._callAsFunctionHandler.data;
|
|
8179
|
+
callbackInfo.args = args;
|
|
8180
|
+
callbackInfo.thiz = this;
|
|
8181
|
+
callbackInfo.holder = this;
|
|
8182
|
+
callbackInfo.fn = instance;
|
|
8183
|
+
let ret = 0;
|
|
8184
|
+
try {
|
|
8185
|
+
ret = template._callAsFunctionHandler.callbackWrap(scope.id, template._callAsFunctionHandler.callback);
|
|
8186
|
+
} catch (err) {
|
|
8187
|
+
ctx.throwException(err);
|
|
8188
|
+
}
|
|
8189
|
+
const retNumber = typeof ret === "bigint" ? Number(ret) : ret;
|
|
8190
|
+
const returnValue = retNumber === 0 ? 0 : (() => {
|
|
8191
|
+
const value = ctx.jsValueFromNapiValue(ret);
|
|
8192
|
+
return value === void 0 && retNumber !== 1 && retNumber !== 2 ? retNumber >= 4294967296 || typeof ret === "bigint" ? Math.trunc(Number(ret) / 4294967296) : Number(ret) >> 1 : value;
|
|
8193
|
+
})();
|
|
8194
|
+
ctx.closeScope(scope);
|
|
8195
|
+
if (ctx.hasPendingException()) throw ctx.getAndClearLastException();
|
|
8196
|
+
return returnValue;
|
|
8197
|
+
};
|
|
8198
|
+
} else try {
|
|
7768
8199
|
instance = new Ctor();
|
|
7769
8200
|
} catch (err) {
|
|
7770
8201
|
ctx.throwException(err);
|
|
@@ -7787,8 +8218,12 @@ var FunctionTemplate = class extends Template {
|
|
|
7787
8218
|
this.data = data;
|
|
7788
8219
|
this.className = void 0;
|
|
7789
8220
|
this.signature = signature;
|
|
8221
|
+
this.callHandler = void 0;
|
|
7790
8222
|
this._cached = [void 0];
|
|
7791
8223
|
}
|
|
8224
|
+
setCallHandler(config) {
|
|
8225
|
+
this.callHandler = config;
|
|
8226
|
+
}
|
|
7792
8227
|
setClassName(name) {
|
|
7793
8228
|
this.className = name;
|
|
7794
8229
|
}
|
|
@@ -7803,6 +8238,7 @@ var FunctionTemplate = class extends Template {
|
|
|
7803
8238
|
getFunction() {
|
|
7804
8239
|
if (this._cached[0]) return this._cached[0];
|
|
7805
8240
|
const { ctx, callback, v8FunctionCallback, data, signature, _instanceTemplate } = this;
|
|
8241
|
+
const callHandler = this.callHandler;
|
|
7806
8242
|
function _() {
|
|
7807
8243
|
if (signature && signature.receiver) {
|
|
7808
8244
|
const f = signature.receiver.getFunction();
|
|
@@ -7812,14 +8248,21 @@ var FunctionTemplate = class extends Template {
|
|
|
7812
8248
|
const callbackInfo = scope.callbackInfo;
|
|
7813
8249
|
let returnValue;
|
|
7814
8250
|
try {
|
|
7815
|
-
|
|
8251
|
+
const callbackThis = _instanceTemplate && this instanceof _ ? _instanceTemplate.applyToInstance(this) : this;
|
|
8252
|
+
callbackInfo.data = callHandler ? callHandler.data : data;
|
|
7816
8253
|
callbackInfo.args = arguments;
|
|
7817
|
-
callbackInfo.thiz =
|
|
7818
|
-
callbackInfo.holder = findHolder(
|
|
8254
|
+
callbackInfo.thiz = callbackThis;
|
|
8255
|
+
callbackInfo.holder = signature ? callbackThis : findHolder(callbackThis, _) || callbackThis;
|
|
7819
8256
|
callbackInfo.fn = _;
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
8257
|
+
const ret = callHandler ? callHandler.callbackWrap(ctx.getCurrentScope().id, callHandler.callback) : callback ? callback(ctx.getCurrentScope().id, v8FunctionCallback) : 0;
|
|
8258
|
+
if (callHandler) {
|
|
8259
|
+
const retNumber = typeof ret === "bigint" ? Number(ret) : ret;
|
|
8260
|
+
if (retNumber === 0) returnValue = 0;
|
|
8261
|
+
else {
|
|
8262
|
+
const value = ctx.jsValueFromNapiValue(ret);
|
|
8263
|
+
returnValue = value === void 0 && retNumber !== 1 && retNumber !== 2 ? retNumber >= 4294967296 || typeof ret === "bigint" ? Math.trunc(Number(ret) / 4294967296) : Number(ret) >> 1 : value;
|
|
8264
|
+
}
|
|
8265
|
+
} else returnValue = ret ? ctx.jsValueFromNapiValue(ret) : void 0;
|
|
7823
8266
|
} catch (err) {
|
|
7824
8267
|
if (err !== "unwind") ctx.throwException(err);
|
|
7825
8268
|
} finally {
|
|
@@ -7908,6 +8351,7 @@ var Isolate = class {
|
|
|
7908
8351
|
this._scopeStore = new ScopeStore();
|
|
7909
8352
|
this._handleStore = new HandleStore(this.features);
|
|
7910
8353
|
this.globalHandleStore = new PersistentStore();
|
|
8354
|
+
this._globalIdentityStore = new GlobalIdentityStore(this);
|
|
7911
8355
|
this._lastException = new Persistent(this);
|
|
7912
8356
|
this._externalMemory = new ExternalMemory(options?.onExternalMemoryChange);
|
|
7913
8357
|
}
|
|
@@ -7943,6 +8387,15 @@ var Isolate = class {
|
|
|
7943
8387
|
getRef(ref) {
|
|
7944
8388
|
return this.globalHandleStore.deref(ref);
|
|
7945
8389
|
}
|
|
8390
|
+
acquireGlobalValueIdentity(value) {
|
|
8391
|
+
return this._globalIdentityStore.acquire(value);
|
|
8392
|
+
}
|
|
8393
|
+
retainGlobalValueIdentity(slot) {
|
|
8394
|
+
this._globalIdentityStore.retain(slot);
|
|
8395
|
+
}
|
|
8396
|
+
releaseGlobalValueIdentity(slot) {
|
|
8397
|
+
this._globalIdentityStore.release(slot);
|
|
8398
|
+
}
|
|
7946
8399
|
removeRef(ref, force = false) {
|
|
7947
8400
|
if (force || this._scopeStore.isEmpty()) this.globalHandleStore.deref(ref)?.dispose();
|
|
7948
8401
|
else this.globalHandleStore.markUnused(ref);
|
|
@@ -8251,9 +8704,9 @@ var Context = class {
|
|
|
8251
8704
|
return env;
|
|
8252
8705
|
}
|
|
8253
8706
|
createFunction(envObject, napiCallback, data, name, dynamicExecution) {
|
|
8254
|
-
if (envObject.ctx !== this) throw new Error(`The napi_env (${envObject.
|
|
8707
|
+
if (envObject.ctx !== this) throw new Error(`The napi_env (${envObject.address}) is not created by this context`);
|
|
8255
8708
|
const callback = (envObject) => {
|
|
8256
|
-
return napiCallback(envObject.
|
|
8709
|
+
return napiCallback(envObject.address, envObject.ctx.getCurrentScope().id);
|
|
8257
8710
|
};
|
|
8258
8711
|
let _;
|
|
8259
8712
|
const staticFunctionWrapper = (withScope, envObject, data, callbackWrapper, callback) => {
|
|
@@ -8355,7 +8808,7 @@ function getDefaultContext$1() {
|
|
|
8355
8808
|
if (!defaultContext) defaultContext = createContext$1();
|
|
8356
8809
|
return defaultContext;
|
|
8357
8810
|
}
|
|
8358
|
-
//
|
|
8811
|
+
// ../../../node_modules/.store/@napi-rs-wasm-runtime-virtual-456d1dbffc/package/dist/emnapi-plugins.js
|
|
8359
8812
|
function asyncWork(emnapiPluginCtx) {
|
|
8360
8813
|
const { emnapiCtx, emnapiNodeBinding, emnapiAsyncWorkPoolSize } = emnapiPluginCtx;
|
|
8361
8814
|
var mod = (function(exports, emnapi_shared, emscripten_runtime) {
|
|
@@ -9834,7 +10287,7 @@ const withAddonModuleAlias = (plugin) => {
|
|
|
9834
10287
|
};
|
|
9835
10288
|
const emnapiAsyncWorkPlugin = withAddonModuleAlias(asyncWork);
|
|
9836
10289
|
const emnapiTSFNPlugin = withAddonModuleAlias(threadsafeFunction);
|
|
9837
|
-
//
|
|
10290
|
+
// ../../../node_modules/.store/@tybys-wasm-util-npm-0.10.5-06fb949e8d/package/dist/wasm-util.esm-bundler.js
|
|
9838
10291
|
const _WebAssembly = typeof WebAssembly !== "undefined" ? WebAssembly : typeof WXWebAssembly !== "undefined" ? WXWebAssembly : void 0;
|
|
9839
10292
|
if (!_WebAssembly) throw new Error("WebAssembly is not supported in this environment");
|
|
9840
10293
|
function validateObject(value, name) {
|
|
@@ -10255,11 +10708,20 @@ var FileDescriptor = class {
|
|
|
10255
10708
|
this.size = BigInt(0);
|
|
10256
10709
|
}
|
|
10257
10710
|
seek(offset, whence) {
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
|
|
10711
|
+
let seekOffset;
|
|
10712
|
+
try {
|
|
10713
|
+
seekOffset = BigInt(offset);
|
|
10714
|
+
} catch (_) {
|
|
10715
|
+
throw new WasiError("Invalid seek offset", 28);
|
|
10716
|
+
}
|
|
10717
|
+
let position;
|
|
10718
|
+
if (whence === 0) position = seekOffset;
|
|
10719
|
+
else if (whence === 1) position = BigInt(this.pos) + seekOffset;
|
|
10720
|
+
else if (whence === 2) position = BigInt(this.size) + seekOffset;
|
|
10261
10721
|
else throw new WasiError("Unknown whence", 29);
|
|
10262
|
-
|
|
10722
|
+
if (position < BigInt(0)) throw new WasiError("Invalid seek offset", 28);
|
|
10723
|
+
this.pos = position;
|
|
10724
|
+
return position;
|
|
10263
10725
|
}
|
|
10264
10726
|
};
|
|
10265
10727
|
var StandardOutput = class extends FileDescriptor {
|
|
@@ -10609,6 +11071,12 @@ async function resolvePathAsync(fs, fileDescriptor, path, flags) {
|
|
|
10609
11071
|
const encoder = /*#__PURE__*/ new TextEncoder();
|
|
10610
11072
|
const decoder = /*#__PURE__*/ new TextDecoder();
|
|
10611
11073
|
const INT64_MAX = (BigInt(1) << BigInt(63)) - BigInt(1);
|
|
11074
|
+
const NANOSECONDS_PER_SECOND = BigInt(1e9);
|
|
11075
|
+
function nanosecondsToSeconds(nanoseconds) {
|
|
11076
|
+
const seconds = nanoseconds / NANOSECONDS_PER_SECOND;
|
|
11077
|
+
const remainder = nanoseconds % NANOSECONDS_PER_SECOND;
|
|
11078
|
+
return Number(seconds) + Number(remainder) / Number(NANOSECONDS_PER_SECOND);
|
|
11079
|
+
}
|
|
10612
11080
|
function readStdin() {
|
|
10613
11081
|
const value = window.prompt();
|
|
10614
11082
|
if (value === null) return /* @__PURE__ */ new Uint8Array();
|
|
@@ -10983,8 +11451,8 @@ var WASI$1 = class WASI$1 {
|
|
|
10983
11451
|
}, ["i32", "i64"], ["i32"]);
|
|
10984
11452
|
function fdFilestatGetTimes(fd, atim, mtim, flags) {
|
|
10985
11453
|
const fileDescriptor = _wasi.get(this).fds.get(fd, WasiRights.FD_FILESTAT_SET_TIMES, BigInt(0));
|
|
10986
|
-
if ((flags & 2) === 2) atim = BigInt(Date.now() * 1e6);
|
|
10987
|
-
if ((flags & 8) === 8) mtim = BigInt(Date.now() * 1e6);
|
|
11454
|
+
if ((flags & 2) === 2) atim = BigInt(Date.now()) * BigInt(1e6);
|
|
11455
|
+
if ((flags & 8) === 8) mtim = BigInt(Date.now()) * BigInt(1e6);
|
|
10988
11456
|
return {
|
|
10989
11457
|
fileDescriptor,
|
|
10990
11458
|
atim,
|
|
@@ -10994,12 +11462,12 @@ var WASI$1 = class WASI$1 {
|
|
|
10994
11462
|
defineImport("fd_filestat_set_times", function fd_filestat_set_times(fd, atim, mtim, flags) {
|
|
10995
11463
|
if (validateFstFlagsOrReturn(flags)) return 28;
|
|
10996
11464
|
const { fileDescriptor, atim: atimRes, mtim: mtimRes } = fdFilestatGetTimes.call(this, fd, atim, mtim, flags);
|
|
10997
|
-
getFs(this).futimesSync(fileDescriptor.fd,
|
|
11465
|
+
getFs(this).futimesSync(fileDescriptor.fd, nanosecondsToSeconds(atimRes), nanosecondsToSeconds(mtimRes));
|
|
10998
11466
|
return 0;
|
|
10999
11467
|
}, async function fd_filestat_set_times(fd, atim, mtim, flags) {
|
|
11000
11468
|
if (validateFstFlagsOrReturn(flags)) return 28;
|
|
11001
11469
|
const { fileDescriptor, atim: atimRes, mtim: mtimRes } = fdFilestatGetTimes.call(this, fd, atim, mtim, flags);
|
|
11002
|
-
await fileDescriptor.fd.utimes(
|
|
11470
|
+
await fileDescriptor.fd.utimes(nanosecondsToSeconds(atimRes), nanosecondsToSeconds(mtimRes));
|
|
11003
11471
|
return 0;
|
|
11004
11472
|
}, [
|
|
11005
11473
|
"i32",
|
|
@@ -11408,9 +11876,9 @@ var WASI$1 = class WASI$1 {
|
|
|
11408
11876
|
if (validateFstFlagsOrReturn(fst_flags)) return 28;
|
|
11409
11877
|
const fs = getFs(this);
|
|
11410
11878
|
const resolvedPath = resolvePathSync(fs, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
|
|
11411
|
-
if ((fst_flags & 2) === 2) atim = BigInt(Date.now() * 1e6);
|
|
11412
|
-
if ((fst_flags & 8) === 8) mtim = BigInt(Date.now() * 1e6);
|
|
11413
|
-
fs.utimesSync(resolvedPath,
|
|
11879
|
+
if ((fst_flags & 2) === 2) atim = BigInt(Date.now()) * BigInt(1e6);
|
|
11880
|
+
if ((fst_flags & 8) === 8) mtim = BigInt(Date.now()) * BigInt(1e6);
|
|
11881
|
+
fs.utimesSync(resolvedPath, nanosecondsToSeconds(atim), nanosecondsToSeconds(mtim));
|
|
11414
11882
|
return 0;
|
|
11415
11883
|
}, async function path_filestat_set_times(fd, flags, path, path_len, atim, mtim, fst_flags) {
|
|
11416
11884
|
path = Number(path);
|
|
@@ -11421,9 +11889,9 @@ var WASI$1 = class WASI$1 {
|
|
|
11421
11889
|
if (validateFstFlagsOrReturn(fst_flags)) return 28;
|
|
11422
11890
|
const fs = getFs(this);
|
|
11423
11891
|
const resolvedPath = await resolvePathAsync(fs, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
|
|
11424
|
-
if ((fst_flags & 2) === 2) atim = BigInt(Date.now() * 1e6);
|
|
11425
|
-
if ((fst_flags & 8) === 8) mtim = BigInt(Date.now() * 1e6);
|
|
11426
|
-
await fs.promises.utimes(resolvedPath,
|
|
11892
|
+
if ((fst_flags & 2) === 2) atim = BigInt(Date.now()) * BigInt(1e6);
|
|
11893
|
+
if ((fst_flags & 8) === 8) mtim = BigInt(Date.now()) * BigInt(1e6);
|
|
11894
|
+
await fs.promises.utimes(resolvedPath, nanosecondsToSeconds(atim), nanosecondsToSeconds(mtim));
|
|
11427
11895
|
return 0;
|
|
11428
11896
|
}, [
|
|
11429
11897
|
"i32",
|
|
@@ -11928,7 +12396,7 @@ function wasiReturnOnProcExit(rval) {
|
|
|
11928
12396
|
this[kExitCode] = rval;
|
|
11929
12397
|
throw kExitCode;
|
|
11930
12398
|
}
|
|
11931
|
-
//
|
|
12399
|
+
// ../../../node_modules/.store/@napi-rs-wasm-runtime-virtual-456d1dbffc/package/runtime.js
|
|
11932
12400
|
const { instantiateNapiModuleSync, instantiateNapiModule, MessageHandler } = emnapi_core_exports;
|
|
11933
12401
|
const { createContext, getDefaultContext } = emnapi_exports;
|
|
11934
12402
|
// xlsxdown-node-wasm.wasip1-deferred.js
|