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+

Description Sander 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.
Comment 1 Sander 2012-01-30 08:25:00 PST
Created attachment 124555 [details]
Testcase
Comment 2 Gavin Barraclough 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).
Comment 3 Oliver Hunt 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
Comment 4 Oliver Hunt 2012-01-30 13:22:07 PST
Building on my Air, so i won't have patch for ~an hour
Comment 5 Zoltan Herczeg 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
Comment 6 Oliver Hunt 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?
Comment 7 Oliver Hunt 2012-01-30 15:21:36 PST
Created attachment 124613 [details]
Patch
Comment 8 Oliver Hunt 2012-01-30 16:15:51 PST
Committed r106297: <http://trac.webkit.org/changeset/106297>