RESOLVED INVALID 18053
Can't eval() an anonymous function
https://bugs.webkit.org/show_bug.cgi?id=18053
Summary Can't eval() an anonymous function
David Kilzer (:ddkilzer)
Reported 2008-03-24 17:39:23 PDT
* SUMMARY Attempting to call eval() on a string containing an anonymous function fails in WebKit. Works in Firefox 2.0.0.x. * STEPS TO REPRODUCE 1. Launch Safari/WebKit. 2. Open attached test case. RESULTS Prints "FAILED" message on Safari/WebKit. Prints "SUCCESS" message on Firefox 2.0.0.x. REGRESSION Unknown.
Attachments
Test case (264 bytes, text/html)
2008-03-24 17:39 PDT, David Kilzer (:ddkilzer)
no flags
Better test case (198 bytes, text/html)
2008-03-25 09:02 PDT, David Kilzer (:ddkilzer)
no flags
David Kilzer (:ddkilzer)
Comment 1 2008-03-24 17:39:56 PDT
Created attachment 20016 [details] Test case
David Kilzer (:ddkilzer)
Comment 2 2008-03-24 17:42:05 PDT
See also Bug 12131 for issues with using onload on <script> tags.
David Kilzer (:ddkilzer)
Comment 3 2008-03-24 17:42:49 PDT
David Kilzer (:ddkilzer)
Comment 4 2008-03-25 09:02:15 PDT
Created attachment 20031 [details] Better test case
Maciej Stachowiak
Comment 5 2008-04-16 12:19:10 PDT
Technically, it is correct to treat this as a syntax error (it is treated as an erroneous function declaration, rather than as a unction expression). Do sites depend on this, or do other browsers handle it?
David Kilzer (:ddkilzer)
Comment 6 2008-04-16 13:32:22 PDT
(In reply to comment #5) > Technically, it is correct to treat this as a syntax error (it is treated as an > erroneous function declaration, rather than as a unction expression). Do sites > depend on this, or do other browsers handle it? Not that I'm aware of. This bug was filed in response to an email to the safari-iphone-web-dev mailing list: http://lists.apple.com/archives/Safari-iPhone-Web-Dev/2008/Mar/msg00020.html
Maciej Stachowiak
Comment 7 2008-04-16 16:53:07 PDT
The original email on that thread claims it works in Firefox and IE - someone should test in other browsers.
Geoffrey Garen
Comment 8 2008-04-29 11:21:33 PDT
This used to fail in IE, which is why we didn't implement it. It passes in IE7, though, so we should probably copy the behavior.
Simo Kinnunen
Comment 9 2008-12-21 12:04:59 PST
(In reply to comment #8) > This used to fail in IE, which is why we didn't implement it. It passes in IE7, > though, so we should probably copy the behavior. > You may or may not be aware of this, but it works just fine if you make it an expression - for example, eval('(function() { alert("PASSED") })')().
Patrick Mueller
Comment 10 2009-12-04 07:38:46 PST
Trolling through JSC bugs, tried the "Better test case" on some browsers on the Mac: WebKit nightly r51580: FAILED: SyntaxError: Parse error Opera 10.10: SUCCESS Chrome 4.0.249.22: FAILED: SyntaxError: Unexpected token ( FireFox 3.5.5: FAILED: SyntaxError: syntax error Given the initial report that it "works in Firefox 2.0.0.x", and the fact that it no longer works in FireFox 3.5.5, I'd just close this as a WORKSFORME at this point.
Kent Hansen
Comment 11 2010-02-04 07:37:00 PST
This is bugging QtScript after switching to JSC, since our old parser used to support it: http://bugreports.qt.nokia.com/browse/QTBUG-5757 It still works with SpiderMonkey from Mozilla trunk (the one I have compiled is from Jan 4 2010). Should be possible to fix by rewriting a couple of the grammar rules. Haven't tried it on this new parser though: https://bugs.webkit.org/show_bug.cgi?id=34019
Kent Hansen
Comment 12 2010-05-25 08:32:21 PDT
Relevant discussion from ES mailing list: https://mail.mozilla.org/pipermail/es5-discuss/2009-June/002822.html As per Geoffrey's reply, JavaScriptCore did actually support this syntax at one point in time, but then went the same way as FireFox (compliance argument). I'm guessing the chances of that being reverted now are slim.
Gavin Barraclough
Comment 13 2012-03-07 17:46:16 PST
Our behaviour matches FireFox, Chrome, and the spec. If we change this, it will be to more closely match harmony defined behaviour in modules, this is not something we want to support.
Note You need to log in before you can comment on or make changes to this bug.