summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-01-12 00:15:10 +0100
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-01-18 08:03:25 +0100
commit2c0a75118cd6a2eaf6b45fe8c67336f44c86ab0f (patch)
tree58b5f79ec97025d0935907794e0219fb29d8d399 /lib
parent27f9a55cf66390195ad36eae0eb21fb4d07bb500 (diff)
downloadandroid-node-v8-2c0a75118cd6a2eaf6b45fe8c67336f44c86ab0f.tar.gz
android-node-v8-2c0a75118cd6a2eaf6b45fe8c67336f44c86ab0f.tar.bz2
android-node-v8-2c0a75118cd6a2eaf6b45fe8c67336f44c86ab0f.zip
util: fix iterable types with special prototype
The fallback should only be taken for a null prototype. If an iterable data type (e.g., Array) has a prototype without `Symbol.iterator`, just try the best to visualize it as object. PR-URL: https://github.com/nodejs/node/pull/25457 Fixes: https://github.com/nodejs/node/issues/25451 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/util/inspect.js28
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 88362f8615..0f81ab5d02 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -463,28 +463,22 @@ function clazzWithNullPrototype(clazz, name) {
function noPrototypeIterator(ctx, value, recurseTimes) {
let newVal;
if (isSet(value)) {
- const clazz = Object.getPrototypeOf(value) ||
- clazzWithNullPrototype(Set, 'Set');
+ const clazz = clazzWithNullPrototype(Set, 'Set');
newVal = new clazz(setValues(value));
} else if (isMap(value)) {
- const clazz = Object.getPrototypeOf(value) ||
- clazzWithNullPrototype(Map, 'Map');
+ const clazz = clazzWithNullPrototype(Map, 'Map');
newVal = new clazz(mapEntries(value));
} else if (Array.isArray(value)) {
- const clazz = Object.getPrototypeOf(value) ||
- clazzWithNullPrototype(Array, 'Array');
+ const clazz = clazzWithNullPrototype(Array, 'Array');
newVal = new clazz(value.length);
} else if (isTypedArray(value)) {
- let clazz = Object.getPrototypeOf(value);
- if (!clazz) {
- const constructor = findTypedConstructor(value);
- clazz = clazzWithNullPrototype(constructor, constructor.name);
- }
+ const constructor = findTypedConstructor(value);
+ const clazz = clazzWithNullPrototype(constructor, constructor.name);
newVal = new clazz(value);
}
- if (newVal) {
+ if (newVal !== undefined) {
Object.defineProperties(newVal, Object.getOwnPropertyDescriptors(value));
- return formatValue(ctx, newVal, recurseTimes);
+ return formatRaw(ctx, newVal, recurseTimes);
}
}
@@ -728,9 +722,11 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
} else {
// The input prototype got manipulated. Special handle these. We have to
// rebuild the information so we are able to display everything.
- const specialIterator = noPrototypeIterator(ctx, value, recurseTimes);
- if (specialIterator) {
- return specialIterator;
+ if (constructor === null) {
+ const specialIterator = noPrototypeIterator(ctx, value, recurseTimes);
+ if (specialIterator) {
+ return specialIterator;
+ }
}
if (isMapIterator(value)) {
braces = [`[${tag || 'Map Iterator'}] {`, '}'];