@@ -78,7 +78,6 @@ function lazyUtilColors() {
7878}
7979
8080// Track amount of indentation required via `console.group()`.
81- const kGroupIndent = Symbol ( 'kGroupIndent' ) ;
8281const kGroupIndentationWidth = Symbol ( 'kGroupIndentWidth' ) ;
8382const kFormatForStderr = Symbol ( 'kFormatForStderr' ) ;
8483const kFormatForStdout = Symbol ( 'kFormatForStdout' ) ;
@@ -91,7 +90,6 @@ const kBindStreamsEager = Symbol('kBindStreamsEager');
9190const kBindStreamsLazy = Symbol ( 'kBindStreamsLazy' ) ;
9291const kUseStdout = Symbol ( 'kUseStdout' ) ;
9392const kUseStderr = Symbol ( 'kUseStderr' ) ;
94- const kInternalTimeLogImpl = Symbol ( 'kInternalTimeLogImpl' ) ;
9593
9694const optionsMap = new SafeWeakMap ( ) ;
9795function Console ( options /* or: stdout, stderr, ignoreErrors = true */ ) {
@@ -178,6 +176,8 @@ ObjectDefineProperty(Console, SymbolHasInstance, {
178176const kColorInspectOptions = { colors : true } ;
179177const kNoColorInspectOptions = { } ;
180178
179+ const internalIndentationMap = new SafeWeakMap ( ) ;
180+
181181ObjectDefineProperties ( Console . prototype , {
182182 [ kBindStreamsEager ] : {
183183 __proto__ : null ,
@@ -247,7 +247,6 @@ ObjectDefineProperties(Console.prototype, {
247247 [ kCounts ] : { __proto__ : null , ...consolePropAttributes , value : new SafeMap ( ) } ,
248248 [ kColorMode ] : { __proto__ : null , ...consolePropAttributes , value : colorMode } ,
249249 [ kIsConsole ] : { __proto__ : null , ...consolePropAttributes , value : true } ,
250- [ kGroupIndent ] : { __proto__ : null , ...consolePropAttributes , value : '' } ,
251250 [ kGroupIndentationWidth ] : {
252251 __proto__ : null ,
253252 ...consolePropAttributes ,
@@ -268,7 +267,7 @@ ObjectDefineProperties(Console.prototype, {
268267 ...consolePropAttributes ,
269268 value : function ( streamSymbol , string , color = '' ) {
270269 const ignoreErrors = this . _ignoreErrors ;
271- const groupIndent = this [ kGroupIndent ] ;
270+ const groupIndent = internalIndentationMap . get ( this ) || '' ;
272271
273272 const useStdout = streamSymbol === kUseStdout ;
274273 const stream = useStdout ? this . _stdout : this . _stderr ;
@@ -372,11 +371,11 @@ function createWriteErrorHandler(instance, streamSymbol) {
372371 } ;
373372}
374373
375- function timeLogImpl ( label , formatted , args ) {
374+ function timeLogImpl ( consoleRef , label , formatted , args ) {
376375 if ( args === undefined ) {
377- this . log ( '%s: %s' , label , formatted ) ;
376+ consoleRef . log ( '%s: %s' , label , formatted ) ;
378377 } else {
379- this . log ( '%s: %s' , label , formatted , ...new SafeArrayIterator ( args ) ) ;
378+ consoleRef . log ( '%s: %s' , label , formatted , ...new SafeArrayIterator ( args ) ) ;
380379 }
381380}
382381
@@ -407,17 +406,11 @@ const consoleMethods = {
407406 } ,
408407
409408 timeEnd ( label = 'default' ) {
410- if ( this [ kInternalTimeLogImpl ] === undefined )
411- this [ kInternalTimeLogImpl ] = FunctionPrototypeBind ( timeLogImpl , this ) ;
412-
413- timeEnd ( this . _times , kTraceConsoleCategory , 'console.timeEnd()' , kNone , this [ kInternalTimeLogImpl ] , label , `time::${ label } ` ) ;
409+ timeEnd ( this . _times , kTraceConsoleCategory , 'console.timeEnd()' , kNone , ( label , formatted , args ) => timeLogImpl ( this , label , formatted , args ) , label , `time::${ label } ` ) ;
414410 } ,
415411
416412 timeLog ( label = 'default' , ...data ) {
417- if ( this [ kInternalTimeLogImpl ] === undefined )
418- this [ kInternalTimeLogImpl ] = FunctionPrototypeBind ( timeLogImpl , this ) ;
419-
420- timeLog ( this . _times , kTraceConsoleCategory , 'console.timeLog()' , kNone , this [ kInternalTimeLogImpl ] , label , `time::${ label } ` , data ) ;
413+ timeLog ( this . _times , kTraceConsoleCategory , 'console.timeLog()' , kNone , ( label , formatted , args ) => timeLogImpl ( this , label , formatted , args ) , label , `time::${ label } ` , data ) ;
421414 } ,
422415
423416 trace : function trace ( ...args ) {
@@ -489,16 +482,22 @@ const consoleMethods = {
489482 if ( data . length > 0 ) {
490483 ReflectApply ( this . log , this , data ) ;
491484 }
492- this [ kGroupIndent ] +=
493- StringPrototypeRepeat ( ' ' , this [ kGroupIndentationWidth ] ) ;
485+
486+ let currentIndentation = internalIndentationMap . get ( this ) || '' ;
487+ currentIndentation += StringPrototypeRepeat ( ' ' , this [ kGroupIndentationWidth ] ) ;
488+
489+ internalIndentationMap . set ( this , currentIndentation ) ;
494490 } ,
495491
496492 groupEnd ( ) {
497- this [ kGroupIndent ] = StringPrototypeSlice (
498- this [ kGroupIndent ] ,
493+ const currentIndentation = internalIndentationMap . get ( this ) || '' ;
494+ const newIndentation = StringPrototypeSlice (
495+ currentIndentation ,
499496 0 ,
500- this [ kGroupIndent ] . length - this [ kGroupIndentationWidth ] ,
497+ currentIndentation . length - this [ kGroupIndentationWidth ] ,
501498 ) ;
499+
500+ internalIndentationMap . set ( this , newIndentation ) ;
502501 } ,
503502
504503 // https://console.spec.whatwg.org/#table
0 commit comments