@@ -121,7 +121,7 @@ export class DOMEvent implements Event {
121
121
122
122
// Strictly speaking, we should use { public get, private set } for all of
123
123
// `eventPhase`, `currentTarget`, and `target`, but using simple properties
124
- // saves 800 nanoseconds per run of handleEvent () (and so is one of our
124
+ // saves 800 nanoseconds per run of dispatchTo () (and so is one of our
125
125
// biggest optimisations).
126
126
127
127
/**
@@ -393,14 +393,6 @@ export class DOMEvent implements Event {
393
393
for ( let i = this . listenersLazyCopy . length - 1 ; i >= 0 ; i -- ) {
394
394
const listener = this . listenersLazyCopy [ i ] ;
395
395
396
- // Assigning variables this old-fashioned way is up to 50
397
- // nanoseconds faster per run than ESM destructuring syntax.
398
- const callback = listener . callback ;
399
- const capture = listener . capture ;
400
- const thisArg = listener . thisArg ;
401
- const once = listener . once ;
402
- const passive = listener . once ;
403
-
404
396
// The event listener may have been removed since we took a copy of
405
397
// the array, so bail out if so.
406
398
//
@@ -418,14 +410,21 @@ export class DOMEvent implements Event {
418
410
continue ;
419
411
}
420
412
413
+ // Assigning variables this old-fashioned way is up to 50
414
+ // nanoseconds faster per run than ESM destructuring syntax.
415
+ const capture = listener . capture ;
416
+
421
417
// Handle only the events appropriate to the phase. Global events
422
418
// (a NativeScript-only concept) are allowed to be handled
423
419
// regardless of phase, for backwards-compatibility.
424
420
if ( ! isGlobal && ( ( phase === DOMEvent . CAPTURING_PHASE && ! capture ) || ( phase === DOMEvent . BUBBLING_PHASE && capture ) ) ) {
425
421
continue ;
426
422
}
427
423
428
- if ( once ) {
424
+ const callback = listener . callback ;
425
+ const thisArg = listener . thisArg ;
426
+
427
+ if ( listener . once ) {
429
428
// Calling with the context (rather than eagerly pre-binding it)
430
429
// saves about 100 nanoseconds per dispatchTo() call.
431
430
removeEventListener . call ( removeEventListenerContext , this . type , callback , thisArg , capture ) ;
@@ -441,11 +440,14 @@ export class DOMEvent implements Event {
441
440
442
441
// This ensures that errors thrown inside asynchronous functions do
443
442
// not get swallowed.
443
+ //
444
+ // This check costs only 25 nanoseconds per dispatchTo(), so is not
445
+ // a huge deal.
444
446
if ( returnValue instanceof Promise ) {
445
447
returnValue . catch ( console . error ) ;
446
448
}
447
449
448
- if ( passive && this . defaultPrevented ) {
450
+ if ( listener . passive && this . defaultPrevented ) {
449
451
console . warn ( 'Unexpected call to event.preventDefault() in passive event listener.' ) ;
450
452
}
451
453
0 commit comments