summaryrefslogtreecommitdiff
path: root/runtime/js/30_os.js
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/js/30_os.js')
-rw-r--r--runtime/js/30_os.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/runtime/js/30_os.js b/runtime/js/30_os.js
index 236131432..23c3d8de6 100644
--- a/runtime/js/30_os.js
+++ b/runtime/js/30_os.js
@@ -24,6 +24,13 @@
return core.jsonOpSync("op_system_cpu_info");
}
+ // This is an internal only method used by the test harness to override the
+ // behavior of exit when the exit sanitizer is enabled.
+ let exitHandler = null;
+ function setExitHandler(fn) {
+ exitHandler = fn;
+ }
+
function exit(code = 0) {
// Dispatches `unload` only when it's not dispatched yet.
if (!window[Symbol.for("isUnloadDispatched")]) {
@@ -31,6 +38,12 @@
// ref: https://github.com/denoland/deno/issues/3603
window.dispatchEvent(new Event("unload"));
}
+
+ if (exitHandler) {
+ exitHandler(code);
+ return;
+ }
+
core.jsonOpSync("op_exit", { code });
throw new Error("Code not reachable");
}
@@ -63,6 +76,7 @@
window.__bootstrap.os = {
env,
execPath,
+ setExitHandler,
exit,
osRelease,
systemMemoryInfo,