@php-wasm/node-7-4 3.1.61 → 3.1.63

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.
@@ -15,7 +15,7 @@ const currentDirPath =
15
15
  : path.dirname(fileURLToPath(import.meta.url));
16
16
  const dependencyFilename = path.join(currentDirPath, '7_4_33', 'php_7_4.wasm');
17
17
  export { dependencyFilename };
18
- export const dependenciesTotalSize = 18765536;
18
+ export const dependenciesTotalSize = 18765542;
19
19
  const phpVersionString = '7.4.33';
20
20
  export function init(RuntimeName, PHPLoader) {
21
21
  // The rest of the code comes from the built php.js file and esm-suffix.js
@@ -8551,6 +8551,14 @@ export function init(RuntimeName, PHPLoader) {
8551
8551
 
8552
8552
  _emscripten_resize_heap.sig = 'ip';
8553
8553
 
8554
+ var runAndAbortIfError = (func) => {
8555
+ try {
8556
+ return func();
8557
+ } catch (e) {
8558
+ abort(e);
8559
+ }
8560
+ };
8561
+
8554
8562
  var runtimeKeepalivePush = () => {
8555
8563
  runtimeKeepaliveCounter += 1;
8556
8564
  };
@@ -8563,6 +8571,242 @@ export function init(RuntimeName, PHPLoader) {
8563
8571
 
8564
8572
  runtimeKeepalivePop.sig = 'v';
8565
8573
 
8574
+ var Asyncify = {
8575
+ instrumentWasmImports(imports) {
8576
+ var importPattern =
8577
+ /^(invoke_i|invoke_ii|invoke_iii|invoke_iiii|invoke_iiiii|invoke_iiiiii|invoke_iiiiiii|invoke_iiiiiiii|invoke_iiiiiiiii|invoke_iiiiiiiiii|invoke_v|invoke_vi|invoke_vii|invoke_viidii|invoke_viii|invoke_viiii|invoke_viiiii|invoke_viiiiii|invoke_viiiiiii|invoke_viiiiiiiii|invoke_i|invoke_ii|invoke_iii|invoke_iiii|invoke_iiiii|invoke_iiiiii|invoke_iiiiiii|invoke_iiiiiiii|invoke_iiiiiiiiii|invoke_iij|invoke_iiji|invoke_iiij|invoke_iijii|invoke_iijiji|invoke_jii|invoke_jiii|invoke_viijii|invoke_vji|js_open_process|_js_open_process|_asyncjs__js_open_process|js_popen_to_file|_js_popen_to_file|_asyncjs__js_popen_to_file|__syscall_fcntl64|___syscall_fcntl64|_asyncjs___syscall_fcntl64|js_release_file_locks|_js_release_file_locks|_async_js_release_file_locks|js_flock|_js_flock|_async_js_flock|js_fd_read|_js_fd_read|fd_close|_fd_close|_asyncjs__fd_close|close|_close|js_module_onMessage|zend_hash_str_find|_js_module_onMessage|_asyncjs__js_module_onMessage|js_waitpid|_js_waitpid|_asyncjs__js_waitpid|wasm_poll_socket|_wasm_poll_socket|_asyncjs__wasm_poll_socket|_wasm_shutdown|_asyncjs__wasm_shutdown|recv|_recv|setsockopt|_setsockopt|wasm_connect|_wasm_connect|__asyncjs__.*)$/;
8578
+ for (let [x, original] of Object.entries(imports)) {
8579
+ if (typeof original == 'function') {
8580
+ let isAsyncifyImport =
8581
+ original.isAsync || importPattern.test(x);
8582
+ }
8583
+ }
8584
+ },
8585
+ instrumentFunction(original) {
8586
+ var wrapper = (...args) => {
8587
+ Asyncify.exportCallStack.push(original);
8588
+ try {
8589
+ return original(...args);
8590
+ } finally {
8591
+ if (!ABORT) {
8592
+ var top = Asyncify.exportCallStack.pop();
8593
+ Asyncify.maybeStopUnwind();
8594
+ }
8595
+ }
8596
+ };
8597
+ Asyncify.funcWrappers.set(original, wrapper);
8598
+ wrapper.orig = original;
8599
+ return wrapper;
8600
+ },
8601
+ instrumentWasmExports(exports) {
8602
+ var ret = {};
8603
+ for (let [x, original] of Object.entries(exports)) {
8604
+ if (typeof original == 'function') {
8605
+ var wrapper = Asyncify.instrumentFunction(original);
8606
+ ret[x] = wrapper;
8607
+ } else {
8608
+ ret[x] = original;
8609
+ }
8610
+ }
8611
+ return ret;
8612
+ },
8613
+ State: {
8614
+ Normal: 0,
8615
+ Unwinding: 1,
8616
+ Rewinding: 2,
8617
+ Disabled: 3,
8618
+ },
8619
+ state: 0,
8620
+ StackSize: 4096,
8621
+ currData: null,
8622
+ handleSleepReturnValue: 0,
8623
+ exportCallStack: [],
8624
+ callstackFuncToId: new Map(),
8625
+ callStackIdToFunc: new Map(),
8626
+ funcWrappers: new Map(),
8627
+ callStackId: 0,
8628
+ asyncPromiseHandlers: null,
8629
+ sleepCallbacks: [],
8630
+ getCallStackId(func) {
8631
+ if (!Asyncify.callstackFuncToId.has(func)) {
8632
+ var id = Asyncify.callStackId++;
8633
+ Asyncify.callstackFuncToId.set(func, id);
8634
+ Asyncify.callStackIdToFunc.set(id, func);
8635
+ }
8636
+ return Asyncify.callstackFuncToId.get(func);
8637
+ },
8638
+ maybeStopUnwind() {
8639
+ if (
8640
+ Asyncify.currData &&
8641
+ Asyncify.state === Asyncify.State.Unwinding &&
8642
+ Asyncify.exportCallStack.length === 0
8643
+ ) {
8644
+ // We just finished unwinding.
8645
+ // Be sure to set the state before calling any other functions to avoid
8646
+ // possible infinite recursion here (For example in debug pthread builds
8647
+ // the dbg() function itself can call back into WebAssembly to get the
8648
+ // current pthread_self() pointer).
8649
+ Asyncify.state = Asyncify.State.Normal;
8650
+ runtimeKeepalivePush();
8651
+ // Keep the runtime alive so that a re-wind can be done later.
8652
+ runAndAbortIfError(_asyncify_stop_unwind);
8653
+ if (typeof Fibers != 'undefined') {
8654
+ Fibers.trampoline();
8655
+ }
8656
+ }
8657
+ },
8658
+ whenDone() {
8659
+ return new Promise((resolve, reject) => {
8660
+ Asyncify.asyncPromiseHandlers = {
8661
+ resolve,
8662
+ reject,
8663
+ };
8664
+ });
8665
+ },
8666
+ allocateData() {
8667
+ // An asyncify data structure has three fields:
8668
+ // 0 current stack pos
8669
+ // 4 max stack pos
8670
+ // 8 id of function at bottom of the call stack (callStackIdToFunc[id] == wasm func)
8671
+ // The Asyncify ABI only interprets the first two fields, the rest is for the runtime.
8672
+ // We also embed a stack in the same memory region here, right next to the structure.
8673
+ // This struct is also defined as asyncify_data_t in emscripten/fiber.h
8674
+ var ptr = _malloc(12 + Asyncify.StackSize);
8675
+ Asyncify.setDataHeader(ptr, ptr + 12, Asyncify.StackSize);
8676
+ Asyncify.setDataRewindFunc(ptr);
8677
+ return ptr;
8678
+ },
8679
+ setDataHeader(ptr, stack, stackSize) {
8680
+ HEAPU32[ptr >> 2] = stack;
8681
+ HEAPU32[(ptr + 4) >> 2] = stack + stackSize;
8682
+ },
8683
+ setDataRewindFunc(ptr) {
8684
+ var bottomOfCallStack = Asyncify.exportCallStack[0];
8685
+ var rewindId = Asyncify.getCallStackId(bottomOfCallStack);
8686
+ HEAP32[(ptr + 8) >> 2] = rewindId;
8687
+ },
8688
+ getDataRewindFunc(ptr) {
8689
+ var id = HEAP32[(ptr + 8) >> 2];
8690
+ var func = Asyncify.callStackIdToFunc.get(id);
8691
+ return func;
8692
+ },
8693
+ doRewind(ptr) {
8694
+ var original = Asyncify.getDataRewindFunc(ptr);
8695
+ var func = Asyncify.funcWrappers.get(original);
8696
+ // Once we have rewound and the stack we no longer need to artificially
8697
+ // keep the runtime alive.
8698
+ runtimeKeepalivePop();
8699
+ return func();
8700
+ },
8701
+ handleSleep(startAsync) {
8702
+ if (ABORT) return;
8703
+ if (Asyncify.state === Asyncify.State.Normal) {
8704
+ // Prepare to sleep. Call startAsync, and see what happens:
8705
+ // if the code decided to call our callback synchronously,
8706
+ // then no async operation was in fact begun, and we don't
8707
+ // need to do anything.
8708
+ var reachedCallback = false;
8709
+ var reachedAfterCallback = false;
8710
+ startAsync((handleSleepReturnValue = 0) => {
8711
+ if (ABORT) return;
8712
+ Asyncify.handleSleepReturnValue = handleSleepReturnValue;
8713
+ reachedCallback = true;
8714
+ if (!reachedAfterCallback) {
8715
+ // We are happening synchronously, so no need for async.
8716
+ return;
8717
+ }
8718
+ Asyncify.state = Asyncify.State.Rewinding;
8719
+ runAndAbortIfError(() =>
8720
+ _asyncify_start_rewind(Asyncify.currData)
8721
+ );
8722
+ if (typeof MainLoop != 'undefined' && MainLoop.func) {
8723
+ MainLoop.resume();
8724
+ }
8725
+ var asyncWasmReturnValue,
8726
+ isError = false;
8727
+ try {
8728
+ asyncWasmReturnValue = Asyncify.doRewind(
8729
+ Asyncify.currData
8730
+ );
8731
+ } catch (err) {
8732
+ asyncWasmReturnValue = err;
8733
+ isError = true;
8734
+ }
8735
+ // Track whether the return value was handled by any promise handlers.
8736
+ var handled = false;
8737
+ if (!Asyncify.currData) {
8738
+ // All asynchronous execution has finished.
8739
+ // `asyncWasmReturnValue` now contains the final
8740
+ // return value of the exported async WASM function.
8741
+ // Note: `asyncWasmReturnValue` is distinct from
8742
+ // `Asyncify.handleSleepReturnValue`.
8743
+ // `Asyncify.handleSleepReturnValue` contains the return
8744
+ // value of the last C function to have executed
8745
+ // `Asyncify.handleSleep()`, where as `asyncWasmReturnValue`
8746
+ // contains the return value of the exported WASM function
8747
+ // that may have called C functions that
8748
+ // call `Asyncify.handleSleep()`.
8749
+ var asyncPromiseHandlers =
8750
+ Asyncify.asyncPromiseHandlers;
8751
+ if (asyncPromiseHandlers) {
8752
+ Asyncify.asyncPromiseHandlers = null;
8753
+ (isError
8754
+ ? asyncPromiseHandlers.reject
8755
+ : asyncPromiseHandlers.resolve)(
8756
+ asyncWasmReturnValue
8757
+ );
8758
+ handled = true;
8759
+ }
8760
+ }
8761
+ if (isError && !handled) {
8762
+ // If there was an error and it was not handled by now, we have no choice but to
8763
+ // rethrow that error into the global scope where it can be caught only by
8764
+ // `onerror` or `onunhandledpromiserejection`.
8765
+ throw asyncWasmReturnValue;
8766
+ }
8767
+ });
8768
+ reachedAfterCallback = true;
8769
+ if (!reachedCallback) {
8770
+ // A true async operation was begun; start a sleep.
8771
+ Asyncify.state = Asyncify.State.Unwinding;
8772
+ // TODO: reuse, don't alloc/free every sleep
8773
+ if (!Asyncify._cachedData) {
8774
+ Asyncify._cachedData = Asyncify.allocateData();
8775
+ } else {
8776
+ Asyncify.setDataHeader(
8777
+ Asyncify._cachedData,
8778
+ Asyncify._cachedData + 12,
8779
+ Asyncify.StackSize
8780
+ );
8781
+ Asyncify.setDataRewindFunc(Asyncify._cachedData);
8782
+ }
8783
+ Asyncify.currData = Asyncify._cachedData;
8784
+ if (typeof MainLoop != 'undefined' && MainLoop.func) {
8785
+ MainLoop.pause();
8786
+ }
8787
+ runAndAbortIfError(() =>
8788
+ _asyncify_start_unwind(Asyncify.currData)
8789
+ );
8790
+ }
8791
+ } else if (Asyncify.state === Asyncify.State.Rewinding) {
8792
+ // Stop a resume.
8793
+ Asyncify.state = Asyncify.State.Normal;
8794
+ runAndAbortIfError(_asyncify_stop_rewind);
8795
+ Asyncify.currData = null;
8796
+ // Call all sleep callbacks now that the sleep-resume is all done.
8797
+ Asyncify.sleepCallbacks.forEach(callUserCallback);
8798
+ } else {
8799
+ abort(`invalid state: ${Asyncify.state}`);
8800
+ }
8801
+ return Asyncify.handleSleepReturnValue;
8802
+ },
8803
+ handleAsync: (startAsync) =>
8804
+ Asyncify.handleSleep((wakeUp) => {
8805
+ // TODO: add error handling as a second param when handleSleep implements it.
8806
+ startAsync().then(wakeUp);
8807
+ }),
8808
+ };
8809
+
8566
8810
  /** @param {number=} timeout */ var safeSetTimeout = (func, timeout) => {
8567
8811
  runtimeKeepalivePush();
8568
8812
  return setTimeout(() => {
@@ -8571,8 +8815,22 @@ export function init(RuntimeName, PHPLoader) {
8571
8815
  }, timeout);
8572
8816
  };
8573
8817
 
8574
- var _emscripten_sleep = (ms) =>
8575
- Asyncify.handleSleep((wakeUp) => safeSetTimeout(wakeUp, ms));
8818
+ var _emscripten_sleep = function (ms) {
8819
+ return Asyncify.handleSleep((wakeUp) => {
8820
+ // select() yields between socket reads. Nested zero-delay timers are
8821
+ // clamped by browsers, adding seconds to even a local curl download.
8822
+ // Use a task (not a microtask) so network events still get a turn.
8823
+ if (ms === 0 && globalThis.scheduler?.postTask) {
8824
+ runtimeKeepalivePush();
8825
+ globalThis.scheduler.postTask(() => {
8826
+ runtimeKeepalivePop();
8827
+ callUserCallback(wakeUp);
8828
+ });
8829
+ } else {
8830
+ safeSetTimeout(wakeUp, ms);
8831
+ }
8832
+ });
8833
+ };
8576
8834
 
8577
8835
  _emscripten_sleep.sig = 'vi';
8578
8836
 
@@ -9103,13 +9361,11 @@ export function init(RuntimeName, PHPLoader) {
9103
9361
  envLength
9104
9362
  ) {
9105
9363
  if (!command) {
9106
- ___errno_location(ERRNO_CODES.EINVAL);
9107
- return -1;
9364
+ return -ERRNO_CODES.EINVAL;
9108
9365
  }
9109
9366
  const cmdstr = UTF8ToString(command);
9110
9367
  if (!cmdstr.length) {
9111
- ___errno_location(ERRNO_CODES.EINVAL);
9112
- return -1;
9368
+ return -ERRNO_CODES.EINVAL;
9113
9369
  }
9114
9370
  let argsArray = [];
9115
9371
  if (argsLength) {
@@ -9169,13 +9425,11 @@ export function init(RuntimeName, PHPLoader) {
9169
9425
  }
9170
9426
  } catch (e) {
9171
9427
  if (e.code === 'SPAWN_UNSUPPORTED') {
9172
- ___errno_location(ERRNO_CODES.ENOSYS);
9173
- return -1;
9428
+ return -ERRNO_CODES.ENOSYS;
9174
9429
  }
9175
9430
  if (typeof FS == 'undefined' || !(e.name === 'ErrnoError'))
9176
9431
  throw e;
9177
- ___errno_location(e.code);
9178
- return -1;
9432
+ return -e.errno;
9179
9433
  }
9180
9434
  const ProcInfo = {
9181
9435
  pid: cp.pid,
@@ -9189,20 +9443,31 @@ export function init(RuntimeName, PHPLoader) {
9189
9443
  stderrChildFd = std[2]?.child,
9190
9444
  stderrParentFd = std[2]?.parent;
9191
9445
  const detachPipeDataListeners = [];
9192
- cp.on('exit', function (code) {
9446
+ /**
9447
+ * Closes the child ends of the pipes so a blocking fread() on the
9448
+ * parent end sees a broken pipe instead of polling forever. Runs on
9449
+ * 'exit' and when the spawn wait fails, because a failed spawn may
9450
+ * never emit 'exit'.
9451
+ *
9452
+ * Runs at most once. After the first call, PHP may reuse these fd
9453
+ * numbers for unrelated streams that a late 'exit' must not close.
9454
+ */ let childPipesClosed = false;
9455
+ const closeChildPipes = function () {
9456
+ if (childPipesClosed) {
9457
+ return;
9458
+ }
9459
+ childPipesClosed = true;
9193
9460
  for (const detach of detachPipeDataListeners) {
9194
9461
  detach();
9195
9462
  }
9196
- for (const fd of [
9197
- // The child process exited. Let's clean up its output streams:
9198
- stdoutChildFd,
9199
- stderrChildFd,
9200
- stdinChildFd,
9201
- ]) {
9463
+ for (const fd of [stdoutChildFd, stderrChildFd, stdinChildFd]) {
9202
9464
  if (FS.streams[fd] && !FS.isClosed(FS.streams[fd])) {
9203
9465
  FS.close(FS.streams[fd]);
9204
9466
  }
9205
9467
  }
9468
+ };
9469
+ cp.on('exit', function (code) {
9470
+ closeChildPipes();
9206
9471
  ProcInfo.exitCode = code;
9207
9472
  ProcInfo.exited = true;
9208
9473
  });
@@ -9310,6 +9575,10 @@ export function init(RuntimeName, PHPLoader) {
9310
9575
  // Process already started. Even if it exited early, PHP still
9311
9576
  // needs to know about the pid and clean up the resources.
9312
9577
  console.error(e);
9578
+ closeChildPipes();
9579
+ if (!ProcInfo.pid) {
9580
+ return -(ERRNO_CODES[e.code] ?? ERRNO_CODES.ECHILD);
9581
+ }
9313
9582
  return ProcInfo.pid;
9314
9583
  }
9315
9584
  // Now we want to pass data from the STDIN source supplied by PHP
@@ -9919,250 +10188,6 @@ export function init(RuntimeName, PHPLoader) {
9919
10188
  return PHPWASM.shutdownSocket(socketd, how);
9920
10189
  }
9921
10190
 
9922
- var runAndAbortIfError = (func) => {
9923
- try {
9924
- return func();
9925
- } catch (e) {
9926
- abort(e);
9927
- }
9928
- };
9929
-
9930
- var Asyncify = {
9931
- instrumentWasmImports(imports) {
9932
- var importPattern =
9933
- /^(invoke_i|invoke_ii|invoke_iii|invoke_iiii|invoke_iiiii|invoke_iiiiii|invoke_iiiiiii|invoke_iiiiiiii|invoke_iiiiiiiii|invoke_iiiiiiiiii|invoke_v|invoke_vi|invoke_vii|invoke_viidii|invoke_viii|invoke_viiii|invoke_viiiii|invoke_viiiiii|invoke_viiiiiii|invoke_viiiiiiiii|invoke_i|invoke_ii|invoke_iii|invoke_iiii|invoke_iiiii|invoke_iiiiii|invoke_iiiiiii|invoke_iiiiiiii|invoke_iiiiiiiiii|invoke_iij|invoke_iiji|invoke_iiij|invoke_iijii|invoke_iijiji|invoke_jii|invoke_jiii|invoke_viijii|invoke_vji|js_open_process|_js_open_process|_asyncjs__js_open_process|js_popen_to_file|_js_popen_to_file|_asyncjs__js_popen_to_file|__syscall_fcntl64|___syscall_fcntl64|_asyncjs___syscall_fcntl64|js_release_file_locks|_js_release_file_locks|_async_js_release_file_locks|js_flock|_js_flock|_async_js_flock|js_fd_read|_js_fd_read|fd_close|_fd_close|_asyncjs__fd_close|close|_close|js_module_onMessage|zend_hash_str_find|_js_module_onMessage|_asyncjs__js_module_onMessage|js_waitpid|_js_waitpid|_asyncjs__js_waitpid|wasm_poll_socket|_wasm_poll_socket|_asyncjs__wasm_poll_socket|_wasm_shutdown|_asyncjs__wasm_shutdown|recv|_recv|setsockopt|_setsockopt|wasm_connect|_wasm_connect|__asyncjs__.*)$/;
9934
- for (let [x, original] of Object.entries(imports)) {
9935
- if (typeof original == 'function') {
9936
- let isAsyncifyImport =
9937
- original.isAsync || importPattern.test(x);
9938
- }
9939
- }
9940
- },
9941
- instrumentFunction(original) {
9942
- var wrapper = (...args) => {
9943
- Asyncify.exportCallStack.push(original);
9944
- try {
9945
- return original(...args);
9946
- } finally {
9947
- if (!ABORT) {
9948
- var top = Asyncify.exportCallStack.pop();
9949
- Asyncify.maybeStopUnwind();
9950
- }
9951
- }
9952
- };
9953
- Asyncify.funcWrappers.set(original, wrapper);
9954
- wrapper.orig = original;
9955
- return wrapper;
9956
- },
9957
- instrumentWasmExports(exports) {
9958
- var ret = {};
9959
- for (let [x, original] of Object.entries(exports)) {
9960
- if (typeof original == 'function') {
9961
- var wrapper = Asyncify.instrumentFunction(original);
9962
- ret[x] = wrapper;
9963
- } else {
9964
- ret[x] = original;
9965
- }
9966
- }
9967
- return ret;
9968
- },
9969
- State: {
9970
- Normal: 0,
9971
- Unwinding: 1,
9972
- Rewinding: 2,
9973
- Disabled: 3,
9974
- },
9975
- state: 0,
9976
- StackSize: 4096,
9977
- currData: null,
9978
- handleSleepReturnValue: 0,
9979
- exportCallStack: [],
9980
- callstackFuncToId: new Map(),
9981
- callStackIdToFunc: new Map(),
9982
- funcWrappers: new Map(),
9983
- callStackId: 0,
9984
- asyncPromiseHandlers: null,
9985
- sleepCallbacks: [],
9986
- getCallStackId(func) {
9987
- if (!Asyncify.callstackFuncToId.has(func)) {
9988
- var id = Asyncify.callStackId++;
9989
- Asyncify.callstackFuncToId.set(func, id);
9990
- Asyncify.callStackIdToFunc.set(id, func);
9991
- }
9992
- return Asyncify.callstackFuncToId.get(func);
9993
- },
9994
- maybeStopUnwind() {
9995
- if (
9996
- Asyncify.currData &&
9997
- Asyncify.state === Asyncify.State.Unwinding &&
9998
- Asyncify.exportCallStack.length === 0
9999
- ) {
10000
- // We just finished unwinding.
10001
- // Be sure to set the state before calling any other functions to avoid
10002
- // possible infinite recursion here (For example in debug pthread builds
10003
- // the dbg() function itself can call back into WebAssembly to get the
10004
- // current pthread_self() pointer).
10005
- Asyncify.state = Asyncify.State.Normal;
10006
- runtimeKeepalivePush();
10007
- // Keep the runtime alive so that a re-wind can be done later.
10008
- runAndAbortIfError(_asyncify_stop_unwind);
10009
- if (typeof Fibers != 'undefined') {
10010
- Fibers.trampoline();
10011
- }
10012
- }
10013
- },
10014
- whenDone() {
10015
- return new Promise((resolve, reject) => {
10016
- Asyncify.asyncPromiseHandlers = {
10017
- resolve,
10018
- reject,
10019
- };
10020
- });
10021
- },
10022
- allocateData() {
10023
- // An asyncify data structure has three fields:
10024
- // 0 current stack pos
10025
- // 4 max stack pos
10026
- // 8 id of function at bottom of the call stack (callStackIdToFunc[id] == wasm func)
10027
- // The Asyncify ABI only interprets the first two fields, the rest is for the runtime.
10028
- // We also embed a stack in the same memory region here, right next to the structure.
10029
- // This struct is also defined as asyncify_data_t in emscripten/fiber.h
10030
- var ptr = _malloc(12 + Asyncify.StackSize);
10031
- Asyncify.setDataHeader(ptr, ptr + 12, Asyncify.StackSize);
10032
- Asyncify.setDataRewindFunc(ptr);
10033
- return ptr;
10034
- },
10035
- setDataHeader(ptr, stack, stackSize) {
10036
- HEAPU32[ptr >> 2] = stack;
10037
- HEAPU32[(ptr + 4) >> 2] = stack + stackSize;
10038
- },
10039
- setDataRewindFunc(ptr) {
10040
- var bottomOfCallStack = Asyncify.exportCallStack[0];
10041
- var rewindId = Asyncify.getCallStackId(bottomOfCallStack);
10042
- HEAP32[(ptr + 8) >> 2] = rewindId;
10043
- },
10044
- getDataRewindFunc(ptr) {
10045
- var id = HEAP32[(ptr + 8) >> 2];
10046
- var func = Asyncify.callStackIdToFunc.get(id);
10047
- return func;
10048
- },
10049
- doRewind(ptr) {
10050
- var original = Asyncify.getDataRewindFunc(ptr);
10051
- var func = Asyncify.funcWrappers.get(original);
10052
- // Once we have rewound and the stack we no longer need to artificially
10053
- // keep the runtime alive.
10054
- runtimeKeepalivePop();
10055
- return func();
10056
- },
10057
- handleSleep(startAsync) {
10058
- if (ABORT) return;
10059
- if (Asyncify.state === Asyncify.State.Normal) {
10060
- // Prepare to sleep. Call startAsync, and see what happens:
10061
- // if the code decided to call our callback synchronously,
10062
- // then no async operation was in fact begun, and we don't
10063
- // need to do anything.
10064
- var reachedCallback = false;
10065
- var reachedAfterCallback = false;
10066
- startAsync((handleSleepReturnValue = 0) => {
10067
- if (ABORT) return;
10068
- Asyncify.handleSleepReturnValue = handleSleepReturnValue;
10069
- reachedCallback = true;
10070
- if (!reachedAfterCallback) {
10071
- // We are happening synchronously, so no need for async.
10072
- return;
10073
- }
10074
- Asyncify.state = Asyncify.State.Rewinding;
10075
- runAndAbortIfError(() =>
10076
- _asyncify_start_rewind(Asyncify.currData)
10077
- );
10078
- if (typeof MainLoop != 'undefined' && MainLoop.func) {
10079
- MainLoop.resume();
10080
- }
10081
- var asyncWasmReturnValue,
10082
- isError = false;
10083
- try {
10084
- asyncWasmReturnValue = Asyncify.doRewind(
10085
- Asyncify.currData
10086
- );
10087
- } catch (err) {
10088
- asyncWasmReturnValue = err;
10089
- isError = true;
10090
- }
10091
- // Track whether the return value was handled by any promise handlers.
10092
- var handled = false;
10093
- if (!Asyncify.currData) {
10094
- // All asynchronous execution has finished.
10095
- // `asyncWasmReturnValue` now contains the final
10096
- // return value of the exported async WASM function.
10097
- // Note: `asyncWasmReturnValue` is distinct from
10098
- // `Asyncify.handleSleepReturnValue`.
10099
- // `Asyncify.handleSleepReturnValue` contains the return
10100
- // value of the last C function to have executed
10101
- // `Asyncify.handleSleep()`, where as `asyncWasmReturnValue`
10102
- // contains the return value of the exported WASM function
10103
- // that may have called C functions that
10104
- // call `Asyncify.handleSleep()`.
10105
- var asyncPromiseHandlers =
10106
- Asyncify.asyncPromiseHandlers;
10107
- if (asyncPromiseHandlers) {
10108
- Asyncify.asyncPromiseHandlers = null;
10109
- (isError
10110
- ? asyncPromiseHandlers.reject
10111
- : asyncPromiseHandlers.resolve)(
10112
- asyncWasmReturnValue
10113
- );
10114
- handled = true;
10115
- }
10116
- }
10117
- if (isError && !handled) {
10118
- // If there was an error and it was not handled by now, we have no choice but to
10119
- // rethrow that error into the global scope where it can be caught only by
10120
- // `onerror` or `onunhandledpromiserejection`.
10121
- throw asyncWasmReturnValue;
10122
- }
10123
- });
10124
- reachedAfterCallback = true;
10125
- if (!reachedCallback) {
10126
- // A true async operation was begun; start a sleep.
10127
- Asyncify.state = Asyncify.State.Unwinding;
10128
- // TODO: reuse, don't alloc/free every sleep
10129
- if (!Asyncify._cachedData) {
10130
- Asyncify._cachedData = Asyncify.allocateData();
10131
- } else {
10132
- Asyncify.setDataHeader(
10133
- Asyncify._cachedData,
10134
- Asyncify._cachedData + 12,
10135
- Asyncify.StackSize
10136
- );
10137
- Asyncify.setDataRewindFunc(Asyncify._cachedData);
10138
- }
10139
- Asyncify.currData = Asyncify._cachedData;
10140
- if (typeof MainLoop != 'undefined' && MainLoop.func) {
10141
- MainLoop.pause();
10142
- }
10143
- runAndAbortIfError(() =>
10144
- _asyncify_start_unwind(Asyncify.currData)
10145
- );
10146
- }
10147
- } else if (Asyncify.state === Asyncify.State.Rewinding) {
10148
- // Stop a resume.
10149
- Asyncify.state = Asyncify.State.Normal;
10150
- runAndAbortIfError(_asyncify_stop_rewind);
10151
- Asyncify.currData = null;
10152
- // Call all sleep callbacks now that the sleep-resume is all done.
10153
- Asyncify.sleepCallbacks.forEach(callUserCallback);
10154
- } else {
10155
- abort(`invalid state: ${Asyncify.state}`);
10156
- }
10157
- return Asyncify.handleSleepReturnValue;
10158
- },
10159
- handleAsync: (startAsync) =>
10160
- Asyncify.handleSleep((wakeUp) => {
10161
- // TODO: add error handling as a second param when handleSleep implements it.
10162
- startAsync().then(wakeUp);
10163
- }),
10164
- };
10165
-
10166
10191
  var getCFunc = (ident) => {
10167
10192
  var func = Module['_' + ident];
10168
10193
  // closure exported function
@@ -10631,10 +10656,7 @@ export function init(RuntimeName, PHPLoader) {
10631
10656
  return ERRNO_CODES.EWOULDBLOCK;
10632
10657
  }
10633
10658
  return returnCallback(async (wakeUp) => {
10634
- var retries = 0;
10635
10659
  var interval = 50;
10636
- var timeout = 5e3;
10637
- var maxRetries = timeout / interval;
10638
10660
  while (true) {
10639
10661
  var returnCode;
10640
10662
  var stream;
@@ -10658,7 +10680,6 @@ export function init(RuntimeName, PHPLoader) {
10658
10680
  return wakeUp(0);
10659
10681
  }
10660
10682
  if (
10661
- ++retries > maxRetries ||
10662
10683
  !stream ||
10663
10684
  FS.isClosed(stream) ||
10664
10685
  returnCode !== ERRNO_CODES.EWOULDBLOCK ||
@@ -11920,57 +11941,57 @@ export function init(RuntimeName, PHPLoader) {
11920
11941
  wasmExports['__indirect_function_table'];
11921
11942
  }
11922
11943
 
11923
- var _core_globals = (Module['_core_globals'] = 11043392);
11944
+ var _core_globals = (Module['_core_globals'] = 11043296);
11924
11945
 
11925
- var _php_ini_opened_path = (Module['_php_ini_opened_path'] = 10973376);
11946
+ var _php_ini_opened_path = (Module['_php_ini_opened_path'] = 10973280);
11926
11947
 
11927
- var _php_ini_scanned_path = (Module['_php_ini_scanned_path'] = 10973380);
11948
+ var _php_ini_scanned_path = (Module['_php_ini_scanned_path'] = 10973284);
11928
11949
 
11929
- var _php_ini_scanned_files = (Module['_php_ini_scanned_files'] = 10973384);
11950
+ var _php_ini_scanned_files = (Module['_php_ini_scanned_files'] = 10973288);
11930
11951
 
11931
- var _sapi_module = (Module['_sapi_module'] = 10987160);
11952
+ var _sapi_module = (Module['_sapi_module'] = 10987064);
11932
11953
 
11933
- var _sapi_globals = (Module['_sapi_globals'] = 10987304);
11954
+ var _sapi_globals = (Module['_sapi_globals'] = 10987208);
11934
11955
 
11935
- var _compiler_globals = (Module['_compiler_globals'] = 10971640);
11956
+ var _compiler_globals = (Module['_compiler_globals'] = 10971544);
11936
11957
 
11937
- var _executor_globals = (Module['_executor_globals'] = 10972056);
11958
+ var _executor_globals = (Module['_executor_globals'] = 10971960);
11938
11959
 
11939
- var _zend_compile_file = (Module['_zend_compile_file'] = 10973192);
11960
+ var _zend_compile_file = (Module['_zend_compile_file'] = 10973096);
11940
11961
 
11941
- var _zend_execute_ex = (Module['_zend_execute_ex'] = 10966168);
11962
+ var _zend_execute_ex = (Module['_zend_execute_ex'] = 10966072);
11942
11963
 
11943
- var _zend_execute_internal = (Module['_zend_execute_internal'] = 10966172);
11964
+ var _zend_execute_internal = (Module['_zend_execute_internal'] = 10966076);
11944
11965
 
11945
- var _zend_write = (Module['_zend_write'] = 10971576);
11966
+ var _zend_write = (Module['_zend_write'] = 10971480);
11946
11967
 
11947
- var _zend_error_cb = (Module['_zend_error_cb'] = 10971584);
11968
+ var _zend_error_cb = (Module['_zend_error_cb'] = 10971488);
11948
11969
 
11949
- var _zend_post_startup_cb = (Module['_zend_post_startup_cb'] = 10971556);
11970
+ var _zend_post_startup_cb = (Module['_zend_post_startup_cb'] = 10971460);
11950
11971
 
11951
- var _module_registry = (Module['_module_registry'] = 10966176);
11972
+ var _module_registry = (Module['_module_registry'] = 10966080);
11952
11973
 
11953
- var _zend_ce_traversable = (Module['_zend_ce_traversable'] = 10963624);
11974
+ var _zend_ce_traversable = (Module['_zend_ce_traversable'] = 10963528);
11954
11975
 
11955
- var _zend_ce_iterator = (Module['_zend_ce_iterator'] = 10963632);
11976
+ var _zend_ce_iterator = (Module['_zend_ce_iterator'] = 10963536);
11956
11977
 
11957
- var _zend_ce_countable = (Module['_zend_ce_countable'] = 10963644);
11978
+ var _zend_ce_countable = (Module['_zend_ce_countable'] = 10963548);
11958
11979
 
11959
- var _zend_ce_exception = (Module['_zend_ce_exception'] = 10963364);
11980
+ var _zend_ce_exception = (Module['_zend_ce_exception'] = 10963268);
11960
11981
 
11961
- var _zend_ce_error = (Module['_zend_ce_error'] = 10963492);
11982
+ var _zend_ce_error = (Module['_zend_ce_error'] = 10963396);
11962
11983
 
11963
11984
  var _zend_throw_exception_hook = (Module['_zend_throw_exception_hook'] =
11964
- 10963356);
11985
+ 10963260);
11965
11986
 
11966
- var _gc_collect_cycles = (Module['_gc_collect_cycles'] = 10967332);
11987
+ var _gc_collect_cycles = (Module['_gc_collect_cycles'] = 10967236);
11967
11988
 
11968
- var _zend_ce_closure = (Module['_zend_ce_closure'] = 10963504);
11989
+ var _zend_ce_closure = (Module['_zend_ce_closure'] = 10963408);
11969
11990
 
11970
- var _zend_empty_string = (Module['_zend_empty_string'] = 10961736);
11991
+ var _zend_empty_string = (Module['_zend_empty_string'] = 10961640);
11971
11992
 
11972
11993
  var _zend_string_init_interned = (Module['_zend_string_init_interned'] =
11973
- 10961804);
11994
+ 10961708);
11974
11995
 
11975
11996
  var _std_object_handlers = (Module['_std_object_handlers'] = 10207080);
11976
11997
 
@@ -11982,20 +12003,20 @@ export function init(RuntimeName, PHPLoader) {
11982
12003
 
11983
12004
  var _stderr = (Module['_stderr'] = 10954880);
11984
12005
 
11985
- var ___THREW__ = (Module['___THREW__'] = 11092084);
12006
+ var ___THREW__ = (Module['___THREW__'] = 11091988);
11986
12007
 
11987
- var ___threwValue = (Module['___threwValue'] = 11092088);
12008
+ var ___threwValue = (Module['___threwValue'] = 11091992);
11988
12009
 
11989
12010
  var _stdout = (Module['_stdout'] = 10955184);
11990
12011
 
11991
- var _timezone = (Module['_timezone'] = 11078848);
12012
+ var _timezone = (Module['_timezone'] = 11078752);
11992
12013
 
11993
- var _tzname = (Module['_tzname'] = 11078856);
12014
+ var _tzname = (Module['_tzname'] = 11078760);
11994
12015
 
11995
- var ___heap_base = 12140768;
12016
+ var ___heap_base = 12140672;
11996
12017
 
11997
12018
  var __ZNSt3__25ctypeIcE2idE = (Module['__ZNSt3__25ctypeIcE2idE'] =
11998
- 11092172);
12019
+ 11092076);
11999
12020
 
12000
12021
  var __ZTVN10__cxxabiv120__si_class_type_infoE = (Module[
12001
12022
  '__ZTVN10__cxxabiv120__si_class_type_infoE'