diff options
Diffstat (limited to 'runtime/js/30_os.js')
-rw-r--r-- | runtime/js/30_os.js | 11 |
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"); } |