The default bug view has changed. See this FAQ.

Element iterators should use [[Get]] and not peculiarly ignore the prototype chain

RESOLVED FIXED in mozilla13



JavaScript Engine
5 years ago
5 years ago


(Reporter: jorendorff, Assigned: jorendorff)


(Blocks: 1 bug)

Other Branch

Firefox Tracking Flags

(Not tracked)



(1 attachment)



5 years ago
This only matters in dumb corner cases, but basically:

    Array.prototype[2] = "potato";
    for (let x of [0, 1, , 3])

should print 0, 1, "potato", 3
rather than 0, 1, undefined, 3.

Comment 1

5 years ago
Created attachment 595257 [details] [diff] [review]

I don't know what I was thinking. Just randomly hating on holes.

The fast path for dense arrays could be thrown away too. It really depends on how we want to implement this.
Attachment #595257 - Flags: review?(jwalden+bmo)
Attachment #595257 - Attachment is patch: true
Comment on attachment 595257 [details] [diff] [review]

Review of attachment 595257 [details] [diff] [review]:

Agreed about throwing out the dense array fast path, I think.  We can pick up fast paths when they're demonstrably necessary; in the meantime, clarity and concision are more important.

::: js/src/jsiter.cpp
@@ -1153,5 @@
> -        } else {
> -            Value v = DoubleValue(i);
> -            if (!js_ValueToStringId(cx, v, &id))
> -                goto error;
> -        }

Did I review this code and not require IndexToString?  :-(
Attachment #595257 - Flags: review?(jwalden+bmo) → review+
Oh, I express no position on whether it is better to have for-of look up the prototype chain (as happens with this patch) or look only at own properties (as happens currently).  Definitely whatever the rationale is should be recorded in this bug, tho.

Comment 4

5 years ago
The rationale, in broad strokes:

  - it is more like the canonical for loop that way
  - nothing in the language currently does this kind of "get if own property";
    for better or worse, everything uses [[Get]]
  - just how unusual this is shows up as code complexity
  - everybody says ignoring the prototype chain won't make for-of any faster

In any case TC39 will kick this back and forth and eventually come to some decision, and we'll implement that.

Comment 5

5 years ago
Incidentally, removing the "simple" fast path fixes bug 726212, so the patch I check in for that bug will just be a few tests.

Comment 6

5 years ago
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla13
Nice diffstat!
You need to log in before you can comment on or make changes to this bug.