22
22
'use strict' ;
23
23
24
24
const {
25
+ ArrayPrototypeIndexOf,
26
+ ArrayPrototypeJoin,
27
+ ArrayPrototypeShift,
25
28
ArrayPrototypeSlice,
29
+ ArrayPrototypeSplice,
26
30
Boolean,
27
31
Error,
28
32
ErrorCaptureStackTrace,
33
+ FunctionPrototypeBind,
34
+ FunctionPrototypeCall,
29
35
MathMin,
30
36
NumberIsNaN,
31
37
ObjectCreate,
@@ -38,9 +44,10 @@ const {
38
44
PromiseResolve,
39
45
ReflectOwnKeys,
40
46
String,
47
+ StringPrototypeSplit,
41
48
Symbol,
42
49
SymbolFor,
43
- SymbolAsyncIterator
50
+ SymbolAsyncIterator,
44
51
} = primordials ;
45
52
const kRejection = SymbolFor ( 'nodejs.rejection' ) ;
46
53
@@ -265,7 +272,7 @@ EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
265
272
function identicalSequenceRange ( a , b ) {
266
273
for ( let i = 0 ; i < a . length - 3 ; i ++ ) {
267
274
// Find the first entry of b that matches the current entry of a.
268
- const pos = b . indexOf ( a [ i ] ) ;
275
+ const pos = ArrayPrototypeIndexOf ( b , a [ i ] ) ;
269
276
if ( pos !== - 1 ) {
270
277
const rest = b . length - pos ;
271
278
if ( rest > 3 ) {
@@ -294,16 +301,18 @@ function enhanceStackTrace(err, own) {
294
301
} catch { }
295
302
const sep = `\nEmitted 'error' event${ ctorInfo } at:\n` ;
296
303
297
- const errStack = err . stack . split ( '\n' ) . slice ( 1 ) ;
298
- const ownStack = own . stack . split ( '\n' ) . slice ( 1 ) ;
304
+ const errStack = ArrayPrototypeSlice (
305
+ StringPrototypeSplit ( err . stack , '\n' ) , 1 ) ;
306
+ const ownStack = ArrayPrototypeSlice (
307
+ StringPrototypeSplit ( own . stack , '\n' ) , 1 ) ;
299
308
300
309
const { 0 : len , 1 : off } = identicalSequenceRange ( ownStack , errStack ) ;
301
310
if ( len > 0 ) {
302
- ownStack . splice ( off + 1 , len - 2 ,
303
- ' [... lines matching original stack trace ...]' ) ;
311
+ ArrayPrototypeSplice ( ownStack , off + 1 , len - 2 ,
312
+ ' [... lines matching original stack trace ...]' ) ;
304
313
}
305
314
306
- return err . stack + sep + ownStack . join ( '\n' ) ;
315
+ return err . stack + sep + ArrayPrototypeJoin ( ownStack , '\n' ) ;
307
316
}
308
317
309
318
EventEmitter . prototype . emit = function emit ( type , ...args ) {
@@ -327,7 +336,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
327
336
const capture = { } ;
328
337
ErrorCaptureStackTrace ( capture , EventEmitter . prototype . emit ) ;
329
338
ObjectDefineProperty ( er , kEnhanceStackBeforeInspector , {
330
- value : enhanceStackTrace . bind ( this , er , capture ) ,
339
+ value : FunctionPrototypeBind ( enhanceStackTrace , this , er , capture ) ,
331
340
configurable : true
332
341
} ) ;
333
342
} catch { }
@@ -620,7 +629,7 @@ EventEmitter.listenerCount = function(emitter, type) {
620
629
if ( typeof emitter . listenerCount === 'function' ) {
621
630
return emitter . listenerCount ( type ) ;
622
631
}
623
- return listenerCount . call ( emitter , type ) ;
632
+ return FunctionPrototypeCall ( listenerCount , emitter , type ) ;
624
633
} ;
625
634
626
635
EventEmitter . prototype . listenerCount = listenerCount ;
@@ -858,7 +867,7 @@ function on(emitter, event, options) {
858
867
}
859
868
860
869
function eventHandler ( ...args ) {
861
- const promise = unconsumedPromises . shift ( ) ;
870
+ const promise = ArrayPrototypeShift ( unconsumedPromises ) ;
862
871
if ( promise ) {
863
872
promise . resolve ( createIterResult ( args , false ) ) ;
864
873
} else {
@@ -869,7 +878,7 @@ function on(emitter, event, options) {
869
878
function errorHandler ( err ) {
870
879
finished = true ;
871
880
872
- const toError = unconsumedPromises . shift ( ) ;
881
+ const toError = ArrayPrototypeShift ( unconsumedPromises ) ;
873
882
874
883
if ( toError ) {
875
884
toError . reject ( err ) ;
0 commit comments