libwz 0.1.0 → 0.1.1
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/README.md +462 -101
- package/dist/libwz.js +350 -390
- package/dist/libwz.wasm +0 -0
- package/package.json +1 -1
package/dist/libwz.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// This code implements the `-sMODULARIZE` settings by taking the generated
|
|
2
2
|
// JS program code (INNER_JS_CODE) and wrapping it in a factory function.
|
|
3
3
|
|
|
4
|
-
// When
|
|
4
|
+
// When targeting node and ES6 we use `await import ..` in the generated code
|
|
5
5
|
// so the outer function needs to be marked as async.
|
|
6
6
|
async function Module(moduleArg = {}) {
|
|
7
|
-
var
|
|
8
|
-
|
|
7
|
+
var Module = moduleArg;
|
|
9
8
|
// include: shell.js
|
|
9
|
+
// include: minimum_runtime_check.js
|
|
10
|
+
// end include: minimum_runtime_check.js
|
|
10
11
|
// The Module object: Our interface to the outside world. We import
|
|
11
12
|
// and export values on it. There are various ways Module can be used:
|
|
12
13
|
// 1. Not defined. We create it here
|
|
@@ -20,29 +21,27 @@ async function Module(moduleArg = {}) {
|
|
|
20
21
|
// after the generated code, you will need to define var Module = {};
|
|
21
22
|
// before the code. Then that object will be used in the code, and you
|
|
22
23
|
// can continue to use Module afterwards as well.
|
|
23
|
-
var Module = moduleArg;
|
|
24
|
-
|
|
25
24
|
// Determine the runtime environment we are in. You can customize this by
|
|
26
25
|
// setting the ENVIRONMENT setting at compile time (see settings.js).
|
|
27
26
|
// Attempt to auto-detect the environment
|
|
28
|
-
var ENVIRONMENT_IS_WEB =
|
|
27
|
+
var ENVIRONMENT_IS_WEB = !!globalThis.window;
|
|
29
28
|
|
|
30
|
-
var ENVIRONMENT_IS_WORKER =
|
|
29
|
+
var ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope;
|
|
31
30
|
|
|
32
31
|
// N.b. Electron.js environment is simultaneously a NODE-environment, but
|
|
33
32
|
// also a web environment.
|
|
34
|
-
var ENVIRONMENT_IS_NODE =
|
|
33
|
+
var ENVIRONMENT_IS_NODE = globalThis.process?.versions?.node && globalThis.process?.type != "renderer";
|
|
35
34
|
|
|
36
35
|
if (ENVIRONMENT_IS_NODE) {
|
|
37
36
|
// When building an ES module `require` is not normally available.
|
|
38
37
|
// We need to use `createRequire()` to construct the require()` function.
|
|
39
|
-
const {createRequire} = process.getBuiltinModule('module');
|
|
38
|
+
const {createRequire} = process.getBuiltinModule('node:module');
|
|
40
39
|
/** @suppress{duplicate} */ var require = createRequire(import.meta.url);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
// --pre-jses are emitted after the Module integration code, so that they can
|
|
44
43
|
// refer to Module (if they choose; they can also define Module)
|
|
45
|
-
var
|
|
44
|
+
var programArgs = [];
|
|
46
45
|
|
|
47
46
|
var thisProgram = "./this.program";
|
|
48
47
|
|
|
@@ -68,9 +67,9 @@ var readAsync, readBinary;
|
|
|
68
67
|
if (ENVIRONMENT_IS_NODE) {
|
|
69
68
|
// These modules will usually be used on Node.js. Load them eagerly to avoid
|
|
70
69
|
// the complexity of lazy-loading.
|
|
71
|
-
var fs = require("fs");
|
|
70
|
+
var fs = require("node:fs");
|
|
72
71
|
if (_scriptName.startsWith("file:")) {
|
|
73
|
-
scriptDirectory = require("path").dirname(require("url").fileURLToPath(_scriptName)) + "/";
|
|
72
|
+
scriptDirectory = require("node:path").dirname(require("node:url").fileURLToPath(_scriptName)) + "/";
|
|
74
73
|
}
|
|
75
74
|
// include: node_shell_read.js
|
|
76
75
|
readBinary = filename => {
|
|
@@ -89,7 +88,7 @@ if (ENVIRONMENT_IS_NODE) {
|
|
|
89
88
|
if (process.argv.length > 1) {
|
|
90
89
|
thisProgram = process.argv[1].replace(/\\/g, "/");
|
|
91
90
|
}
|
|
92
|
-
|
|
91
|
+
programArgs = process.argv.slice(2);
|
|
93
92
|
quit_ = (status, toThrow) => {
|
|
94
93
|
process.exitCode = status;
|
|
95
94
|
throw toThrow;
|
|
@@ -157,24 +156,33 @@ var ABORT = false;
|
|
|
157
156
|
// include: runtime_stack_check.js
|
|
158
157
|
// end include: runtime_stack_check.js
|
|
159
158
|
// include: runtime_exceptions.js
|
|
159
|
+
// Base Emscripten EH error class
|
|
160
|
+
class EmscriptenEH {}
|
|
161
|
+
|
|
162
|
+
class EmscriptenSjLj extends EmscriptenEH {}
|
|
163
|
+
|
|
160
164
|
// end include: runtime_exceptions.js
|
|
161
165
|
// include: runtime_debug.js
|
|
162
166
|
// end include: runtime_debug.js
|
|
163
|
-
var readyPromiseResolve, readyPromiseReject;
|
|
164
|
-
|
|
165
167
|
// Memory management
|
|
166
|
-
var wasmMemory;
|
|
167
|
-
|
|
168
|
-
var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /** @type {!Float64Array} */ HEAPF64;
|
|
169
|
-
|
|
170
|
-
// BigInt64Array type is not correctly defined in closure
|
|
171
|
-
var /** not-@type {!BigInt64Array} */ HEAP64, /* BigUint64Array type is not correctly defined in closure
|
|
172
|
-
/** not-@type {!BigUint64Array} */ HEAPU64;
|
|
173
|
-
|
|
174
168
|
var runtimeInitialized = false;
|
|
175
169
|
|
|
170
|
+
// When ALLOW_MEMORY_GROWTH is enabled, the conversion from Wasm
|
|
171
|
+
// memory to ArrayBuffer requires some additional logic.
|
|
172
|
+
function getMemoryBuffer() {
|
|
173
|
+
try {
|
|
174
|
+
// This method may be missing or could fail with `Memory must have a maximum`
|
|
175
|
+
var b = wasmMemory.toResizableBuffer();
|
|
176
|
+
return b;
|
|
177
|
+
} catch {}
|
|
178
|
+
return wasmMemory.buffer;
|
|
179
|
+
}
|
|
180
|
+
|
|
176
181
|
function updateMemoryViews() {
|
|
177
|
-
|
|
182
|
+
// If we already have a heap that is resizeable/growable buffer we don't
|
|
183
|
+
// need to do anything in updateMemoryViews.
|
|
184
|
+
if (HEAP8?.buffer?.resizable) return;
|
|
185
|
+
var b = getMemoryBuffer();
|
|
178
186
|
HEAP8 = new Int8Array(b);
|
|
179
187
|
HEAP16 = new Int16Array(b);
|
|
180
188
|
Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
|
|
@@ -191,11 +199,10 @@ function updateMemoryViews() {
|
|
|
191
199
|
// end include: memoryprofiler.js
|
|
192
200
|
// end include: runtime_common.js
|
|
193
201
|
function preRun() {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
202
|
+
var preRun = Module["preRun"];
|
|
203
|
+
if (preRun) {
|
|
204
|
+
if (typeof preRun == "function") preRun = [ preRun ];
|
|
205
|
+
onPreRuns.push(...preRun);
|
|
199
206
|
}
|
|
200
207
|
// Begin ATPRERUNS hooks
|
|
201
208
|
callRuntimeCallbacks(onPreRuns);
|
|
@@ -213,49 +220,20 @@ function initRuntime() {
|
|
|
213
220
|
}
|
|
214
221
|
|
|
215
222
|
function postRun() {
|
|
216
|
-
|
|
217
|
-
if (
|
|
218
|
-
if (typeof
|
|
219
|
-
|
|
220
|
-
addOnPostRun(Module["postRun"].shift());
|
|
221
|
-
}
|
|
223
|
+
var postRun = Module["postRun"];
|
|
224
|
+
if (postRun) {
|
|
225
|
+
if (typeof postRun == "function") postRun = [ postRun ];
|
|
226
|
+
onPostRuns.push(...postRun);
|
|
222
227
|
}
|
|
223
228
|
// Begin ATPOSTRUNS hooks
|
|
224
229
|
callRuntimeCallbacks(onPostRuns);
|
|
225
230
|
}
|
|
226
231
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
// Module.preRun (used by emcc to add file preloading).
|
|
231
|
-
// Note that you can add dependencies in preRun, even though
|
|
232
|
-
// it happens right before run - run will be postponed until
|
|
233
|
-
// the dependencies are met.
|
|
234
|
-
var runDependencies = 0;
|
|
235
|
-
|
|
236
|
-
var dependenciesFulfilled = null;
|
|
237
|
-
|
|
238
|
-
// overridden to take different actions when all run dependencies are fulfilled
|
|
239
|
-
function addRunDependency(id) {
|
|
240
|
-
runDependencies++;
|
|
241
|
-
Module["monitorRunDependencies"]?.(runDependencies);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function removeRunDependency(id) {
|
|
245
|
-
runDependencies--;
|
|
246
|
-
Module["monitorRunDependencies"]?.(runDependencies);
|
|
247
|
-
if (runDependencies == 0) {
|
|
248
|
-
if (dependenciesFulfilled) {
|
|
249
|
-
var callback = dependenciesFulfilled;
|
|
250
|
-
dependenciesFulfilled = null;
|
|
251
|
-
callback();
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** @param {string|number=} what */ function abort(what) {
|
|
232
|
+
/**
|
|
233
|
+
* @param {string|number=} what
|
|
234
|
+
*/ function abort(what) {
|
|
257
235
|
Module["onAbort"]?.(what);
|
|
258
|
-
what =
|
|
236
|
+
what = `Aborted(${what})`;
|
|
259
237
|
// TODO(sbc): Should we remove printing and leave it up to whoever
|
|
260
238
|
// catches the exception?
|
|
261
239
|
err(what);
|
|
@@ -274,7 +252,6 @@ function removeRunDependency(id) {
|
|
|
274
252
|
// though it can.
|
|
275
253
|
// TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.
|
|
276
254
|
/** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what);
|
|
277
|
-
readyPromiseReject?.(e);
|
|
278
255
|
// Throw the error whether or not MODULARIZE is set because abort is used
|
|
279
256
|
// in code paths apart from instantiation where an exception is expected
|
|
280
257
|
// to be thrown when abort is called.
|
|
@@ -292,12 +269,11 @@ function findWasmBinary() {
|
|
|
292
269
|
}
|
|
293
270
|
|
|
294
271
|
function getBinarySync(file) {
|
|
295
|
-
if (file == wasmBinaryFile && wasmBinary) {
|
|
296
|
-
return new Uint8Array(wasmBinary);
|
|
297
|
-
}
|
|
298
272
|
if (readBinary) {
|
|
299
273
|
return readBinary(file);
|
|
300
274
|
}
|
|
275
|
+
// Throwing a plain string here, even though it not normally advisable since
|
|
276
|
+
// this gets turning into an `abort` in instantiateArrayBuffer.
|
|
301
277
|
throw "both async and sync fetching of the wasm failed";
|
|
302
278
|
}
|
|
303
279
|
|
|
@@ -326,7 +302,7 @@ async function instantiateArrayBuffer(binaryFile, imports) {
|
|
|
326
302
|
}
|
|
327
303
|
|
|
328
304
|
async function instantiateAsync(binary, binaryFile, imports) {
|
|
329
|
-
if (!binary &&
|
|
305
|
+
if (!binary && !ENVIRONMENT_IS_NODE) {
|
|
330
306
|
try {
|
|
331
307
|
var response = fetch(binaryFile, {
|
|
332
308
|
credentials: "same-origin"
|
|
@@ -345,9 +321,10 @@ async function instantiateAsync(binary, binaryFile, imports) {
|
|
|
345
321
|
|
|
346
322
|
function getWasmImports() {
|
|
347
323
|
// prepare imports
|
|
348
|
-
|
|
324
|
+
var imports = {
|
|
349
325
|
"a": wasmImports
|
|
350
326
|
};
|
|
327
|
+
return imports;
|
|
351
328
|
}
|
|
352
329
|
|
|
353
330
|
// Create the wasm instance.
|
|
@@ -356,17 +333,12 @@ async function createWasm() {
|
|
|
356
333
|
// Load the wasm module and create an instance of using native support in the JS engine.
|
|
357
334
|
// handle a generated wasm instance, receiving its exports and
|
|
358
335
|
// performing other necessary setup
|
|
359
|
-
|
|
336
|
+
function receiveInstance(instance) {
|
|
360
337
|
wasmExports = instance.exports;
|
|
361
|
-
wasmMemory = wasmExports["V"];
|
|
362
|
-
updateMemoryViews();
|
|
363
|
-
wasmTable = wasmExports["X"];
|
|
364
338
|
assignWasmExports(wasmExports);
|
|
365
|
-
|
|
339
|
+
updateMemoryViews();
|
|
366
340
|
return wasmExports;
|
|
367
341
|
}
|
|
368
|
-
// wait for the pthread pool (if any)
|
|
369
|
-
addRunDependency("wasm-instantiate");
|
|
370
342
|
// Prefer streaming instantiation if available.
|
|
371
343
|
function receiveInstantiationResult(result) {
|
|
372
344
|
// 'result' is a ResultObject object which has both the module and instance.
|
|
@@ -382,11 +354,10 @@ async function createWasm() {
|
|
|
382
354
|
// performing.
|
|
383
355
|
// Also pthreads and wasm workers initialize the wasm instance through this
|
|
384
356
|
// path.
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
});
|
|
357
|
+
var instantiateWasm = Module["instantiateWasm"];
|
|
358
|
+
if (instantiateWasm) {
|
|
359
|
+
return new Promise(resolve => {
|
|
360
|
+
instantiateWasm(info, inst => resolve(receiveInstance(inst)));
|
|
390
361
|
});
|
|
391
362
|
}
|
|
392
363
|
wasmBinaryFile ??= findWasmBinary();
|
|
@@ -405,6 +376,26 @@ class ExitStatus {
|
|
|
405
376
|
}
|
|
406
377
|
}
|
|
407
378
|
|
|
379
|
+
/** @type {!Int16Array} */ var HEAP16;
|
|
380
|
+
|
|
381
|
+
/** @type {!Int32Array} */ var HEAP32;
|
|
382
|
+
|
|
383
|
+
/** not-@type {!BigInt64Array} */ var HEAP64;
|
|
384
|
+
|
|
385
|
+
/** @type {!Int8Array} */ var HEAP8;
|
|
386
|
+
|
|
387
|
+
/** @type {!Float32Array} */ var HEAPF32;
|
|
388
|
+
|
|
389
|
+
/** @type {!Float64Array} */ var HEAPF64;
|
|
390
|
+
|
|
391
|
+
/** @type {!Uint16Array} */ var HEAPU16;
|
|
392
|
+
|
|
393
|
+
/** @type {!Uint32Array} */ var HEAPU32;
|
|
394
|
+
|
|
395
|
+
/** not-@type {!BigUint64Array} */ var HEAPU64;
|
|
396
|
+
|
|
397
|
+
/** @type {!Uint8Array} */ var HEAPU8;
|
|
398
|
+
|
|
408
399
|
var callRuntimeCallbacks = callbacks => {
|
|
409
400
|
while (callbacks.length > 0) {
|
|
410
401
|
// Pass the module as the first argument.
|
|
@@ -414,15 +405,11 @@ var callRuntimeCallbacks = callbacks => {
|
|
|
414
405
|
|
|
415
406
|
var onPostRuns = [];
|
|
416
407
|
|
|
417
|
-
var addOnPostRun = cb => onPostRuns.push(cb);
|
|
418
|
-
|
|
419
408
|
var onPreRuns = [];
|
|
420
409
|
|
|
421
|
-
var addOnPreRun = cb => onPreRuns.push(cb);
|
|
422
|
-
|
|
423
410
|
var noExitRuntime = true;
|
|
424
411
|
|
|
425
|
-
|
|
412
|
+
var syscallGetVarargI = () => {
|
|
426
413
|
// the `+` prepended here is necessary to convince the JSCompiler that varargs is indeed a number.
|
|
427
414
|
var ret = HEAP32[((+SYSCALLS.varargs) >> 2)];
|
|
428
415
|
SYSCALLS.varargs += 4;
|
|
@@ -492,16 +479,13 @@ var PATH = {
|
|
|
492
479
|
var initRandomFill = () => {
|
|
493
480
|
// This block is not needed on v19+ since crypto.getRandomValues is builtin
|
|
494
481
|
if (ENVIRONMENT_IS_NODE) {
|
|
495
|
-
var nodeCrypto = require("crypto");
|
|
496
|
-
return view => nodeCrypto.randomFillSync(view);
|
|
482
|
+
var nodeCrypto = require("node:crypto");
|
|
483
|
+
return view => (nodeCrypto.randomFillSync(view), 0);
|
|
497
484
|
}
|
|
498
|
-
return view => crypto.getRandomValues(view);
|
|
485
|
+
return view => (crypto.getRandomValues(view), 0);
|
|
499
486
|
};
|
|
500
487
|
|
|
501
|
-
var randomFill = view =>
|
|
502
|
-
// Lazily init on the first invocation.
|
|
503
|
-
(randomFill = initRandomFill())(view);
|
|
504
|
-
};
|
|
488
|
+
var randomFill = view => (randomFill = initRandomFill())(view);
|
|
505
489
|
|
|
506
490
|
var PATH_FS = {
|
|
507
491
|
resolve: (...args) => {
|
|
@@ -556,9 +540,15 @@ var PATH_FS = {
|
|
|
556
540
|
}
|
|
557
541
|
};
|
|
558
542
|
|
|
559
|
-
var UTF8Decoder =
|
|
543
|
+
var UTF8Decoder = globalThis.TextDecoder && new TextDecoder;
|
|
560
544
|
|
|
561
|
-
|
|
545
|
+
/**
|
|
546
|
+
* heapOrArray is either a regular array, or a JavaScript typed array view.
|
|
547
|
+
* @param {number} idx
|
|
548
|
+
* @param {number=} maxBytesToRead
|
|
549
|
+
* @param {boolean=} ignoreNul
|
|
550
|
+
* @return {number}
|
|
551
|
+
*/ var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {
|
|
562
552
|
var maxIdx = idx + maxBytesToRead;
|
|
563
553
|
if (ignoreNul) return maxIdx;
|
|
564
554
|
// TextDecoder needs to know the byte length in advance, it doesn't stop on
|
|
@@ -570,23 +560,21 @@ var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {
|
|
|
570
560
|
};
|
|
571
561
|
|
|
572
562
|
/**
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
563
|
+
* Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given
|
|
564
|
+
* array that contains uint8 values, returns a copy of that string as a
|
|
565
|
+
* Javascript String object.
|
|
566
|
+
* heapOrArray is either a regular array, or a JavaScript typed array view.
|
|
567
|
+
* @param {number=} idx
|
|
568
|
+
* @param {number=} maxBytesToRead
|
|
569
|
+
* @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
|
|
570
|
+
* @return {string}
|
|
571
|
+
*/ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
|
|
582
572
|
var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
|
|
583
573
|
// When using conditional TextDecoder, skip it for short strings as the overhead of the native call is not worth it.
|
|
584
574
|
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
585
575
|
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
586
576
|
}
|
|
587
577
|
var str = "";
|
|
588
|
-
// If building with TextDecoder, we have already computed the string length
|
|
589
|
-
// above, so test loop end condition against that
|
|
590
578
|
while (idx < endPtr) {
|
|
591
579
|
// For UTF8 byte structure, see:
|
|
592
580
|
// http://en.wikipedia.org/wiki/UTF-8#Description
|
|
@@ -717,7 +705,7 @@ var FS_stdin_getChar = () => {
|
|
|
717
705
|
if (bytesRead > 0) {
|
|
718
706
|
result = buf.slice(0, bytesRead).toString("utf-8");
|
|
719
707
|
}
|
|
720
|
-
} else if (
|
|
708
|
+
} else if (globalThis.window?.prompt) {
|
|
721
709
|
// Browser.
|
|
722
710
|
result = window.prompt("Input: ");
|
|
723
711
|
// returns null on cancel
|
|
@@ -867,7 +855,7 @@ var MEMFS = {
|
|
|
867
855
|
},
|
|
868
856
|
createNode(parent, name, mode, dev) {
|
|
869
857
|
if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
|
|
870
|
-
//
|
|
858
|
+
// not supported
|
|
871
859
|
throw new FS.ErrnoError(63);
|
|
872
860
|
}
|
|
873
861
|
MEMFS.ops_table ||= {
|
|
@@ -924,12 +912,14 @@ var MEMFS = {
|
|
|
924
912
|
} else if (FS.isFile(node.mode)) {
|
|
925
913
|
node.node_ops = MEMFS.ops_table.file.node;
|
|
926
914
|
node.stream_ops = MEMFS.ops_table.file.stream;
|
|
915
|
+
// The actual number of bytes used in the typed array, as opposed to
|
|
916
|
+
// contents.length which gives the whole capacity.
|
|
927
917
|
node.usedBytes = 0;
|
|
928
|
-
// The
|
|
929
|
-
//
|
|
930
|
-
//
|
|
931
|
-
//
|
|
932
|
-
node.contents =
|
|
918
|
+
// The byte data of the file is stored in a typed array.
|
|
919
|
+
// Note: typed arrays are not resizable like normal JS arrays are, so
|
|
920
|
+
// there is a small penalty involved for appending file writes that
|
|
921
|
+
// continuously grow a file similar to std::vector capacity vs used.
|
|
922
|
+
node.contents = MEMFS.emptyFileContents ??= new Uint8Array(0);
|
|
933
923
|
} else if (FS.isLink(node.mode)) {
|
|
934
924
|
node.node_ops = MEMFS.ops_table.link.node;
|
|
935
925
|
node.stream_ops = MEMFS.ops_table.link.stream;
|
|
@@ -946,42 +936,34 @@ var MEMFS = {
|
|
|
946
936
|
return node;
|
|
947
937
|
},
|
|
948
938
|
getFileDataAsTypedArray(node) {
|
|
949
|
-
|
|
950
|
-
if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes);
|
|
951
|
-
// Make sure to not return excess unused bytes.
|
|
952
|
-
return new Uint8Array(node.contents);
|
|
939
|
+
return node.contents.subarray(0, node.usedBytes);
|
|
953
940
|
},
|
|
954
941
|
expandFileStorage(node, newCapacity) {
|
|
955
|
-
var prevCapacity = node.contents
|
|
942
|
+
var prevCapacity = node.contents.length;
|
|
956
943
|
if (prevCapacity >= newCapacity) return;
|
|
957
944
|
// No need to expand, the storage was already large enough.
|
|
958
|
-
// Don't expand strictly to the given requested limit if it's only a very
|
|
959
|
-
//
|
|
960
|
-
//
|
|
945
|
+
// Don't expand strictly to the given requested limit if it's only a very
|
|
946
|
+
// small increase, but instead geometrically grow capacity.
|
|
947
|
+
// For small filesizes (<1MB), perform size*2 geometric increase, but for
|
|
948
|
+
// large sizes, do a much more conservative size*1.125 increase to avoid
|
|
949
|
+
// overshooting the allocation cap by a very large margin.
|
|
961
950
|
var CAPACITY_DOUBLING_MAX = 1024 * 1024;
|
|
962
951
|
newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2 : 1.125)) >>> 0);
|
|
963
|
-
if (prevCapacity
|
|
952
|
+
if (prevCapacity) newCapacity = Math.max(newCapacity, 256);
|
|
964
953
|
// At minimum allocate 256b for each file when expanding.
|
|
965
|
-
var oldContents = node
|
|
954
|
+
var oldContents = MEMFS.getFileDataAsTypedArray(node);
|
|
966
955
|
node.contents = new Uint8Array(newCapacity);
|
|
967
956
|
// Allocate new storage.
|
|
968
|
-
|
|
957
|
+
node.contents.set(oldContents);
|
|
969
958
|
},
|
|
970
959
|
resizeFileStorage(node, newSize) {
|
|
971
960
|
if (node.usedBytes == newSize) return;
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
node.contents = new Uint8Array(newSize);
|
|
979
|
-
// Allocate new storage.
|
|
980
|
-
if (oldContents) {
|
|
981
|
-
node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes)));
|
|
982
|
-
}
|
|
983
|
-
node.usedBytes = newSize;
|
|
984
|
-
}
|
|
961
|
+
var oldContents = node.contents;
|
|
962
|
+
node.contents = new Uint8Array(newSize);
|
|
963
|
+
// Allocate new storage.
|
|
964
|
+
node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes)));
|
|
965
|
+
// Copy old data over to the new storage.
|
|
966
|
+
node.usedBytes = newSize;
|
|
985
967
|
},
|
|
986
968
|
node_ops: {
|
|
987
969
|
getattr(node) {
|
|
@@ -1086,53 +1068,33 @@ var MEMFS = {
|
|
|
1086
1068
|
var contents = stream.node.contents;
|
|
1087
1069
|
if (position >= stream.node.usedBytes) return 0;
|
|
1088
1070
|
var size = Math.min(stream.node.usedBytes - position, length);
|
|
1089
|
-
|
|
1090
|
-
// non-trivial, and typed array
|
|
1091
|
-
buffer.set(contents.subarray(position, position + size), offset);
|
|
1092
|
-
} else {
|
|
1093
|
-
for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
|
|
1094
|
-
}
|
|
1071
|
+
buffer.set(contents.subarray(position, position + size), offset);
|
|
1095
1072
|
return size;
|
|
1096
1073
|
},
|
|
1097
1074
|
write(stream, buffer, offset, length, position, canOwn) {
|
|
1098
1075
|
// If the buffer is located in main memory (HEAP), and if
|
|
1099
1076
|
// memory can grow, we can't hold on to references of the
|
|
1100
1077
|
// memory buffer, as they may get invalidated. That means we
|
|
1101
|
-
// need to
|
|
1078
|
+
// need to copy its contents.
|
|
1102
1079
|
if (buffer.buffer === HEAP8.buffer) {
|
|
1103
1080
|
canOwn = false;
|
|
1104
1081
|
}
|
|
1105
1082
|
if (!length) return 0;
|
|
1106
1083
|
var node = stream.node;
|
|
1107
1084
|
node.mtime = node.ctime = Date.now();
|
|
1108
|
-
if (
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
node.usedBytes = length;
|
|
1118
|
-
return length;
|
|
1119
|
-
} else if (position + length <= node.usedBytes) {
|
|
1120
|
-
// Writing to an already allocated and used subrange of the file?
|
|
1121
|
-
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
1122
|
-
return length;
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
// Appending to an existing file and we need to reallocate, or source data did not come as a typed array.
|
|
1126
|
-
MEMFS.expandFileStorage(node, position + length);
|
|
1127
|
-
if (node.contents.subarray && buffer.subarray) {
|
|
1085
|
+
if (canOwn) {
|
|
1086
|
+
node.contents = buffer.subarray(offset, offset + length);
|
|
1087
|
+
node.usedBytes = length;
|
|
1088
|
+
} else if (node.usedBytes === 0 && position === 0) {
|
|
1089
|
+
// If this is a simple first write to an empty file, do a fast set since we don't need to care about old data.
|
|
1090
|
+
node.contents = buffer.slice(offset, offset + length);
|
|
1091
|
+
node.usedBytes = length;
|
|
1092
|
+
} else {
|
|
1093
|
+
MEMFS.expandFileStorage(node, position + length);
|
|
1128
1094
|
// Use typed array write which is available.
|
|
1129
1095
|
node.contents.set(buffer.subarray(offset, offset + length), position);
|
|
1130
|
-
|
|
1131
|
-
for (var i = 0; i < length; i++) {
|
|
1132
|
-
node.contents[position + i] = buffer[offset + i];
|
|
1133
|
-
}
|
|
1096
|
+
node.usedBytes = Math.max(node.usedBytes, position + length);
|
|
1134
1097
|
}
|
|
1135
|
-
node.usedBytes = Math.max(node.usedBytes, position + length);
|
|
1136
1098
|
return length;
|
|
1137
1099
|
},
|
|
1138
1100
|
llseek(stream, offset, whence) {
|
|
@@ -1157,7 +1119,7 @@ var MEMFS = {
|
|
|
1157
1119
|
var allocated;
|
|
1158
1120
|
var contents = stream.node.contents;
|
|
1159
1121
|
// Only make a new copy when MAP_PRIVATE is specified.
|
|
1160
|
-
if (!(flags & 2) && contents
|
|
1122
|
+
if (!(flags & 2) && contents.buffer === HEAP8.buffer) {
|
|
1161
1123
|
// We can't emulate MAP_SHARED when the file is not backed by the
|
|
1162
1124
|
// buffer we're mapping to (e.g. the HEAP buffer).
|
|
1163
1125
|
allocated = false;
|
|
@@ -1193,63 +1155,8 @@ var MEMFS = {
|
|
|
1193
1155
|
}
|
|
1194
1156
|
};
|
|
1195
1157
|
|
|
1196
|
-
var asyncLoad = async url => {
|
|
1197
|
-
var arrayBuffer = await readAsync(url);
|
|
1198
|
-
return new Uint8Array(arrayBuffer);
|
|
1199
|
-
};
|
|
1200
|
-
|
|
1201
|
-
var FS_createDataFile = (...args) => FS.createDataFile(...args);
|
|
1202
|
-
|
|
1203
|
-
var getUniqueRunDependency = id => id;
|
|
1204
|
-
|
|
1205
|
-
var preloadPlugins = [];
|
|
1206
|
-
|
|
1207
|
-
var FS_handledByPreloadPlugin = (byteArray, fullname, finish, onerror) => {
|
|
1208
|
-
// Ensure plugins are ready.
|
|
1209
|
-
if (typeof Browser != "undefined") Browser.init();
|
|
1210
|
-
var handled = false;
|
|
1211
|
-
preloadPlugins.forEach(plugin => {
|
|
1212
|
-
if (handled) return;
|
|
1213
|
-
if (plugin["canHandle"](fullname)) {
|
|
1214
|
-
plugin["handle"](byteArray, fullname, finish, onerror);
|
|
1215
|
-
handled = true;
|
|
1216
|
-
}
|
|
1217
|
-
});
|
|
1218
|
-
return handled;
|
|
1219
|
-
};
|
|
1220
|
-
|
|
1221
|
-
var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
|
|
1222
|
-
// TODO we should allow people to just pass in a complete filename instead
|
|
1223
|
-
// of parent and name being that we just join them anyways
|
|
1224
|
-
var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
|
|
1225
|
-
var dep = getUniqueRunDependency(`cp ${fullname}`);
|
|
1226
|
-
// might have several active requests for the same fullname
|
|
1227
|
-
function processData(byteArray) {
|
|
1228
|
-
function finish(byteArray) {
|
|
1229
|
-
preFinish?.();
|
|
1230
|
-
if (!dontCreateFile) {
|
|
1231
|
-
FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
|
|
1232
|
-
}
|
|
1233
|
-
onload?.();
|
|
1234
|
-
removeRunDependency(dep);
|
|
1235
|
-
}
|
|
1236
|
-
if (FS_handledByPreloadPlugin(byteArray, fullname, finish, () => {
|
|
1237
|
-
onerror?.();
|
|
1238
|
-
removeRunDependency(dep);
|
|
1239
|
-
})) {
|
|
1240
|
-
return;
|
|
1241
|
-
}
|
|
1242
|
-
finish(byteArray);
|
|
1243
|
-
}
|
|
1244
|
-
addRunDependency(dep);
|
|
1245
|
-
if (typeof url == "string") {
|
|
1246
|
-
asyncLoad(url).then(processData, onerror);
|
|
1247
|
-
} else {
|
|
1248
|
-
processData(url);
|
|
1249
|
-
}
|
|
1250
|
-
};
|
|
1251
|
-
|
|
1252
1158
|
var FS_modeStringToFlags = str => {
|
|
1159
|
+
if (typeof str != "string") return str;
|
|
1253
1160
|
var flagModes = {
|
|
1254
1161
|
"r": 0,
|
|
1255
1162
|
"r+": 2,
|
|
@@ -1265,6 +1172,16 @@ var FS_modeStringToFlags = str => {
|
|
|
1265
1172
|
return flags;
|
|
1266
1173
|
};
|
|
1267
1174
|
|
|
1175
|
+
var FS_fileDataToTypedArray = data => {
|
|
1176
|
+
if (typeof data == "string") {
|
|
1177
|
+
data = intArrayFromString(data, true);
|
|
1178
|
+
}
|
|
1179
|
+
if (!data.subarray) {
|
|
1180
|
+
data = new Uint8Array(data);
|
|
1181
|
+
}
|
|
1182
|
+
return data;
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1268
1185
|
var FS_getMode = (canRead, canWrite) => {
|
|
1269
1186
|
var mode = 0;
|
|
1270
1187
|
if (canRead) mode |= 292 | 73;
|
|
@@ -1639,10 +1556,10 @@ var NODEFS = {
|
|
|
1639
1556
|
stream.shared.refcount++;
|
|
1640
1557
|
},
|
|
1641
1558
|
read(stream, buffer, offset, length, position) {
|
|
1642
|
-
return NODEFS.tryFSOperation(() => fs.readSync(stream.nfd,
|
|
1559
|
+
return NODEFS.tryFSOperation(() => fs.readSync(stream.nfd, buffer, offset, length, position));
|
|
1643
1560
|
},
|
|
1644
1561
|
write(stream, buffer, offset, length, position) {
|
|
1645
|
-
return NODEFS.tryFSOperation(() => fs.writeSync(stream.nfd,
|
|
1562
|
+
return NODEFS.tryFSOperation(() => fs.writeSync(stream.nfd, buffer, offset, length, position));
|
|
1646
1563
|
},
|
|
1647
1564
|
llseek(stream, offset, whence) {
|
|
1648
1565
|
var position = offset;
|
|
@@ -1680,6 +1597,80 @@ var NODEFS = {
|
|
|
1680
1597
|
}
|
|
1681
1598
|
};
|
|
1682
1599
|
|
|
1600
|
+
var asyncLoad = async url => {
|
|
1601
|
+
var arrayBuffer = await readAsync(url);
|
|
1602
|
+
return new Uint8Array(arrayBuffer);
|
|
1603
|
+
};
|
|
1604
|
+
|
|
1605
|
+
var FS_createDataFile = (...args) => FS.createDataFile(...args);
|
|
1606
|
+
|
|
1607
|
+
var getUniqueRunDependency = id => id;
|
|
1608
|
+
|
|
1609
|
+
var dependenciesPromise = null;
|
|
1610
|
+
|
|
1611
|
+
var resolveRunDependencies = async () => dependenciesPromise;
|
|
1612
|
+
|
|
1613
|
+
var runDependencies = 0;
|
|
1614
|
+
|
|
1615
|
+
var removeRunDependency = id => {
|
|
1616
|
+
runDependencies--;
|
|
1617
|
+
Module["monitorRunDependencies"]?.(runDependencies);
|
|
1618
|
+
if (!runDependencies) {
|
|
1619
|
+
dependenciesPromise.resolve();
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
|
|
1623
|
+
var addRunDependency = id => {
|
|
1624
|
+
if (!runDependencies) {
|
|
1625
|
+
var resolve;
|
|
1626
|
+
dependenciesPromise = new Promise(r => resolve = r);
|
|
1627
|
+
dependenciesPromise.resolve = resolve;
|
|
1628
|
+
}
|
|
1629
|
+
runDependencies++;
|
|
1630
|
+
Module["monitorRunDependencies"]?.(runDependencies);
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1633
|
+
var preloadPlugins = [];
|
|
1634
|
+
|
|
1635
|
+
var FS_handledByPreloadPlugin = async (byteArray, fullname) => {
|
|
1636
|
+
// Ensure plugins are ready.
|
|
1637
|
+
if (typeof Browser != "undefined") Browser.init();
|
|
1638
|
+
for (var plugin of preloadPlugins) {
|
|
1639
|
+
if (plugin["canHandle"](fullname)) {
|
|
1640
|
+
return plugin["handle"](byteArray, fullname);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
// If no plugin handled this file then return the original/unmodified
|
|
1644
|
+
// byteArray.
|
|
1645
|
+
return byteArray;
|
|
1646
|
+
};
|
|
1647
|
+
|
|
1648
|
+
var FS_preloadFile = async (parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish) => {
|
|
1649
|
+
// TODO we should allow people to just pass in a complete filename instead
|
|
1650
|
+
// of parent and name being that we just join them anyways
|
|
1651
|
+
var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent;
|
|
1652
|
+
var dep = getUniqueRunDependency(`cp ${fullname}`);
|
|
1653
|
+
// might have several active requests for the same fullname
|
|
1654
|
+
addRunDependency(dep);
|
|
1655
|
+
try {
|
|
1656
|
+
var byteArray = url;
|
|
1657
|
+
if (typeof url == "string") {
|
|
1658
|
+
byteArray = await asyncLoad(url);
|
|
1659
|
+
}
|
|
1660
|
+
byteArray = await FS_handledByPreloadPlugin(byteArray, fullname);
|
|
1661
|
+
preFinish?.();
|
|
1662
|
+
if (!dontCreateFile) {
|
|
1663
|
+
FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
|
|
1664
|
+
}
|
|
1665
|
+
} finally {
|
|
1666
|
+
removeRunDependency(dep);
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
|
|
1670
|
+
var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => {
|
|
1671
|
+
FS_preloadFile(parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish).then(onload).catch(onerror);
|
|
1672
|
+
};
|
|
1673
|
+
|
|
1683
1674
|
var FS = {
|
|
1684
1675
|
root: null,
|
|
1685
1676
|
mounts: [],
|
|
@@ -1692,7 +1683,6 @@ var FS = {
|
|
|
1692
1683
|
ignorePermissions: true,
|
|
1693
1684
|
filesystems: null,
|
|
1694
1685
|
syncFSRequests: 0,
|
|
1695
|
-
readFiles: {},
|
|
1696
1686
|
ErrnoError: class {
|
|
1697
1687
|
name="ErrnoError";
|
|
1698
1688
|
// We set the `name` property to be able to identify `FS.ErrnoError`
|
|
@@ -1780,7 +1770,7 @@ var FS = {
|
|
|
1780
1770
|
if (!PATH.isAbs(path)) {
|
|
1781
1771
|
path = FS.cwd() + "/" + path;
|
|
1782
1772
|
}
|
|
1783
|
-
// limit max consecutive symlinks to
|
|
1773
|
+
// limit max consecutive symlinks to SYMLOOP_MAX.
|
|
1784
1774
|
linkloop: for (var nlinks = 0; nlinks < 40; nlinks++) {
|
|
1785
1775
|
// split the absolute path
|
|
1786
1776
|
var parts = path.split("/").filter(p => !!p);
|
|
@@ -1951,9 +1941,11 @@ var FS = {
|
|
|
1951
1941
|
// return 0 if any user, group or owner bits are set.
|
|
1952
1942
|
if (perms.includes("r") && !(node.mode & 292)) {
|
|
1953
1943
|
return 2;
|
|
1954
|
-
}
|
|
1944
|
+
}
|
|
1945
|
+
if (perms.includes("w") && !(node.mode & 146)) {
|
|
1955
1946
|
return 2;
|
|
1956
|
-
}
|
|
1947
|
+
}
|
|
1948
|
+
if (perms.includes("x") && !(node.mode & 73)) {
|
|
1957
1949
|
return 2;
|
|
1958
1950
|
}
|
|
1959
1951
|
return 0;
|
|
@@ -1993,10 +1985,8 @@ var FS = {
|
|
|
1993
1985
|
if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
|
|
1994
1986
|
return 10;
|
|
1995
1987
|
}
|
|
1996
|
-
} else {
|
|
1997
|
-
|
|
1998
|
-
return 31;
|
|
1999
|
-
}
|
|
1988
|
+
} else if (FS.isDir(node.mode)) {
|
|
1989
|
+
return 31;
|
|
2000
1990
|
}
|
|
2001
1991
|
return 0;
|
|
2002
1992
|
},
|
|
@@ -2006,13 +1996,16 @@ var FS = {
|
|
|
2006
1996
|
}
|
|
2007
1997
|
if (FS.isLink(node.mode)) {
|
|
2008
1998
|
return 32;
|
|
2009
|
-
}
|
|
2010
|
-
|
|
2011
|
-
|
|
1999
|
+
}
|
|
2000
|
+
var mode = FS.flagsToPermissionString(flags);
|
|
2001
|
+
if (FS.isDir(node.mode)) {
|
|
2002
|
+
// opening for write
|
|
2003
|
+
// TODO: check for O_SEARCH? (== search for dir only)
|
|
2004
|
+
if (mode !== "r" || (flags & (512 | 64))) {
|
|
2012
2005
|
return 31;
|
|
2013
2006
|
}
|
|
2014
2007
|
}
|
|
2015
|
-
return FS.nodePermissions(node,
|
|
2008
|
+
return FS.nodePermissions(node, mode);
|
|
2016
2009
|
},
|
|
2017
2010
|
checkOpExists(op, err) {
|
|
2018
2011
|
if (!op) {
|
|
@@ -2060,7 +2053,14 @@ var FS = {
|
|
|
2060
2053
|
var arg = setattr ? stream : node;
|
|
2061
2054
|
setattr ??= node.node_ops.setattr;
|
|
2062
2055
|
FS.checkOpExists(setattr, 63);
|
|
2063
|
-
|
|
2056
|
+
try {
|
|
2057
|
+
setattr(arg, attr);
|
|
2058
|
+
} catch (e) {
|
|
2059
|
+
if (e instanceof RangeError) {
|
|
2060
|
+
throw new FS.ErrnoError(22);
|
|
2061
|
+
}
|
|
2062
|
+
throw e;
|
|
2063
|
+
}
|
|
2064
2064
|
},
|
|
2065
2065
|
chrdev_stream_ops: {
|
|
2066
2066
|
open(stream) {
|
|
@@ -2121,12 +2121,13 @@ var FS = {
|
|
|
2121
2121
|
}
|
|
2122
2122
|
}
|
|
2123
2123
|
// sync all mounts
|
|
2124
|
-
|
|
2125
|
-
if (
|
|
2126
|
-
|
|
2124
|
+
for (var mount of mounts) {
|
|
2125
|
+
if (mount.type.syncfs) {
|
|
2126
|
+
mount.type.syncfs(mount, populate, done);
|
|
2127
|
+
} else {
|
|
2128
|
+
done(null);
|
|
2127
2129
|
}
|
|
2128
|
-
|
|
2129
|
-
});
|
|
2130
|
+
}
|
|
2130
2131
|
},
|
|
2131
2132
|
mount(type, opts, mountpoint) {
|
|
2132
2133
|
var root = mountpoint === "/";
|
|
@@ -2181,8 +2182,7 @@ var FS = {
|
|
|
2181
2182
|
var node = lookup.node;
|
|
2182
2183
|
var mount = node.mounted;
|
|
2183
2184
|
var mounts = FS.getMounts(mount);
|
|
2184
|
-
Object.
|
|
2185
|
-
var current = FS.nameTable[hash];
|
|
2185
|
+
for (var [hash, current] of Object.entries(FS.nameTable)) {
|
|
2186
2186
|
while (current) {
|
|
2187
2187
|
var next = current.name_next;
|
|
2188
2188
|
if (mounts.includes(current.mount)) {
|
|
@@ -2190,7 +2190,7 @@ var FS = {
|
|
|
2190
2190
|
}
|
|
2191
2191
|
current = next;
|
|
2192
2192
|
}
|
|
2193
|
-
}
|
|
2193
|
+
}
|
|
2194
2194
|
// no longer a mountpoint
|
|
2195
2195
|
node.mounted = null;
|
|
2196
2196
|
// remove this mount from the child mounts
|
|
@@ -2578,7 +2578,7 @@ var FS = {
|
|
|
2578
2578
|
if (path === "") {
|
|
2579
2579
|
throw new FS.ErrnoError(44);
|
|
2580
2580
|
}
|
|
2581
|
-
flags =
|
|
2581
|
+
flags = FS_modeStringToFlags(flags);
|
|
2582
2582
|
if ((flags & 64)) {
|
|
2583
2583
|
mode = (mode & 4095) | 32768;
|
|
2584
2584
|
} else {
|
|
@@ -2613,7 +2613,7 @@ var FS = {
|
|
|
2613
2613
|
} else {
|
|
2614
2614
|
// node doesn't exist, try to create it
|
|
2615
2615
|
// Ignore the permission bits here to ensure we can `open` this new
|
|
2616
|
-
// file below. We use chmod below
|
|
2616
|
+
// file below. We use chmod below to apply the permissions once the
|
|
2617
2617
|
// file is open.
|
|
2618
2618
|
node = FS.mknod(path, mode | 511, 0);
|
|
2619
2619
|
created = true;
|
|
@@ -2665,11 +2665,6 @@ var FS = {
|
|
|
2665
2665
|
if (created) {
|
|
2666
2666
|
FS.chmod(node, mode & 511);
|
|
2667
2667
|
}
|
|
2668
|
-
if (Module["logReadFiles"] && !(flags & 1)) {
|
|
2669
|
-
if (!(path in FS.readFiles)) {
|
|
2670
|
-
FS.readFiles[path] = 1;
|
|
2671
|
-
}
|
|
2672
|
-
}
|
|
2673
2668
|
return stream;
|
|
2674
2669
|
},
|
|
2675
2670
|
close(stream) {
|
|
@@ -2796,10 +2791,10 @@ var FS = {
|
|
|
2796
2791
|
return stream.stream_ops.ioctl(stream, cmd, arg);
|
|
2797
2792
|
},
|
|
2798
2793
|
readFile(path, opts = {}) {
|
|
2799
|
-
opts.flags = opts.flags
|
|
2800
|
-
opts.encoding = opts.encoding
|
|
2794
|
+
opts.flags = opts.flags ?? 0;
|
|
2795
|
+
opts.encoding = opts.encoding ?? "binary";
|
|
2801
2796
|
if (opts.encoding !== "utf8" && opts.encoding !== "binary") {
|
|
2802
|
-
|
|
2797
|
+
abort(`Invalid encoding type "${opts.encoding}"`);
|
|
2803
2798
|
}
|
|
2804
2799
|
var stream = FS.open(path, opts.flags);
|
|
2805
2800
|
var stat = FS.stat(path);
|
|
@@ -2813,16 +2808,10 @@ var FS = {
|
|
|
2813
2808
|
return buf;
|
|
2814
2809
|
},
|
|
2815
2810
|
writeFile(path, data, opts = {}) {
|
|
2816
|
-
opts.flags = opts.flags
|
|
2811
|
+
opts.flags = opts.flags ?? 577;
|
|
2817
2812
|
var stream = FS.open(path, opts.flags, opts.mode);
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
}
|
|
2821
|
-
if (ArrayBuffer.isView(data)) {
|
|
2822
|
-
FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
|
|
2823
|
-
} else {
|
|
2824
|
-
throw new Error("Unsupported data type");
|
|
2825
|
-
}
|
|
2813
|
+
data = FS_fileDataToTypedArray(data);
|
|
2814
|
+
FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
|
|
2826
2815
|
FS.close(stream);
|
|
2827
2816
|
},
|
|
2828
2817
|
cwd: () => FS.currentPath,
|
|
@@ -3053,11 +3042,7 @@ var FS = {
|
|
|
3053
3042
|
var mode = FS_getMode(canRead, canWrite);
|
|
3054
3043
|
var node = FS.create(path, mode);
|
|
3055
3044
|
if (data) {
|
|
3056
|
-
|
|
3057
|
-
var arr = new Array(data.length);
|
|
3058
|
-
for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
|
|
3059
|
-
data = arr;
|
|
3060
|
-
}
|
|
3045
|
+
data = FS_fileDataToTypedArray(data);
|
|
3061
3046
|
// make sure we can write to the file
|
|
3062
3047
|
FS.chmod(node, mode | 146);
|
|
3063
3048
|
var stream = FS.open(node, 577);
|
|
@@ -3122,13 +3107,12 @@ var FS = {
|
|
|
3122
3107
|
},
|
|
3123
3108
|
forceLoadFile(obj) {
|
|
3124
3109
|
if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
|
|
3125
|
-
if (
|
|
3126
|
-
|
|
3110
|
+
if (globalThis.XMLHttpRequest) {
|
|
3111
|
+
abort("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");
|
|
3127
3112
|
} else {
|
|
3128
3113
|
// Command-line.
|
|
3129
3114
|
try {
|
|
3130
3115
|
obj.contents = readBinary(obj.url);
|
|
3131
|
-
obj.usedBytes = obj.contents.length;
|
|
3132
3116
|
} catch (e) {
|
|
3133
3117
|
throw new FS.ErrnoError(29);
|
|
3134
3118
|
}
|
|
@@ -3157,7 +3141,7 @@ var FS = {
|
|
|
3157
3141
|
var xhr = new XMLHttpRequest;
|
|
3158
3142
|
xhr.open("HEAD", url, false);
|
|
3159
3143
|
xhr.send(null);
|
|
3160
|
-
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304))
|
|
3144
|
+
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr.status);
|
|
3161
3145
|
var datalength = Number(xhr.getResponseHeader("Content-length"));
|
|
3162
3146
|
var header;
|
|
3163
3147
|
var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
|
|
@@ -3167,8 +3151,8 @@ var FS = {
|
|
|
3167
3151
|
if (!hasByteServing) chunkSize = datalength;
|
|
3168
3152
|
// Function to get a range from the remote URL.
|
|
3169
3153
|
var doXHR = (from, to) => {
|
|
3170
|
-
if (from > to)
|
|
3171
|
-
if (to > datalength - 1)
|
|
3154
|
+
if (from > to) abort(`invalid range (${from}, ${to}) or no bytes requested!`);
|
|
3155
|
+
if (to > datalength - 1) abort(`only ${datalength} bytes available! programmer error!`);
|
|
3172
3156
|
// TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
|
|
3173
3157
|
var xhr = new XMLHttpRequest;
|
|
3174
3158
|
xhr.open("GET", url, false);
|
|
@@ -3179,11 +3163,11 @@ var FS = {
|
|
|
3179
3163
|
xhr.overrideMimeType("text/plain; charset=x-user-defined");
|
|
3180
3164
|
}
|
|
3181
3165
|
xhr.send(null);
|
|
3182
|
-
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304))
|
|
3166
|
+
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr.status);
|
|
3183
3167
|
if (xhr.response !== undefined) {
|
|
3184
3168
|
return new Uint8Array(/** @type{Array<number>} */ (xhr.response || []));
|
|
3185
3169
|
}
|
|
3186
|
-
return intArrayFromString(xhr.responseText
|
|
3170
|
+
return intArrayFromString(xhr.responseText ?? "", true);
|
|
3187
3171
|
};
|
|
3188
3172
|
var lazyArray = this;
|
|
3189
3173
|
lazyArray.setDataGetter(chunkNum => {
|
|
@@ -3195,7 +3179,7 @@ var FS = {
|
|
|
3195
3179
|
if (typeof lazyArray.chunks[chunkNum] == "undefined") {
|
|
3196
3180
|
lazyArray.chunks[chunkNum] = doXHR(start, end);
|
|
3197
3181
|
}
|
|
3198
|
-
if (typeof lazyArray.chunks[chunkNum] == "undefined")
|
|
3182
|
+
if (typeof lazyArray.chunks[chunkNum] == "undefined") abort("doXHR failed!");
|
|
3199
3183
|
return lazyArray.chunks[chunkNum];
|
|
3200
3184
|
});
|
|
3201
3185
|
if (usesGzip || !datalength) {
|
|
@@ -3223,8 +3207,8 @@ var FS = {
|
|
|
3223
3207
|
return this._chunkSize;
|
|
3224
3208
|
}
|
|
3225
3209
|
}
|
|
3226
|
-
if (
|
|
3227
|
-
if (!ENVIRONMENT_IS_WORKER)
|
|
3210
|
+
if (globalThis.XMLHttpRequest) {
|
|
3211
|
+
if (!ENVIRONMENT_IS_WORKER) abort("Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc");
|
|
3228
3212
|
var lazyArray = new LazyUint8Array;
|
|
3229
3213
|
var properties = {
|
|
3230
3214
|
isDevice: false,
|
|
@@ -3256,14 +3240,12 @@ var FS = {
|
|
|
3256
3240
|
});
|
|
3257
3241
|
// override each stream op with one that tries to force load the lazy file first
|
|
3258
3242
|
var stream_ops = {};
|
|
3259
|
-
|
|
3260
|
-
keys.forEach(key => {
|
|
3261
|
-
var fn = node.stream_ops[key];
|
|
3243
|
+
for (const [key, fn] of Object.entries(node.stream_ops)) {
|
|
3262
3244
|
stream_ops[key] = (...args) => {
|
|
3263
3245
|
FS.forceLoadFile(node);
|
|
3264
3246
|
return fn(...args);
|
|
3265
3247
|
};
|
|
3266
|
-
}
|
|
3248
|
+
}
|
|
3267
3249
|
function writeChunks(stream, buffer, offset, length, position) {
|
|
3268
3250
|
var contents = stream.node.contents;
|
|
3269
3251
|
if (position >= contents.length) return 0;
|
|
@@ -3305,21 +3287,21 @@ var FS = {
|
|
|
3305
3287
|
};
|
|
3306
3288
|
|
|
3307
3289
|
/**
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3290
|
+
* Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the
|
|
3291
|
+
* emscripten HEAP, returns a copy of that string as a Javascript String object.
|
|
3292
|
+
*
|
|
3293
|
+
* @param {number} ptr
|
|
3294
|
+
* @param {number=} maxBytesToRead - An optional length that specifies the
|
|
3295
|
+
* maximum number of bytes to read. You can omit this parameter to scan the
|
|
3296
|
+
* string until the first 0 byte. If maxBytesToRead is passed, and the string
|
|
3297
|
+
* at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the
|
|
3298
|
+
* string will cut short at that byte index.
|
|
3299
|
+
* @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.
|
|
3300
|
+
* @return {string}
|
|
3301
|
+
*/ var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : "";
|
|
3320
3302
|
|
|
3321
3303
|
var SYSCALLS = {
|
|
3322
|
-
|
|
3304
|
+
currentUmask: 18,
|
|
3323
3305
|
calculateAt(dirfd, path, allowEmpty) {
|
|
3324
3306
|
if (PATH.isAbs(path)) {
|
|
3325
3307
|
return path;
|
|
@@ -3341,12 +3323,12 @@ var SYSCALLS = {
|
|
|
3341
3323
|
return dir + "/" + path;
|
|
3342
3324
|
},
|
|
3343
3325
|
writeStat(buf, stat) {
|
|
3344
|
-
|
|
3345
|
-
|
|
3326
|
+
HEAPU32[((buf) >> 2)] = stat.dev;
|
|
3327
|
+
HEAPU32[(((buf) + (4)) >> 2)] = stat.mode;
|
|
3346
3328
|
HEAPU32[(((buf) + (8)) >> 2)] = stat.nlink;
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3329
|
+
HEAPU32[(((buf) + (12)) >> 2)] = stat.uid;
|
|
3330
|
+
HEAPU32[(((buf) + (16)) >> 2)] = stat.gid;
|
|
3331
|
+
HEAPU32[(((buf) + (20)) >> 2)] = stat.rdev;
|
|
3350
3332
|
HEAP64[(((buf) + (24)) >> 3)] = BigInt(stat.size);
|
|
3351
3333
|
HEAP32[(((buf) + (32)) >> 2)] = 4096;
|
|
3352
3334
|
HEAP32[(((buf) + (36)) >> 2)] = stat.blocks;
|
|
@@ -3363,17 +3345,17 @@ var SYSCALLS = {
|
|
|
3363
3345
|
return 0;
|
|
3364
3346
|
},
|
|
3365
3347
|
writeStatFs(buf, stats) {
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3348
|
+
HEAPU32[(((buf) + (4)) >> 2)] = stats.bsize;
|
|
3349
|
+
HEAPU32[(((buf) + (60)) >> 2)] = stats.bsize;
|
|
3350
|
+
HEAP64[(((buf) + (8)) >> 3)] = BigInt(stats.blocks);
|
|
3351
|
+
HEAP64[(((buf) + (16)) >> 3)] = BigInt(stats.bfree);
|
|
3352
|
+
HEAP64[(((buf) + (24)) >> 3)] = BigInt(stats.bavail);
|
|
3353
|
+
HEAP64[(((buf) + (32)) >> 3)] = BigInt(stats.files);
|
|
3354
|
+
HEAP64[(((buf) + (40)) >> 3)] = BigInt(stats.ffree);
|
|
3355
|
+
HEAPU32[(((buf) + (48)) >> 2)] = stats.fsid;
|
|
3356
|
+
HEAPU32[(((buf) + (64)) >> 2)] = stats.flags;
|
|
3375
3357
|
// ST_NOSUID
|
|
3376
|
-
|
|
3358
|
+
HEAPU32[(((buf) + (56)) >> 2)] = stats.namelen;
|
|
3377
3359
|
},
|
|
3378
3360
|
doMsync(addr, stream, len, flags, offset) {
|
|
3379
3361
|
if (!FS.isFile(stream.node.mode)) {
|
|
@@ -3383,7 +3365,7 @@ var SYSCALLS = {
|
|
|
3383
3365
|
// MAP_PRIVATE calls need not to be synced back to underlying fs
|
|
3384
3366
|
return 0;
|
|
3385
3367
|
}
|
|
3386
|
-
var buffer = HEAPU8.
|
|
3368
|
+
var buffer = HEAPU8.subarray(addr, addr + len);
|
|
3387
3369
|
FS.msync(stream, buffer, offset, len, flags);
|
|
3388
3370
|
},
|
|
3389
3371
|
getStreamFromFD(fd) {
|
|
@@ -3427,7 +3409,8 @@ function ___syscall_fcntl64(fd, cmd, varargs) {
|
|
|
3427
3409
|
case 4:
|
|
3428
3410
|
{
|
|
3429
3411
|
var arg = syscallGetVarargI();
|
|
3430
|
-
|
|
3412
|
+
var mask = 289792;
|
|
3413
|
+
stream.flags = (stream.flags & ~mask) | (arg & mask);
|
|
3431
3414
|
return 0;
|
|
3432
3415
|
}
|
|
3433
3416
|
|
|
@@ -3581,6 +3564,7 @@ function ___syscall_mkdirat(dirfd, path, mode) {
|
|
|
3581
3564
|
try {
|
|
3582
3565
|
path = SYSCALLS.getStr(path);
|
|
3583
3566
|
path = SYSCALLS.calculateAt(dirfd, path);
|
|
3567
|
+
mode &= ~SYSCALLS.currentUmask;
|
|
3584
3568
|
FS.mkdir(path, mode, 0);
|
|
3585
3569
|
return 0;
|
|
3586
3570
|
} catch (e) {
|
|
@@ -3595,6 +3579,9 @@ function ___syscall_openat(dirfd, path, flags, varargs) {
|
|
|
3595
3579
|
path = SYSCALLS.getStr(path);
|
|
3596
3580
|
path = SYSCALLS.calculateAt(dirfd, path);
|
|
3597
3581
|
var mode = varargs ? syscallGetVarargI() : 0;
|
|
3582
|
+
if (flags & 64) {
|
|
3583
|
+
mode &= ~SYSCALLS.currentUmask;
|
|
3584
|
+
}
|
|
3598
3585
|
return FS.open(path, flags, mode).fd;
|
|
3599
3586
|
} catch (e) {
|
|
3600
3587
|
if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e;
|
|
@@ -4179,7 +4166,7 @@ var bigintToI53Checked = num => (num < INT53_MIN || num > INT53_MAX) ? NaN : Num
|
|
|
4179
4166
|
function _fd_seek(fd, offset, whence, newOffset) {
|
|
4180
4167
|
offset = bigintToI53Checked(offset);
|
|
4181
4168
|
try {
|
|
4182
|
-
if (isNaN(offset)) return
|
|
4169
|
+
if (isNaN(offset)) return 22;
|
|
4183
4170
|
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
4184
4171
|
FS.llseek(stream, offset, whence);
|
|
4185
4172
|
HEAP64[((newOffset) >> 3)] = BigInt(stream.position);
|
|
@@ -4762,8 +4749,6 @@ function _napi_create_uint32(env, value, result) {
|
|
|
4762
4749
|
|
|
4763
4750
|
var wasmTableMirror = [];
|
|
4764
4751
|
|
|
4765
|
-
/** @type {WebAssembly.Table} */ var wasmTable;
|
|
4766
|
-
|
|
4767
4752
|
var getWasmTableEntry = funcPtr => {
|
|
4768
4753
|
var func = wasmTableMirror[funcPtr];
|
|
4769
4754
|
if (!func) {
|
|
@@ -5445,6 +5430,8 @@ var FS_createDevice = (...args) => FS.createDevice(...args);
|
|
|
5445
5430
|
|
|
5446
5431
|
FS.createPreloadedFile = FS_createPreloadedFile;
|
|
5447
5432
|
|
|
5433
|
+
FS.preloadFile = FS_preloadFile;
|
|
5434
|
+
|
|
5448
5435
|
FS.staticInit();
|
|
5449
5436
|
|
|
5450
5437
|
if (ENVIRONMENT_IS_NODE) {
|
|
@@ -5462,13 +5449,20 @@ emnapiString.init();
|
|
|
5462
5449
|
{
|
|
5463
5450
|
// Begin ATMODULES hooks
|
|
5464
5451
|
if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
|
|
5465
|
-
if (Module["preloadPlugins"]) preloadPlugins = Module["preloadPlugins"];
|
|
5466
5452
|
if (Module["print"]) out = Module["print"];
|
|
5467
5453
|
if (Module["printErr"]) err = Module["printErr"];
|
|
5468
|
-
if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
|
|
5469
5454
|
// End ATMODULES hooks
|
|
5470
|
-
if (Module["arguments"])
|
|
5455
|
+
if (Module["arguments"]) programArgs = Module["arguments"];
|
|
5471
5456
|
if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
|
|
5457
|
+
var preInit = Module["preInit"];
|
|
5458
|
+
if (preInit) {
|
|
5459
|
+
if (typeof preInit == "function") Module["preInit"] = preInit = [ preInit ];
|
|
5460
|
+
// Written as a loop so that preInit functions that themselves add more
|
|
5461
|
+
// preInit functions. Is this actually needed?
|
|
5462
|
+
while (preInit.length > 0) {
|
|
5463
|
+
preInit.shift()();
|
|
5464
|
+
}
|
|
5465
|
+
}
|
|
5472
5466
|
}
|
|
5473
5467
|
|
|
5474
5468
|
// Begin runtime exports
|
|
@@ -5476,7 +5470,7 @@ Module["addRunDependency"] = addRunDependency;
|
|
|
5476
5470
|
|
|
5477
5471
|
Module["removeRunDependency"] = removeRunDependency;
|
|
5478
5472
|
|
|
5479
|
-
Module["
|
|
5473
|
+
Module["FS_preloadFile"] = FS_preloadFile;
|
|
5480
5474
|
|
|
5481
5475
|
Module["FS_unlink"] = FS_unlink;
|
|
5482
5476
|
|
|
@@ -5499,13 +5493,15 @@ Module["NODEFS"] = NODEFS;
|
|
|
5499
5493
|
// End JS library exports
|
|
5500
5494
|
// end include: postlibrary.js
|
|
5501
5495
|
// Imports from the Wasm binary.
|
|
5502
|
-
var _node_api_module_get_api_version_v1, _napi_register_wasm_v1, _malloc, _free;
|
|
5496
|
+
var _node_api_module_get_api_version_v1, _napi_register_wasm_v1, _malloc, _free, memory, __indirect_function_table, wasmMemory, wasmTable;
|
|
5503
5497
|
|
|
5504
5498
|
function assignWasmExports(wasmExports) {
|
|
5505
|
-
Module["_node_api_module_get_api_version_v1"] =
|
|
5506
|
-
Module["_napi_register_wasm_v1"] =
|
|
5507
|
-
Module["_malloc"] =
|
|
5508
|
-
Module["_free"] =
|
|
5499
|
+
_node_api_module_get_api_version_v1 = Module["_node_api_module_get_api_version_v1"] = wasmExports["Y"];
|
|
5500
|
+
_napi_register_wasm_v1 = Module["_napi_register_wasm_v1"] = wasmExports["Z"];
|
|
5501
|
+
_malloc = Module["_malloc"] = wasmExports["_"];
|
|
5502
|
+
_free = Module["_free"] = wasmExports["$"];
|
|
5503
|
+
memory = wasmMemory = wasmExports["V"];
|
|
5504
|
+
__indirect_function_table = wasmTable = wasmExports["X"];
|
|
5509
5505
|
}
|
|
5510
5506
|
|
|
5511
5507
|
var wasmImports = {
|
|
@@ -5558,73 +5554,37 @@ var wasmImports = {
|
|
|
5558
5554
|
/** @export */ z: _napi_typeof
|
|
5559
5555
|
};
|
|
5560
5556
|
|
|
5561
|
-
var wasmExports = await createWasm();
|
|
5562
|
-
|
|
5563
5557
|
// include: postamble.js
|
|
5564
5558
|
// === Auto-generated postamble setup entry stuff ===
|
|
5565
|
-
function run() {
|
|
5566
|
-
if (runDependencies > 0) {
|
|
5567
|
-
dependenciesFulfilled = run;
|
|
5568
|
-
return;
|
|
5569
|
-
}
|
|
5559
|
+
async function run() {
|
|
5570
5560
|
preRun();
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
dependenciesFulfilled = run;
|
|
5574
|
-
return;
|
|
5575
|
-
}
|
|
5576
|
-
function doRun() {
|
|
5577
|
-
// run may have just been called through dependencies being fulfilled just in this very frame,
|
|
5578
|
-
// or while the async setStatus time below was happening
|
|
5579
|
-
Module["calledRun"] = true;
|
|
5580
|
-
if (ABORT) return;
|
|
5581
|
-
initRuntime();
|
|
5582
|
-
readyPromiseResolve?.(Module);
|
|
5583
|
-
Module["onRuntimeInitialized"]?.();
|
|
5584
|
-
postRun();
|
|
5561
|
+
if (runDependencies) {
|
|
5562
|
+
await resolveRunDependencies();
|
|
5585
5563
|
}
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
doRun();
|
|
5564
|
+
var setStatus = Module["setStatus"];
|
|
5565
|
+
if (setStatus) {
|
|
5566
|
+
setStatus("Running...");
|
|
5567
|
+
// Yield to the event loop to allow the browser to paint "Running..."
|
|
5568
|
+
await new Promise(resolve => setTimeout(resolve, 1));
|
|
5569
|
+
// Then we want to clear the status text, but only after the rest of this function runs.
|
|
5570
|
+
setTimeout(setStatus, 1, "");
|
|
5594
5571
|
}
|
|
5572
|
+
if (ABORT) return;
|
|
5573
|
+
initRuntime();
|
|
5574
|
+
Module["onRuntimeInitialized"]?.();
|
|
5575
|
+
postRun();
|
|
5595
5576
|
}
|
|
5596
5577
|
|
|
5597
|
-
|
|
5598
|
-
if (Module["preInit"]) {
|
|
5599
|
-
if (typeof Module["preInit"] == "function") Module["preInit"] = [ Module["preInit"] ];
|
|
5600
|
-
while (Module["preInit"].length > 0) {
|
|
5601
|
-
Module["preInit"].shift()();
|
|
5602
|
-
}
|
|
5603
|
-
}
|
|
5604
|
-
}
|
|
5578
|
+
var wasmExports;
|
|
5605
5579
|
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
// include: postamble_modularize.js
|
|
5612
|
-
// In MODULARIZE mode we wrap the generated code in a factory function
|
|
5613
|
-
// and return either the Module itself, or a promise of the module.
|
|
5614
|
-
// We assign to the `moduleRtn` global here and configure closure to see
|
|
5615
|
-
// this as and extern so it won't get minified.
|
|
5616
|
-
if (runtimeInitialized) {
|
|
5617
|
-
moduleRtn = Module;
|
|
5618
|
-
} else {
|
|
5619
|
-
// Set up the promise that indicates the Module is initialized
|
|
5620
|
-
moduleRtn = new Promise((resolve, reject) => {
|
|
5621
|
-
readyPromiseResolve = resolve;
|
|
5622
|
-
readyPromiseReject = reject;
|
|
5623
|
-
});
|
|
5624
|
-
}
|
|
5580
|
+
// In modularize mode the generated code is within a factory function so we
|
|
5581
|
+
// can use await here (since it's not top-level-await).
|
|
5582
|
+
wasmExports = await createWasm();
|
|
5583
|
+
|
|
5584
|
+
await run();
|
|
5625
5585
|
|
|
5626
5586
|
|
|
5627
|
-
return
|
|
5587
|
+
return Module;
|
|
5628
5588
|
}
|
|
5629
5589
|
|
|
5630
5590
|
// Export using a UMD style export, or ES6 exports if selected
|