[Webkit-unassigned] [Bug 154865] New: Function.name should be the inferred name when the function is anonymous.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Mar 1 11:09:14 PST 2016


https://bugs.webkit.org/show_bug.cgi?id=154865

            Bug ID: 154865
           Summary: Function.name should be the inferred name when the
                    function is anonymous.
    Classification: Unclassified
           Product: WebKit
           Version: WebKit Local Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: mark.lam at apple.com

THE ECMA spec on assignment (https://tc39.github.io/ecma262/#sec-assignment-operators-runtime-semantics-evaluation) says:

If IsAnonymousFunctionDefinition(AssignmentExpression) and IsIdentifierRef of LeftHandSideExpression are both true, then
    Let hasNameProperty be ? HasOwnProperty(rval, "name").
    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 "foo" implied from the var name.
    print(bar.name); // Should be "baz" 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 = "foo";
    print(Function.prototype.apply); // Prints "function apply() { [native code] }".

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

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 (https://github.com/rwaldron/tc39-notes/blob/master/es7/2016-01/2016-01-28.md),

    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).

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20160301/c74bf7c8/attachment.html>


More information about the webkit-unassigned mailing list