Array extras feedback

Jeff Walden jwalden+es at MIT.EDU
Fri Jul 31 13:10:42 PDT 2009


On 31.7.09 08:47, Allen Wirfs-Brock wrote:
> javascript:[].indexOf(2,{valueOf: function() {alert("valueof"); return -1}})
>
> My quick experiments show that Firefox (3.5.1) does the early exit as currently spec'ed by ES5 while Chrome (2.0.172.37), Safari (4.0), and Opera (
> 9.63) exhibit the side-effect before returning. Note that the actual FF behavior is different from Mozilla's published algorithm which is apparently what the other browsers implemented.
>
> I'm not aware of any articulated pattern for JavaScript functions regarding whether or not arguments should be fully evaluated for side-effects.  As there is a divergence among implementations and since we are trying to close down changes to the draft I'm inclined to leave things as currently specified unless some there are strong arguments to support making the change.

Oh, hm, you're right; I missed that when transcribing the C implementation to JS, and I was looking at the JS implementations as a shortcut to avoid having to get bogged down in verbose C++.  I guess that lessens the concern; I'm not sure it eliminates it, still seems like a somewhat odd inconsistency.

Jeff


More information about the es-discuss mailing list