summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/web/02_event.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/ext/web/02_event.js b/ext/web/02_event.js
index 40731af4c..dd8b4f57b 100644
--- a/ext/web/02_event.js
+++ b/ext/web/02_event.js
@@ -1056,6 +1056,15 @@ class EventTarget {
prefix: "Failed to execute 'dispatchEvent' on 'EventTarget'",
});
+ // This is an optimization to avoid creating an event listener
+ // on each startup.
+ // Stores the flag for checking whether unload is dispatched or not.
+ // This prevents the recursive dispatches of unload events.
+ // See https://github.com/denoland/deno/issues/9201.
+ if (event.type === "unload" && self === globalThis_) {
+ globalThis_[SymbolFor("isUnloadDispatched")] = true;
+ }
+
const { listeners } = self[eventTargetData];
if (!ReflectHas(listeners, event.type)) {
setTarget(event, this);