summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-08-12 21:17:47 -0400
committerzhangyongsheng <zhangyongsheng@youzan.com>2019-08-15 16:29:36 +0800
commita15cd9d4186df4588a08aa0bf8df20e772c03053 (patch)
tree6f6e6b6275acef4ea9d7ef270843be849b76c2de /lib
parentec60b625b66288cb63d63a51b115661a8503e19e (diff)
downloadandroid-node-v8-a15cd9d4186df4588a08aa0bf8df20e772c03053.tar.gz
android-node-v8-a15cd9d4186df4588a08aa0bf8df20e772c03053.tar.bz2
android-node-v8-a15cd9d4186df4588a08aa0bf8df20e772c03053.zip
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/console/constructor.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js
index e3de39f812..a618457124 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';