diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2021-01-12 19:32:58 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-12 05:32:58 -0500 |
commit | fd56fa89f36016a816450cd0e8df5853c66d170c (patch) | |
tree | 7d21163bf2a1c5a4d5f73f998afbaa2e4c2b7a91 | |
parent | 5c6ab75de1e5817df3620a5cdd85eba748b2a8a6 (diff) |
fix(cli): dispatch unload on exit (#9088)
-rw-r--r-- | cli/tests/078_unload_on_exit.ts | 4 | ||||
-rw-r--r-- | cli/tests/078_unload_on_exit.ts.out | 1 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 5 | ||||
-rw-r--r-- | runtime/js/30_os.js | 3 |
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"); } |