Bug 17012

Summary: REGRESSION: JSC can't round trip an object literal
Product: WebKit Reporter: Oliver Hunt <oliver>
Component: JavaScriptCoreAssignee: Oliver Hunt <oliver>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, jruderman, sam, slewis
Priority: P2 Keywords: HasReduction, Regression
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.4   
Bug Depends on:    
Bug Blocks: 13638    
Attachments:
Description Flags
Patch to fix the bug
oliver: review-
New version of fix mjs: review+

Description Oliver Hunt 2008-01-25 19:01:42 PST
JSC looses a pair of parenthesis when performing toString on a function, so that
  function f(){
   ({}).x;
  }
  f.toString()
produces
  function f(){
   {}.x;
  }
which is invalid.

This was found by jsfunfuzz
Comment 1 Oliver Hunt 2008-01-25 19:14:21 PST
I have a one line fix for this

Comment 2 Sam Weinig 2008-01-25 19:15:48 PST
This is a regression from shipping Safari.
Comment 3 Jesse Ruderman 2008-01-25 19:17:08 PST
toSource and uneval have to put parens around functions, but toString doesn't have to.  JSC's current behavior matches Spidermonkey.
Comment 4 Jesse Ruderman 2008-01-25 19:26:16 PST
Never mind, I misread the bug.
Comment 5 Oliver Hunt 2008-01-25 19:59:29 PST
this also occurs with function expressions

Comment 6 Oliver Hunt 2008-01-25 22:12:49 PST
I was wrong, it looks like our current funciton expression behaviour is sufficient
Comment 7 Oliver Hunt 2008-01-25 22:22:13 PST
Created attachment 18697 [details]
Patch to fix the bug
Comment 8 Darin Adler 2008-01-25 22:36:05 PST
Comment on attachment 18697 [details]
Patch to fix the bug

r=me

But is this a bug fix or not?
Comment 9 Oliver Hunt 2008-01-25 22:47:58 PST
Comment on attachment 18697 [details]
Patch to fix the bug

This is a bug fix -- the current code means Function.toString can produce incorrect code.

Maciej suggested an approach that would not use unnecessary ()'s for object literals.
Comment 10 Oliver Hunt 2008-01-25 23:39:44 PST
Created attachment 18699 [details]
New version of fix

No longer introduce unnecessary ()'s
Comment 11 Maciej Stachowiak 2008-01-25 23:43:50 PST
Comment on attachment 18699 [details]
New version of fix

r=me
Comment 12 Oliver Hunt 2008-01-25 23:56:53 PST
Landed r29802