Repository navigation
Map.keys() returns empty object (4.1.1) #3107
Description
Activity
It's not an empty object, it's just how console represents iterator object
- addedutilIssues and PRs related to the built-in util module.Issues and PRs related to the built-in util module.
on Sep 28, 2015 Ah I see, I also realize I was using the wrong paradigm to iterator over it which is why it seemed empty to me.
This can be closed unless you think the representation should be updated.
Suggestions on how to improve it? I'm actually not sure what a good way is of detecting iterator objects apart from V8 specific magic like
%_ClassOf(it) === 'Map Iterator'.Well,
Object.prototype.toStringreports[object Map Iterator]I don't think that's tamper resistant enough. With
--harmony_tostring:> var it = { [Symbol.toStringTag]: 'Map Iterator' } undefined > Object.prototype.toString.call(it) '[object Map Iterator]' > %_ClassOf(it) 'Object'@bnoordhuis right, but the same applies to
RegExp,Date, etc, and we really use this approach with themAlso we can use mirrors, they are already used to inspect promises
the same applies to RegExp, Date, etc
Yes, but that's a) a status quo appeal, and b) code that predates ES6.
we can use mirrors, they are already used to inspect promises
That's not a bad idea although it might be slow for large object graphs. I suppose we could test with
v8::Value::IsMapIterator()andv8::Value::IsSetIterator()before creating the actual iterator mirror.@bnoordhuis didn't know about those, if we have them, then why use mirrors? though we could probably take advantage of
previewmethod to show iterators content, I bet it's what Chromium doesThat sounds plausible. We use a promise mirror for the same reason, so we can print the status.
In case you're wondering why we're not using
v8::Value::IsPromise()now: we can useDebug.ObjectIsPromise()in JS once we upgrade V8.Ben, why
Debug.ObjectIsPromise()is better?It's faster and creates less garbage than
Debug.MakeMirror()orv8::Value::IsPromise().Do these three methods return
truefor instances ofclass MyPromise extends Promise {...}?@targos Yes.
I just realized we don't have to wait for a V8 upgrade to switch to
ObjectIsPromise(): #3130
Calling
keys()on a Map returns an empty object rather than the keys of the Map:This works in Chrome45 which is using a similar v8 (V8 4.5.103.35):