Skip to content

Commit ee1f567

Browse files
committed
[ASYNCIFY] Run continuations under callUserCallback
1 parent 877dc2c commit ee1f567

8 files changed

+25
-26
lines changed

src/lib/libasync.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,9 @@ addToLibrary({
323323
// can just call the function with no args at all since the engine will produce zeros
324324
// for all arguments. However, for i64 arguments we get `undefined cannot be converted to
325325
// BigInt`.
326-
return func(...Asyncify.restoreRewindArguments(original));
327-
#else
328-
return func();
326+
func = func.bind(0, ...Asyncify.restoreRewindArguments(original));
329327
#endif
328+
return callUserCallback(func);
330329
},
331330

332331
// This receives a function to call to start the async operation, and
@@ -482,7 +481,7 @@ addToLibrary({
482481

483482
emscripten_sleep__deps: ['$safeSetTimeout'],
484483
emscripten_sleep__async: true,
485-
emscripten_sleep: (ms) => Asyncify.handleSleep((wakeUp) => safeSetTimeout(wakeUp, ms)),
484+
emscripten_sleep: (ms) => Asyncify.handleSleep((wakeUp) => setTimeout(wakeUp, ms)),
486485

487486
emscripten_wget_data__deps: ['$asyncLoad', 'malloc'],
488487
emscripten_wget_data__async: true,

src/lib/libcore.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,9 @@ addToLibrary({
19961996
err('Stack overflow detected. You can try increasing -sSTACK_SIZE (currently set to {{{ STACK_SIZE }}})');
19971997
}
19981998
}
1999+
#endif
2000+
#if RUNTIME_DEBUG
2001+
dbg("handleException: got unexpected exception, calling quit_")
19992002
#endif
20002003
quit_(1, e);
20012004
},
@@ -2066,10 +2069,11 @@ addToLibrary({
20662069
return;
20672070
}
20682071
try {
2069-
func();
2070-
maybeExit();
2072+
return func();
20712073
} catch (e) {
20722074
handleException(e);
2075+
} finally {
2076+
maybeExit();
20732077
}
20742078
},
20752079

test/codesize/test_codesize_cxx_lto.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 18993,
3-
"a.out.js.gz": 7823,
2+
"a.out.js": 19001,
3+
"a.out.js.gz": 7824,
44
"a.out.nodebug.wasm": 106448,
55
"a.out.nodebug.wasm.gz": 42638,
6-
"total": 125441,
7-
"total_gz": 50461,
6+
"total": 125449,
7+
"total_gz": 50462,
88
"sent": [
99
"a (emscripten_resize_heap)",
1010
"b (_setitimer_js)",

test/codesize/test_codesize_hello_dylink_all.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"a.out.js": 244848,
2+
"a.out.js": 244863,
33
"a.out.nodebug.wasm": 577879,
4-
"total": 822727,
4+
"total": 822742,
55
"sent": [
66
"IMG_Init",
77
"IMG_Load",

test/codesize/test_codesize_minimal_pthreads.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 7722,
3-
"a.out.js.gz": 3812,
2+
"a.out.js": 7737,
3+
"a.out.js.gz": 3816,
44
"a.out.nodebug.wasm": 19604,
55
"a.out.nodebug.wasm.gz": 9079,
6-
"total": 27326,
7-
"total_gz": 12891,
6+
"total": 27341,
7+
"total_gz": 12895,
88
"sent": [
99
"a (memory)",
1010
"b (emscripten_get_now)",

test/codesize/test_codesize_minimal_pthreads_memgrowth.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"a.out.js": 8145,
3-
"a.out.js.gz": 4011,
2+
"a.out.js": 8160,
3+
"a.out.js.gz": 4015,
44
"a.out.nodebug.wasm": 19605,
55
"a.out.nodebug.wasm.gz": 9080,
6-
"total": 27750,
7-
"total_gz": 13091,
6+
"total": 27765,
7+
"total_gz": 13095,
88
"sent": [
99
"a (memory)",
1010
"b (emscripten_get_now)",

test/test_async_exit_after_wakeup.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ addToLibrary({
22
async_func__async: true,
33
async_func: (value) => {
44
return Asyncify.handleSleep((wakeUp) => {
5-
// Currently with -sASYNCIFY the wakeUp call needs to be wrapped in
6-
// callUserCallback, otherwise things like `exit()` won't work from
7-
// the continuation.
8-
// TODO(https://github.com/emscripten-core/emscripten/issues/26093)
9-
setTimeout(() => callUserCallback(() => wakeUp(42)), 0);
5+
setTimeout(() => wakeUp(42), 0);
106
});
117
},
128
});

test/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9587,7 +9587,7 @@ def test_embind_lib_with_asyncify(self, args):
95879587
'-sINCOMING_MODULE_JS_API=onRuntimeInitialized',
95889588
]
95899589
self.cflags += args
9590-
self.do_core_test('embind_lib_with_asyncify.cpp')
9590+
self.do_core_test('embind_lib_with_asyncify.cpp', assert_returncode=NON_ZERO)
95919591

95929592
@no_asan('asyncify stack operations confuse asan')
95939593
@with_asyncify_and_jspi

0 commit comments

Comments
 (0)