@@ -960,7 +960,7 @@ var LibraryPThread = {
960
960
$proxyToMainThreadPtr: (...args) => BigInt(proxyToMainThread(...args)),
961
961
#endif
962
962
963
- $proxyToMainThread__deps: ['$withStackSave ', '$stackAlloc', '_emscripten_run_on_main_thread_js'].concat(i53ConversionDeps),
963
+ $proxyToMainThread__deps: ['$stackSave', '$stackRestore ', '$stackAlloc', '_emscripten_run_on_main_thread_js'].concat(i53ConversionDeps),
964
964
$proxyToMainThread__docs: '/** @type{function(number, (number|boolean), ...number)} */',
965
965
$proxyToMainThread: (funcIndex, emAsmAddr, sync, ...callArgs) => {
966
966
// EM_ASM proxying is done by passing a pointer to the address of the EM_ASM
@@ -973,34 +973,36 @@ var LibraryPThread = {
973
973
// all the args here.
974
974
// We also pass 'sync' to C separately, since C needs to look at it.
975
975
// Allocate a buffer, which will be copied by the C code.
976
- return withStackSave(() => {
977
- // First passed parameter specifies the number of arguments to the function.
978
- // When BigInt support is enabled, we must handle types in a more complex
979
- // way, detecting at runtime if a value is a BigInt or not (as we have no
980
- // type info here). To do that, add a "prefix" before each value that
981
- // indicates if it is a BigInt, which effectively doubles the number of
982
- // values we serialize for proxying. TODO: pack this?
983
- var serializedNumCallArgs = callArgs.length {{{ WASM_BIGINT ? "* 2" : "" }}};
984
- var args = stackAlloc(serializedNumCallArgs * 8);
985
- var b = {{{ getHeapOffset('args', 'i64') }}};
986
- for (var i = 0; i < callArgs.length; i++) {
987
- var arg = callArgs[i];
976
+ //
977
+ // First passed parameter specifies the number of arguments to the function.
978
+ // When BigInt support is enabled, we must handle types in a more complex
979
+ // way, detecting at runtime if a value is a BigInt or not (as we have no
980
+ // type info here). To do that, add a "prefix" before each value that
981
+ // indicates if it is a BigInt, which effectively doubles the number of
982
+ // values we serialize for proxying. TODO: pack this?
983
+ var serializedNumCallArgs = callArgs.length {{{ WASM_BIGINT ? "* 2" : "" }}};
984
+ var sp = stackSave();
985
+ var args = stackAlloc(serializedNumCallArgs * 8);
986
+ var b = {{{ getHeapOffset('args', 'i64') }}};
987
+ for (var i = 0; i < callArgs.length; i++) {
988
+ var arg = callArgs[i];
988
989
#if WASM_BIGINT
989
- if (typeof arg == 'bigint') {
990
- // The prefix is non-zero to indicate a bigint.
991
- HEAP64[b + 2*i] = 1n;
992
- HEAP64[b + 2*i + 1] = arg;
993
- } else {
994
- // The prefix is zero to indicate a JS Number.
995
- HEAP64[b + 2*i] = 0n;
996
- HEAPF64[b + 2*i + 1] = arg;
997
- }
990
+ if (typeof arg == 'bigint') {
991
+ // The prefix is non-zero to indicate a bigint.
992
+ HEAP64[b + 2*i] = 1n;
993
+ HEAP64[b + 2*i + 1] = arg;
994
+ } else {
995
+ // The prefix is zero to indicate a JS Number.
996
+ HEAP64[b + 2*i] = 0n;
997
+ HEAPF64[b + 2*i + 1] = arg;
998
+ }
998
999
#else
999
- HEAPF64[b + i] = arg;
1000
+ HEAPF64[b + i] = arg;
1000
1001
#endif
1001
- }
1002
- return __emscripten_run_on_main_thread_js(funcIndex, emAsmAddr, serializedNumCallArgs, args, sync);
1003
- });
1002
+ }
1003
+ var rtn = __emscripten_run_on_main_thread_js(funcIndex, emAsmAddr, serializedNumCallArgs, args, sync);
1004
+ stackRestore(sp);
1005
+ return rtn;
1004
1006
},
1005
1007
1006
1008
// Reuse global JS array to avoid creating JS garbage for each proxied call
0 commit comments