summaryrefslogtreecommitdiff
path: root/lib/internal/console/constructor.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2019-03-25 10:37:57 -0700
committerRich Trott <rtrott@gmail.com>2019-03-27 17:22:36 -0700
commit86517c9f8f2aacf624025839ab8f03167c8d70dd (patch)
tree8b77138fed59389dcaa45a40e6a036a2ca5c2c4c /lib/internal/console/constructor.js
parentb5ea925c8e30aa85f1821f3bd9833b52608bf91e (diff)
downloadandroid-node-v8-86517c9f8f2aacf624025839ab8f03167c8d70dd.tar.gz
android-node-v8-86517c9f8f2aacf624025839ab8f03167c8d70dd.tar.bz2
android-node-v8-86517c9f8f2aacf624025839ab8f03167c8d70dd.zip
console: remove unreachable code
In the current code, line 497 checks if `item` is `null` or `undefined`. However, `item` is guaranteed to be a non-null object or function at that point. * Lines 484/485 set `primitive` to `true` if `item` is null or undefined. * Line 486 skips line 497 if `primitive` is true (which it will always be if `item` is null or undefined) and `properties` is undefined. So the only way to get to line 497 when `item` is null or undefined is if `properties` is specified. * Line 494 skips line 497 if `primitive` is true (which it will always be if `item` is null or undefined) and `properties` are specified (which will always be the case or else this `else` block is skipped.) Here are the current lines 484 through 497: const primitive = item === null || (typeof item !== 'function' && typeof item !== 'object'); if (properties === undefined && primitive) { hasPrimitives = true; valuesKeyArray[i] = _inspect(item); } else { const keys = properties || ObjectKeys(item); for (const key of keys) { if (map[key] === undefined) map[key] = []; if ((primitive && properties) || !hasOwnProperty(item, key)) map[key][i] = ''; else map[key][i] = item == null ? item : _inspect(item[key]); This change removes the unnecessary ternary in that final line, simplifying it to: map[key][i] = _inspect(item[key]); PR-URL: https://github.com/nodejs/node/pull/26906 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Diffstat (limited to 'lib/internal/console/constructor.js')
-rw-r--r--lib/internal/console/constructor.js2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js
index b00707d1fd..5041abfd4d 100644
--- a/lib/internal/console/constructor.js
+++ b/lib/internal/console/constructor.js
@@ -494,7 +494,7 @@ const consoleMethods = {
if ((primitive && properties) || !hasOwnProperty(item, key))
map[key][i] = '';
else
- map[key][i] = item == null ? item : _inspect(item[key]);
+ map[key][i] = _inspect(item[key]);
}
}
}