Array Generics and null

Mike Shaver mike.shaver at
Mon Mar 24 11:05:36 PDT 2008

On Sat, Mar 22, 2008 at 1:42 PM, Garrett Smith <dhtmlkitchen at> wrote:
>  Array generic methods will be safer if they check their args and throw
>  an error - InvalidArgumentError, TypeError, UnlikeError - (whatever).
>  Invalid: (this will crash Firefox with endless loop):-
>  Array.forEach( { length : -1, "0": 12 }, iter );

Well, really a loop to 0xffffffff, just as the ES3 generics will do.
Many ES3 Array.prototype methods explicitly specified to be generic
(see the NOTEs for join, concat, pop, push, reverse, shift, slice,
unshift, sort, splice in 15.4.4.*) and I don't see why forEach would
be different; that generic nature is very useful when operating on DOM
NodeLists, ES3 argument objects, and so forth.

o = {length:-1, reverse:[].reverse, forEach:[].forEach};
o.forEach(function () { })
Array.forEach(o, function() { })

In my FF3 nightly all of those are handled the same way: slow script
dialog after a few seconds.  Fx2 doesn't have the same mechanism
bounding "internal" loops, but that's just a bug, and eliminating
script-DoS on the web is pretty Sisyphean.


More information about the Es4-discuss mailing list