* SUMMARY A 'return' statement outside of the body of a function should be syntactically incorrect. JavaScriptCore currently accepts such a construct. * STEPS TO REPRODUCE 1. Open test case in Safari/WebKit. * EXPECTED RESULTS "PASS" should appear on the page. * ACTUAL RESULTS "FAIL" appears on the page. * REGRESSION This is not a regression as Safari 2.0.4 (419.3) with original WebKit on Mac OS X 10.4.10 (8R218) behaves the same way. Tested with a local debug build of WebKit r25505 with Safari 3 Public Beta v. 3.0.3 (522.12.1) on Mac OS X 10.4.10 (8R218).
Created attachment 16274 [details] Test case
Interesting. I know we disallow return statements in other cases. This must be an edge case we didn't catch before.
The syntax error is generated, but it is only thrown if the return statement would otherwise be executed. For compatibility reasons, this is the approach we take with all other "you are using this statement in the wrong place" syntax errors. Should we do it differently in this case?
(In reply to comment #3) > The syntax error is generated, but it is only thrown if the return statement > would otherwise be executed. For compatibility reasons, this is the approach we > take with all other "you are using this statement in the wrong place" syntax > errors. Should we do it differently in this case? Firefox 3.0.10 "passes" the test and prints this to its Error Console: Error: return not in function Line 4
This is fixed in ToT - we made all syntax error early errors (per ES5) a while back.