Skip to content

Commit 2a0862c

Browse files
BridgeARtargos
authored andcommitted
console: fix timeEnd() not coercing the input
The input of console.timeEnd() was not coerced to a string. That way labels were not found and the entry was not removed anymore. PR-URL: #21779 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 73cafd8 commit 2a0862c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/console.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,22 @@ Console.prototype.time = function time(label = 'default') {
231231
};
232232

233233
Console.prototype.timeEnd = function timeEnd(label = 'default') {
234+
// Coerces everything other than Symbol to a string
235+
label = `${label}`;
234236
const hasWarned = timeLogImpl(this, 'timeEnd', label);
235237
if (!hasWarned) {
236238
this._times.delete(label);
237239
}
238240
};
239241

240242
Console.prototype.timeLog = function timeLog(label, ...data) {
243+
// Coerces everything other than Symbol to a string
244+
label = `${label}`;
241245
timeLogImpl(this, 'timeLog', label, data);
242246
};
243247

244248
// Returns true if label was not found
245249
function timeLogImpl(self, name, label = 'default', data) {
246-
// Coerces everything other than Symbol to a string
247-
label = `${label}`;
248250
const time = self._times.get(label);
249251
if (!time) {
250252
process.emitWarning(`No such label '${label}' for console.${name}()`);

test/parallel/test-console.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,14 @@ console.timeEnd('constructor');
132132
console.time('hasOwnProperty');
133133
console.timeEnd('hasOwnProperty');
134134

135-
// verify that values are coerced to strings
135+
// Verify that values are coerced to strings.
136136
console.time([]);
137137
console.timeEnd([]);
138138
console.time({});
139139
console.timeEnd({});
140+
// Repeat the object call to verify that everything really worked.
141+
console.time({});
142+
console.timeEnd({});
140143
console.time(null);
141144
console.timeEnd(null);
142145
console.time(undefined);
@@ -212,6 +215,7 @@ assert.ok(/^hasOwnProperty: \d+\.\d{3}ms$/.test(strings.shift().trim()));
212215
// verify that console.time() coerces label values to strings as expected
213216
assert.ok(/^: \d+\.\d{3}ms$/.test(strings.shift().trim()));
214217
assert.ok(/^\[object Object\]: \d+\.\d{3}ms$/.test(strings.shift().trim()));
218+
assert.ok(/^\[object Object\]: \d+\.\d{3}ms$/.test(strings.shift().trim()));
215219
assert.ok(/^null: \d+\.\d{3}ms$/.test(strings.shift().trim()));
216220
assert.ok(/^default: \d+\.\d{3}ms$/.test(strings.shift().trim()));
217221
assert.ok(/^default: \d+\.\d{3}ms$/.test(strings.shift().trim()));

0 commit comments

Comments
 (0)