@@ -78,7 +78,6 @@ function lazyUtilColors() {
78
78
}
79
79
80
80
// Track amount of indentation required via `console.group()`.
81
-
const kGroupIndent = Symbol('kGroupIndent');
82
81
const kGroupIndentationWidth = Symbol('kGroupIndentWidth');
83
82
const kFormatForStderr = Symbol('kFormatForStderr');
84
83
const kFormatForStdout = Symbol('kFormatForStdout');
@@ -91,7 +90,6 @@ const kBindStreamsEager = Symbol('kBindStreamsEager');
91
90
const kBindStreamsLazy = Symbol('kBindStreamsLazy');
92
91
const kUseStdout = Symbol('kUseStdout');
93
92
const kUseStderr = Symbol('kUseStderr');
94
-
const kInternalTimeLogImpl = Symbol('kInternalTimeLogImpl');
95
93
96
94
const optionsMap = new SafeWeakMap();
97
95
function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
@@ -178,6 +176,8 @@ ObjectDefineProperty(Console, SymbolHasInstance, {
178
176
const kColorInspectOptions = { colors: true };
179
177
const kNoColorInspectOptions = {};
180
178
179
+
const internalIndentationMap = new SafeWeakMap();
180
+
181
181
ObjectDefineProperties(Console.prototype, {
182
182
[kBindStreamsEager]: {
183
183
__proto__: null,
@@ -247,7 +247,6 @@ ObjectDefineProperties(Console.prototype, {
247
247
[kCounts]: { __proto__: null, ...consolePropAttributes, value: new SafeMap() },
248
248
[kColorMode]: { __proto__: null, ...consolePropAttributes, value: colorMode },
249
249
[kIsConsole]: { __proto__: null, ...consolePropAttributes, value: true },
250
-
[kGroupIndent]: { __proto__: null, ...consolePropAttributes, value: '' },
251
250
[kGroupIndentationWidth]: {
252
251
__proto__: null,
253
252
...consolePropAttributes,
@@ -268,7 +267,7 @@ ObjectDefineProperties(Console.prototype, {
268
267
...consolePropAttributes,
269
268
value: function(streamSymbol, string, color = '') {
270
269
const ignoreErrors = this._ignoreErrors;
271
-
const groupIndent = this[kGroupIndent];
270
+
const groupIndent = internalIndentationMap.get(this) || '';
272
271
273
272
const useStdout = streamSymbol === kUseStdout;
274
273
const stream = useStdout ? this._stdout : this._stderr;
@@ -372,11 +371,11 @@ function createWriteErrorHandler(instance, streamSymbol) {
372
371
};
373
372
}
374
373
375
-
function timeLogImpl(label, formatted, args) {
374
+
function timeLogImpl(consoleRef, label, formatted, args) {
376
375
if (args === undefined) {
377
-
this.log('%s: %s', label, formatted);
376
+
consoleRef.log('%s: %s', label, formatted);
378
377
} else {
379
-
this.log('%s: %s', label, formatted, ...new SafeArrayIterator(args));
378
+
consoleRef.log('%s: %s', label, formatted, ...new SafeArrayIterator(args));
380
379
}
381
380
}
382
381
@@ -407,17 +406,11 @@ const consoleMethods = {
407
406
},
408
407
409
408
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}`);
414
410
},
415
411
416
412
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);
421
414
},
422
415
423
416
trace: function trace(...args) {
@@ -489,16 +482,22 @@ const consoleMethods = {
489
482
if (data.length > 0) {
490
483
ReflectApply(this.log, this, data);
491
484
}
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);
494
490
},
495
491
496
492
groupEnd() {
497
-
this[kGroupIndent] = StringPrototypeSlice(
498
-
this[kGroupIndent],
493
+
const currentIndentation = internalIndentationMap.get(this) || '';
494
+
const newIndentation = StringPrototypeSlice(
495
+
currentIndentation,
499
496
0,
500
-
this[kGroupIndent].length - this[kGroupIndentationWidth],
497
+
currentIndentation.length - this[kGroupIndentationWidth],
501
498
);
499
+
500
+
internalIndentationMap.set(this, newIndentation);
502
501
},
503
502
504
503
// https://console.spec.whatwg.org/#table
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4