Bug 10891 - REGRESSION: eval("return 1") no longer works
Summary: REGRESSION: eval("return 1") no longer works
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P1 Normal
Assignee: Nobody
URL: javascript:alert(eval("return 1"))
Keywords: HasReduction, InRadar, Regression
Depends on:
Blocks:
 
Reported: 2006-09-16 13:23 PDT by Alexey Proskuryakov
Modified: 2007-01-22 16:57 PST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Proskuryakov 2006-09-16 13:23:05 PDT
Evaluating a return statement (see bug URL) now results in an error:
---------------------------------
SyntaxError: Invalid return statement.
undefined
---------------------------------

This causes many AppleScripts to fail, e.g.

tell application "Safari" to do JavaScript "return 'qwerty';" in document 1
Comment 1 Timothy Hatcher 2006-09-16 13:56:48 PDT
<rdar://problem/4673695>
Comment 2 Sanjay Madhav (chmmravatar) 2007-01-21 18:25:12 PST
It seems that according to §10.1.2 and §12.9 of the ECMAScript Language Spec, return statements are only valid in the context of a FunctionBody. An eval statement is the equivalent of script executing in the context of a global scope, and as such "return" is invalid. So even though this is a regression in the sense that release Safari does not complain, the ToT behavior is the correct behavior for specification conformance.

I additionally tested the script in Firefox and IE7, and both browsers similarly complained about a return statement outside of a function. So given the behavior of other browsers and the spec, this bug should probably be resolved as invalid.
Comment 3 Mark Rowe (bdash) 2007-01-22 16:57:10 PST
Based on Sanjay's comment I am closing this as INVALID.  If this affects any major real-world applications or sites we should revisit this, otherwise the new behaviour is closer to the specification.