Bug 17018 - Incorrect code generated from Function.toString for get/setters in object literals
Summary: Incorrect code generated from Function.toString for get/setters in object lit...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Oliver Hunt
URL:
Keywords: HasReduction
: 13621 (view as bug list)
Depends on:
Blocks: 13638
  Show dependency treegraph
 
Reported: 2008-01-26 03:38 PST by Oliver Hunt
Modified: 2008-02-11 17:04 PST (History)
3 users (show)

See Also:


Attachments
Patch! (3.84 KB, patch)
2008-01-26 04:41 PST, Oliver Hunt
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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. ***