Skip to content

Commit db0c026

Browse files
authored
Fix Asyncify in the d8 shell (#16340)
This is similar to the Node.js path. This code is necessary for us to throw an exception to stop execution, but keep going after it is caught, rather than call d8's quit which halts us immediately. Also remove some misleading annotations on tests. d8 does have setTimeout, despite what the comments say - but perhaps it didn't in the past.
1 parent 6298bd0 commit db0c026

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/shell.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,20 @@ if (ENVIRONMENT_IS_SHELL) {
309309

310310
if (typeof quit == 'function') {
311311
quit_ = (status, toThrow) => {
312+
// Unlike node which has process.exitCode, d8 has no such mechanism. So we
313+
// have no way to set the exit code and then let the program exit with
314+
// that code when it naturally stops running (say, when all setTimeouts
315+
// have completed). For that reason we must call `quit` - the only way to
316+
// set the exit code - but quit also halts immediately, so we need to be
317+
// careful of whether the runtime is alive or not, which is why this code
318+
// path looks different than node. It also has the downside that it will
319+
// halt the entire program when no code remains to run, which means this
320+
// is not friendly for bundling this code into a larger codebase, and for
321+
// that reason the "shell" environment is mainly useful for testing whole
322+
// programs by themselves, basically.
323+
if (runtimeKeepaliveCounter) {
324+
throw toThrow;
325+
}
312326
logExceptionOnExit(toThrow);
313327
quit(status);
314328
};

tests/test_core.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from common import RunnerCore, path_from_root, requires_native_clang, test_file, create_file
2727
from common import skip_if, needs_dylink, no_windows, no_mac, is_slow_test, parameterized
2828
from common import env_modify, with_env_modify, disabled, node_pthreads
29-
from common import read_file, read_binary, require_node, require_v8
29+
from common import read_file, read_binary, require_v8
3030
from common import NON_ZERO, WEBIDL_BINDER, EMBUILDER
3131
import clang_native
3232

@@ -7613,8 +7613,6 @@ def test_setlocale(self):
76137613
def test_vswprintf_utf8(self):
76147614
self.do_run_in_out_file_test('vswprintf_utf8.c')
76157615

7616-
# needs setTimeout which only node has
7617-
@require_node
76187616
@no_memory64('TODO: asyncify for wasm64')
76197617
def test_async_hello(self):
76207618
# needs to flush stdio streams
@@ -7640,7 +7638,11 @@ def test_async_hello(self):
76407638

76417639
self.do_runf('main.c', 'HelloWorld!99')
76427640

7643-
@require_node
7641+
@require_v8
7642+
@no_memory64('TODO: asyncify for wasm64')
7643+
def test_async_hello_v8(self):
7644+
self.test_async_hello()
7645+
76447646
@no_memory64('TODO: asyncify for wasm64')
76457647
def test_async_ccall_bad(self):
76467648
# check bad ccall use
@@ -7672,7 +7674,6 @@ def test_async_ccall_bad(self):
76727674
self.emcc_args += ['--pre-js', 'pre.js']
76737675
self.do_runf('main.c', 'The call to main is running asynchronously.')
76747676

7675-
@require_node
76767677
@no_memory64('TODO: asyncify for wasm64')
76777678
def test_async_ccall_good(self):
76787679
# check reasonable ccall use

0 commit comments

Comments
 (0)