|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Function.prototype.toString Change ProposalES5 Committee,
In Function.prototype.toString, the representation should be a "Function Definition". The current text requires a "FunctionDeclaration". Many (if not most) implementations today, do not follow the standard in the following cases: 1) anonymous function 2) native code Example:- javascript: alert([parseInt, function(){}].join('\n\n')); Many browsers produce a result something like: function parseInt() { [native code] } function () { } An implementation could probably change the first to produce a result such as:- function () { /* [native code] */ } That should be harmless, and wacky scripts that try to parse [native code] could continue to do so without breaking. For an anonymous function, an implementation could produce:- function anonymous(){} But that would be a bit odd, as the function does not have the identifier "anonymous". The specification should allow FunctionExpression, so that:- function(){} - would be legal. This change would have no negative impact on existing scripts, and would allow existing implementations to continue to exhibit the behavior they exhibit today, legally. The proposed text is as follows:- | 15.3.4.2 Function.prototype.toString ( ) | | An implementation-dependent representation of the | function is returned. This representation has the | syntax of a Function Definition. Note in particular | that the use and placement of white space, line | terminators, and semicolons within the representation | string is implementation-dependent. Garrett _______________________________________________ es-discuss mailing list es-discuss@... https://mail.mozilla.org/listinfo/es-discuss |
|
|
Re: Function.prototype.toString Change ProposalOn Sep 17, 2009, at 11:52 PM, Garrett Smith wrote: > ES5 Committee, > > In Function.prototype.toString, the representation should be a > "Function Definition". The current text requires a > "FunctionDeclaration". Many (if not most) implementations today, do > not follow the standard in the following cases: > > 1) anonymous function > 2) native code > > Example:- > javascript: alert([parseInt, function(){}].join('\n\n')); > > Many browsers produce a result something like: > function parseInt() { > [native code] > } > > function () { > } > > An implementation could probably change the first to produce a > result such as:- > > function () { /* [native code] */ } > > That should be harmless, and wacky scripts that try to parse [native > code] could continue to do so without breaking. > > For an anonymous function, an implementation could produce:- > > function anonymous(){} > > But that would be a bit odd, as the function does not have the > identifier "anonymous". > > The specification should allow FunctionExpression, so that:- > > function(){} Alas these changes would break things -- In JSC we have had many bug reports due about site breakage, which ended up being due to slight changes in in the formatting of function [[ToString]] conversion. Any changes to it are immensely risky (we've had at least a couple of bugs that were due to specific spaces and newlines not being in the "right" place), the degree of changes you're asking for are almost certain to break sites. --Oliver _______________________________________________ es-discuss mailing list es-discuss@... https://mail.mozilla.org/listinfo/es-discuss |
|
|
Re: Function.prototype.toString Change ProposalOn Thu, Sep 17, 2009 at 11:57 PM, Oliver Hunt <oliver@...> wrote:
> > On Sep 17, 2009, at 11:52 PM, Garrett Smith wrote: > >> ES5 Committee, >> >> In Function.prototype.toString, the representation should be a >> "Function Definition". The current text requires a >> "FunctionDeclaration". Many (if not most) implementations today, do >> not follow the standard in the following cases: >> >> 1) anonymous function >> 2) native code >> >> Example:- >> javascript: alert([parseInt, function(){}].join('\n\n')); >> >> Many browsers produce a result something like: >> function parseInt() { >> [native code] >> } >> >> function () { >> } >> >> An implementation could probably change the first to produce a result such >> as:- >> >> function () { /* [native code] */ } >> >> That should be harmless, and wacky scripts that try to parse [native >> code] could continue to do so without breaking. >> >> For an anonymous function, an implementation could produce:- >> >> function anonymous(){} >> >> But that would be a bit odd, as the function does not have the >> identifier "anonymous". >> >> The specification should allow FunctionExpression, so that:- >> >> function(){} > > Alas these changes would break things -- In JSC we have had many bug reports > due about site breakage, which ended up being due to slight changes in in > the formatting of function [[ToString]] conversion. Any changes to it are > immensely risky (we've had at least a couple of bugs that were due to > specific spaces and newlines not being in the "right" place), the degree of > changes you're asking for are almost certain to break sites. > How? javascript: alert(function(){}) Safari 4 elerts: "function () {}" The current specification doesn't allow that. Why not? The current specification requires the result of Function.prototype.toString to be a FunctionDeclaration and "function(){}" is not a FunctionDeclaration representation. So it seems you want Safari to change, but the specification to remain. I would have to disagree, as that might break sites (and for absolutely no good reason). I propose that browsers today stay as they are (Safari, Firefox, Chrome, IE, etc all produce that result). The specification should allow them to do so. Garrett _______________________________________________ es-discuss mailing list es-discuss@... https://mail.mozilla.org/listinfo/es-discuss |
|
|
Re: Function.prototype.toString Change Proposal
I was referring mainly to the changes in representation of the native functions sorry. I'm also unsure whether it would be possible to add 'anonymous' as a function name. I vaguely recall one site failing when we removed the space on either side of the ()'s so that does worry me. I also believe the eBay (at least in the past) did string replacement on the result of function.toString to create new functions which caused us a headache back then as well.
--Oliver _______________________________________________ es-discuss mailing list es-discuss@... https://mail.mozilla.org/listinfo/es-discuss |
|
|
|
| Free embeddable forum powered by Nabble | Forum Help |