Bug 77340

Summary: Unexpected syntax error
Product: WebKit Reporter: Sander <sander>
Component: JavaScriptCoreAssignee: Oliver Hunt <oliver>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, barraclough, bugs.webkit.org, oliver, zherczeg
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Mac (Intel)   
OS: OS X 10.7   
Attachments:
Description Flags
Testcase
none
Patch barraclough: review+

Sander
Reported 2012-01-30 08:24:23 PST
A single line of JS triggers a syntax error which I wouldn't expect since the code within the function is correct and should not be executed at all. > function a() { new x('x'+y).c = ''; } Results in a syntax error: > SyntaxError: Unexpected token '=' Upon removing variable y within this function, the syntax error magically disappears: > function a() { new x('x').c = ''; } Also reproducible in stable versions of Safari. Executing this code in Firefox / Chrome works just fine.
Attachments
Testcase (151 bytes, text/html)
2012-01-30 08:25 PST, Sander
no flags
Patch (6.07 KB, patch)
2012-01-30 15:21 PST, Oliver Hunt
barraclough: review+
Sander
Comment 1 2012-01-30 08:25:00 PST
Created attachment 124555 [details] Testcase
Gavin Barraclough
Comment 2 2012-01-30 13:05:13 PST
Huh, interesting. I can repro the issue, looks like a bug. I think the spec defined parsing here may be odd (looks like this should evaluate as: new (x('x'+y).c) = '' and not: (new x('x'+y)).c = '' Very strange that removing the +y influences behavior. We have some caching of the parsing of very small functions, possible that this works correctly in the initial parse of the outer program, and fails on the reparse of the function body (and in the case without +y maybe the caching means we get to skip the reparse).
Oliver Hunt
Comment 3 2012-01-30 13:19:17 PST
I have a fix, we weren't doing the correct logic when handling a 'new expr()' expression, so we end up thinking that we don't have a lhs element to assign to
Oliver Hunt
Comment 4 2012-01-30 13:22:07 PST
Building on my Air, so i won't have patch for ~an hour
Zoltan Herczeg
Comment 5 2012-01-30 13:25:40 PST
Oh those new expressions... I remember them. Parsing them is a nightmare. Btw 11.2 in Ecma-262
Oliver Hunt
Comment 6 2012-01-30 13:32:20 PST
(In reply to comment #5) > Oh those new expressions... I remember them. Parsing them is a nightmare. Btw 11.2 in Ecma-262 This is a regression due to some strictness hardening i did (in terms of parser strictness, rather than "strict mode"), the fix is trivial, alas this machine is slow. /me wants someone to invent a 24 core processor that runs at 3ghz, produces no heat, and has ~30 hours of battery life. is that too much to ask?
Oliver Hunt
Comment 7 2012-01-30 15:21:36 PST
Oliver Hunt
Comment 8 2012-01-30 16:15:51 PST
Note You need to log in before you can comment on or make changes to this bug.