funicular 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -0
  3. data/demo/test_chartjs.html +9 -9
  4. data/demo/test_component.html +8 -8
  5. data/demo/test_error_boundary.html +44 -41
  6. data/demo/test_router.html +48 -48
  7. data/demo/tic-tac-toe.html +25 -25
  8. data/docs/architecture.md +46 -9
  9. data/lib/funicular/ssr/runtime.rb +1 -0
  10. data/lib/funicular/vendor/mrbc/VERSION +1 -1
  11. data/lib/funicular/vendor/mrbc/mrbc.js +613 -486
  12. data/lib/funicular/vendor/mrbc/mrbc.wasm +0 -0
  13. data/lib/funicular/vendor/picoruby/VERSION +1 -1
  14. data/lib/funicular/vendor/picoruby/debug/picoruby.js +669 -449
  15. data/lib/funicular/vendor/picoruby/debug/picoruby.wasm +0 -0
  16. data/lib/funicular/vendor/picoruby/dist/picoruby.js +2 -2
  17. data/lib/funicular/vendor/picoruby/dist/picoruby.wasm +0 -0
  18. data/lib/funicular/vendor/picoruby-test-node/VERSION +1 -1
  19. data/lib/funicular/vendor/picoruby-test-node/picoruby.js +921 -629
  20. data/lib/funicular/vendor/picoruby-test-node/picoruby.wasm +0 -0
  21. data/lib/funicular/vendor/picoruby-test-node/picoruby.wasm.map +1 -1
  22. data/lib/funicular/version.rb +1 -1
  23. data/lib/generators/funicular/chat/templates/funicular_chat_component.rb.tt +37 -38
  24. data/minitest/dsl_test.rb +237 -0
  25. data/minitest/fixtures/funicular_app/components/greeting_component.rb +5 -5
  26. data/minitest/form_for_test.rb +2 -2
  27. data/minitest/hydration_test.rb +2 -2
  28. data/minitest/sig_tags_test.rb +30 -0
  29. data/minitest/view_context_test.rb +15 -15
  30. data/mrblib/0_tags.rb +62 -0
  31. data/mrblib/component.rb +113 -23
  32. data/mrblib/error_boundary.rb +25 -19
  33. data/mrblib/form_builder.rb +10 -10
  34. data/mrblib/funicular.rb +1 -1
  35. data/mrblib/styles.rb +102 -12
  36. data/mrblib/view_context.rb +3 -32
  37. data/sig/component.rbs +18 -4
  38. data/sig/error_boundary.rbs +4 -4
  39. data/sig/styles.rbs +18 -5
  40. data/sig/tags.rbs +54 -0
  41. data/sig/view_context.rbs +47 -34
  42. metadata +5 -1
@@ -4,8 +4,7 @@
4
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 moduleRtn;
8
-
7
+ var Module = moduleArg;
9
8
  // include: shell.js
10
9
  // include: minimum_runtime_check.js
