From b085b94fcee4b18c54481b634df806b7ba51c351 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 12 Aug 2019 21:17:47 -0400 Subject: [PATCH] console: minor timeLogImpl() refactor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/29100 Reviewed-By: James M Snell Reviewed-By: Anto Aravinth Reviewed-By: Rich Trott Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca --- lib/internal/console/constructor.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index e3de39f8126b7c..a618457124c877 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -310,9 +310,9 @@ const consoleMethods = { timeEnd(label = 'default') { // Coerces everything other than Symbol to a string label = `${label}`; - const hasWarned = timeLogImpl(this, 'timeEnd', label); + const found = timeLogImpl(this, 'timeEnd', label); trace(kTraceEnd, kTraceConsoleCategory, `time::${label}`, 0); - if (!hasWarned) { + if (found) { this._times.delete(label); } }, @@ -509,12 +509,12 @@ const consoleMethods = { }, }; -// Returns true if label was not found +// Returns true if label was found function timeLogImpl(self, name, label, data) { const time = self._times.get(label); - if (!time) { + if (time === undefined) { process.emitWarning(`No such label '${label}' for console.${name}()`); - return true; + return false; } const duration = process.hrtime(time); const ms = duration[0] * 1000 + duration[1] / 1e6; @@ -523,7 +523,7 @@ function timeLogImpl(self, name, label, data) { } else { self.log('%s: %sms', label, ms.toFixed(3), ...data); } - return false; + return true; } const keyKey = 'Key';