Node: Incorrect inspection of Set iterator for set.entries()

Created on 24 Nov 2018  路  9Comments  路  Source: nodejs/node

  • Version: 10, 11, master
  • Platform: Linux
  • Subsystem: util
var set = new Set([1, 2])
console.log(set.entries())

In Node 6 and 8, it outputs:

SetIterator { [ 1, 1 ], [ 2, 2 ] }

In Node 10, 11 and master:

[Set Iterator] { 1, 2 }
V8 Engine confirmed-bug util

Most helpful comment

I just fixed Object::PreviewEntries to work as intended locally and I'll raise a PR to V8 as soon as I set up the whole machinery for V8 PRs and I'll backport that as soon as it lands.

ruben@BridgeAR-T450s:~/repos/node/node$ ./node
> a = new Set([1,2,3])
Set { 1, 2, 3 }
> a.values()
[Set Iterator] { 1, 2, 3 }
> a.keys()
[Set Iterator] { 1, 2, 3 }
> a.entries()
[Set Iterator] { [ 1, 1 ], [ 2, 2 ], [ 3, 3 ] }
> process.versions
{ http_parser: '2.8.0',
  node: '12.0.0-pre',
  v8: '7.0.276.38-node.13',

Refs: #20831 (the original PR that changed the behavior)

All 9 comments

Object::PreviewEntries reports unkeyed and gives the flat array.

@nodejs/v8

Yeah, Chrome has the same behavior:

image

/ping @BridgeAR

AFAIC this works as intended. With the change to using Object::PreviewEntries this difference has been discussed as well and we decided to follow chrome.
The set entries only contain the values, so there is no need to display it as an array with the value duplicated.

@BridgeAR its not an accurate representation of the actual iterator results though...

> new Set([2, 4]).entries()
[Set Iterator] { 2, 4 }
> // oh ok its just some numbers
> new Set([2, 4]).entries().next()
{ value: [ 2, 2 ], done: false }
> // wait value is an array now?
>

It's true that they contain the values but they are still in arrays, so IMHO it is confusing to not see that in the preview.

I just fixed Object::PreviewEntries to work as intended locally and I'll raise a PR to V8 as soon as I set up the whole machinery for V8 PRs and I'll backport that as soon as it lands.

ruben@BridgeAR-T450s:~/repos/node/node$ ./node
> a = new Set([1,2,3])
Set { 1, 2, 3 }
> a.values()
[Set Iterator] { 1, 2, 3 }
> a.keys()
[Set Iterator] { 1, 2, 3 }
> a.entries()
[Set Iterator] { [ 1, 1 ], [ 2, 2 ], [ 3, 3 ] }
> process.versions
{ http_parser: '2.8.0',
  node: '12.0.0-pre',
  v8: '7.0.276.38-node.13',

Refs: #20831 (the original PR that changed the behavior)

@BridgeAR what's the status?

@targos I have to fix the Node.js test expectation first in another PR for V8 as those tests will now fail (Which is intended). I am working on that.

The actual CL to fix the preview: https://chromium-review.googlesource.com/c/v8/v8/+/1350790

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ksushilmaurya picture ksushilmaurya  路  3Comments

cong88 picture cong88  路  3Comments

dfahlander picture dfahlander  路  3Comments

filipesilvaa picture filipesilvaa  路  3Comments

loretoparisi picture loretoparisi  路  3Comments