Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b085b94

Browse filesBrowse 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 <jasnell@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 31c50e5 commit b085b94
Copy full SHA for b085b94

File tree

Expand file treeCollapse file tree

1 file changed

+6
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-6
lines changed
Open diff view settings
Collapse file

‎lib/internal/console/constructor.js‎

Copy file name to clipboardExpand all lines: lib/internal/console/constructor.js
+6-6Lines changed: 6 additions & 6 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.