Skip to content
Permalink
Browse files

util: update set iterator entries inspection

The inspection output for Set#entries() was wrong so far as it did
not return an array as it should have. That was a bug in V8 that is
now fixed and the code in Node.js has to be updated accordingly.

PR-URL: #25941
Fixes: #24629
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information...
BridgeAR committed Feb 5, 2019
1 parent e557647 commit 3d62d0c4804813ff36a051160a57fc4596804b8f
Showing with 9 additions and 13 deletions.
  1. +5 −10 lib/internal/util/inspect.js
  2. +1 −1 src/node_util.cc
  3. +3 −2 test/parallel/test-util-inspect.js
@@ -595,11 +595,11 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
} else if (isMapIterator(value)) {
keys = getKeys(value, ctx.showHidden);
braces = [`[${tag}] {`, '}'];
formatter = formatMapIterator;
formatter = formatIterator;
} else if (isSetIterator(value)) {
keys = getKeys(value, ctx.showHidden);
braces = [`[${tag}] {`, '}'];
formatter = formatSetIterator;
formatter = formatIterator;
} else {
noIterator = true;
}
@@ -731,10 +731,10 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
}
if (isMapIterator(value)) {
braces = [`[${tag || 'Map Iterator'}] {`, '}'];
formatter = formatMapIterator;
formatter = formatIterator;
} else if (isSetIterator(value)) {
braces = [`[${tag || 'Set Iterator'}] {`, '}'];
formatter = formatSetIterator;
formatter = formatIterator;
// Handle other regular objects again.
} else if (keys.length === 0) {
if (isExternal(value))
@@ -1091,12 +1091,7 @@ function formatWeakMap(ctx, value, recurseTimes) {
return formatMapIterInner(ctx, recurseTimes, entries, kWeak);
}
function formatSetIterator(ctx, value, recurseTimes) {
const entries = previewEntries(value);
return formatSetIterInner(ctx, recurseTimes, entries, kIterator);
}
function formatMapIterator(ctx, value, recurseTimes) {
function formatIterator(ctx, value, recurseTimes) {
const [entries, isKeyValue] = previewEntries(value, true);
if (isKeyValue) {
return formatMapIterInner(ctx, recurseTimes, entries, kMapEntries);
@@ -100,7 +100,7 @@ static void PreviewEntries(const FunctionCallbackInfo<Value>& args) {
Local<Array> entries;
if (!args[0].As<Object>()->PreviewEntries(&is_key_value).ToLocal(&entries))
return;
// Fast path for WeakMap, WeakSet and Set iterators.
// Fast path for WeakMap and WeakSet.
if (args.Length() == 1)
return args.GetReturnValue().Set(entries);

@@ -995,7 +995,8 @@ if (typeof Symbol !== 'undefined') {
const aSet = new Set([1, 3]);
assert.strictEqual(util.inspect(aSet.keys()), '[Set Iterator] { 1, 3 }');
assert.strictEqual(util.inspect(aSet.values()), '[Set Iterator] { 1, 3 }');
assert.strictEqual(util.inspect(aSet.entries()), '[Set Iterator] { 1, 3 }');
assert.strictEqual(util.inspect(aSet.entries()),
'[Set Iterator] { [ 1, 1 ], [ 3, 3 ] }');
// Make sure the iterator doesn't get consumed.
const keys = aSet.keys();
assert.strictEqual(util.inspect(keys), '[Set Iterator] { 1, 3 }');
@@ -1609,7 +1610,7 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
[{ a: 5 }, '{ a: 5 }'],
[new Set([1, 2]), 'Set { 1, 2 }'],
[new Map([[1, 2]]), 'Map { 1 => 2 }'],
[new Set([1, 2]).entries(), '[Set Iterator] { 1, 2 }'],
[new Set([1, 2]).entries(), '[Set Iterator] { [ 1, 1 ], [ 2, 2 ] }'],
[new Map([[1, 2]]).keys(), '[Map Iterator] { 1 }'],
[new Date(2000), '1970-01-01T00:00:02.000Z'],
[new Uint8Array(2), 'Uint8Array [ 0, 0 ]'],

0 comments on commit 3d62d0c

Please sign in to comment.
You can’t perform that action at this time.