mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(cli): dispatch unload on exit (#9088)
This commit is contained in:
parent
5c6ab75de1
commit
fd56fa89f3
4 changed files with 13 additions and 0 deletions
4
cli/tests/078_unload_on_exit.ts
Normal file
4
cli/tests/078_unload_on_exit.ts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
window.onunload = () => {
|
||||||
|
console.log("onunload is called");
|
||||||
|
};
|
||||||
|
Deno.exit(0);
|
1
cli/tests/078_unload_on_exit.ts.out
Normal file
1
cli/tests/078_unload_on_exit.ts.out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[WILDCARD]onunload is called
|
|
@ -2646,6 +2646,11 @@ itest!(_077_fetch_empty {
|
||||||
exit_code: 1,
|
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 {
|
itest!(js_import_detect {
|
||||||
args: "run --quiet --reload js_import_detect.ts",
|
args: "run --quiet --reload js_import_detect.ts",
|
||||||
output: "js_import_detect.ts.out",
|
output: "js_import_detect.ts.out",
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function exit(code = 0) {
|
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 });
|
core.jsonOpSync("op_exit", { code });
|
||||||
throw new Error("Code not reachable");
|
throw new Error("Code not reachable");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue