Skip to content

Commit

Permalink
fix(cli): dispatch unload on exit (#9088)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Jan 12, 2021
1 parent 5c6ab75 commit fd56fa8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/tests/078_unload_on_exit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
window.onunload = () => {
console.log("onunload is called");
};
Deno.exit(0);
1 change: 1 addition & 0 deletions cli/tests/078_unload_on_exit.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[WILDCARD]onunload is called
5 changes: 5 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions runtime/js/30_os.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit fd56fa8

Please sign in to comment.