RESOLVED FIXED 142992
ES6: Object Literal Methods toString is missing method name
https://bugs.webkit.org/show_bug.cgi?id=142992
Summary ES6: Object Literal Methods toString is missing method name
Joseph Pecoraro
Reported 2015-03-23 15:45:25 PDT
* SUMMARY Object Literal Methods toString is missing method name. * TEST o = { method(a,b){} }; o.method.toString(); * EXPECTED: method(a,b){} * ACTUAL (a,b){}
Attachments
[PATCH] Proposed Fix (160.80 KB, patch)
2015-03-23 17:47 PDT, Joseph Pecoraro
no flags
Joseph Pecoraro
Comment 1 2015-03-23 15:54:10 PDT
Function.prototype.string: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.tostring Note that the output can, and should be, the syntax of a `MethodDefinition`, not `FunctionDeclaration FunctionExpression` in this case. I'm not sure what would be best for computed method names: o = { ['method'](a,b){} }; o.method.name; // "" o.method.toString(); // => ??? That is a MethodDefinition. Firefox outputs "function (a,b){}" in that case, which I think makes some sense.
Joseph Pecoraro
Comment 2 2015-03-23 15:56:06 PDT
Wow, I didn't realize this, but this was in my test and failing: =( LayoutTests/js/object-literal-methods.html
Joseph Pecoraro
Comment 3 2015-03-23 16:12:37 PDT
(In reply to comment #2) > Wow, I didn't realize this, but this was in my test and failing: =( > LayoutTests/js/object-literal-methods.html Oh, never mind. This broke with r181810! <https://webkit.org/b/142853> Function.prototype.toString should not decompile the AST
Geoffrey Garen
Comment 4 2015-03-23 16:37:37 PDT
It looks like Firefox strigifies by concatenating "function " + function.name + [all text from opening paren to closing brace], with a separate code path for arrow functions. I think that's a reasonable solution.
Joseph Pecoraro
Comment 5 2015-03-23 17:24:40 PDT
(In reply to comment #4) > It looks like Firefox strigifies by concatenating "function " + > function.name + [all text from opening paren to closing brace], with a > separate code path for arrow functions. I think that's a reasonable solution. This will add back the space for an anonymous function: (function(a,b){}).toString(); // Currently : "function(a,b){}" // Always Space: "function (a,b){}" But this does match Firefox, always adding the space. So I'll go that route.
Joseph Pecoraro
Comment 6 2015-03-23 17:47:13 PDT
Created attachment 249305 [details] [PATCH] Proposed Fix I want this to run through all tests on EWS because I only did a subset based on what the previous change had changed.
Geoffrey Garen
Comment 7 2015-03-24 11:30:23 PDT
Comment on attachment 249305 [details] [PATCH] Proposed Fix r=me
WebKit Commit Bot
Comment 8 2015-03-24 13:08:11 PDT
Comment on attachment 249305 [details] [PATCH] Proposed Fix Clearing flags on attachment: 249305 Committed r181901: <http://trac.webkit.org/changeset/181901>
WebKit Commit Bot
Comment 9 2015-03-24 13:08:22 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.