Skip to content

Commit b085b94

Browse files
cjihrigtargos
authored andcommitted
console: minor timeLogImpl() refactor
This commit does two things: - Reverses the boolean value returned by timeLogImpl(). The new values make more sense semantically (IMO anyway), and save a a single NOT operation. - Explicitly check for undefined when calling _times.get() instead of coercing the value. PR-URL: #29100 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 31c50e5 commit b085b94

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/internal/console/constructor.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ const consoleMethods = {
310310
timeEnd(label = 'default') {
311311
// Coerces everything other than Symbol to a string
312312
label = `${label}`;
313-
const hasWarned = timeLogImpl(this, 'timeEnd', label);
313+
const found = timeLogImpl(this, 'timeEnd', label);
314314
trace(kTraceEnd, kTraceConsoleCategory, `time::${label}`, 0);
315-
if (!hasWarned) {
315+
if (found) {
316316
this._times.delete(label);
317317
}
318318
},
@@ -509,12 +509,12 @@ const consoleMethods = {
509509
},
510510
};
511511

512-
// Returns true if label was not found
512+
// Returns true if label was found
513513
function timeLogImpl(self, name, label, data) {
514514
const time = self._times.get(label);
515-
if (!time) {
515+
if (time === undefined) {
516516
process.emitWarning(`No such label '${label}' for console.${name}()`);
517-
return true;
517+
return false;
518518
}
519519
const duration = process.hrtime(time);
520520
const ms = duration[0] * 1000 + duration[1] / 1e6;
@@ -523,7 +523,7 @@ function timeLogImpl(self, name, label, data) {
523523
} else {
524524
self.log('%s: %sms', label, ms.toFixed(3), ...data);
525525
}
526-
return false;
526+
return true;
527527
}
528528

529529
const keyKey = 'Key';

0 commit comments

Comments
 (0)