File tree 2 files changed +9
-11
lines changed
2 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -1056,6 +1056,15 @@ class EventTarget {
1056
1056
prefix : "Failed to execute 'dispatchEvent' on 'EventTarget'" ,
1057
1057
} ) ;
1058
1058
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
+
1059
1068
const { listeners } = self [ eventTargetData ] ;
1060
1069
if ( ! ReflectHas ( listeners , event . type ) ) {
1061
1070
setTarget ( event , this ) ;
Original file line number Diff line number Diff line change @@ -30,7 +30,6 @@ const {
30
30
ObjectSetPrototypeOf,
31
31
PromiseResolve,
32
32
Symbol,
33
- SymbolFor,
34
33
SymbolIterator,
35
34
PromisePrototypeThen,
36
35
SafeWeakMap,
@@ -404,7 +403,6 @@ function bootstrapMainRuntime(runtimeOptions) {
404
403
if ( hasBootstrapped ) {
405
404
throw new Error ( "Worker runtime already bootstrapped" ) ;
406
405
}
407
-
408
406
performance . setTimeOrigin ( DateNow ( ) ) ;
409
407
globalThis_ = globalThis ;
410
408
@@ -451,15 +449,6 @@ function bootstrapMainRuntime(runtimeOptions) {
451
449
452
450
core . setPromiseRejectCallback ( promiseRejectCallback ) ;
453
451
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
-
463
452
runtimeStart ( runtimeOptions ) ;
464
453
465
454
setNumCpus ( runtimeOptions . cpuCount ) ;
You can’t perform that action at this time.
0 commit comments