From a080acc1b46ce9915760ce5c818763c64be8dca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 15 Apr 2024 19:08:33 +0100 Subject: 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 --- runtime/js/99_main.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'runtime/js') 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); -- cgit v1.2.3