<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Function.name should be the inferred name when the function is anonymous."
   href="https://bugs.webkit.org/show_bug.cgi?id=154865">154865</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Function.name should be the inferred name when the function is anonymous.
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>WebKit Local Build
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>JavaScriptCore
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mark.lam&#64;apple.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>THE ECMA spec on assignment (<a href="https://tc39.github.io/ecma262/#sec-assignment-operators-runtime-semantics-evaluation">https://tc39.github.io/ecma262/#sec-assignment-operators-runtime-semantics-evaluation</a>) says:

If IsAnonymousFunctionDefinition(AssignmentExpression) and IsIdentifierRef of LeftHandSideExpression are both true, then
    Let hasNameProperty be ? HasOwnProperty(rval, &quot;name&quot;).
    If hasNameProperty is false, perform SetFunctionName(rval, GetReferencedName(lref)).

This means the following:

    var foo = function() {};
    var bar = function baz() {};
    print(foo.name); // Should be &quot;foo&quot; implied from the var name.
    print(bar.name); // Should be &quot;baz&quot; because it's explicitly specified and not anonymous.

Implementing this behavior exposes a nuanced behavior in JSC.  Note that the default attributes of Function.name are [[Writable]]:false [[Enumerable]]:false [[Configurable]]:true.  While Function.name is writable by default, it can be made writable.  The issue to consider is what should toString() print as the name of the function if we alter Function.name.

On Chrome and Firefox (after changing the name property to be writable):
    Function.prototype.apply.name = &quot;foo&quot;;
    print(Function.prototype.apply); // Prints &quot;function apply() { [native code] }&quot;.

In JSC with the above spec fix, we'll get:
    Function.prototype.apply.name = &quot;foo&quot;;
    print(Function.prototype.apply); // Prints &quot;function foo() { [native code] }&quot;.

Strictly speaking, this issue is already in ToT, but the above spec fix will start manifesting test failures due to this issue.

According to the Jan 28, 2016 TC-39 discussion on Function#toString (<a href="https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-01/2016-01-28.md">https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-01/2016-01-28.md</a>),

    discussion about what method name to use, and what if it isn't an identifier
    MM: Don't use the current value of the name property.

There wasn't any other discussion of what name to use beyond that, but Chrome and Firefox's implementations implies that they have consensus that the toString'ed function name should be the original name of the function, and not the value of Function.name (i.e. JSC needs a fix).</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>