Bug 142992 - ES6: Object Literal Methods toString is missing method name
Summary: ES6: Object Literal Methods toString is missing method name
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-23 15:45 PDT by Joseph Pecoraro
Modified: 2015-03-24 13:08 PDT (History)
3 users (show)

See Also:


Attachments
[PATCH] Proposed Fix (160.80 KB, patch)
2015-03-23 17:47 PDT, Joseph Pecoraro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 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){}
Comment 1 Joseph Pecoraro 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.
Comment 2 Joseph Pecoraro 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
Comment 3 Joseph Pecoraro 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
Comment 4 Geoffrey Garen 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.
Comment 5 Joseph Pecoraro 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.
Comment 6 Joseph Pecoraro 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.
Comment 7 Geoffrey Garen 2015-03-24 11:30:23 PDT
Comment on attachment 249305 [details]
[PATCH] Proposed Fix

r=me
Comment 8 WebKit Commit Bot 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>
Comment 9 WebKit Commit Bot 2015-03-24 13:08:22 PDT
All reviewed patches have been landed.  Closing bug.