Skip to content

Commit 20d18db

Browse files
authored
Merge branch 'main' into perf_sqlite_pragma
2 parents 30eeab9 + 0f9df73 commit 20d18db

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

ext/web/02_event.js

+9
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,15 @@ class EventTarget {
10561056
prefix: "Failed to execute 'dispatchEvent' on 'EventTarget'",
10571057
});
10581058

1059+
// This is an optimization to avoid creating an event listener
1060+
// on each startup.
1061+
// Stores the flag for checking whether unload is dispatched or not.
1062+
// This prevents the recursive dispatches of unload events.
1063+
// See https://github.com/denoland/deno/issues/9201.
1064+
if (event.type === "unload" && self === globalThis_) {
1065+
globalThis_[SymbolFor("isUnloadDispatched")] = true;
1066+
}
1067+
10591068
const { listeners } = self[eventTargetData];
10601069
if (!ReflectHas(listeners, event.type)) {
10611070
setTarget(event, this);

runtime/js/99_main.js

-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const {
3030
ObjectSetPrototypeOf,
3131
PromiseResolve,
3232
Symbol,
33-
SymbolFor,
3433
SymbolIterator,
3534
PromisePrototypeThen,
3635
SafeWeakMap,
@@ -404,7 +403,6 @@ function bootstrapMainRuntime(runtimeOptions) {
404403
if (hasBootstrapped) {
405404
throw new Error("Worker runtime already bootstrapped");
406405
}
407-
408406
performance.setTimeOrigin(DateNow());
409407
globalThis_ = globalThis;
410408

@@ -451,15 +449,6 @@ function bootstrapMainRuntime(runtimeOptions) {
451449

452450
core.setPromiseRejectCallback(promiseRejectCallback);
453451

454-
const isUnloadDispatched = SymbolFor("isUnloadDispatched");
455-
// Stores the flag for checking whether unload is dispatched or not.
456-
// This prevents the recursive dispatches of unload events.
457-
// See https://github.com/denoland/deno/issues/9201.
458-
globalThis[isUnloadDispatched] = false;
459-
globalThis.addEventListener("unload", () => {
460-
globalThis_[isUnloadDispatched] = true;
461-
});
462-
463452
runtimeStart(runtimeOptions);
464453

465454
setNumCpus(runtimeOptions.cpuCount);

0 commit comments

Comments
 (0)