6
6
const {
7
7
ArrayFrom,
8
8
ArrayIsArray,
9
+ ArrayPrototypePush,
10
+ ArrayPrototypeUnshift,
9
11
Boolean,
10
12
ErrorCaptureStackTrace,
11
- Map ,
13
+ FunctionPrototypeBind ,
12
14
MathFloor,
13
15
Number,
16
+ NumberPrototypeToFixed,
14
17
ObjectDefineProperties,
15
18
ObjectDefineProperty,
16
19
ObjectKeys,
17
20
ObjectPrototypeHasOwnProperty,
18
21
ObjectValues,
19
22
ReflectOwnKeys,
23
+ SafeMap,
24
+ SafeWeakMap,
25
+ StringPrototypeIncludes,
26
+ StringPrototypePadStart,
27
+ StringPrototypeRepeat,
28
+ StringPrototypeReplace,
29
+ StringPrototypeSlice,
30
+ StringPrototypeSplit,
20
31
Symbol,
21
32
SymbolHasInstance,
22
33
SymbolToStringTag,
23
- WeakMap,
24
34
} = primordials ;
25
35
26
36
const { trace } = internalBinding ( 'trace_events' ) ;
@@ -80,7 +90,7 @@ const kBindStreamsLazy = Symbol('kBindStreamsLazy');
80
90
const kUseStdout = Symbol ( 'kUseStdout' ) ;
81
91
const kUseStderr = Symbol ( 'kUseStderr' ) ;
82
92
83
- const optionsMap = new WeakMap ( ) ;
93
+ const optionsMap = new SafeWeakMap ( ) ;
84
94
85
95
function Console ( options /* or: stdout, stderr, ignoreErrors = true */ ) {
86
96
// We have to test new.target here to see if this function is called
@@ -142,7 +152,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
142
152
// We have to bind the methods grabbed from the instance instead of from
143
153
// the prototype so that users extending the Console can override them
144
154
// from the prototype chain of the subclass.
145
- this [ key ] = this [ key ] . bind ( this ) ;
155
+ this [ key ] = FunctionPrototypeBind ( this [ key ] , this ) ;
146
156
ObjectDefineProperty ( this [ key ] , 'name' , {
147
157
value : key
148
158
} ) ;
@@ -224,9 +234,9 @@ ObjectDefineProperties(Console.prototype, {
224
234
...consolePropAttributes ,
225
235
value : Boolean ( ignoreErrors )
226
236
} ,
227
- '_times' : { ...consolePropAttributes , value : new Map ( ) } ,
237
+ '_times' : { ...consolePropAttributes , value : new SafeMap ( ) } ,
228
238
// Corresponds to https://console.spec.whatwg.org/#count-map
229
- [ kCounts ] : { ...consolePropAttributes , value : new Map ( ) } ,
239
+ [ kCounts ] : { ...consolePropAttributes , value : new SafeMap ( ) } ,
230
240
[ kColorMode ] : { ...consolePropAttributes , value : colorMode } ,
231
241
[ kIsConsole ] : { ...consolePropAttributes , value : true } ,
232
242
[ kGroupIndent ] : { ...consolePropAttributes , value : '' } ,
@@ -255,8 +265,8 @@ ObjectDefineProperties(Console.prototype, {
255
265
this . _stdoutErrorHandler : this . _stderrErrorHandler ;
256
266
257
267
if ( groupIndent . length !== 0 ) {
258
- if ( string . includes ( '\n' ) ) {
259
- string = string . replace ( / \n / g, `\n${ groupIndent } ` ) ;
268
+ if ( StringPrototypeIncludes ( string , '\n' ) ) {
269
+ string = StringPrototypeReplace ( string , / \n / g, `\n${ groupIndent } ` ) ;
260
270
}
261
271
string = groupIndent + string ;
262
272
}
@@ -450,13 +460,16 @@ const consoleMethods = {
450
460
if ( data . length > 0 ) {
451
461
this . log ( ...data ) ;
452
462
}
453
- this [ kGroupIndent ] += ' ' . repeat ( this [ kGroupIndentationWidth ] ) ;
463
+ this [ kGroupIndent ] +=
464
+ StringPrototypeRepeat ( ' ' , this [ kGroupIndentationWidth ] ) ;
454
465
} ,
455
466
456
467
groupEnd ( ) {
457
- this [ kGroupIndent ] =
458
- this [ kGroupIndent ] . slice ( 0 , this [ kGroupIndent ] . length -
459
- this [ kGroupIndentationWidth ] ) ;
468
+ this [ kGroupIndent ] = StringPrototypeSlice (
469
+ this [ kGroupIndent ] ,
470
+ 0 ,
471
+ this [ kGroupIndent ] . length - this [ kGroupIndentationWidth ]
472
+ ) ;
460
473
} ,
461
474
462
475
// https://console.spec.whatwg.org/#table
@@ -501,14 +514,14 @@ const consoleMethods = {
501
514
let length = 0 ;
502
515
if ( mapIter ) {
503
516
for ( ; i < tabularData . length / 2 ; ++ i ) {
504
- keys . push ( _inspect ( tabularData [ i * 2 ] ) ) ;
505
- values . push ( _inspect ( tabularData [ i * 2 + 1 ] ) ) ;
517
+ ArrayPrototypePush ( keys , _inspect ( tabularData [ i * 2 ] ) ) ;
518
+ ArrayPrototypePush ( values , _inspect ( tabularData [ i * 2 + 1 ] ) ) ;
506
519
length ++ ;
507
520
}
508
521
} else {
509
522
for ( const [ k , v ] of tabularData ) {
510
- keys . push ( _inspect ( k ) ) ;
511
- values . push ( _inspect ( v ) ) ;
523
+ ArrayPrototypePush ( keys , _inspect ( k ) ) ;
524
+ ArrayPrototypePush ( values , _inspect ( v ) ) ;
512
525
length ++ ;
513
526
}
514
527
}
@@ -530,7 +543,7 @@ const consoleMethods = {
530
543
const values = [ ] ;
531
544
let length = 0 ;
532
545
for ( const v of tabularData ) {
533
- values . push ( _inspect ( v ) ) ;
546
+ ArrayPrototypePush ( values , _inspect ( v ) ) ;
534
547
length ++ ;
535
548
}
536
549
return final ( [ iterKey , valuesKey ] , [ getIndexArray ( length ) , values ] ) ;
@@ -565,11 +578,11 @@ const consoleMethods = {
565
578
const keys = ObjectKeys ( map ) ;
566
579
const values = ObjectValues ( map ) ;
567
580
if ( hasPrimitives ) {
568
- keys . push ( valuesKey ) ;
569
- values . push ( valuesKeyArray ) ;
581
+ ArrayPrototypePush ( keys , valuesKey ) ;
582
+ ArrayPrototypePush ( values , valuesKeyArray ) ;
570
583
}
571
- keys . unshift ( indexKey ) ;
572
- values . unshift ( indexKeyArray ) ;
584
+ ArrayPrototypeUnshift ( keys , indexKey ) ;
585
+ ArrayPrototypeUnshift ( values , indexKeyArray ) ;
573
586
574
587
return final ( keys , values ) ;
575
588
} ,
@@ -596,7 +609,7 @@ function timeLogImpl(self, name, label, data) {
596
609
}
597
610
598
611
function pad ( value ) {
599
- return `${ value } ` . padStart ( 2 , '0' ) ;
612
+ return StringPrototypePadStart ( `${ value } ` , 2 , '0' ) ;
600
613
}
601
614
602
615
function formatTime ( ms ) {
@@ -617,16 +630,19 @@ function formatTime(ms) {
617
630
}
618
631
619
632
if ( hours !== 0 || minutes !== 0 ) {
620
- [ seconds , ms ] = seconds . toFixed ( 3 ) . split ( '.' ) ;
633
+ [ seconds , ms ] = StringPrototypeSplit (
634
+ NumberPrototypeToFixed ( seconds , 3 ) ,
635
+ '.'
636
+ ) ;
621
637
const res = hours !== 0 ? `${ hours } :${ pad ( minutes ) } ` : minutes ;
622
638
return `${ res } :${ pad ( seconds ) } .${ ms } (${ hours !== 0 ? 'h:m' : '' } m:ss.mmm)` ;
623
639
}
624
640
625
641
if ( seconds !== 0 ) {
626
- return `${ seconds . toFixed ( 3 ) } s` ;
642
+ return `${ NumberPrototypeToFixed ( seconds , 3 ) } s` ;
627
643
}
628
644
629
- return `${ Number ( ms . toFixed ( 3 ) ) } ms` ;
645
+ return `${ Number ( NumberPrototypeToFixed ( ms , 3 ) ) } ms` ;
630
646
}
631
647
632
648
const keyKey = 'Key' ;
0 commit comments