diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2022-05-20 11:57:05 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 11:57:05 +0900 |
commit | e7c894e8f54ebd2d9fd61c97a265906ac54e2068 (patch) | |
tree | 86ae707a89d2e069bfdfb93a32b7c9525e010680 | |
parent | 0a96cb62a83f1d881ebc7fd93dee1796d20f17ff (diff) |
fix: prevent Deno.exit to fail when dispatchEvent tampered (#14665)
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
-rw-r--r-- | cli/tests/integration/run_tests.rs | 6 | ||||
-rw-r--r-- | cli/tests/testdata/deno_exit_tampering.ts | 3 | ||||
-rw-r--r-- | runtime/js/30_os.js | 4 |
3 files changed, 12 insertions, 1 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index a9e7d93cc..f5929ee55 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -922,6 +922,12 @@ itest!(set_exit_code_in_worker { exit_code: 42, }); +itest!(deno_exit_tampering { + args: "run --no-check --unstable deno_exit_tampering.ts", + output: "empty.out", + exit_code: 42, +}); + itest!(heapstats { args: "run --quiet --unstable --v8-flags=--expose-gc heapstats.js", output: "heapstats.js.out", diff --git a/cli/tests/testdata/deno_exit_tampering.ts b/cli/tests/testdata/deno_exit_tampering.ts new file mode 100644 index 000000000..3b24261e2 --- /dev/null +++ b/cli/tests/testdata/deno_exit_tampering.ts @@ -0,0 +1,3 @@ +delete globalThis.dispatchEvent; +delete EventTarget.prototype.dispatchEvent; +Deno.exit(42); diff --git a/runtime/js/30_os.js b/runtime/js/30_os.js index e8467c268..9cc2ba5c7 100644 --- a/runtime/js/30_os.js +++ b/runtime/js/30_os.js @@ -8,6 +8,8 @@ SymbolFor, } = window.__bootstrap.primordials; + const windowDispatchEvent = window.dispatchEvent.bind(window); + function loadavg() { return core.opSync("op_loadavg"); } @@ -51,7 +53,7 @@ if (!window[SymbolFor("isUnloadDispatched")]) { // Invokes the `unload` hooks before exiting // ref: https://github.com/denoland/deno/issues/3603 - window.dispatchEvent(new Event("unload")); + windowDispatchEvent(new Event("unload")); } if (exitHandler) { |