summaryrefslogtreecommitdiff
path: root/runtime/js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2021-11-28 00:45:38 +0100
committerGitHub <noreply@github.com>2021-11-28 00:45:38 +0100
commit993a1dd41ae5f96bdb24b09757e24c2ac24126d0 (patch)
tree8b6c0d4de8f8101bf8a3c31fe4f163d18c2c298e /runtime/js
parent1d3f734e1815bf1649e0cac445be9eacb4cd296d (diff)
feat(runtime): add op_set_exit_code (#12911)
Set the exit code to use if none is provided to Deno.exit(), or when Deno exits naturally. Needed for process.exitCode Node compat. Paves the way for #12888.
Diffstat (limited to 'runtime/js')
-rw-r--r--runtime/js/30_os.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/runtime/js/30_os.js b/runtime/js/30_os.js
index 15df6f554..f6bada6a5 100644
--- a/runtime/js/30_os.js
+++ b/runtime/js/30_os.js
@@ -31,7 +31,14 @@
exitHandler = fn;
}
- function exit(code = 0) {
+ function exit(code) {
+ // Set exit code first so unload event listeners can override it.
+ if (typeof code === "number") {
+ core.opSync("op_set_exit_code", code);
+ } else {
+ code = 0;
+ }
+
// Dispatches `unload` only when it's not dispatched yet.
if (!window[SymbolFor("isUnloadDispatched")]) {
// Invokes the `unload` hooks before exiting
@@ -44,7 +51,7 @@
return;
}
- core.opSync("op_exit", code);
+ core.opSync("op_exit");
throw new Error("Code not reachable");
}