A random collection of ES4 draft spec surprises and thoughts

Maciej Stachowiak mjs at apple.com
Tue May 27 00:09:46 PDT 2008

On May 26, 2008, at 11:48 PM, Brendan Eich wrote:

> On May 26, 2008, at 11:40 PM, Maciej Stachowiak wrote:
>> On May 26, 2008, at 11:58 AM, Jason Orendorff wrote:
>>> As far as I know, this is unchanged from ES3, in which "functions  
>>> are
>>> permitted to return References" but "This possibility is admitted
>>> purely for the sake of host objects. No built-in ECMAScript function
>>> defined by this specification returns a reference and there is no
>>> provision for a user-defined function to return a reference.":
>>> http://bclary.com/2004/11/07/#a-8.7
>>> and an implementation that doesn't hold with such nonsense is also
>>> allowed to reject "foo(a)++" as a syntax error:
>>> http://bclary.com/2004/11/07/#a-16
>> In practice, for Web compatibility, it has to be a runtime error  
>> not a
>> parse error.
> Could you provide a list of URLs?

I don't mean that actually supporting Reference return is  
incompatible. Just that treating foo(a)++ as a syntax error is  
incompatible. In JavaScriptCore we detect at parse time when the  
operand of a ++ or -- is not syntactically an lvalue and emit code to  
throw an exception at runtime, because apparently some scripts on the  
Web include functions with such constructs that they never call, so  
treating it as a syntax error and aborting parsing would break the  
page, but throwing at runtime does not.

We tried to treat this a syntax error and at the time it broke  
300themovie.warnerbros.com and fedex.com. There were probably more  
than these two, we did not do an exhaustive search. Since Mozilla and  
IE both support this syntax I imagine this is no surprise.

> We added support for "lvalue return" to SpiderMonkey years ago,  
> based on someone using the code and wanting to port VBScript- 
> infected JScript. I don't recall the name (it wasn't AOL :-P), but  
> there may be a post from me in reply on the old "jseng" Mozilla  
> USENET group.
>> I don't know of any implementation making use of a
>> function returning a reference however (in WebKit's implementation
>> Reference is not a real type, just a spec fiction, and I assume this
>> is true in other implementations).
> SpiderMonkey erases References except where a native function calls  
> a special API to return one.

I did not know that. Probably not something we are keen to add.

  - Maciej

More information about the Es4-discuss mailing list