Bug 15200 - some 'return' statements are allowed outside the body of a function
Summary: some 'return' statements are allowed outside the body of a function
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 523.x (Safari 3)
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Nobody
URL:
Keywords: HasReduction
Depends on:
Blocks:
 
Reported: 2007-09-12 22:43 PDT by David Kilzer (:ddkilzer)
Modified: 2011-06-14 17:23 PDT (History)
3 users (show)

See Also:


Attachments
Test case (124 bytes, text/html)
2007-09-12 22:44 PDT, David Kilzer (:ddkilzer)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2007-09-12 22:43:15 PDT
* 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).
Comment 1 David Kilzer (:ddkilzer) 2007-09-12 22:44:05 PDT
Created attachment 16274 [details]
Test case
Comment 2 Geoffrey Garen 2007-09-12 22:47:12 PDT
Interesting. I know we disallow return statements in other cases. This must be an edge case we didn't catch before.
Comment 3 Cameron Zwarich (cpst) 2008-06-09 22:51:55 PDT
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?
Comment 4 David Kilzer (:ddkilzer) 2009-05-24 07:05:56 PDT
(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
Comment 5 Gavin Barraclough 2011-06-14 17:23:32 PDT
This is fixed in ToT - we made all syntax error early errors (per ES5) a while back.