diff --git a/src/lib/libasync.js b/src/lib/libasync.js index 71893b6f19e78..3664038bea99e 100644 --- a/src/lib/libasync.js +++ b/src/lib/libasync.js @@ -323,10 +323,9 @@ addToLibrary({ // can just call the function with no args at all since the engine will produce zeros // for all arguments. However, for i64 arguments we get `undefined cannot be converted to // BigInt`. - return func(...Asyncify.restoreRewindArguments(original)); -#else - return func(); + func = func.bind(0, ...Asyncify.restoreRewindArguments(original)); #endif + return callUserCallback(func); }, // This receives a function to call to start the async operation, and @@ -480,9 +479,8 @@ addToLibrary({ #endif }, - emscripten_sleep__deps: ['$safeSetTimeout'], emscripten_sleep__async: true, - emscripten_sleep: (ms) => Asyncify.handleSleep((wakeUp) => safeSetTimeout(wakeUp, ms)), + emscripten_sleep: (ms) => Asyncify.handleSleep((wakeUp) => setTimeout(wakeUp, ms)), emscripten_wget_data__deps: ['$asyncLoad', 'malloc'], emscripten_wget_data__async: 'auto', @@ -501,7 +499,6 @@ addToLibrary({ } }, - emscripten_scan_registers__deps: ['$safeSetTimeout'], emscripten_scan_registers__async: true, emscripten_scan_registers: (func) => { return Asyncify.handleSleep((wakeUp) => { @@ -509,7 +506,7 @@ addToLibrary({ // we are pausing we do the actual scan. After that we can resume. Note // how using a timeout here avoids unbounded call stack growth, which // could happen if we tried to scan the stack immediately after unwinding. - safeSetTimeout(() => { + setTimeout(() => { var stackBegin = Asyncify.currData + {{{ C_STRUCTS.asyncify_data_s.__size__ }}}; var stackEnd = {{{ makeGetValue('Asyncify.currData', 0, '*') }}}; {{{ makeDynCall('vpp', 'func') }}}(stackBegin, stackEnd); diff --git a/src/lib/libcore.js b/src/lib/libcore.js index 958aa1e5a9eae..0ccf09ed67632 100644 --- a/src/lib/libcore.js +++ b/src/lib/libcore.js @@ -1996,6 +1996,9 @@ addToLibrary({ err('Stack overflow detected. You can try increasing -sSTACK_SIZE (currently set to {{{ STACK_SIZE }}})'); } } +#endif +#if RUNTIME_DEBUG + dbg("handleException: got unexpected exception, calling quit_") #endif quit_(1, e); }, @@ -2066,10 +2069,11 @@ addToLibrary({ return; } try { - func(); - maybeExit(); + return func(); } catch (e) { handleException(e); + } finally { + maybeExit(); } }, diff --git a/test/codesize/test_codesize_cxx_lto.json b/test/codesize/test_codesize_cxx_lto.json index f940e9bb676e5..e377761f03c37 100644 --- a/test/codesize/test_codesize_cxx_lto.json +++ b/test/codesize/test_codesize_cxx_lto.json @@ -1,10 +1,10 @@ { - "a.out.js": 18993, - "a.out.js.gz": 7823, + "a.out.js": 19001, + "a.out.js.gz": 7824, "a.out.nodebug.wasm": 106448, "a.out.nodebug.wasm.gz": 42638, - "total": 125441, - "total_gz": 50461, + "total": 125449, + "total_gz": 50462, "sent": [ "a (emscripten_resize_heap)", "b (_setitimer_js)", diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index e3040a1f35327..eacfe85951b16 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { - "a.out.js": 244848, + "a.out.js": 244863, "a.out.nodebug.wasm": 577879, - "total": 822727, + "total": 822742, "sent": [ "IMG_Init", "IMG_Load", diff --git a/test/codesize/test_codesize_minimal_pthreads.json b/test/codesize/test_codesize_minimal_pthreads.json index e1047891f0a3e..e84f8e5da9f0e 100644 --- a/test/codesize/test_codesize_minimal_pthreads.json +++ b/test/codesize/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { - "a.out.js": 7722, - "a.out.js.gz": 3812, + "a.out.js": 7737, + "a.out.js.gz": 3816, "a.out.nodebug.wasm": 19604, "a.out.nodebug.wasm.gz": 9079, - "total": 27326, - "total_gz": 12891, + "total": 27341, + "total_gz": 12895, "sent": [ "a (memory)", "b (emscripten_get_now)", diff --git a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json index 5439f3a922107..c1b3e56b8cd0e 100644 --- a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { - "a.out.js": 8145, - "a.out.js.gz": 4011, + "a.out.js": 8160, + "a.out.js.gz": 4015, "a.out.nodebug.wasm": 19605, "a.out.nodebug.wasm.gz": 9080, - "total": 27750, - "total_gz": 13091, + "total": 27765, + "total_gz": 13095, "sent": [ "a (memory)", "b (emscripten_get_now)", diff --git a/test/embind_with_asyncify.cpp b/test/embind_with_asyncify.cpp index 7a8c2df72015e..b5893744df36d 100644 --- a/test/embind_with_asyncify.cpp +++ b/test/embind_with_asyncify.cpp @@ -15,8 +15,5 @@ int main() { val async_text = response.call("text"); std::string text = async_text.await().as(); assert(text == "foo"); - // This explicit exit() should not be necessary here. - // TODO(https://github.com/emscripten-core/emscripten/issues/26093) - exit(0); return 0; } diff --git a/test/test_async_exit_after_wakeup.js b/test/test_async_exit_after_wakeup.js index 860d0ff803b16..e648efd02f336 100644 --- a/test/test_async_exit_after_wakeup.js +++ b/test/test_async_exit_after_wakeup.js @@ -2,11 +2,7 @@ addToLibrary({ async_func__async: true, async_func: (value) => { return Asyncify.handleSleep((wakeUp) => { - // Currently with -sASYNCIFY the wakeUp call needs to be wrapped in - // callUserCallback, otherwise things like `exit()` won't work from - // the continuation. - // TODO(https://github.com/emscripten-core/emscripten/issues/26093) - setTimeout(() => callUserCallback(() => wakeUp(42)), 0); + setTimeout(() => wakeUp(42), 0); }); }, }); diff --git a/test/test_core.py b/test/test_core.py index b911cb30e32ce..929e6f9b32ddf 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -9587,7 +9587,7 @@ def test_embind_lib_with_asyncify(self, args): '-sINCOMING_MODULE_JS_API=onRuntimeInitialized', ] self.cflags += args - self.do_core_test('embind_lib_with_asyncify.cpp') + self.do_core_test('embind_lib_with_asyncify.cpp', assert_returncode=NON_ZERO) @no_asan('asyncify stack operations confuse asan') @with_asyncify_and_jspi