Bug 17018

Summary: Incorrect code generated from Function.toString for get/setters in object literals
Product: WebKit Reporter: Oliver Hunt <oliver>
Component: JavaScriptCoreAssignee: Oliver Hunt <oliver>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, jruderman, oliver
Priority: P2 Keywords: HasReduction
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.4   
Bug Depends on:    
Bug Blocks: 13638    
Attachments:
Description Flags
Patch! darin: review+

Description Oliver Hunt 2008-01-26 03:38:42 PST
If you have a function:
function f() {
   ({ set g(x){} });
}

Then f.toString will produce incorrect (non-compilable) output as it quotes the identifier string:
function f() {
   ({ set "g"(x){} });
}

Found by jsfunfuzz -- maybe i had recopmilation set to not test these cases when i was running these?
Comment 1 Oliver Hunt 2008-01-26 03:58:17 PST
Fix appears to be
diff --git a/JavaScriptCore/kjs/nodes2string.cpp b/JavaScriptCore/kjs/nodes2string.cpp
index 0432b7f..79a0675 100644
--- a/JavaScriptCore/kjs/nodes2string.cpp
+++ b/JavaScriptCore/kjs/nodes2string.cpp
@@ -370,11 +370,11 @@ void PropertyNode::streamTo(SourceStream& s) const
         case Setter: {
             const FuncExprNode* func = static_cast<const FuncExprNode*>(assign.get());
             if (type == Getter)
-                s << "get \""; 
+                s << "get "; 
             else
-                s << "set \"";
+                s << "set ";
             s << escapeStringForPrettyPrinting(name().ustring())
-                << "\"(" << func->param << ')' << func->body;
+                << "(" << func->param << ')' << func->body;
             break;
         }
     }


But I can't see why they were ever escaped strings -- is there a case i am missing where 'set "foo"(x)' would be valid?
Comment 2 Oliver Hunt 2008-01-26 04:41:26 PST
Created attachment 18706 [details]
Patch!
Comment 3 Darin Adler 2008-01-26 08:13:46 PST
Comment on attachment 18706 [details]
Patch!

r=me

What about getters and setters with unusual names?
Comment 4 Oliver Hunt 2008-02-01 00:00:44 PST
Fixed in r29812
Comment 5 Jesse Ruderman 2008-02-11 17:04:44 PST
*** Bug 13621 has been marked as a duplicate of this bug. ***