22
22
'use strict' ;
23
23
24
24
const {
25
- ArrayPrototypeForEach,
26
- ArrayPrototypePush,
27
25
ArrayPrototypeSlice,
28
26
Boolean,
29
27
Error,
30
28
ErrorCaptureStackTrace,
31
- FunctionPrototypeCall,
32
29
MathMin,
33
30
NumberIsNaN,
34
31
ObjectCreate,
@@ -39,7 +36,6 @@ const {
39
36
Promise,
40
37
PromiseReject,
41
38
PromiseResolve,
42
- ReflectApply,
43
39
ReflectOwnKeys,
44
40
String,
45
41
Symbol,
@@ -84,7 +80,7 @@ const lazyDOMException = hideStackFrames((message, name) => {
84
80
85
81
86
82
function EventEmitter ( opts ) {
87
- FunctionPrototypeCall ( EventEmitter . init , this , opts ) ;
83
+ EventEmitter . init . call ( this , opts ) ;
88
84
}
89
85
module . exports = EventEmitter ;
90
86
module . exports . once = once ;
@@ -175,8 +171,8 @@ EventEmitter.setMaxListeners =
175
171
if ( isEventTarget === undefined )
176
172
isEventTarget = require ( 'internal/event_target' ) . isEventTarget ;
177
173
178
- // Performance for forEach is now comparable with regular for-loop
179
- ArrayPrototypeForEach ( eventTargets , ( target ) => {
174
+ for ( let i = 0 ; i < eventTargets . length ; i ++ ) {
175
+ const target = eventTargets [ i ] ;
180
176
if ( isEventTarget ( target ) ) {
181
177
target [ kMaxEventTargetListeners ] = n ;
182
178
target [ kMaxEventTargetListenersWarned ] = false ;
@@ -188,7 +184,7 @@ EventEmitter.setMaxListeners =
188
184
[ 'EventEmitter' , 'EventTarget' ] ,
189
185
target ) ;
190
186
}
191
- } ) ;
187
+ }
192
188
}
193
189
} ;
194
190
@@ -227,7 +223,7 @@ function addCatch(that, promise, type, args) {
227
223
const then = promise . then ;
228
224
229
225
if ( typeof then === 'function' ) {
230
- FunctionPrototypeCall ( then , promise , undefined , function ( err ) {
226
+ then . call ( promise , undefined , function ( err ) {
231
227
// The callback is called with nextTick to avoid a follow-up
232
228
// rejection from this promise.
233
229
process . nextTick ( emitUnhandledRejectionOrErr , that , err , type , args ) ;
@@ -376,7 +372,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
376
372
return false ;
377
373
378
374
if ( typeof handler === 'function' ) {
379
- const result = ReflectApply ( handler , this , args ) ;
375
+ const result = handler . apply ( this , args ) ;
380
376
381
377
// We check if result is undefined first because that
382
378
// is the most common case so we do not pay any perf
@@ -388,7 +384,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
388
384
const len = handler . length ;
389
385
const listeners = arrayClone ( handler ) ;
390
386
for ( let i = 0 ; i < len ; ++ i ) {
391
- const result = ReflectApply ( listeners [ i ] , this , args ) ;
387
+ const result = listeners [ i ] . apply ( this , args ) ;
392
388
393
389
// We check if result is undefined first because that
394
390
// is the most common case so we do not pay any perf
@@ -698,7 +694,7 @@ function getEventListeners(emitterOrTarget, type) {
698
694
const listeners = [ ] ;
699
695
let handler = root ?. next ;
700
696
while ( handler ?. listener !== undefined ) {
701
- ArrayPrototypePush ( listeners , handler . listener ) ;
697
+ listeners . push ( handler . listener ) ;
702
698
handler = handler . next ;
703
699
}
704
700
return listeners ;
@@ -842,7 +838,7 @@ function on(emitter, event, options) {
842
838
843
839
// Wait until an event happens
844
840
return new Promise ( function ( resolve , reject ) {
845
- ArrayPrototypePush ( unconsumedPromises , { resolve, reject } ) ;
841
+ unconsumedPromises . push ( { resolve, reject } ) ;
846
842
} ) ;
847
843
} ,
848
844
@@ -906,7 +902,7 @@ function on(emitter, event, options) {
906
902
if ( promise ) {
907
903
promise . resolve ( createIterResult ( args , false ) ) ;
908
904
} else {
909
- ArrayPrototypePush ( unconsumedEvents , args ) ;
905
+ unconsumedEvents . push ( args ) ;
910
906
}
911
907
}
912
908
0 commit comments