Since I talked about valueOf in my original message I'm going to interpret 
Oliver's comment as saying that even in ES3, without getter/setter extensions, 
you can still observed the separation of "evaluation" from "coercion".  That's 
correct. In general, the way the ES3 (and 5) spec is written for binary 
operators of the form expr1 op expr2 any coercion of the value of expr1 types 
place after the evaluation of expr2.  Since expr2 can potentially be an 
arbitrary expression that includes function calls, side-effects can be 
generated whi8le evaluating expr2 that are observed to occur before any 
side-effects from coercion (side-effects of valueOf, etc.) of expr1.

"Fixing" this would require substantial changes to the specification and to 
existing implementations that I doubt anyone wants to make.

So, the main point is that a belief that ECMAScript has or is supposed to have 
a strict left-to-right evaluation order (as the concept is likely to be 
understood by typical users of the language) is wrong. For consistency, 
Dave-Sarah's observation that we first "evaluate" and then "coerce" the 
operands is probably the guideline we should continue to follow if we ever 
define any additional operators where the distinction is relevant.

allen

-----Original Message-----
From: es5-discuss-boun...@mozilla.org [mailto:es5-discuss-boun...@mozilla.org] 
On Behalf Of Oliver Hunt
Sent: Friday, November 20, 2009 5:07 PM
To: David-Sarah Hopwood
Cc: es5-disc...@mozilla.org
Subject: Re: ES5 left-to-right evaluation order issues

It was also observable through valueOf, toString, etc

--Oliver

On Nov 20, 2009, at 4:40 PM, David-Sarah Hopwood wrote:

> Allen Wirfs-Brock wrote:
>> var o={get a() {alert("get a");return a}, get b() {alert ("get b");return 
>> b}};
>> o.a*o.b;
>> 
>> GetValue calls the accessor get functions, so based upon the above algorithm,
>> you would expect to see the alert sequence: "get a", "get b", "a valueOf",
>> "b valueOf".  This is exactly what happens for existing getter/setter
>> implementations in at least FF and Chrome.
> 
> I don't see a significant problem here. The arguments are still *evaluated*
> in left-to-right order. They're just not *coerced* at the same time as they
> are evaluated. But that was always the case in ES3; it hasn't changed in
> ES5. It's just a little bit more easily observable in ES5 because of
> getters.
> 
> -- 
> David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com
> 
> _______________________________________________
> es5-discuss mailing list
> es5-disc...@mozilla.org
> https://mail.mozilla.org/listinfo/es5-discuss

_______________________________________________
es5-discuss mailing list
es5-disc...@mozilla.org
https://mail.mozilla.org/listinfo/es5-discuss
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to