WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
41844
JavaScript parser violates ECMA automatic semicolon insertion rule
https://bugs.webkit.org/show_bug.cgi?id=41844
Summary
JavaScript parser violates ECMA automatic semicolon insertion rule
Kent Hansen
Reported
2010-07-08 02:51:44 PDT
The following snippet: JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL); const char *script = "if (0)"; JSValueRef val = JSEvaluateScript(context, JSStringCreateWithUTF8CString(script), NULL, NULL, 1, NULL); JSStringRef str = JSValueToStringCopy(context, val, NULL); char buf[256]; JSStringGetUTF8CString(str, buf, 256); printf("%s\n", buf); prints "undefined". ECMA-262 5th ed, section 7.9.1 "Rules of automatic semicolon", states: "When, as the program is parsed from left to right, the end of the input stream of tokens is encountered and the parser is unable to parse the input token stream as a single complete ECMAScript Program, then a semicolon is automatically inserted at the end of the input stream." So far, so good. But then the above is followed by: "However, there is an additional overriding condition on the preceding rules: a semicolon is never inserted automatically if the semicolon would then be parsed as an empty statement [...]." When the program is "if (0)", as in the above snippet, per the above rule, a semicolon should _not_ automatically be inserted. Instead a SyntaxError should be thrown.
Attachments
Patch
(4.23 KB, patch)
2010-07-08 15:56 PDT
,
Oliver Hunt
barraclough
: review+
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Oliver Hunt
Comment 1
2010-07-08 15:18:59 PDT
This isn't automatic semicolon insertion for the usual reasons eg. { if (0) } will fail to parse. The parse success is due to the lexer automatically inserting a semicolon to the end of a script if it has not seen a line terminator when it reaches the end. I'm no sure what the specific reason for it is.
Oliver Hunt
Comment 2
2010-07-08 15:56:09 PDT
Created
attachment 60976
[details]
Patch
Darin Adler
Comment 3
2010-07-08 16:10:02 PDT
Comment on
attachment 60976
[details]
Patch What’s the chance that some real world WebKit-only content depends on the broken behavior?
Oliver Hunt
Comment 4
2010-07-08 16:14:55 PDT
(In reply to
comment #3
)
> (From update of
attachment 60976
[details]
) > What’s the chance that some real world WebKit-only content depends on the broken behavior?
Fairly low -- no other browser does this, and it depends on having the incorrect code as the very last thing in the file (eg. no trailing new lines or other syntax)
Oliver Hunt
Comment 5
2010-07-08 16:24:04 PDT
Committed
r62862
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug