summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/078_unload_on_exit.ts4
-rw-r--r--cli/tests/078_unload_on_exit.ts.out1
-rw-r--r--cli/tests/integration_tests.rs5
-rw-r--r--runtime/js/30_os.js3
4 files changed, 13 insertions, 0 deletions
diff --git a/cli/tests/078_unload_on_exit.ts b/cli/tests/078_unload_on_exit.ts
new file mode 100644
index 000000000..e8288ef31
--- /dev/null
+++ b/cli/tests/078_unload_on_exit.ts
@@ -0,0 +1,4 @@
+window.onunload = () => {
+ console.log("onunload is called");
+};
+Deno.exit(0);
diff --git a/cli/tests/078_unload_on_exit.ts.out b/cli/tests/078_unload_on_exit.ts.out
new file mode 100644
index 000000000..e213f9632
--- /dev/null
+++ b/cli/tests/078_unload_on_exit.ts.out
@@ -0,0 +1 @@
+[WILDCARD]onunload is called
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index feb3f7f04..40da5c627 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -2646,6 +2646,11 @@ itest!(_077_fetch_empty {
exit_code: 1,
});
+itest!(_078_unload_on_exit {
+ args: "run 078_unload_on_exit.ts",
+ output: "078_unload_on_exit.ts.out",
+});
+
itest!(js_import_detect {
args: "run --quiet --reload js_import_detect.ts",
output: "js_import_detect.ts.out",
diff --git a/runtime/js/30_os.js b/runtime/js/30_os.js
index 74af82124..1d700b561 100644
--- a/runtime/js/30_os.js
+++ b/runtime/js/30_os.js
@@ -24,6 +24,9 @@
}
function exit(code = 0) {
+ // Invokes the `unload` hooks before exiting
+ // ref: https://github.com/denoland/deno/issues/3603
+ window.dispatchEvent(new Event("unload"));
core.jsonOpSync("op_exit", { code });
throw new Error("Code not reachable");
}