Strengthening Function.prototype.toString

Hallvord R. M. Steen hallvord at
Fri Sep 26 14:32:16 PDT 2008

On Fri, 26 Sep 2008 19:58:27 +0200, liorean <liorean at> wrote:

> 2008/9/26 Erik Arvidsson <erik.arvidsson at>:
>> I know that Opera on mobile phones used to return a string
>> representation that did not reflect the original.
> Yeah. Opera Mobile returned "[ECMAScript code]" or "[ecmascript
> code]". This was contrary to the ES3 spec (must be parsable as a
> function definition, IIRC) and also breaks the eval roundtripping by
> throwing a parse error.
> Anybody know if those issues have been fixed in more modern versions?

No, not consistently across "modern versions". It's not likely to be  
properly "fixed" for a while yet. The reason is that on many platforms  
where memory is scarce, not enabling JS decompilation helps reduce memory  

Unfortunately several major libraries (prototype in particular, jQuery to  
a minor extent) have started (ab)using decompilation for various purposes.  
Pages that rely on this tend to malfunction in Opera on low-memory  
devices. Some Opera versions make at least some of these pages work again  
by returning "function(){[ecmascript code]}" instead but that's of course  
a silly hack..

(It would be great if ES-next could have a look at why these libraries  
rely on toString - hacks and make it possible to do equivalent things with  
nicer language constructs. One of the reasons toString is used is probably  
outside the group's scope and caused by typeOf bugs in IE: prototype's  
isFunction method uses toString in order to reliably detect whether  
something is a function reference. Another usage is apparently - from my  
memory - to look at the names of the named arguments and do something  
magic if the first argument is $super. I'm not up-to-date on whether the  
next iteration has an elegant solution for this apparent requirement.)

Hallvord R. M. Steen
Core QA JavaScript tester, Opera Software
Opera - simply the best Internet experience

More information about the Es-discuss mailing list