User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:126.96.36.199) Gecko/20060508 Firefox/188.8.131.52
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:184.108.40.206) Gecko/20060508 Firefox/220.127.116.11
From the documentation for Array.forEach():
forEach executes the provided function (callback) once for each element present in the array. Arrays are treated as "dense", meaning that callback will be invoked for each index less than the array's length, even if a given index has never been explicitly assigned.
However, the implementation of Array.forEach() does not actually invoke the callback for unassigned array elements.
Steps to Reproduce:
var a = ;
a = 1;
alert is called once, with a parameter of "1".
alert should be called twice, first with a parameter of "undefined", and then with a parameter of "1".
I think this is a doc bug. Holes in arrays are not properties, so any primitive method that calls a function "for each property" in the array should not call for those ids that index holes (i.e., for missing properties). Consider a js shell example:
js> a = [1,2,3]
1 0 1,2,3
2 1 1,2,3
3 2 1,2,3
js> delete a
1 0 1,,3
3 2 1,,3
It would be odd to see a line for item 2 (element 1) after it was deleted, especially in light of the |this| value for the other two lines (1,,3).
Shaver, can you render a verdict?
(In reply to comment #1)
> I think this is a doc bug.
More like a spec bug, in that it documents what was intentional behaviour, but I now agree that it's not desirable.
Do we have compatibility issues here if we change it now?
I'll keep watching this bug for a decision on whether the doc or the implementation gets changed.
I agree with Brendan here: this should be a documentation bug. I've updated the MDC docs for all the array extras to indicate that they do not act upon array indexes which have not been assigned or which have been deleted (at the time of being visited). Also, the JS implementations I plan to add to each page (for use when the user's browser doesn't support the extras) will obey this rule as well.
So, does that mean we can resolve this bug, or is there more left to be done?
I'm marking this fixed now, since it seems to be. If anyone disagrees, please reopen and say what's still not done so we can get it taken care of.
see bug 390592 for the test and bug 311082 for the discussion.
(In reply to comment #7)
> see bug 390592 for the test and bug 311082 for the discussion.
The first bug # is wrong.
(In reply to comment #8)
see bug 290592 for the test and bug 311082 for the discussion.