11
10
  (function() {
@@ -24,12 +23,17 @@ async function Module(moduleArg = {}) {
24
23
 
25
24
  // Note: We use a typeof check here instead of optional chaining using
26
25
  // globalThis because older browsers might not have globalThis defined.
27
- var currentNodeVersion = typeof process !== 'undefined' && process.versions?.node ? humanReadableVersionToPacked(process.versions.node) : TARGET_NOT_SUPPORTED;
28
- if (currentNodeVersion < TARGET_NOT_SUPPORTED) {
29
- throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
30
- }
31
- if (currentNodeVersion < 2147483647) {
32
- throw new Error(`This emscripten-generated code requires node v${ packedVersionToHumanReadable(2147483647) } (detected v${packedVersionToHumanReadable(currentNodeVersion)})`);
26
+
27
+ // We skip the node version checking when running on Bun/Deno since the node
28
+ // version they report doesn't seem to be useful.
29
+ if (typeof process !== 'undefined' && !process.versions?.bun && typeof Deno == "undefined") {
30
+ var currentNodeVersion = process.versions?.node ? humanReadableVersionToPacked(process.versions.node) : TARGET_NOT_SUPPORTED;
31
+ if (currentNodeVersion < TARGET_NOT_SUPPORTED) {
32
+ throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
33
+ }
34
+ if (currentNodeVersion < 2147483647) {
35
+ throw new Error(`This emscripten-generated code requires node v${ packedVersionToHumanReadable(2147483647) } (detected v${packedVersionToHumanReadable(currentNodeVersion)})`);
36
+ }
33
37
  }
34
38
 
35
39
  var userAgent = typeof navigator !== 'undefined' && navigator.userAgent;
@@ -67,7 +71,6 @@ async function Module(moduleArg = {}) {
67
71
  // after the generated code, you will need to define var Module = {};
68
72
  // before the code. Then that object will be used in the code, and you
69
73
  // can continue to use Module afterwards as well.
70
- var Module = moduleArg;
71
74
 
72
75
  // Determine the runtime environment we are in. You can customize this by
73
76
  // setting the ENVIRONMENT setting at compile time (see settings.js).
@@ -84,7 +87,7 @@ var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIR
84
87
  // refer to Module (if they choose; they can also define Module)
85
88
 
86
89
 
87
- var arguments_ = [];
90
+ var programArgs = [];
88
91
  var thisProgram = './this.program';
89
92
  var quit_ = (status, toThrow) => {
90
93
  throw toThrow;
@@ -154,11 +157,11 @@ var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js';
154
157
  // perform assertions in shell.js after we set up out() and err(), as otherwise
155
158
  // if an assertion fails it cannot print the message
156
159
 
157
- assert(!ENVIRONMENT_IS_WORKER, 'worker environment detected but not enabled at build time. Add `worker` to `-sENVIRONMENT` to enable.');
160
+ assert(!ENVIRONMENT_IS_WORKER, 'worker environment detected but not enabled at build time (add `worker` to `-sENVIRONMENT` to enable)');
158
161
 
159
- assert(!ENVIRONMENT_IS_NODE, 'node environment detected but not enabled at build time. Add `node` to `-sENVIRONMENT` to enable.');
162
+ assert(!ENVIRONMENT_IS_NODE, 'node environment detected but not enabled at build time (add `node` to `-sENVIRONMENT` to enable)');
160
163
 
161
- assert(!ENVIRONMENT_IS_SHELL, 'shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable.');
164
+ assert(!ENVIRONMENT_IS_SHELL, 'shell environment detected but not enabled at build time (add `shell` to `-sENVIRONMENT` to enable)');
162
165
 
163
166
  // end include: shell.js
164
167
 
@@ -215,45 +218,12 @@ function assert(condition, text) {
215
218
  var isFileURI = (filename) => filename.startsWith('file://');
216
219
 
217
220
  // include: runtime_common.js
218
- // include: runtime_stack_check.js
219
- // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
220
- function writeStackCookie() {
221
- var max = _emscripten_stack_get_end();
222
- assert((max & 3) == 0);
223
- // If the stack ends at address zero we write our cookies 4 bytes into the
224
- // stack. This prevents interference with SAFE_HEAP and ASAN which also
225
- // monitor writes to address zero.
226
- if (max == 0) {
227
- max += 4;
228
- }
229
- // The stack grow downwards towards _emscripten_stack_get_end.
230
- // We write cookies to the final two words in the stack and detect if they are
231
- // ever overwritten.
232
- HEAPU32[((max)>>2)] = 0x02135467;
233
- HEAPU32[(((max)+(4))>>2)] = 0x89BACDFE;
234
- // Also test the global address 0 for integrity.
235
- HEAPU32[((0)>>2)] = 1668509029;
236
- }
237
-
238
- function checkStackCookie() {
239
- if (ABORT) return;
240
- var max = _emscripten_stack_get_end();
241
- // See writeStackCookie().
242
- if (max == 0) {
243
- max += 4;
244
- }
245
- var cookie1 = HEAPU32[((max)>>2)];
246
- var cookie2 = HEAPU32[(((max)+(4))>>2)];
247
- if (cookie1 != 0x02135467 || cookie2 != 0x89BACDFE) {
248
- abort(`Stack overflow! Stack cookie has been overwritten at ${ptrToString(max)}, expected hex dwords 0x89BACDFE and 0x2135467, but received ${ptrToString(cookie2)} ${ptrToString(cookie1)}`);
249
- }
250
- // Also test the global address 0 for integrity.
251
- if (HEAPU32[((0)>>2)] != 0x63736d65 /* 'emsc' */) {
252
- abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
253
- }
254
- }
255
- // end include: runtime_stack_check.js
256
221
  // include: runtime_exceptions.js
222
+ // Base Emscripten EH error class
223
+ class EmscriptenEH {}
224
+
225
+ class EmscriptenSjLj extends EmscriptenEH {}
226
+
257
227
  // end include: runtime_exceptions.js
258
228
  // include: runtime_debug.js
259
229
  var runtimeDebug = true; // Switch to false at runtime to disable logging at the right times
@@ -275,15 +245,31 @@ function dbg(...args) {
275
245
  })();
276
246
 
277
247
  function consumedModuleProp(prop) {
278
- if (!Object.getOwnPropertyDescriptor(Module, prop)) {
279
- Object.defineProperty(Module, prop, {
280
- configurable: true,
281
- set() {
282
- abort(`Attempt to set \`Module.${prop}\` after it has already been processed. This can happen, for example, when code is injected via '--post-js' rather than '--pre-js'`);
283
-
248
+ var value = Module[prop];
249
+ var msg = `Attempt to modify \`Module.${prop}\` after it has already been processed. This can happen, for example, when code is injected via '--post-js' rather than '--pre-js'`;
250
+ if (Array.isArray(value)) {
251
+ value = new Proxy(value, {
252
+ set(target, key, val) {
253
+ abort(msg);
254
+ return false;
255
+ },
256
+ defineProperty(target, key, descriptor) {
257
+ abort(msg);
258
+ return false;
259
+ },
260
+ deleteProperty(target, key) {
261
+ abort(msg);
262
+ return false;
284
263
  }
285
264
  });
286
265
  }
266
+ Object.defineProperty(Module, prop, {
267
+ configurable: true,
268
+ get() { return value; },
269
+ set() {
270
+ abort(msg);
271
+ }
272
+ });
287
273
  }
288
274
 
289
275
  function makeInvalidEarlyAccess(name) {
@@ -334,41 +320,68 @@ function unexportedRuntimeSymbol(sym) {
334
320
  }
335
321
 
336
322
  // end include: runtime_debug.js
337
- var readyPromiseResolve, readyPromiseReject;
323
+ // include: runtime_stack_check.js
324
+ const stackCookie1 = 0x02135467;
325
+ const stackCookie2 = 0x89BACDFE;
326
+
327
+ // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.
328
+ function writeStackCookie() {
329
+ var max = _emscripten_stack_get_end();
330
+ assert((max & 3) == 0);
331
+ // If the stack ends at address zero we write our cookies 4 bytes into the
332
+ // stack. This prevents interference with SAFE_HEAP and ASAN which also
333
+ // monitor writes to address zero.
334
+ if (max == 0) {
335
+ max += 4;
336
+ }
337
+ // The stack grow downwards towards _emscripten_stack_get_end.
338
+ // We write cookies to the final two words in the stack and detect if they are
339
+ // ever overwritten.
340
+ HEAPU32[((max)>>2)] = stackCookie1;
341
+ HEAPU32[(((max)+(4))>>2)] = stackCookie2;
342
+ // Also test the global address 0 for integrity.
343
+ HEAPU32[((0)>>2)] = 1668509029;
344
+ }
345
+
346
+ function u32ToHexString(num) {
347
+ return '0x' + (num >>> 0).toString(16).padStart(8, '0');
348
+ }
338
349
 
350
+ function checkStackCookie() {
351
+ if (ABORT) return;
352
+ var max = _emscripten_stack_get_end();
353
+ // See writeStackCookie().
354
+ if (max == 0) {
355
+ max += 4;
356
+ }
357
+ var val1 = HEAPU32[((max)>>2)];
358
+ var val2 = HEAPU32[(((max)+(4))>>2)];
359
+ if (val1 != stackCookie1 || val2 != stackCookie2) {
360
+ abort(`Stack overflow! Stack cookie has been overwritten at ${ptrToString(max)}, expected hex dwords ${u32ToHexString(stackCookie2)} and ${u32ToHexString(stackCookie1)}, but received ${u32ToHexString(val2)} ${u32ToHexString(val1)}`);
361
+ }
362
+ // Also test the global address 0 for integrity.
363
+ if (HEAPU32[((0)>>2)] != 0x63736d65 /* 'emsc' */) {
364
+ abort('Runtime error: The application has corrupted its heap memory area (address zero)!');
365
+ }
366
+ }
367
+ // end include: runtime_stack_check.js
339
368
  // Memory management
340
- var
341
- /** @type {!Int8Array} */
342
- HEAP8,
343
- /** @type {!Uint8Array} */
344
- HEAPU8,
345
- /** @type {!Int16Array} */
346
- HEAP16,
347
- /** @type {!Uint16Array} */
348
- HEAPU16,
349
- /** @type {!Int32Array} */
350
- HEAP32,
351
- /** @type {!Uint32Array} */
352
- HEAPU32,
353
- /** @type {!Float32Array} */
354
- HEAPF32,
355
- /** @type {!Float64Array} */
356
- HEAPF64;
357
-
358
- // BigInt64Array type is not correctly defined in closure
359
- var
360
- /** not-@type {!BigInt64Array} */
361
- HEAP64,
362
- /* BigUint64Array type is not correctly defined in closure
363
- /** not-@type {!BigUint64Array} */
364
- HEAPU64;
365
369
 
366
370
  var runtimeInitialized = false;
367
371
 
368
372
 
369
373
 
374
+ // When ALLOW_MEMORY_GROWTH is enabled, the conversion from Wasm
375
+ // memory to ArrayBuffer requires some additional logic.
376
+ function getMemoryBuffer() {
377
+ return wasmMemory.buffer;
378
+ }
379
+
370
380
  function updateMemoryViews() {
371
- var b = wasmMemory.buffer;
381
+ // If we already have a heap that is resizeable/growable buffer we don't
382
+ // need to do anything in updateMemoryViews.
383
+ if (HEAP8?.buffer?.resizable) return;
384
+ var b = getMemoryBuffer();
372
385
  HEAP8 = new Int8Array(b);
373
386
  HEAP16 = new Int16Array(b);
374
387
  Module['HEAPU8'] = HEAPU8 = new Uint8Array(b);
@@ -388,11 +401,10 @@ assert(globalThis.Int32Array && globalThis.Float64Array && Int32Array.prototype.
388
401
  'JS engine does not provide full typed array support');
389
402
 
390
403
  function preRun() {
391
- if (Module['preRun']) {
392
- if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
393
- while (Module['preRun'].length) {
394
- addOnPreRun(Module['preRun'].shift());
395
- }
404
+ var preRun = Module['preRun'];
405
+ if (preRun) {
406
+ if (typeof preRun == 'function') preRun = [preRun];
407
+ onPreRuns.push(...preRun);
396
408
  }
397
409
  consumedModuleProp('preRun');
398
410
  // Begin ATPRERUNS hooks
@@ -417,17 +429,17 @@ PIPEFS.root = FS.mount(PIPEFS, {}, null);
417
429
  // Begin ATPOSTCTORS hooks
418
430
  FS.ignorePermissions = false;
419
431
  // End ATPOSTCTORS hooks
432
+
433
+ checkStackCookie();
420
434
  }
421
435
 
422
436
  function postRun() {
423
437
  checkStackCookie();
424
- // PThreads reuse the runtime from the main thread.
425
438
 
426
- if (Module['postRun']) {
427
- if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
428
- while (Module['postRun'].length) {
429
- addOnPostRun(Module['postRun'].shift());
430
- }
439
+ var postRun = Module['postRun'];
440
+ if (postRun) {
441
+ if (typeof postRun == 'function') postRun = [postRun];
442
+ onPostRuns.push(...postRun);
431
443
  }
432
444
  consumedModuleProp('postRun');
433
445
 
@@ -436,11 +448,13 @@ function postRun() {
436
448
  // End ATPOSTRUNS hooks
437
449
  }
438
450
 
439
- /** @param {string|number=} what */
451
+ /**
452
+ * @param {string|number=} what
453
+ */
440
454
  function abort(what) {
441
455
  Module['onAbort']?.(what);
442
456
 
443
- what = 'Aborted(' + what + ')';
457
+ what = `Aborted(${what})`;
444
458
  // TODO(sbc): Should we remove printing and leave it up to whoever
445
459
  // catches the exception?
446
460
  err(what);
@@ -463,21 +477,19 @@ function abort(what) {
463
477
  /** @suppress {checkTypes} */
464
478
  var e = new WebAssembly.RuntimeError(what);
465
479
 
466
- readyPromiseReject?.(e);
467
480
  // Throw the error whether or not MODULARIZE is set because abort is used
468
481
  // in code paths apart from instantiation where an exception is expected
469
482
  // to be thrown when abort is called.
470
483
  throw e;
471
484
  }
472
485
 
473
- function createExportWrapper(name, nargs) {
486
+ function createExportWrapper(name, func, nargs) {
487
+ assert(func);
474
488
  return (...args) => {
475
489
  assert(runtimeInitialized, `native function \`${name}\` called before runtime initialization`);
476
- var f = wasmExports[name];
477
- assert(f, `exported native function \`${name}\` not found`);
478
490
  // Only assert for too many arguments. Too few can be valid since the missing arguments will be zero filled.
479
491
  assert(args.length <= nargs, `native function \`${name}\` called with ${args.length} args but expects ${nargs}`);
480
- return f(...args);
492
+ return func(...args);
481
493
  };
482
494
  }
483
495
 
@@ -495,9 +507,6 @@ function findWasmBinary() {
495
507
  }
496
508
 
497
509
  function getBinarySync(file) {
498
- if (file == wasmBinaryFile && wasmBinary) {
499
- return new Uint8Array(wasmBinary);
500
- }
501
510
  if (readBinary) {
502
511
  return readBinary(file);
503
512
  }
@@ -571,8 +580,7 @@ async function createWasm() {
571
580
  // Load the wasm module and create an instance of using native support in the JS engine.
572
581
  // handle a generated wasm instance, receiving its exports and
573
582
  // performing other necessary setup
574
- /** @param {WebAssembly.Module=} module*/
575
- function receiveInstance(instance, module) {
583
+ function receiveInstance(instance) {
576
584
  wasmExports = instance.exports;
577
585
 
578
586
  assignWasmExports(wasmExports);
@@ -605,15 +613,14 @@ async function createWasm() {
605
613
  // performing.
606
614
  // Also pthreads and wasm workers initialize the wasm instance through this
607
615
  // path.
608
- if (Module['instantiateWasm']) {
609
- return new Promise((resolve, reject) => {
616
+ var instantiateWasm = Module['instantiateWasm'];
617
+ if (instantiateWasm) {
618
+ return new Promise((resolve) => {
610
619
  try {
611
- Module['instantiateWasm'](info, (inst, mod) => {
612
- resolve(receiveInstance(inst, mod));
613
- });
620
+ instantiateWasm(info, (inst) => resolve(receiveInstance(inst)));
614
621
  } catch(e) {
615
622
  err(`Module.instantiateWasm callback failed with error: ${e}`);
616
- reject(e);
623
+ throw e;
617
624
  }
618
625
  });
619
626
  }
@@ -637,6 +644,36 @@ async function createWasm() {
637
644
  }
638
645
  }
639
646
 
647
+ /** @type {!Int16Array} */
648
+ var HEAP16;
649
+
650
+ /** @type {!Int32Array} */
651
+ var HEAP32;
652
+
653
+ /** not-@type {!BigInt64Array} */
654
+ var HEAP64;
655
+
656
+ /** @type {!Int8Array} */
657
+ var HEAP8;
658
+
659
+ /** @type {!Float32Array} */
660
+ var HEAPF32;
661
+
662
+ /** @type {!Float64Array} */
663
+ var HEAPF64;
664
+
665
+ /** @type {!Uint16Array} */
666
+ var HEAPU16;
667
+
668
+ /** @type {!Uint32Array} */
669
+ var HEAPU32;
670
+
671
+ /** not-@type {!BigUint64Array} */
672
+ var HEAPU64;
673
+
674
+ /** @type {!Uint8Array} */
675
+ var HEAPU8;
676
+
640
677
  var callRuntimeCallbacks = (callbacks) => {
641
678
  while (callbacks.length > 0) {
642
679
  // Pass the module as the first argument.
@@ -672,12 +709,12 @@ async function createWasm() {
672
709
 
673
710
  var noExitRuntime = true;
674
711
 
675
- var ptrToString = (ptr) => {
712
+ function ptrToString(ptr) {
676
713
  assert(typeof ptr === 'number', `ptrToString expects a number, got ${typeof ptr}`);
677
714
  // Convert to 32-bit unsigned value
678
715
  ptr >>>= 0;
679
716
  return '0x' + ptr.toString(16).padStart(8, '0');
680
- };
717
+ }
681
718
 
682
719
 
683
720
  /**
@@ -716,6 +753,14 @@ async function createWasm() {
716
753
 
717
754
  var UTF8Decoder = globalThis.TextDecoder && new TextDecoder();
718
755
 
756
+
757
+ /**
758
+ * heapOrArray is either a regular array, or a JavaScript typed array view.
759
+ * @param {number} idx
760
+ * @param {number=} maxBytesToRead
761
+ * @param {boolean=} ignoreNul
762
+ * @return {number}
763
+ */
719
764
  var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {
720
765
  var maxIdx = idx + maxBytesToRead;
721
766
  if (ignoreNul) return maxIdx;
@@ -760,7 +805,7 @@ async function createWasm() {
760
805
  if ((u0 & 0xF0) == 0xE0) {
761
806
  u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
762
807
  } else {
763
- if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte ' + ptrToString(u0) + ' encountered when deserializing a UTF-8 string in wasm memory to a JS string!');
808
+ if ((u0 & 0xF8) != 0xF0) warnOnce(`Invalid UTF-8 leading byte ${ptrToString(u0)} encountered when deserializing a UTF-8 string in wasm memory to a JS string!`);
764
809
  u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
765
810
  }
766
811
 
@@ -804,7 +849,7 @@ async function createWasm() {
804
849
  wasmTableMirror[funcPtr] = func = wasmTable.get(funcPtr);
805
850
  }
806
851
  /** @suppress {checkTypes} */
807
- assert(wasmTable.get(funcPtr) == func, 'JavaScript-side Wasm function table mirror is out of date!');
852
+ assert(wasmTable.get(funcPtr) == func, 'table mirror is out of date');
808
853
  return func;
809
854
  };
810
855
  var ___call_sighandler = (fp, sig) => getWasmTableEntry(fp)(sig);
@@ -872,12 +917,9 @@ join2:(l, r) => PATH.normalize(l + '/' + r),
872
917
 
873
918
  var initRandomFill = () => {
874
919
 
875
- return (view) => crypto.getRandomValues(view);
876
- };
877
- var randomFill = (view) => {
878
- // Lazily init on the first invocation.
879
- (randomFill = initRandomFill())(view);
920
+ return (view) => (crypto.getRandomValues(view), 0);
880
921
  };
922
+ var randomFill = (view) => (randomFill = initRandomFill())(view);
881
923
 
882
924
 
883
925
 
@@ -988,7 +1030,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
988
1030
  heap[outIdx++] = 0x80 | (u & 63);
989
1031
  } else {
990
1032
  if (outIdx + 3 >= endIdx) break;
991
- if (u > 0x10FFFF) warnOnce('Invalid Unicode code point ' + ptrToString(u) + ' encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).');
1033
+ if (u > 0x10FFFF) warnOnce(`Invalid Unicode code point ${ptrToString(u)} encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).`);
992
1034
  heap[outIdx++] = 0xF0 | (u >> 18);
993
1035
  heap[outIdx++] = 0x80 | ((u >> 12) & 63);
994
1036
  heap[outIdx++] = 0x80 | ((u >> 6) & 63);
@@ -1174,7 +1216,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1174
1216
  var zeroMemory = (ptr, size) => HEAPU8.fill(0, ptr, ptr + size);
1175
1217
 
1176
1218
  var alignMemory = (size, alignment) => {
1177
- assert(alignment, "alignment argument is required");
1219
+ assert(alignment, 'alignment argument is required');
1178
1220
  return Math.ceil(size / alignment) * alignment;
1179
1221
  };
1180
1222
  var mmapAlloc = (size) => {
@@ -1247,11 +1289,14 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1247
1289
  } else if (FS.isFile(node.mode)) {
1248
1290
  node.node_ops = MEMFS.ops_table.file.node;
1249
1291
  node.stream_ops = MEMFS.ops_table.file.stream;
1250
- node.usedBytes = 0; // The actual number of bytes used in the typed array, as opposed to contents.length which gives the whole capacity.
1251
- // When the byte data of the file is populated, this will point to either a typed array, or a normal JS array. Typed arrays are preferred
1252
- // for performance, and used by default. However, typed arrays are not resizable like normal JS arrays are, so there is a small disk size
1253
- // penalty involved for appending file writes that continuously grow a file similar to std::vector capacity vs used -scheme.
1254
- node.contents = null;
1292
+ // The actual number of bytes used in the typed array, as opposed to
1293
+ // contents.length which gives the whole capacity.
1294
+ node.usedBytes = 0;
1295
+ // The byte data of the file is stored in a typed array.
1296
+ // Note: typed arrays are not resizable like normal JS arrays are, so
1297
+ // there is a small penalty involved for appending file writes that
1298
+ // continuously grow a file similar to std::vector capacity vs used.
1299
+ node.contents = MEMFS.emptyFileContents ??= new Uint8Array(0);
1255
1300
  } else if (FS.isLink(node.mode)) {
1256
1301
  node.node_ops = MEMFS.ops_table.link.node;
1257
1302
  node.stream_ops = MEMFS.ops_table.link.stream;
@@ -1268,36 +1313,30 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1268
1313
  return node;
1269
1314
  },
1270
1315
  getFileDataAsTypedArray(node) {
1271
- if (!node.contents) return new Uint8Array(0);
1272
- if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes); // Make sure to not return excess unused bytes.
1273
- return new Uint8Array(node.contents);
1316
+ assert(FS.isFile(node.mode), 'getFileDataAsTypedArray called on non-file');
1317
+ return node.contents.subarray(0, node.usedBytes); // Make sure to not return excess unused bytes.
1274
1318
  },
1275
1319
  expandFileStorage(node, newCapacity) {
1276
- var prevCapacity = node.contents ? node.contents.length : 0;
1320
+ var prevCapacity = node.contents.length;
1277
1321
  if (prevCapacity >= newCapacity) return; // No need to expand, the storage was already large enough.
1278
- // Don't expand strictly to the given requested limit if it's only a very small increase, but instead geometrically grow capacity.
1279
- // For small filesizes (<1MB), perform size*2 geometric increase, but for large sizes, do a much more conservative size*1.125 increase to
1280
- // avoid overshooting the allocation cap by a very large margin.
1322
+ // Don't expand strictly to the given requested limit if it's only a very
1323
+ // small increase, but instead geometrically grow capacity.
1324
+ // For small filesizes (<1MB), perform size*2 geometric increase, but for
1325
+ // large sizes, do a much more conservative size*1.125 increase to avoid
1326
+ // overshooting the allocation cap by a very large margin.
1281
1327
  var CAPACITY_DOUBLING_MAX = 1024 * 1024;
1282
1328
  newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2.0 : 1.125)) >>> 0);
1283
- if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256); // At minimum allocate 256b for each file when expanding.
1284
- var oldContents = node.contents;
1329
+ if (prevCapacity) newCapacity = Math.max(newCapacity, 256); // At minimum allocate 256b for each file when expanding.
1330
+ var oldContents = MEMFS.getFileDataAsTypedArray(node);
1285
1331
  node.contents = new Uint8Array(newCapacity); // Allocate new storage.
1286
- if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0); // Copy old data over to the new storage.
1332
+ node.contents.set(oldContents);
1287
1333
  },
1288
1334
  resizeFileStorage(node, newSize) {
1289
1335
  if (node.usedBytes == newSize) return;
1290
- if (newSize == 0) {
1291
- node.contents = null; // Fully decommit when requesting a resize to zero.
1292
- node.usedBytes = 0;
1293
- } else {
1294
- var oldContents = node.contents;
1295
- node.contents = new Uint8Array(newSize); // Allocate new storage.
1296
- if (oldContents) {
1297
- node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes))); // Copy old data over to the new storage.
1298
- }
1299
- node.usedBytes = newSize;
1300
- }
1336
+ var oldContents = node.contents;
1337
+ node.contents = new Uint8Array(newSize); // Allocate new storage.
1338
+ node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes))); // Copy old data over to the new storage.
1339
+ node.usedBytes = newSize;
1301
1340
  },
1302
1341
  node_ops:{
1303
1342
  getattr(node) {
@@ -1397,16 +1436,11 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1397
1436
  if (position >= stream.node.usedBytes) return 0;
1398
1437
  var size = Math.min(stream.node.usedBytes - position, length);
1399
1438
  assert(size >= 0);
1400
- if (size > 8 && contents.subarray) { // non-trivial, and typed array
1401
- buffer.set(contents.subarray(position, position + size), offset);
1402
- } else {
1403
- for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i];
1404
- }
1439
+ buffer.set(contents.subarray(position, position + size), offset);
1405
1440
  return size;
1406
1441
  },
1407
1442
  write(stream, buffer, offset, length, position, canOwn) {
1408
- // The data buffer should be a typed array view
1409
- assert(!(buffer instanceof ArrayBuffer));
1443
+ assert(buffer.subarray, 'FS.write expects a TypedArray');
1410
1444
  // If the buffer is located in main memory (HEAP), and if
1411
1445
  // memory can grow, we can't hold on to references of the
1412
1446
  // memory buffer, as they may get invalidated. That means we
@@ -1419,33 +1453,19 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1419
1453
  var node = stream.node;
1420
1454
  node.mtime = node.ctime = Date.now();
1421
1455
 
1422
- if (buffer.subarray && (!node.contents || node.contents.subarray)) { // This write is from a typed array to a typed array?
1423
- if (canOwn) {
1424
- assert(position === 0, 'canOwn must imply no weird position inside the file');
1425
- node.contents = buffer.subarray(offset, offset + length);
1426
- node.usedBytes = length;
1427
- return length;
1428
- } else if (node.usedBytes === 0 && position === 0) { // 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.
1429
- node.contents = buffer.slice(offset, offset + length);
1430
- node.usedBytes = length;
1431
- return length;
1432
- } else if (position + length <= node.usedBytes) { // Writing to an already allocated and used subrange of the file?
1433
- node.contents.set(buffer.subarray(offset, offset + length), position);
1434
- return length;
1435
- }
1436
- }
1437
-
1438
- // Appending to an existing file and we need to reallocate, or source data did not come as a typed array.
1439
- MEMFS.expandFileStorage(node, position+length);
1440
- if (node.contents.subarray && buffer.subarray) {
1456
+ if (canOwn) {
1457
+ assert(position === 0, 'canOwn must imply no weird position inside the file');
1458
+ node.contents = buffer.subarray(offset, offset + length);
1459
+ node.usedBytes = length;
1460
+ } else if (node.usedBytes === 0 && position === 0) { // 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.
1461
+ node.contents = buffer.slice(offset, offset + length);
1462
+ node.usedBytes = length;
1463
+ } else {
1464
+ MEMFS.expandFileStorage(node, position+length);
1441
1465
  // Use typed array write which is available.
1442
1466
  node.contents.set(buffer.subarray(offset, offset + length), position);
1443
- } else {
1444
- for (var i = 0; i < length; i++) {
1445
- node.contents[position + i] = buffer[offset + i]; // Or fall back to manual write if not.
1446
- }
1467
+ node.usedBytes = Math.max(node.usedBytes, position + length);
1447
1468
  }
1448
- node.usedBytes = Math.max(node.usedBytes, position + length);
1449
1469
  return length;
1450
1470
  },
1451
1471
  llseek(stream, offset, whence) {
@@ -1470,7 +1490,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1470
1490
  var allocated;
1471
1491
  var contents = stream.node.contents;
1472
1492
  // Only make a new copy when MAP_PRIVATE is specified.
1473
- if (!(flags & 2) && contents && contents.buffer === HEAP8.buffer) {
1493
+ if (!(flags & 2) && contents.buffer === HEAP8.buffer) {
1474
1494
  // We can't emulate MAP_SHARED when the file is not backed by the
1475
1495
  // buffer we're mapping to (e.g. the HEAP buffer).
1476
1496
  allocated = false;
@@ -1504,6 +1524,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1504
1524
  };
1505
1525
 
1506
1526
  var FS_modeStringToFlags = (str) => {
1527
+ if (typeof str != 'string') return str;
1507
1528
  var flagModes = {
1508
1529
  'r': 0,
1509
1530
  'r+': 2,
@@ -1519,6 +1540,16 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1519
1540
  return flags;
1520
1541
  };
1521
1542
 
1543
+ var FS_fileDataToTypedArray = (data) => {
1544
+ if (typeof data == 'string') {
1545
+ data = intArrayFromString(data, true);
1546
+ }
1547
+ if (!data.subarray) {
1548
+ data = new Uint8Array(data);
1549
+ }
1550
+ return data;
1551
+ };
1552
+
1522
1553
  var FS_getMode = (canRead, canWrite) => {
1523
1554
  var mode = 0;
1524
1555
  if (canRead) mode |= 292 | 73;
@@ -1672,10 +1703,12 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1672
1703
  }
1673
1704
  };
1674
1705
 
1706
+ var dependenciesPromise = null;
1707
+ var resolveRunDependencies = async () => dependenciesPromise;
1675
1708
  var runDependencies = 0;
1676
1709
 
1677
1710
 
1678
- var dependenciesFulfilled = null;
1711
+ var dependenciesPromiseResolve = null;
1679
1712
 
1680
1713
  var runDependencyTracking = {
1681
1714
  };
@@ -1689,21 +1722,22 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1689
1722
  assert(id, 'removeRunDependency requires an ID');
1690
1723
  assert(runDependencyTracking[id]);
1691
1724
  delete runDependencyTracking[id];
1692
- if (runDependencies == 0) {
1725
+ if (!runDependencies) {
1693
1726
  if (runDependencyWatcher !== null) {
1694
1727
  clearInterval(runDependencyWatcher);
1695
1728
  runDependencyWatcher = null;
1696
1729
  }
1697
- if (dependenciesFulfilled) {
1698
- var callback = dependenciesFulfilled;
1699
- dependenciesFulfilled = null;
1700
- callback(); // can add another dependenciesFulfilled
1701
- }
1730
+ dependenciesPromiseResolve();
1702
1731
  }
1703
1732
  };
1704
1733
 
1705
1734
 
1735
+
1736
+
1706
1737
  var addRunDependency = (id) => {
1738
+ if (!runDependencies) {
1739
+ dependenciesPromise = new Promise((resolve) => dependenciesPromiseResolve = resolve);
1740
+ }
1707
1741
  runDependencies++;
1708
1742
 
1709
1743
  Module['monitorRunDependencies']?.(runDependencies);
@@ -1873,6 +1907,48 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1873
1907
  get isDevice() {
1874
1908
  return FS.isChrdev(this.mode);
1875
1909
  }
1910
+ // The per-inode readiness wait-queue. The node carries a Set of listener
1911
+ // entries {cb}; producers (SOCKFS, PIPEFS) call notifyListeners on a
1912
+ // readiness transition, and poll()/epoll consume it. It lives on the node
1913
+ // (not the fd) so dup'd fds share one queue. Only nodes that derive real
1914
+ // readiness (sockets, pipes, and an epoll's own node) ever use this -
1915
+ // always-ready types (regular files, ttys) never register or notify.
1916
+ addListener(cb, exclusive = false) {
1917
+ var entry = {cb, exclusive};
1918
+ var listeners = (this.listeners ??= new Set());
1919
+ listeners.add(entry);
1920
+ return {listeners, entry};
1921
+ }
1922
+ notifyListeners(flags) {
1923
+ // Iterates the set without copying, which is safe ONLY under a
1924
+ // load-bearing contract that every internal listener must honour:
1925
+ // 1. A listener must not run user code synchronously (a poll waiter only
1926
+ // resolves a Promise; an epoll registration only re-lists +
1927
+ // re-notifies; the epoll callback only schedules a tick). User code
1928
+ // runs on a later tick, never inside this loop.
1929
+ // 2. A listener may delete entries only from ITS OWN waiter, never from
1930
+ // a sibling node's set that may be mid-iteration. (Deleting an entry
1931
+ // of the set being iterated here is fine - a Set tolerates removal of
1932
+ // a not-yet-visited entry mid-iteration; mutating a *different* node's
1933
+ // set is fine because that set is not being iterated.)
1934
+ // Violating either gives silently skipped wakeups that are near-impossible
1935
+ // to reproduce. Any new producer/listener must preserve it.
1936
+ if (!this.listeners) return;
1937
+ // Fire every non-exclusive listener. Among EPOLLEXCLUSIVE registrations
1938
+ // (one fd watched by several epolls) wake only one, rotating round-robin
1939
+ // per node, to avoid a thundering herd. (Only epoll registrations are ever
1940
+ // exclusive; poll waiters and a node's own consumers are not.)
1941
+ var excl;
1942
+ for (var entry of this.listeners) {
1943
+ if (entry.exclusive) (excl ||= []).push(entry);
1944
+ else entry.cb(flags);
1945
+ }
1946
+ if (excl) {
1947
+ var i = (this.exclTurn || 0) % excl.length;
1948
+ this.exclTurn = i + 1;
1949
+ excl[i].cb(flags);
1950
+ }
1951
+ }
1876
1952
  },
1877
1953
  lookupPath(path, opts = {}) {
1878
1954
  if (!path) {
@@ -1884,7 +1960,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
1884
1960
  path = FS.cwd() + '/' + path;
1885
1961
  }
1886
1962
 
1887
- // limit max consecutive symlinks to 40 (SYMLOOP_MAX).
1963
+ // limit max consecutive symlinks to SYMLOOP_MAX.
1888
1964
  linkloop: for (var nlinks = 0; nlinks < 40; nlinks++) {
1889
1965
  // split the absolute path
1890
1966
  var parts = path.split('/').filter((p) => !!p);
@@ -2176,7 +2252,14 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2176
2252
  var arg = setattr ? stream : node;
2177
2253
  setattr ??= node.node_ops.setattr;
2178
2254
  FS.checkOpExists(setattr, 63)
2179
- setattr(arg, attr);
2255
+ try {
2256
+ setattr(arg, attr);
2257
+ } catch (e) {
2258
+ if (e instanceof RangeError) {
2259
+ throw new FS.ErrnoError(22);
2260
+ }
2261
+ throw e;
2262
+ }
2180
2263
  },
2181
2264
  chrdev_stream_ops:{
2182
2265
  open(stream) {
@@ -2443,6 +2526,25 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2443
2526
  }
2444
2527
  return parent.node_ops.symlink(parent, newname, oldpath);
2445
2528
  },
2529
+ link(oldpath, newpath, flags) {
2530
+ var lookup = FS.lookupPath(newpath, { parent: true });
2531
+ var parent = lookup.node;
2532
+ if (!parent) {
2533
+ throw new FS.ErrnoError(44);
2534
+ }
2535
+ var newname = PATH.basename(newpath);
2536
+ var errCode = FS.mayCreate(parent, newname);
2537
+ if (errCode) {
2538
+ throw new FS.ErrnoError(errCode);
2539
+ }
2540
+ // Hardlinks are only supported by filesystem backends that provide a
2541
+ // `link` node op (e.g. NODERAWFS backed by the host). NODEFS omits it:
2542
+ // a host hardlink cannot be confined to the mount root.
2543
+ if (!parent.node_ops.link) {
2544
+ throw new FS.ErrnoError(34);
2545
+ }
2546
+ return parent.node_ops.link(parent, newname, oldpath, flags);
2547
+ },
2446
2548
  rename(old_path, new_path) {
2447
2549
  var old_dirname = PATH.dirname(old_path);
2448
2550
  var new_dirname = PATH.dirname(new_path);
@@ -2689,20 +2791,19 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2689
2791
  }
2690
2792
  FS.doTruncate(stream, stream.node, len);
2691
2793
  },
2692
- utime(path, atime, mtime) {
2693
- var lookup = FS.lookupPath(path, { follow: true });
2694
- var node = lookup.node;
2695
- var setattr = FS.checkOpExists(node.node_ops.setattr, 63);
2696
- setattr(node, {
2794
+ utime(path, atime, mtime, dontFollow) {
2795
+ var lookup = FS.lookupPath(path, { follow: !dontFollow });
2796
+ FS.doSetAttr(null, lookup.node, {
2697
2797
  atime: atime,
2698
- mtime: mtime
2798
+ mtime: mtime,
2799
+ dontFollow
2699
2800
  });
2700
2801
  },
2701
2802
  open(path, flags, mode = 0o666) {
2702
2803
  if (path === "") {
2703
2804
  throw new FS.ErrnoError(44);
2704
2805
  }
2705
- flags = typeof flags == 'string' ? FS_modeStringToFlags(flags) : flags;
2806
+ flags = FS_modeStringToFlags(flags);
2706
2807
  if ((flags & 64)) {
2707
2808
  mode = (mode & 4095) | 32768;
2708
2809
  } else {
@@ -2796,6 +2897,11 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2796
2897
  throw new FS.ErrnoError(8);
2797
2898
  }
2798
2899
  if (stream.getdents) stream.getdents = null; // free readdir state
2900
+ // The fd is going away: wake anything waiting on it (poll/epoll) with
2901
+ // POLLNVAL so a blocking wait unblocks and an epoll registration is evicted
2902
+ // on its next derive. Only sockets/pipes/epoll ever carry a wait-queue, so
2903
+ // for every other stream (incl. nodeless noderawfs stdio) this is a no-op.
2904
+ stream.node?.notifyListeners(32);
2799
2905
  try {
2800
2906
  if (stream.stream_ops.close) {
2801
2907
  stream.stream_ops.close(stream);
@@ -2853,6 +2959,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2853
2959
  },
2854
2960
  write(stream, buffer, offset, length, position, canOwn) {
2855
2961
  assert(offset >= 0);
2962
+ assert(buffer.subarray, 'FS.write expects a TypedArray');
2856
2963
  if (length < 0 || position < 0) {
2857
2964
  throw new FS.ErrnoError(28);
2858
2965
  }
@@ -2919,8 +3026,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2919
3026
  return stream.stream_ops.ioctl(stream, cmd, arg);
2920
3027
  },
2921
3028
  readFile(path, opts = {}) {
2922
- opts.flags = opts.flags || 0;
2923
- opts.encoding = opts.encoding || 'binary';
3029
+ opts.flags = opts.flags ?? 0;
3030
+ opts.encoding = opts.encoding ?? 'binary';
2924
3031
  if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
2925
3032
  abort(`Invalid encoding type "${opts.encoding}"`);
2926
3033
  }
@@ -2936,16 +3043,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
2936
3043
  return buf;
2937
3044
  },
2938
3045
  writeFile(path, data, opts = {}) {
2939
- opts.flags = opts.flags || 577;
3046
+ opts.flags = opts.flags ?? 577;
2940
3047
  var stream = FS.open(path, opts.flags, opts.mode);
2941
- if (typeof data == 'string') {
2942
- data = new Uint8Array(intArrayFromString(data, true));
2943
- }
2944
- if (ArrayBuffer.isView(data)) {
2945
- FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
2946
- } else {
2947
- abort('Unsupported data type');
2948
- }
3048
+ data = FS_fileDataToTypedArray(data);
3049
+ FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn);
2949
3050
  FS.close(stream);
2950
3051
  },
2951
3052
  cwd:() => FS.currentPath,
@@ -3170,11 +3271,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3170
3271
  var mode = FS_getMode(canRead, canWrite);
3171
3272
  var node = FS.create(path, mode);
3172
3273
  if (data) {
3173
- if (typeof data == 'string') {
3174
- var arr = new Array(data.length);
3175
- for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
3176
- data = arr;
3177
- }
3274
+ data = FS_fileDataToTypedArray(data);
3178
3275
  // make sure we can write to the file
3179
3276
  FS.chmod(node, mode | 146);
3180
3277
  var stream = FS.open(node, 577);
@@ -3283,8 +3380,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3283
3380
 
3284
3381
  // Function to get a range from the remote URL.
3285
3382
  var doXHR = (from, to) => {
3286
- if (from > to) abort("invalid range (" + from + ", " + to + ") or no bytes requested!");
3287
- if (to > datalength-1) abort("only " + datalength + " bytes available! programmer error!");
3383
+ if (from > to) abort(`invalid range (${from}, ${to}) or no bytes requested!`);
3384
+ if (to > datalength-1) abort(`only ${datalength} bytes available! programmer error!`);
3288
3385
 
3289
3386
  // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
3290
3387
  var xhr = new XMLHttpRequest();
@@ -3302,7 +3399,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3302
3399
  if (xhr.response !== undefined) {
3303
3400
  return new Uint8Array(/** @type{Array<number>} */(xhr.response || []));
3304
3401
  }
3305
- return intArrayFromString(xhr.responseText || '', true);
3402
+ return intArrayFromString(xhr.responseText ?? '', true);
3306
3403
  };
3307
3404
  var lazyArray = this;
3308
3405
  lazyArray.setDataGetter((chunkNum) => {
@@ -3409,27 +3506,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3409
3506
  node.stream_ops = stream_ops;
3410
3507
  return node;
3411
3508
  },
3412
- absolutePath() {
3413
- abort('FS.absolutePath has been removed; use PATH_FS.resolve instead');
3414
- },
3415
- createFolder() {
3416
- abort('FS.createFolder has been removed; use FS.mkdir instead');
3417
- },
3418
- createLink() {
3419
- abort('FS.createLink has been removed; use FS.symlink instead');
3420
- },
3421
- joinPath() {
3422
- abort('FS.joinPath has been removed; use PATH.join instead');
3423
- },
3424
- mmapAlloc() {
3425
- abort('FS.mmapAlloc has been replaced by the top level function mmapAlloc');
3426
- },
3427
- standardizePath() {
3428
- abort('FS.standardizePath has been removed; use PATH.normalize instead');
3429
- },
3430
3509
  };
3431
3510
 
3432
3511
  var SYSCALLS = {
3512
+ currentUmask:18,
3433
3513
  calculateAt(dirfd, path, allowEmpty) {
3434
3514
  if (PATH.isAbs(path)) {
3435
3515
  return path;
@@ -3492,7 +3572,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3492
3572
  // MAP_PRIVATE calls need not to be synced back to underlying fs
3493
3573
  return 0;
3494
3574
  }
3495
- var buffer = HEAPU8.slice(addr, addr + len);
3575
+ var buffer = HEAPU8.subarray(addr, addr + len);
3496
3576
  FS.msync(stream, buffer, offset, len, flags);
3497
3577
  },
3498
3578
  getStreamFromFD(fd) {
@@ -3516,6 +3596,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3516
3596
  return -e.errno;
3517
3597
  }
3518
3598
  }
3599
+
3519
3600
 
3520
3601
  function ___syscall_chmod(path, mode) {
3521
3602
  try {
@@ -3528,6 +3609,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3528
3609
  return -e.errno;
3529
3610
  }
3530
3611
  }
3612
+
3531
3613
 
3532
3614
  function ___syscall_dup(fd) {
3533
3615
  try {
@@ -3539,23 +3621,29 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3539
3621
  return -e.errno;
3540
3622
  }
3541
3623
  }
3624
+
3542
3625
 
3543
3626
  function ___syscall_dup3(fd, newfd, flags) {
3544
3627
  try {
3545
3628
 
3629
+ if (fd === newfd) return -28;
3630
+ if (flags & ~524288) return -28;
3546
3631
  var old = SYSCALLS.getStreamFromFD(fd);
3547
- assert(!flags);
3548
- if (old.fd === newfd) return -28;
3549
3632
  // Check newfd is within range of valid open file descriptors.
3550
3633
  if (newfd < 0 || newfd >= FS.MAX_OPEN_FDS) return -8;
3551
3634
  var existing = FS.getStream(newfd);
3552
3635
  if (existing) FS.close(existing);
3553
- return FS.dupStream(old, newfd).fd;
3636
+ var stream = FS.dupStream(old, newfd);
3637
+ if (flags & 524288) {
3638
+ stream.flags |= 524288;
3639
+ }
3640
+ return stream.fd;
3554
3641
  } catch (e) {
3555
3642
  if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
3556
3643
  return -e.errno;
3557
3644
  }
3558
3645
  }
3646
+
3559
3647
 
3560
3648
  var syscallGetVarargI = () => {
3561
3649
  assert(SYSCALLS.varargs != undefined);
@@ -3592,7 +3680,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3592
3680
  return stream.flags;
3593
3681
  case 4: {
3594
3682
  var arg = syscallGetVarargI();
3595
- stream.flags |= arg;
3683
+ var mask = 289792;
3684
+ stream.flags = (stream.flags & ~mask) | (arg & mask);
3596
3685
  return 0;
3597
3686
  }
3598
3687
  case 12: {
@@ -3616,6 +3705,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3616
3705
  return -e.errno;
3617
3706
  }
3618
3707
  }
3708
+
3619
3709
 
3620
3710
  function ___syscall_fstat64(fd, buf) {
3621
3711
  try {
@@ -3626,6 +3716,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3626
3716
  return -e.errno;
3627
3717
  }
3628
3718
  }
3719
+
3629
3720
 
3630
3721
  var INT53_MAX = 9007199254740992;
3631
3722
 
@@ -3637,7 +3728,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3637
3728
 
3638
3729
  try {
3639
3730
 
3640
- if (isNaN(length)) return -61;
3731
+ if (isNaN(length)) return -22;
3641
3732
  FS.ftruncate(fd, length);
3642
3733
  return 0;
3643
3734
  } catch (e) {
@@ -3649,7 +3740,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3649
3740
 
3650
3741
 
3651
3742
  var stringToUTF8 = (str, outPtr, maxBytesToWrite) => {
3652
- assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!');
3743
+ assert(typeof maxBytesToWrite == 'number', 'stringToUTF8 requires a third parameter that specifies the length of the output buffer');
3653
3744
  return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
3654
3745
  };
3655
3746
  function ___syscall_getcwd(buf, size) {
@@ -3666,6 +3757,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3666
3757
  return -e.errno;
3667
3758
  }
3668
3759
  }
3760
+
3669
3761
 
3670
3762
 
3671
3763
  function ___syscall_getdents64(fd, dirp, count) {
@@ -3726,6 +3818,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3726
3818
  return -e.errno;
3727
3819
  }
3728
3820
  }
3821
+
3729
3822
 
3730
3823
 
3731
3824
  function ___syscall_ioctl(fd, op, varargs) {
@@ -3823,6 +3916,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3823
3916
  return -e.errno;
3824
3917
  }
3825
3918
  }
3919
+
3826
3920
 
3827
3921
  function ___syscall_lstat64(path, buf) {
3828
3922
  try {
@@ -3834,12 +3928,14 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3834
3928
  return -e.errno;
3835
3929
  }
3836
3930
  }
3931
+
3837
3932
 
3838
3933
  function ___syscall_mkdirat(dirfd, path, mode) {
3839
3934
  try {
3840
3935
 
3841
3936
  path = SYSCALLS.getStr(path);
3842
3937
  path = SYSCALLS.calculateAt(dirfd, path);
3938
+ mode &= ~SYSCALLS.currentUmask;
3843
3939
  FS.mkdir(path, mode, 0);
3844
3940
  return 0;
3845
3941
  } catch (e) {
@@ -3847,6 +3943,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3847
3943
  return -e.errno;
3848
3944
  }
3849
3945
  }
3946
+
3850
3947
 
3851
3948
  function ___syscall_newfstatat(dirfd, path, buf, flags) {
3852
3949
  try {
@@ -3863,6 +3960,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3863
3960
  return -e.errno;
3864
3961
  }
3865
3962
  }
3963
+
3866
3964
 
3867
3965
 
3868
3966
  function ___syscall_openat(dirfd, path, flags, varargs) {
@@ -3872,12 +3970,16 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3872
3970
  path = SYSCALLS.getStr(path);
3873
3971
  path = SYSCALLS.calculateAt(dirfd, path);
3874
3972
  var mode = varargs ? syscallGetVarargI() : 0;
3973
+ if (flags & 64) {
3974
+ mode &= ~SYSCALLS.currentUmask;
3975
+ }
3875
3976
  return FS.open(path, flags, mode).fd;
3876
3977
  } catch (e) {
3877
3978
  if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
3878
3979
  return -e.errno;
3879
3980
  }
3880
3981
  }
3982
+
3881
3983
 
3882
3984
  var PIPEFS = {
3883
3985
  BUCKET_BUFFER_SIZE:8192,
@@ -3889,9 +3991,15 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3889
3991
  createPipe() {
3890
3992
  var pipe = {
3891
3993
  buckets: [],
3892
- // refcnt 2 because pipe has a read end and a write end. We need to be
3893
- // able to read from the read end after write end is closed.
3894
- refcnt : 2,
3994
+ // Open write ends. When it drops to 0 the reader sees EOF and poll must
3995
+ // report POLLHUP (Linux semantics). Buckets are freed once both counts
3996
+ // reach 0.
3997
+ writerCount: 1,
3998
+ writeClosed: false,
3999
+ // Open read ends. When it drops to 0 the writer sees POLLERR (a further
4000
+ // write would get EPIPE).
4001
+ readerCount: 1,
4002
+ readClosed: false,
3895
4003
  timestamp: new Date(),
3896
4004
  };
3897
4005
 
@@ -3908,6 +4016,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3908
4016
 
3909
4017
  rNode.pipe = pipe;
3910
4018
  wNode.pipe = pipe;
4019
+ // The read end's node carries the reader poll wait-queue (writes wake it);
4020
+ // the write end's node carries the writer wait-queue (read-end close wakes it).
4021
+ pipe.readNode = rNode;
4022
+ pipe.writeNode = wNode;
3911
4023
 
3912
4024
  var readableStream = FS.createStream({
3913
4025
  path: rName,
@@ -3952,24 +4064,50 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
3952
4064
  blocks: 0,
3953
4065
  };
3954
4066
  },
3955
- poll(stream, timeout, notifyCallback) {
4067
+ poll(stream) {
3956
4068
  var pipe = stream.node.pipe;
3957
4069
 
3958
4070
  if ((stream.flags & 2097155) === 1) {
3959
- return (256 | 4);
4071
+ // Linux keeps the write end writable (the write itself fails with
4072
+ // EPIPE) while also signalling POLLERR once every read end is closed.
4073
+ var mask = 256 | 4;
4074
+ if (pipe.readClosed) {
4075
+ mask |= 8;
4076
+ }
4077
+ return mask;
3960
4078
  }
4079
+ var mask = 0;
3961
4080
  for (var bucket of pipe.buckets) {
3962
4081
  if (bucket.offset - bucket.roffset > 0) {
3963
- return (64 | 1);
4082
+ mask = 64 | 1;
4083
+ break;
3964
4084
  }
3965
4085
  }
3966
-
3967
- return 0;
4086
+ // With every write end closed the read end is at EOF: readable (read
4087
+ // returns 0) and hung up.
4088
+ if (pipe.writeClosed) {
4089
+ mask |= 16 | 1;
4090
+ }
4091
+ return mask;
3968
4092
  },
3969
4093
  dup(stream) {
3970
- stream.node.pipe.refcnt++;
4094
+ var pipe = stream.node.pipe;
4095
+ if ((stream.flags & 2097155) === 1) {
4096
+ pipe.writerCount++;
4097
+ } else {
4098
+ pipe.readerCount++;
4099
+ }
3971
4100
  },
3972
- ioctl(stream, request, varargs) {
4101
+ ioctl(stream, request, argp) {
4102
+ if (request == 21531) {
4103
+ var pipe = stream.node.pipe;
4104
+ var currentLength = 0;
4105
+ for (var bucket of pipe.buckets) {
4106
+ currentLength += bucket.offset - bucket.roffset;
4107
+ }
4108
+ HEAP32[((argp)>>2)] = currentLength;
4109
+ return 0;
4110
+ }
3973
4111
  return 28;
3974
4112
  },
3975
4113
  fsync(stream) {
@@ -4062,6 +4200,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4062
4200
  if (freeBytesInCurrBuffer >= dataLen) {
4063
4201
  currBucket.buffer.set(data, currBucket.offset);
4064
4202
  currBucket.offset += dataLen;
4203
+ pipe.readNode.notifyListeners(64 | 1);
4065
4204
  return dataLen;
4066
4205
  } else if (freeBytesInCurrBuffer > 0) {
4067
4206
  currBucket.buffer.set(data.subarray(0, freeBytesInCurrBuffer), currBucket.offset);
@@ -4093,12 +4232,25 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4093
4232
  newBucket.buffer.set(data);
4094
4233
  }
4095
4234
 
4235
+ pipe.readNode.notifyListeners(64 | 1);
4096
4236
  return dataLen;
4097
4237
  },
4098
4238
  close(stream) {
4099
4239
  var pipe = stream.node.pipe;
4100
- pipe.refcnt--;
4101
- if (pipe.refcnt === 0) {
4240
+ // When the last write end closes, wake any poll/epoll waiter on the read
4241
+ // end with POLLHUP so a reader blocked on the writer dropping unblocks.
4242
+ if ((stream.flags & 2097155) === 1) {
4243
+ if (--pipe.writerCount === 0) {
4244
+ pipe.writeClosed = true;
4245
+ pipe.readNode.notifyListeners(16 | 64 | 1);
4246
+ }
4247
+ } else if (--pipe.readerCount === 0) {
4248
+ // Mirror: when the last read end closes, wake any poll/epoll waiter on
4249
+ // the write end with POLLERR (a further write would get EPIPE).
4250
+ pipe.readClosed = true;
4251
+ pipe.writeNode.notifyListeners(8 | 256 | 4);
4252
+ }
4253
+ if (pipe.readerCount === 0 && pipe.writerCount === 0) {
4102
4254
  pipe.buckets = null;
4103
4255
  }
4104
4256
  },
@@ -4110,15 +4262,24 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4110
4262
  return 'pipe[' + (PIPEFS.nextname.current++) + ']';
4111
4263
  },
4112
4264
  };
4113
- function ___syscall_pipe(fdPtr) {
4265
+ function ___syscall_pipe2(fdPtr, flags) {
4114
4266
  try {
4115
4267
 
4116
4268
  if (fdPtr == 0) {
4117
4269
  throw new FS.ErrnoError(21);
4118
4270
  }
4271
+ var validFlags = 524288 | 2048;
4272
+ if (flags & ~validFlags) {
4273
+ throw new FS.ErrnoError(138);
4274
+ }
4119
4275
 
4120
4276
  var res = PIPEFS.createPipe();
4121
4277
 
4278
+ if (flags & 2048) {
4279
+ FS.getStream(res.readable_fd).flags |= 2048;
4280
+ FS.getStream(res.writable_fd).flags |= 2048;
4281
+ }
4282
+
4122
4283
  HEAP32[((fdPtr)>>2)] = res.readable_fd;
4123
4284
  HEAP32[(((fdPtr)+(4))>>2)] = res.writable_fd;
4124
4285
 
@@ -4128,30 +4289,33 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4128
4289
  return -e.errno;
4129
4290
  }
4130
4291
  }
4131
-
4132
- function ___syscall_poll(fds, nfds, timeout) {
4133
- try {
4134
-
4135
4292
 
4293
+
4294
+ var pollOne = (fd, events) => {
4295
+ var stream = FS.getStream(fd);
4296
+ if (!stream) return 32;
4297
+ // Streams without a poll handler (regular files, incl. NODERAWFS/NODEFS
4298
+ // which leave stream_ops unset) are treated as always readable+writable.
4299
+ var flags = stream.stream_ops?.poll
4300
+ ? stream.stream_ops.poll(stream)
4301
+ : 5;
4302
+ return flags & (events | 8 | 16 | 32);
4303
+ };
4304
+ var doPollSync = (fds, nfds) => {
4136
4305
  var count = 0;
4137
- for (var i = 0; i < nfds; i++) {
4138
- var pollfd = fds + 8 * i;
4139
- var fd = HEAP32[((pollfd)>>2)];
4140
- var events = HEAP16[(((pollfd)+(4))>>1)];
4141
- var flags = 32;
4142
- var stream = FS.getStream(fd);
4143
- if (stream) {
4144
- if (stream.stream_ops.poll) {
4145
- flags = stream.stream_ops.poll(stream, -1);
4146
- } else {
4147
- flags = 5;
4148
- }
4149
- }
4150
- flags &= events | 8 | 16;
4151
- if (flags) count++;
4152
- HEAP16[(((pollfd)+(6))>>1)] = flags;
4306
+ for (var i = 0, pollfd = fds; i < nfds; i++, pollfd += 8) {
4307
+ var revents = pollOne(
4308
+ HEAP32[((pollfd)>>2)],
4309
+ HEAP16[(((pollfd)+(4))>>1)]);
4310
+ if (revents) count++;
4311
+ HEAP16[(((pollfd)+(6))>>1)] = revents;
4153
4312
  }
4313
+ return count;
4314
+ };
4315
+ function ___syscall_poll(fds, nfds, timeout) {
4316
+ try {
4154
4317
 
4318
+ var count = doPollSync(fds, nfds);
4155
4319
  if (!count && timeout != 0) warnOnce('non-zero poll() timeout not supported: ' + timeout)
4156
4320
  return count;
4157
4321
  } catch (e) {
@@ -4159,6 +4323,18 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4159
4323
  return -e.errno;
4160
4324
  }
4161
4325
  }
4326
+
4327
+
4328
+ function ___syscall_poll_nonblocking(fds, nfds) {
4329
+ try {
4330
+
4331
+ return doPollSync(fds, nfds);
4332
+ } catch (e) {
4333
+ if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
4334
+ return -e.errno;
4335
+ }
4336
+ }
4337
+
4162
4338
 
4163
4339
 
4164
4340
 
@@ -4182,6 +4358,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4182
4358
  return -e.errno;
4183
4359
  }
4184
4360
  }
4361
+
4185
4362
 
4186
4363
  function ___syscall_renameat(olddirfd, oldpath, newdirfd, newpath) {
4187
4364
  try {
@@ -4197,6 +4374,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4197
4374
  return -e.errno;
4198
4375
  }
4199
4376
  }
4377
+
4200
4378
 
4201
4379
  function ___syscall_rmdir(path) {
4202
4380
  try {
@@ -4209,6 +4387,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4209
4387
  return -e.errno;
4210
4388
  }
4211
4389
  }
4390
+
4212
4391
 
4213
4392
  function ___syscall_stat64(path, buf) {
4214
4393
  try {
@@ -4220,6 +4399,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4220
4399
  return -e.errno;
4221
4400
  }
4222
4401
  }
4402
+
4223
4403
 
4224
4404
  function ___syscall_symlinkat(target, dirfd, linkpath) {
4225
4405
  try {
@@ -4234,6 +4414,20 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4234
4414
  return -e.errno;
4235
4415
  }
4236
4416
  }
4417
+
4418
+
4419
+ function ___syscall_umask(mask) {
4420
+ try {
4421
+
4422
+ var old = SYSCALLS.currentUmask;
4423
+ SYSCALLS.currentUmask = mask;
4424
+ return old;
4425
+ } catch (e) {
4426
+ if (typeof FS == 'undefined' || !(e.name === 'ErrnoError')) throw e;
4427
+ return -e.errno;
4428
+ }
4429
+ }
4430
+
4237
4431
 
4238
4432
  function ___syscall_unlinkat(dirfd, path, flags) {
4239
4433
  try {
@@ -4253,6 +4447,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4253
4447
  return -e.errno;
4254
4448
  }
4255
4449
  }
4450
+
4256
4451
 
4257
4452
  var __abort_js = () =>
4258
4453
  abort('native code called abort()');
@@ -4264,7 +4459,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4264
4459
  };
4265
4460
 
4266
4461
  var __emscripten_throw_longjmp = () => {
4267
- throw Infinity;
4462
+ throw new EmscriptenSjLj;
4268
4463
  };
4269
4464
 
4270
4465
  var isLeapYear = (year) => year%4 === 0 && (year%100 !== 0 || year%400 === 0);
@@ -4285,6 +4480,9 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4285
4480
 
4286
4481
 
4287
4482
  var date = new Date(time*1000);
4483
+ if (isNaN(date.getTime())) {
4484
+ return 1;
4485
+ }
4288
4486
  HEAP32[((tmPtr)>>2)] = date.getSeconds();
4289
4487
  HEAP32[(((tmPtr)+(4))>>2)] = date.getMinutes();
4290
4488
  HEAP32[(((tmPtr)+(8))>>2)] = date.getHours();
@@ -4303,6 +4501,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4303
4501
  var winterOffset = start.getTimezoneOffset();
4304
4502
  var dst = (summerOffset != winterOffset && date.getTimezoneOffset() == Math.min(winterOffset, summerOffset))|0;
4305
4503
  HEAP32[(((tmPtr)+(32))>>2)] = dst;
4504
+ return 0;
4306
4505
  ;
4307
4506
  }
4308
4507
 
@@ -4317,6 +4516,9 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4317
4516
  HEAP32[(((tmPtr)+(4))>>2)],
4318
4517
  HEAP32[((tmPtr)>>2)],
4319
4518
  0);
4519
+ if (isNaN(date.getTime())) {
4520
+ return -1;
4521
+ }
4320
4522
 
4321
4523
  // There's an ambiguous hour when the time goes back; the tm_isdst field is
4322
4524
  // used to disambiguate it. Date() basically guesses, so we fix it up if it
@@ -4329,14 +4531,18 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4329
4531
  var dstOffset = Math.min(winterOffset, summerOffset); // DST is in December in South
4330
4532
  if (dst < 0) {
4331
4533
  // Attention: some regions don't have DST at all.
4332
- HEAP32[(((tmPtr)+(32))>>2)] = Number(summerOffset != winterOffset && dstOffset == guessedOffset);
4534
+ dst = Number(summerOffset != winterOffset && dstOffset == guessedOffset);
4333
4535
  } else if ((dst > 0) != (dstOffset == guessedOffset)) {
4334
4536
  var nonDstOffset = Math.max(winterOffset, summerOffset);
4335
4537
  var trueOffset = dst > 0 ? dstOffset : nonDstOffset;
4336
4538
  // Don't try setMinutes(date.getMinutes() + ...) -- it's messed up.
4337
4539
  date.setTime(date.getTime() + (trueOffset - guessedOffset)*60000);
4540
+ if (isNaN(date.getTime())) {
4541
+ return -1;
4542
+ }
4338
4543
  }
4339
4544
 
4545
+ HEAP32[(((tmPtr)+(32))>>2)] = dst;
4340
4546
  HEAP32[(((tmPtr)+(24))>>2)] = date.getDay();
4341
4547
  var yday = ydayFromDate(date)|0;
4342
4548
  HEAP32[(((tmPtr)+(28))>>2)] = yday;
@@ -4348,12 +4554,8 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4348
4554
  HEAP32[(((tmPtr)+(16))>>2)] = date.getMonth();
4349
4555
  HEAP32[(((tmPtr)+(20))>>2)] = date.getYear();
4350
4556
 
4351
- var timeMs = date.getTime();
4352
- if (isNaN(timeMs)) {
4353
- return -1;
4354
- }
4355
- // Return time in microseconds
4356
- return timeMs / 1000;
4557
+ // Return time in seconds
4558
+ return date.getTime() / 1000;
4357
4559
  })();
4358
4560
  return BigInt(ret);
4359
4561
  };
@@ -4585,11 +4787,10 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4585
4787
  var ENV = {
4586
4788
  };
4587
4789
 
4588
- var getExecutableName = () => thisProgram || './this.program';
4790
+ var getExecutableName = () => thisProgram;
4589
4791
  var getEnvStrings = () => {
4590
4792
  if (!getEnvStrings.strings) {
4591
4793
  // Default values.
4592
- // Browser language detection #8751
4593
4794
  var lang = (globalThis.navigator?.language ?? 'C').replace('-', '_') + '.UTF-8';
4594
4795
  var env = {
4595
4796
  'USER': 'web_user',
@@ -4662,7 +4863,6 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4662
4863
  // if exit() was called explicitly, warn the user if the runtime isn't actually being shut down
4663
4864
  if (keepRuntimeAlive() && !implicit) {
4664
4865
  var msg = `program exited (with status: ${status}), but keepRuntimeAlive() is set (counter=${runtimeKeepaliveCounter}) due to an async operation, so halting execution but not exiting the runtime or preventing further async execution (you can use emscripten_force_exit, if you want to force a true shutdown)`;
4665
- readyPromiseReject?.(msg);
4666
4866
  err(msg);
4667
4867
  }
4668
4868
 
@@ -4681,6 +4881,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4681
4881
  return e.errno;
4682
4882
  }
4683
4883
  }
4884
+
4684
4885
 
4685
4886
  function _fd_fdstat_get(fd, pbuf) {
4686
4887
  try {
@@ -4707,6 +4908,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4707
4908
  return e.errno;
4708
4909
  }
4709
4910
  }
4911
+
4710
4912
 
4711
4913
  /** @param {number=} offset */
4712
4914
  var doReadv = (stream, iov, iovcnt, offset) => {
@@ -4715,7 +4917,18 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4715
4917
  var ptr = HEAPU32[((iov)>>2)];
4716
4918
  var len = HEAPU32[(((iov)+(4))>>2)];
4717
4919
  iov += 8;
4718
- var curr = FS.read(stream, HEAP8, ptr, len, offset);
4920
+ try {
4921
+ var curr = FS.read(stream, HEAP8, ptr, len, offset);
4922
+ } catch (e) {
4923
+ // On a non-blocking stream a subsequent read may would-block after we
4924
+ // already gathered data. POSIX readv is a single gather-read: return
4925
+ // what we have rather than failing the whole call.
4926
+ if (ret > 0 && e instanceof FS.ErrnoError &&
4927
+ (e.errno == 6 || e.errno == 6)) {
4928
+ break;
4929
+ }
4930
+ throw e;
4931
+ }
4719
4932
  if (curr < 0) return -1;
4720
4933
  ret += curr;
4721
4934
  if (curr < len) break; // nothing more to read
@@ -4733,7 +4946,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4733
4946
 
4734
4947
  try {
4735
4948
 
4736
- if (isNaN(offset)) return 61;
4949
+ if (isNaN(offset)) return 22;
4737
4950
  var stream = SYSCALLS.getStreamFromFD(fd)
4738
4951
  var num = doReadv(stream, iov, iovcnt, offset);
4739
4952
  HEAPU32[((pnum)>>2)] = num;
@@ -4747,23 +4960,27 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4747
4960
 
4748
4961
  /** @param {number=} offset */
4749
4962
  var doWritev = (stream, iov, iovcnt, offset) => {
4750
- var ret = 0;
4751
- for (var i = 0; i < iovcnt; i++) {
4963
+ // Gather all iovecs into one contiguous buffer and issue a single
4964
+ // FS.write, matching POSIX writev's single gather-write semantics (as
4965
+ // __syscall_sendmsg already does). Per-iovec writes fragment a stream
4966
+ // socket send into multiple segments, breaking stream byte semantics.
4967
+ if (iovcnt == 1) {
4968
+ // Single iovec: write directly from HEAP8, no gather buffer needed.
4969
+ return FS.write(stream, HEAP8, HEAPU32[((iov)>>2)], HEAPU32[(((iov)+(4))>>2)], offset);
4970
+ }
4971
+ var total = 0;
4972
+ for (var i = 0, p = iov; i < iovcnt; i++, p += 8) {
4973
+ total += HEAPU32[(((p)+(4))>>2)];
4974
+ }
4975
+ var view = new Uint8Array(total);
4976
+ var voff = 0;
4977
+ for (var i = 0; i < iovcnt; i++, iov += 8) {
4752
4978
  var ptr = HEAPU32[((iov)>>2)];
4753
4979
  var len = HEAPU32[(((iov)+(4))>>2)];
4754
- iov += 8;
4755
- var curr = FS.write(stream, HEAP8, ptr, len, offset);
4756
- if (curr < 0) return -1;
4757
- ret += curr;
4758
- if (curr < len) {
4759
- // No more space to write.
4760
- break;
4761
- }
4762
- if (typeof offset != 'undefined') {
4763
- offset += curr;
4764
- }
4980
+ view.set(HEAPU8.subarray(ptr, ptr + len), voff);
4981
+ voff += len;
4765
4982
  }
4766
- return ret;
4983
+ return FS.write(stream, view, 0, total, offset);
4767
4984
  };
4768
4985
 
4769
4986
 
@@ -4773,7 +4990,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4773
4990
 
4774
4991
  try {
4775
4992
 
4776
- if (isNaN(offset)) return 61;
4993
+ if (isNaN(offset)) return 22;
4777
4994
  var stream = SYSCALLS.getStreamFromFD(fd)
4778
4995
  var num = doWritev(stream, iov, iovcnt, offset);
4779
4996
  HEAPU32[((pnum)>>2)] = num;
@@ -4798,6 +5015,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4798
5015
  return e.errno;
4799
5016
  }
4800
5017
  }
5018
+
4801
5019
 
4802
5020
 
4803
5021
  function _fd_seek(fd, offset, whence, newOffset) {
@@ -4806,7 +5024,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4806
5024
 
4807
5025
  try {
4808
5026
 
4809
- if (isNaN(offset)) return 61;
5027
+ if (isNaN(offset)) return 22;
4810
5028
  var stream = SYSCALLS.getStreamFromFD(fd);
4811
5029
  FS.llseek(stream, offset, whence);
4812
5030
  HEAP64[((newOffset)>>3)] = BigInt(stream.position);
@@ -4830,6 +5048,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4830
5048
  return e.errno;
4831
5049
  }
4832
5050
  }
5051
+
4833
5052
 
4834
5053
 
4835
5054
  function _fd_write(fd, iov, iovcnt, pnum) {
@@ -4844,12 +5063,13 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4844
5063
  return e.errno;
4845
5064
  }
4846
5065
  }
5066
+
4847
5067
 
4848
5068
 
4849
5069
 
4850
5070
  var getCFunc = (ident) => {
4851
5071
  var func = Module['_' + ident]; // closure exported function
4852
- assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported');
5072
+ assert(func, `Cannot call unknown function ${ident}, make sure it is exported`);
4853
5073
  return func;
4854
5074
  };
4855
5075
 
@@ -4906,7 +5126,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4906
5126
  var func = getCFunc(ident);
4907
5127
  var cArgs = [];
4908
5128
  var stack = 0;
4909
- assert(returnType !== 'array', 'Return type should not be "array".');
5129
+ assert(returnType !== 'array', 'return type should not be "array"');
4910
5130
  if (args) {
4911
5131
  for (var i = 0; i < args.length; i++) {
4912
5132
  var converter = toC[argTypes[i]];
@@ -4943,6 +5163,7 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4943
5163
 
4944
5164
 
4945
5165
 
5166
+
4946
5167
  FS.createPreloadedFile = FS_createPreloadedFile;
4947
5168
  FS.preloadFile = FS_preloadFile;
4948
5169
  FS.staticInit();;
@@ -4956,15 +5177,14 @@ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
4956
5177
 
4957
5178
  // Begin ATMODULES hooks
4958
5179
  if (Module['noExitRuntime']) noExitRuntime = Module['noExitRuntime'];
4959
- if (Module['preloadPlugins']) preloadPlugins = Module['preloadPlugins'];
5180
+
4960
5181
  if (Module['print']) out = Module['print'];
4961
5182
  if (Module['printErr']) err = Module['printErr'];
4962
- if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
4963
5183
  // End ATMODULES hooks
4964
5184
 
4965
5185
  checkIncomingModuleAPI();
4966
5186
 
4967
- if (Module['arguments']) arguments_ = Module['arguments'];
5187
+ if (Module['arguments']) programArgs = Module['arguments'];
4968
5188
  if (Module['thisProgram']) thisProgram = Module['thisProgram'];
4969
5189
 
4970
5190
  // Assertions on removed incoming Module JS APIs.
@@ -4983,10 +5203,13 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
4983
5203
  assert(typeof Module['wasmMemory'] == 'undefined', 'Use of `wasmMemory` detected. Use -sIMPORTED_MEMORY to define wasmMemory externally');
4984
5204
  assert(typeof Module['INITIAL_MEMORY'] == 'undefined', 'Detected runtime INITIAL_MEMORY setting. Use -sIMPORTED_MEMORY to define wasmMemory dynamically');
4985
5205
 
4986
- if (Module['preInit']) {
4987
- if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
4988
- while (Module['preInit'].length > 0) {
4989
- Module['preInit'].shift()();
5206
+ var preInit = Module['preInit'];
5207
+ if (preInit) {
5208
+ if (typeof preInit == 'function') Module['preInit'] = preInit = [preInit];
5209
+ // Written as a loop so that preInit functions that themselves add more
5210
+ // preInit functions. Is this actually needed?
5211
+ while (preInit.length > 0) {
5212
+ preInit.shift()();
4990
5213
  }
4991
5214
  }
4992
5215
  consumedModuleProp('preInit');
@@ -5074,12 +5297,14 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
5074
5297
  'registerOrientationChangeEventCallback',
5075
5298
  'fillFullscreenChangeEventData',
5076
5299
  'registerFullscreenChangeEventCallback',
5300
+ 'callCanvasResizedCallback',
5077
5301
  'JSEvents_requestFullscreen',
5078
5302
  'JSEvents_resizeCanvasForFullscreen',
5079
5303
  'registerRestoreOldStyle',
5080
5304
  'hideEverythingExceptGivenElement',
5081
5305
  'restoreHiddenElements',
5082
5306
  'setLetterbox',
5307
+ 'currentFullscreenStrategy',
5083
5308
  'softFullscreenResizeWebGLRenderTarget',
5084
5309
  'doRequestFullscreen',
5085
5310
  'fillPointerlockChangeEventData',
@@ -5109,10 +5334,13 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
5109
5334
  'registerPreMainLoop',
5110
5335
  'getPromise',
5111
5336
  'makePromise',
5337
+ 'addPromise',
5112
5338
  'idsToPromises',
5113
5339
  'makePromiseCallback',
5114
5340
  'ExceptionInfo',
5115
5341
  'findMatchingCatch',
5342
+ 'incrementUncaughtExceptionCount',
5343
+ 'decrementUncaughtExceptionCount',
5116
5344
  'Browser_asyncPrepareDataCounter',
5117
5345
  'arraySum',
5118
5346
  'addDays',
@@ -5134,6 +5362,7 @@ if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];
5134
5362
  'colorChannelsInGlTextureFormat',
5135
5363
  'emscriptenWebGLGetTexPixelData',
5136
5364
  'emscriptenWebGLGetUniform',
5365
+ 'webglGetProgramUniformLocation',
5137
5366
  'webglGetUniformLocation',
5138
5367
  'webglPrepareUniformLocationsBeforeFirstUse',
5139
5368
  'webglGetLeftBracePos',
@@ -5162,20 +5391,20 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
5162
5391
  'callMain',
5163
5392
  'abort',
5164
5393
  'wasmExports',
5165
- 'HEAPF32',
5166
- 'HEAPF64',
5394
+ 'writeStackCookie',
5395
+ 'checkStackCookie',
5396
+ 'INT53_MAX',
5397
+ 'INT53_MIN',
5398
+ 'bigintToI53Checked',
5167
5399
  'HEAP8',
5168
5400
  'HEAP16',
5169
5401
  'HEAPU16',
5170
5402
  'HEAP32',
5171
5403
  'HEAPU32',
5404
+ 'HEAPF32',
5405
+ 'HEAPF64',
5172
5406
  'HEAP64',
5173
5407
  'HEAPU64',
5174
- 'writeStackCookie',
5175
- 'checkStackCookie',
5176
- 'INT53_MAX',
5177
- 'INT53_MIN',
5178
- 'bigintToI53Checked',
5179
5408
  'stackSave',
5180
5409
  'stackRestore',
5181
5410
  'stackAlloc',
@@ -5224,7 +5453,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
5224
5453
  'JSEvents',
5225
5454
  'specialHTMLTargets',
5226
5455
  'findCanvasEventTarget',
5227
- 'currentFullscreenStrategy',
5228
5456
  'restoreOldWindowedStyle',
5229
5457
  'UNWIND_CACHE',
5230
5458
  'ExitStatus',
@@ -5239,7 +5467,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
5239
5467
  'emClearImmediate',
5240
5468
  'promiseMap',
5241
5469
  'uncaughtExceptionCount',
5242
- 'exceptionLast',
5243
5470
  'exceptionCaught',
5244
5471
  'Browser',
5245
5472
  'requestFullscreen',
@@ -5261,6 +5488,7 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
5261
5488
  'FS_preloadFile',
5262
5489
  'FS_modeStringToFlags',
5263
5490
  'FS_getMode',
5491
+ 'FS_fileDataToTypedArray',
5264
5492
  'FS_stdin_getChar_buffer',
5265
5493
  'FS_stdin_getChar',
5266
5494
  'FS_unlink',
@@ -5328,6 +5556,7 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
5328
5556
  'FS_mkdir',
5329
5557
  'FS_mkdev',
5330
5558
  'FS_symlink',
5559
+ 'FS_link',
5331
5560
  'FS_rename',
5332
5561
  'FS_rmdir',
5333
5562
  'FS_readdir',
@@ -5372,12 +5601,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol)
5372
5601
  'FS_createDataFile',
5373
5602
  'FS_forceLoadFile',
5374
5603
  'FS_createLazyFile',
5375
- 'FS_absolutePath',
5376
- 'FS_createFolder',
5377
- 'FS_createLink',
5378
- 'FS_joinPath',
5379
- 'FS_mmapAlloc',
5380
- 'FS_standardizePath',
5381
5604
  'MEMFS',
5382
5605
  'TTY',
5383
5606
  'PIPEFS',
@@ -5409,16 +5632,40 @@ function checkIncomingModuleAPI() {
5409
5632
  ignoredModuleProp('fetchSettings');
5410
5633
  ignoredModuleProp('logReadFiles');
5411
5634
  ignoredModuleProp('loadSplitModule');
5635
+ ignoredModuleProp('onMalloc');
5636
+ ignoredModuleProp('onRealloc');
5637
+ ignoredModuleProp('onFree');
5638
+ ignoredModuleProp('onSbrkGrow');
5639
+ ignoredModuleProp('onCOSCacheHit');
5640
+ ignoredModuleProp('onCOSCacheMiss');
5641
+ ignoredModuleProp('onCOSStore');
5642
+ ignoredModuleProp('GL_MAX_TEXTURE_IMAGE_UNITS');
5643
+ ignoredModuleProp('SDL_canPlayWithWebAudio');
5644
+ ignoredModuleProp('SDL_numSimultaneouslyQueuedBuffers');
5645
+ ignoredModuleProp('freePreloadedMediaOnUse');
5646
+ ignoredModuleProp('preinitializedWebGLContext');
5647
+ ignoredModuleProp('keyboardListeningElement');
5648
+ ignoredModuleProp('doNotCaptureKeyboard');
5649
+ ignoredModuleProp('extraStackTrace');
5650
+ ignoredModuleProp('preloadPlugins');
5651
+ ignoredModuleProp('preMainLoop');
5652
+ ignoredModuleProp('postMainLoop');
5653
+ ignoredModuleProp('forcedAspectRatio');
5654
+ ignoredModuleProp('mainScriptUrlOrBlob');
5655
+ ignoredModuleProp('onFullScreen');
5656
+ ignoredModuleProp('INITIAL_MEMORY');
5657
+ ignoredModuleProp('wasmMemory');
5658
+ ignoredModuleProp('wasmBinary');
5412
5659
  }
5413
5660
  var ASM_CONSTS = {
5414
- 2652134: ($0) => { globalThis.picorubyRefs[$0] = null; },
5415
- 2652174: ($0) => { globalThis.picorubyRefs[$0] = true; },
5416
- 2652214: ($0) => { globalThis.picorubyRefs[$0] = false; },
5417
- 2652255: ($0, $1) => { globalThis.picorubyRefs[$0] = $1; },
5418
- 2652293: ($0, $1) => { globalThis.picorubyRefs[$0] = $1; },
5419
- 2652331: ($0, $1, $2) => { const str = UTF8ToString($1, $2); globalThis.picorubyRefs[$0] = str; },
5420
- 2652404: ($0, $1) => { const arr = globalThis.picorubyRefs[$0]; const elem = globalThis.picorubyRefs[$1]; arr.push(elem); delete globalThis.picorubyRefs[$1]; },
5421
- 2652543: ($0, $1, $2) => { const obj = globalThis.picorubyRefs[$0]; const key = UTF8ToString($1); const val = globalThis.picorubyRefs[$2]; obj[key] = val; delete globalThis.picorubyRefs[$2]; }
5661
+ 2651478: ($0) => { globalThis.picorubyRefs[$0] = null; },
5662
+ 2651518: ($0) => { globalThis.picorubyRefs[$0] = true; },
5663
+ 2651558: ($0) => { globalThis.picorubyRefs[$0] = false; },
5664
+ 2651599: ($0, $1) => { globalThis.picorubyRefs[$0] = $1; },
5665
+ 2651637: ($0, $1) => { globalThis.picorubyRefs[$0] = $1; },
5666
+ 2651675: ($0, $1, $2) => { const str = UTF8ToString($1, $2); globalThis.picorubyRefs[$0] = str; },
5667
+ 2651748: ($0, $1) => { const arr = globalThis.picorubyRefs[$0]; const elem = globalThis.picorubyRefs[$1]; arr.push(elem); delete globalThis.picorubyRefs[$1]; },
5668
+ 2651887: ($0, $1, $2) => { const obj = globalThis.picorubyRefs[$0]; const key = UTF8ToString($1); const val = globalThis.picorubyRefs[$2]; obj[key] = val; delete globalThis.picorubyRefs[$2]; }
5422
5669
  };
5423
5670
  function ble_dataview_length(ref_id) { try { const dv = globalThis.picorubyRefs[ref_id]; if (dv && dv.byteLength !== undefined) { return dv.byteLength; } return 0; } catch(e) { console.error('ble_dataview_length failed:', e); return 0; } }
5424
5671
  function ble_dataview_read(ref_id,out_buf,max_len) { try { const dv = globalThis.picorubyRefs[ref_id]; if (!dv) return 0; const len = Math.min(dv.byteLength, max_len); for (let i = 0; i < len; i++) { HEAPU8[out_buf + i] = dv.getUint8(i); } return len; } catch(e) { console.error('ble_dataview_read failed:', e); return 0; } }
@@ -5617,41 +5864,41 @@ function assignWasmExports(wasmExports) {
5617
5864
  assert(typeof wasmExports['emscripten_stack_get_current'] != 'undefined', 'missing Wasm export: emscripten_stack_get_current');
5618
5865
  assert(typeof wasmExports['memory'] != 'undefined', 'missing Wasm export: memory');
5619
5866
  assert(typeof wasmExports['__indirect_function_table'] != 'undefined', 'missing Wasm export: __indirect_function_table');
5620
- _ble_notify_callback = Module['_ble_notify_callback'] = createExportWrapper('ble_notify_callback', 3);
5621
- _mrb_get_globals_json = Module['_mrb_get_globals_json'] = createExportWrapper('mrb_get_globals_json', 0);
5622
- _mrb_get_component_debug_info = Module['_mrb_get_component_debug_info'] = createExportWrapper('mrb_get_component_debug_info', 1);
5623
- _mrb_get_component_state_by_id = Module['_mrb_get_component_state_by_id'] = createExportWrapper('mrb_get_component_state_by_id', 1);
5624
- _mrb_eval_string = Module['_mrb_eval_string'] = createExportWrapper('mrb_eval_string', 1);
5625
- _mrb_debug_get_status = Module['_mrb_debug_get_status'] = createExportWrapper('mrb_debug_get_status', 0);
5626
- _mrb_debug_continue = Module['_mrb_debug_continue'] = createExportWrapper('mrb_debug_continue', 0);
5627
- _mrb_debug_get_locals = Module['_mrb_debug_get_locals'] = createExportWrapper('mrb_debug_get_locals', 0);
5628
- _mrb_debug_eval_in_binding = Module['_mrb_debug_eval_in_binding'] = createExportWrapper('mrb_debug_eval_in_binding', 1);
5629
- _mrb_debug_step = Module['_mrb_debug_step'] = createExportWrapper('mrb_debug_step', 0);
5630
- _mrb_debug_next = Module['_mrb_debug_next'] = createExportWrapper('mrb_debug_next', 0);
5631
- _mrb_debug_get_callstack = Module['_mrb_debug_get_callstack'] = createExportWrapper('mrb_debug_get_callstack', 0);
5632
- _call_ruby_callback = Module['_call_ruby_callback'] = createExportWrapper('call_ruby_callback', 2);
5633
- _call_ruby_callback_oneshot = Module['_call_ruby_callback_oneshot'] = createExportWrapper('call_ruby_callback_oneshot', 2);
5634
- _resume_promise_task = Module['_resume_promise_task'] = createExportWrapper('resume_promise_task', 4);
5635
- _resume_promise_error_task = Module['_resume_promise_error_task'] = createExportWrapper('resume_promise_error_task', 4);
5636
- _resume_binary_task = Module['_resume_binary_task'] = createExportWrapper('resume_binary_task', 5);
5637
- _call_ruby_callback_sync_generic = Module['_call_ruby_callback_sync_generic'] = createExportWrapper('call_ruby_callback_sync_generic', 3);
5638
- _mrb_tick_wasm = Module['_mrb_tick_wasm'] = createExportWrapper('mrb_tick_wasm', 0);
5639
- _mrb_run_step = Module['_mrb_run_step'] = createExportWrapper('mrb_run_step', 0);
5640
- _mrb_run_step_status = Module['_mrb_run_step_status'] = createExportWrapper('mrb_run_step_status', 0);
5641
- _mrb_gc_scheduler_pending_wasm = Module['_mrb_gc_scheduler_pending_wasm'] = createExportWrapper('mrb_gc_scheduler_pending_wasm', 0);
5642
- _picorb_init = Module['_picorb_init'] = createExportWrapper('picorb_init', 0);
5643
- _picorb_create_task = Module['_picorb_create_task'] = createExportWrapper('picorb_create_task', 1);
5644
- _picorb_create_task_with_filename = Module['_picorb_create_task_with_filename'] = createExportWrapper('picorb_create_task_with_filename', 2);
5645
- _picorb_create_task_from_mrb = Module['_picorb_create_task_from_mrb'] = createExportWrapper('picorb_create_task_from_mrb', 2);
5646
- _serial_data_received = Module['_serial_data_received'] = createExportWrapper('serial_data_received', 3);
5647
- _serial_disconnect_callback = Module['_serial_disconnect_callback'] = createExportWrapper('serial_disconnect_callback', 1);
5648
- _call_ruby_callback_with_binary_data = Module['_call_ruby_callback_with_binary_data'] = createExportWrapper('call_ruby_callback_with_binary_data', 3);
5649
- _fflush = createExportWrapper('fflush', 1);
5650
- _strerror = createExportWrapper('strerror', 1);
5651
- _emscripten_builtin_memalign = createExportWrapper('emscripten_builtin_memalign', 2);
5652
- _malloc = Module['_malloc'] = createExportWrapper('malloc', 1);
5653
- _free = Module['_free'] = createExportWrapper('free', 1);
5654
- _setThrew = createExportWrapper('setThrew', 2);
5867
+ _ble_notify_callback = Module['_ble_notify_callback'] = createExportWrapper('ble_notify_callback', wasmExports['ble_notify_callback'], 3);
5868
+ _mrb_get_globals_json = Module['_mrb_get_globals_json'] = createExportWrapper('mrb_get_globals_json', wasmExports['mrb_get_globals_json'], 0);
5869
+ _mrb_get_component_debug_info = Module['_mrb_get_component_debug_info'] = createExportWrapper('mrb_get_component_debug_info', wasmExports['mrb_get_component_debug_info'], 1);
5870
+ _mrb_get_component_state_by_id = Module['_mrb_get_component_state_by_id'] = createExportWrapper('mrb_get_component_state_by_id', wasmExports['mrb_get_component_state_by_id'], 1);
5871
+ _mrb_eval_string = Module['_mrb_eval_string'] = createExportWrapper('mrb_eval_string', wasmExports['mrb_eval_string'], 1);
5872
+ _mrb_debug_get_status = Module['_mrb_debug_get_status'] = createExportWrapper('mrb_debug_get_status', wasmExports['mrb_debug_get_status'], 0);
5873
+ _mrb_debug_continue = Module['_mrb_debug_continue'] = createExportWrapper('mrb_debug_continue', wasmExports['mrb_debug_continue'], 0);
5874
+ _mrb_debug_get_locals = Module['_mrb_debug_get_locals'] = createExportWrapper('mrb_debug_get_locals', wasmExports['mrb_debug_get_locals'], 0);
5875
+ _mrb_debug_eval_in_binding = Module['_mrb_debug_eval_in_binding'] = createExportWrapper('mrb_debug_eval_in_binding', wasmExports['mrb_debug_eval_in_binding'], 1);
5876
+ _mrb_debug_step = Module['_mrb_debug_step'] = createExportWrapper('mrb_debug_step', wasmExports['mrb_debug_step'], 0);
5877
+ _mrb_debug_next = Module['_mrb_debug_next'] = createExportWrapper('mrb_debug_next', wasmExports['mrb_debug_next'], 0);
5878
+ _mrb_debug_get_callstack = Module['_mrb_debug_get_callstack'] = createExportWrapper('mrb_debug_get_callstack', wasmExports['mrb_debug_get_callstack'], 0);
5879
+ _call_ruby_callback = Module['_call_ruby_callback'] = createExportWrapper('call_ruby_callback', wasmExports['call_ruby_callback'], 2);
5880
+ _call_ruby_callback_oneshot = Module['_call_ruby_callback_oneshot'] = createExportWrapper('call_ruby_callback_oneshot', wasmExports['call_ruby_callback_oneshot'], 2);
5881
+ _resume_promise_task = Module['_resume_promise_task'] = createExportWrapper('resume_promise_task', wasmExports['resume_promise_task'], 4);
5882
+ _resume_promise_error_task = Module['_resume_promise_error_task'] = createExportWrapper('resume_promise_error_task', wasmExports['resume_promise_error_task'], 4);
5883
+ _resume_binary_task = Module['_resume_binary_task'] = createExportWrapper('resume_binary_task', wasmExports['resume_binary_task'], 5);
5884
+ _call_ruby_callback_sync_generic = Module['_call_ruby_callback_sync_generic'] = createExportWrapper('call_ruby_callback_sync_generic', wasmExports['call_ruby_callback_sync_generic'], 3);
5885
+ _mrb_tick_wasm = Module['_mrb_tick_wasm'] = createExportWrapper('mrb_tick_wasm', wasmExports['mrb_tick_wasm'], 0);
5886
+ _mrb_run_step = Module['_mrb_run_step'] = createExportWrapper('mrb_run_step', wasmExports['mrb_run_step'], 0);
5887
+ _mrb_run_step_status = Module['_mrb_run_step_status'] = createExportWrapper('mrb_run_step_status', wasmExports['mrb_run_step_status'], 0);
5888
+ _mrb_gc_scheduler_pending_wasm = Module['_mrb_gc_scheduler_pending_wasm'] = createExportWrapper('mrb_gc_scheduler_pending_wasm', wasmExports['mrb_gc_scheduler_pending_wasm'], 0);
5889
+ _picorb_init = Module['_picorb_init'] = createExportWrapper('picorb_init', wasmExports['picorb_init'], 0);
5890
+ _picorb_create_task = Module['_picorb_create_task'] = createExportWrapper('picorb_create_task', wasmExports['picorb_create_task'], 1);
5891
+ _picorb_create_task_with_filename = Module['_picorb_create_task_with_filename'] = createExportWrapper('picorb_create_task_with_filename', wasmExports['picorb_create_task_with_filename'], 2);
5892
+ _picorb_create_task_from_mrb = Module['_picorb_create_task_from_mrb'] = createExportWrapper('picorb_create_task_from_mrb', wasmExports['picorb_create_task_from_mrb'], 2);
5893
+ _serial_data_received = Module['_serial_data_received'] = createExportWrapper('serial_data_received', wasmExports['serial_data_received'], 3);
5894
+ _serial_disconnect_callback = Module['_serial_disconnect_callback'] = createExportWrapper('serial_disconnect_callback', wasmExports['serial_disconnect_callback'], 1);
5895
+ _call_ruby_callback_with_binary_data = Module['_call_ruby_callback_with_binary_data'] = createExportWrapper('call_ruby_callback_with_binary_data', wasmExports['call_ruby_callback_with_binary_data'], 3);
5896
+ _fflush = createExportWrapper('fflush', wasmExports['fflush'], 1);
5897
+ _strerror = createExportWrapper('strerror', wasmExports['strerror'], 1);
5898
+ _emscripten_builtin_memalign = createExportWrapper('emscripten_builtin_memalign', wasmExports['emscripten_builtin_memalign'], 2);
5899
+ _malloc = Module['_malloc'] = createExportWrapper('malloc', wasmExports['malloc'], 1);
5900
+ _free = Module['_free'] = createExportWrapper('free', wasmExports['free'], 1);
5901
+ _setThrew = createExportWrapper('setThrew', wasmExports['setThrew'], 2);
5655
5902
  _emscripten_stack_init = wasmExports['emscripten_stack_init'];
5656
5903
  _emscripten_stack_get_free = wasmExports['emscripten_stack_get_free'];
5657
5904
  _emscripten_stack_get_base = wasmExports['emscripten_stack_get_base'];
@@ -5697,10 +5944,12 @@ var wasmImports = {
5697
5944
  /** @export */
5698
5945
  __syscall_openat: ___syscall_openat,
5699
5946
  /** @export */
5700
- __syscall_pipe: ___syscall_pipe,
5947
+ __syscall_pipe2: ___syscall_pipe2,
5701
5948
  /** @export */
5702
5949
  __syscall_poll: ___syscall_poll,
5703
5950
  /** @export */
5951
+ __syscall_poll_nonblocking: ___syscall_poll_nonblocking,
5952
+ /** @export */
5704
5953
  __syscall_readlinkat: ___syscall_readlinkat,
5705
5954
  /** @export */
5706
5955
  __syscall_renameat: ___syscall_renameat,
@@ -5711,6 +5960,8 @@ var wasmImports = {
5711
5960
  /** @export */
5712
5961
  __syscall_symlinkat: ___syscall_symlinkat,
5713
5962
  /** @export */
5963
+ __syscall_umask: ___syscall_umask,
5964
+ /** @export */
5714
5965
  __syscall_unlinkat: ___syscall_unlinkat,
5715
5966
  /** @export */
5716
5967
  _abort_js: __abort_js,
@@ -6020,7 +6271,7 @@ function invoke_viii(index,a1,a2,a3) {
6020
6271
  getWasmTableEntry(index)(a1,a2,a3);
6021
6272
  } catch(e) {
6022
6273
  stackRestore(sp);
6023
- if (e !== e+0) throw e;
6274
+ if (!(e instanceof EmscriptenEH)) throw e;
6024
6275
  _setThrew(1, 0);
6025
6276
  }
6026
6277
  }
@@ -6031,7 +6282,7 @@ function invoke_vii(index,a1,a2) {
6031
6282
  getWasmTableEntry(index)(a1,a2);
6032
6283
  } catch(e) {
6033
6284
  stackRestore(sp);
6034
- if (e !== e+0) throw e;
6285
+ if (!(e instanceof EmscriptenEH)) throw e;
6035
6286
  _setThrew(1, 0);
6036
6287
  }
6037
6288
  }
@@ -6042,7 +6293,7 @@ function invoke_ii(index,a1) {
6042
6293
  return getWasmTableEntry(index)(a1);
6043
6294
  } catch(e) {
6044
6295
  stackRestore(sp);
6045
- if (e !== e+0) throw e;
6296
+ if (!(e instanceof EmscriptenEH)) throw e;
6046
6297
  _setThrew(1, 0);
6047
6298
  }
6048
6299
  }
@@ -6053,7 +6304,7 @@ function invoke_ji(index,a1) {
6053
6304
  return getWasmTableEntry(index)(a1);
6054
6305
  } catch(e) {
6055
6306
  stackRestore(sp);
6056
- if (e !== e+0) throw e;
6307
+ if (!(e instanceof EmscriptenEH)) throw e;
6057
6308
  _setThrew(1, 0);
6058
6309
  return 0n;
6059
6310
  }
@@ -6065,7 +6316,7 @@ function invoke_vi(index,a1) {
6065
6316
  getWasmTableEntry(index)(a1);
6066
6317
  } catch(e) {
6067
6318
  stackRestore(sp);
6068
- if (e !== e+0) throw e;
6319
+ if (!(e instanceof EmscriptenEH)) throw e;
6069
6320
  _setThrew(1, 0);
6070
6321
  }
6071
6322
  }
@@ -6076,7 +6327,7 @@ function invoke_iijiiiiii(index,a1,a2,a3,a4,a5,a6,a7,a8) {
6076
6327
  return getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7,a8);
6077
6328
  } catch(e) {
6078
6329
  stackRestore(sp);
6079
- if (e !== e+0) throw e;
6330
+ if (!(e instanceof EmscriptenEH)) throw e;
6080
6331
  _setThrew(1, 0);
6081
6332
  }
6082
6333
  }
@@ -6087,7 +6338,7 @@ function invoke_viijiii(index,a1,a2,a3,a4,a5,a6) {
6087
6338
  getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6);
6088
6339
  } catch(e) {
6089
6340
  stackRestore(sp);
6090
- if (e !== e+0) throw e;
6341
+ if (!(e instanceof EmscriptenEH)) throw e;
6091
6342
  _setThrew(1, 0);
6092
6343
  }
6093
6344
  }
@@ -6098,7 +6349,7 @@ function invoke_iii(index,a1,a2) {
6098
6349
  return getWasmTableEntry(index)(a1,a2);
6099
6350
  } catch(e) {
6100
6351
  stackRestore(sp);
6101
- if (e !== e+0) throw e;
6352
+ if (!(e instanceof EmscriptenEH)) throw e;
6102
6353
  _setThrew(1, 0);
6103
6354
  }
6104
6355
  }
@@ -6109,7 +6360,7 @@ function invoke_viiiii(index,a1,a2,a3,a4,a5) {
6109
6360
  getWasmTableEntry(index)(a1,a2,a3,a4,a5);
6110
6361
  } catch(e) {
6111
6362
  stackRestore(sp);
6112
- if (e !== e+0) throw e;
6363
+ if (!(e instanceof EmscriptenEH)) throw e;
6113
6364
  _setThrew(1, 0);
6114
6365
  }
6115
6366
  }
@@ -6120,7 +6371,7 @@ function invoke_viiiiiii(index,a1,a2,a3,a4,a5,a6,a7) {
6120
6371
  getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7);
6121
6372
  } catch(e) {
6122
6373
  stackRestore(sp);
6123
- if (e !== e+0) throw e;
6374
+ if (!(e instanceof EmscriptenEH)) throw e;
6124
6375
  _setThrew(1, 0);
6125
6376
  }
6126
6377
  }
@@ -6131,7 +6382,7 @@ function invoke_viiii(index,a1,a2,a3,a4) {
6131
6382
  getWasmTableEntry(index)(a1,a2,a3,a4);
6132
6383
  } catch(e) {
6133
6384
  stackRestore(sp);
6134
- if (e !== e+0) throw e;
6385
+ if (!(e instanceof EmscriptenEH)) throw e;
6135
6386
  _setThrew(1, 0);
6136
6387
  }
6137
6388
  }
@@ -6142,7 +6393,7 @@ function invoke_viiiijii(index,a1,a2,a3,a4,a5,a6,a7) {
6142
6393
  getWasmTableEntry(index)(a1,a2,a3,a4,a5,a6,a7);
6143
6394
  } catch(e) {
6144
6395
  stackRestore(sp);
6145
- if (e !== e+0) throw e;
6396
+ if (!(e instanceof EmscriptenEH)) throw e;
6146
6397
  _setThrew(1, 0);
6147
6398
  }
6148
6399
  }
@@ -6153,7 +6404,7 @@ function invoke_iiii(index,a1,a2,a3) {
6153
6404
  return getWasmTableEntry(index)(a1,a2,a3);
6154
6405
  } catch(e) {
6155
6406
  stackRestore(sp);
6156
- if (e !== e+0) throw e;
6407
+ if (!(e instanceof EmscriptenEH)) throw e;
6157
6408
  _setThrew(1, 0);
6158
6409
  }
6159
6410
  }
@@ -6164,7 +6415,7 @@ function invoke_iiiii(index,a1,a2,a3,a4) {
6164
6415
  return getWasmTableEntry(index)(a1,a2,a3,a4);
6165
6416
  } catch(e) {
6166
6417
  stackRestore(sp);
6167
- if (e !== e+0) throw e;
6418
+ if (!(e instanceof EmscriptenEH)) throw e;
6168
6419
  _setThrew(1, 0);
6169
6420
  }
6170
6421
  }
@@ -6175,7 +6426,7 @@ function invoke_viiiij(index,a1,a2,a3,a4,a5) {
6175
6426
  getWasmTableEntry(index)(a1,a2,a3,a4,a5);
6176
6427
  } catch(e) {
6177
6428
  stackRestore(sp);
6178
- if (e !== e+0) throw e;
6429
+ if (!(e instanceof EmscriptenEH)) throw e;
6179
6430
  _setThrew(1, 0);
6180
6431
  }
6181
6432
  }
@@ -6186,7 +6437,7 @@ function invoke_vij(index,a1,a2) {
6186
6437
  getWasmTableEntry(index)(a1,a2);
6187
6438
  } catch(e) {
6188
6439
  stackRestore(sp);
6189
- if (e !== e+0) throw e;
6440
+ if (!(e instanceof EmscriptenEH)) throw e;
6190
6441
  _setThrew(1, 0);
6191
6442
  }
6192
6443
  }
@@ -6197,7 +6448,7 @@ function invoke_viij(index,a1,a2,a3) {
6197
6448
  getWasmTableEntry(index)(a1,a2,a3);
6198
6449
  } catch(e) {
6199
6450
  stackRestore(sp);
6200
- if (e !== e+0) throw e;
6451
+ if (!(e instanceof EmscriptenEH)) throw e;
6201
6452
  _setThrew(1, 0);
6202
6453
  }
6203
6454
  }
@@ -6208,7 +6459,7 @@ function invoke_viiij(index,a1,a2,a3,a4) {
6208
6459
  getWasmTableEntry(index)(a1,a2,a3,a4);
6209
6460
  } catch(e) {
6210
6461
  stackRestore(sp);
6211
- if (e !== e+0) throw e;
6462
+ if (!(e instanceof EmscriptenEH)) throw e;
6212
6463
  _setThrew(1, 0);
6213
6464
  }
6214
6465
  }
@@ -6219,7 +6470,7 @@ function invoke_viiji(index,a1,a2,a3,a4) {
6219
6470
  getWasmTableEntry(index)(a1,a2,a3,a4);
6220
6471
  } catch(e) {
6221
6472
  stackRestore(sp);
6222
- if (e !== e+0) throw e;
6473
+ if (!(e instanceof EmscriptenEH)) throw e;
6223
6474
  _setThrew(1, 0);
6224
6475
  }
6225
6476
  }
@@ -6230,7 +6481,7 @@ function invoke_viijj(index,a1,a2,a3,a4) {
6230
6481
  getWasmTableEntry(index)(a1,a2,a3,a4);
6231
6482
  } catch(e) {
6232
6483
  stackRestore(sp);
6233
- if (e !== e+0) throw e;
6484
+ if (!(e instanceof EmscriptenEH)) throw e;
6234
6485
  _setThrew(1, 0);
6235
6486
  }
6236
6487
  }
@@ -6241,7 +6492,7 @@ function invoke_ddd(index,a1,a2) {
6241
6492
  return getWasmTableEntry(index)(a1,a2);
6242
6493
  } catch(e) {
6243
6494
  stackRestore(sp);
6244
- if (e !== e+0) throw e;
6495
+ if (!(e instanceof EmscriptenEH)) throw e;
6245
6496
  _setThrew(1, 0);
6246
6497
  }
6247
6498
  }
@@ -6252,7 +6503,7 @@ function invoke_iij(index,a1,a2) {
6252
6503
  return getWasmTableEntry(index)(a1,a2);
6253
6504
  } catch(e) {
6254
6505
  stackRestore(sp);
6255
- if (e !== e+0) throw e;
6506
+ if (!(e instanceof EmscriptenEH)) throw e;
6256
6507
  _setThrew(1, 0);
6257
6508
  }
6258
6509
  }
@@ -6263,7 +6514,7 @@ function invoke_jii(index,a1,a2) {
6263
6514
  return getWasmTableEntry(index)(a1,a2);
6264
6515
  } catch(e) {
6265
6516
  stackRestore(sp);
6266
- if (e !== e+0) throw e;
6517
+ if (!(e instanceof EmscriptenEH)) throw e;
6267
6518
  _setThrew(1, 0);
6268
6519
  return 0n;
6269
6520
  }
@@ -6275,7 +6526,7 @@ function invoke_vijii(index,a1,a2,a3,a4) {
6275
6526
  getWasmTableEntry(index)(a1,a2,a3,a4);
6276
6527
  } catch(e) {
6277
6528
  stackRestore(sp);
6278
- if (e !== e+0) throw e;
6529
+ if (!(e instanceof EmscriptenEH)) throw e;
6279
6530
  _setThrew(1, 0);
6280
6531
  }
6281
6532
  }
@@ -6295,54 +6546,37 @@ function stackCheckInit() {
6295
6546
  writeStackCookie();
6296
6547
  }
6297
6548
 
6298
- function run() {
6299
-
6300
- if (runDependencies > 0) {
6301
- dependenciesFulfilled = run;
6302
- return;
6303
- }
6549
+ async function run() {
6550
+ assert(!calledRun);
6551
+ calledRun = true;
6304
6552
 
6305
6553
  stackCheckInit();
6306
6554
 
6307
6555
  preRun();
6308
6556
 
6309
- // a preRun added a dependency, run will be called later
6310
- if (runDependencies > 0) {
6311
- dependenciesFulfilled = run;
6312
- return;
6557
+ if (runDependencies) {
6558
+ await resolveRunDependencies();
6313
6559
  }
6314
6560
 
6315
- function doRun() {
6316
- // run may have just been called through dependencies being fulfilled just in this very frame,
6317
- // or while the async setStatus time below was happening
6318
- assert(!calledRun);
6319
- calledRun = true;
6320
- Module['calledRun'] = true;
6321
-
6322
- if (ABORT) return;
6561
+ var setStatus = Module['setStatus'];
6562
+ if (setStatus) {
6563
+ setStatus('Running...');
6564
+ // Yield to the event loop to allow the browser to paint "Running..."
6565
+ await new Promise((resolve) => setTimeout(resolve, 1));
6566
+ // Then we want to clear the status text, but only after the rest of this function runs.
6567
+ setTimeout(setStatus, 1, '');
6568
+ }
6323
6569
 
6324
- initRuntime();
6570
+ if (ABORT) return;
6325
6571
 
6326
- readyPromiseResolve?.(Module);
6327
- Module['onRuntimeInitialized']?.();
6328
- consumedModuleProp('onRuntimeInitialized');
6572
+ initRuntime();
6329
6573
 
6330
- assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
6574
+ Module['onRuntimeInitialized']?.();
6575
+ consumedModuleProp('onRuntimeInitialized');
6331
6576
 
6332
- postRun();
6333
- }
6577
+ assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]');
6334
6578
 
6335
- if (Module['setStatus']) {
6336
- Module['setStatus']('Running...');
6337
- setTimeout(() => {
6338
- setTimeout(() => Module['setStatus'](''), 1);
6339
- doRun();
6340
- }, 1);
6341
- } else
6342
- {
6343
- doRun();
6344
- }
6345
- checkStackCookie();
6579
+ postRun();
6346
6580
  }
6347
6581
 
6348
6582
  function checkUnflushedContent() {
@@ -6388,28 +6622,14 @@ var wasmExports;
6388
6622
 
6389
6623
  // In modularize mode the generated code is within a factory function so we
6390
6624
  // can use await here (since it's not top-level-await).
6391
- wasmExports = await (createWasm());
6392
-
6393
- run();
6625
+ wasmExports = await createWasm();
6626
+ await run();
6394
6627
 
6395
6628
  // end include: postamble.js
6396
6629
 
6397
6630
  // include: postamble_modularize.js
6398
6631
  // In MODULARIZE mode we wrap the generated code in a factory function
6399
6632
  // and return either the Module itself, or a promise of the module.
6400
- //
6401
- // We assign to the `moduleRtn` global here and configure closure to see
6402
- // this as an extern so it won't get minified.
6403
-
6404
- if (runtimeInitialized) {
6405
- moduleRtn = Module;
6406
- } else {
6407
- // Set up the promise that indicates the Module is initialized
6408
- moduleRtn = new Promise((resolve, reject) => {
6409
- readyPromiseResolve = resolve;
6410
- readyPromiseReject = reject;
6411
- });
6412
- }
6413
6633
 
6414
6634
  // Assertion for attempting to access module properties on the incoming
6415
6635
  // moduleArg. In the past we used this object as the prototype of the module
@@ -6430,7 +6650,7 @@ for (const prop of Object.keys(Module)) {
6430
6650
 
6431
6651
 
6432
6652
 
6433
- return moduleRtn;
6653
+ return Module;
6434
6654
  }
6435
6655
 
6436
6656
  // Export using a UMD style export, or ES6 exports if selected