diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-04-15 19:08:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-15 20:08:33 +0200 |
commit | a080acc1b46ce9915760ce5c818763c64be8dca1 (patch) | |
tree | cbc44ea39628283b4ba73b6941bc2f9528b5b528 /runtime/js/99_main.js | |
parent | f36a8951a420e34d8189cda5792f5eeaa5ce85b7 (diff) |
refactor: move lifecycle events dispatch to Rust (#23358)
This commit moves logic of dispatching lifecycle events (
"load", "beforeunload", "unload") to be triggered from Rust.
Before that we were executing scripts from Rust, but now we
are storing references to functions from "99_main.js" and calling
them directly.
Prerequisite for https://github.com/denoland/deno/issues/23342
Diffstat (limited to 'runtime/js/99_main.js')
-rw-r--r-- | runtime/js/99_main.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index e5b9b9778..0241a1936 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -528,6 +528,20 @@ function processRejectionHandled(promise, reason) { } } +function dispatchLoadEvent() { + globalThis_.dispatchEvent(new Event("load")); +} + +function dispatchBeforeUnloadEvent() { + return globalThis_.dispatchEvent( + new Event("beforeunload", { cancelable: true }), + ); +} + +function dispatchUnloadEvent() { + globalThis_.dispatchEvent(new Event("unload")); +} + let hasBootstrapped = false; // Delete the `console` object that V8 automaticaly adds onto the global wrapper // object on context creation. We don't want this console object to shadow the @@ -995,6 +1009,9 @@ delete globalThis.nodeBootstrap; globalThis.bootstrap = { mainRuntime: bootstrapMainRuntime, workerRuntime: bootstrapWorkerRuntime, + dispatchLoadEvent, + dispatchUnloadEvent, + dispatchBeforeUnloadEvent, }; event.setEventTargetData(globalThis); |