Bug 59795 - Inconsistent SyntaxError from new Function(...)
Summary: Inconsistent SyntaxError from new Function(...)
Status: RESOLVED WORKSFORME
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-29 07:38 PDT by mikesamuel@gmail.com
Modified: 2012-03-11 12:53 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mikesamuel@gmail.com 2011-04-29 07:38:32 PDT
Executing the Function constructor with a mis-parenthesized input thus
    Function("(i + (j)")
exits abruptly with a SyntaxError:
    SyntaxError: Parse error

Executing the same but with the return keyword before the mis-parenthesized expression does not error out:
    Function("return (i + (j)")
evaluates normally with the value
    function anonymous() { return (i + (j);
    }

I expected the first example and the second example to both produce a SyntaxError.
I.e., if this is fixed, I expect
    Function("return (i + (j)")


Note that
    var i = 1
    var j = 2
    typeof Function("return (i + (j)")()
evaluates normally with the string
    "undefined"
not "number" as might be done if bad inputs are being intentionally massaged or a SyntaxError as might be done if parsing is intentionally done lazily.
Comment 1 Gavin Barraclough 2012-03-11 12:53:04 PDT
Looks like these have been fixed, added the extra test cases in r110398