Revert of Revert of [es6] Bound function names (patchset #1 id:1 of https://coderevie...
authorarv <arv@chromium.org>
Mon, 6 Jul 2015 16:20:35 +0000 (09:20 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 6 Jul 2015 16:20:47 +0000 (16:20 +0000)
Reason for revert:
This will prevent rolls. Fixing the root issue instead.

Original issue's description:
> Revert of [es6] Bound function names (patchset #1 id:1 of https://codereview.chromium.org/1195983002/)
>
> Reason for revert:
> Incorrect behavior
>
> Original issue's description:
> > [es6] Bound function names
> >
> > https://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.bind
> >
> > Bound functions should have a name based on the function that was
> > bound.
> >
> > This reverts the revert f2747ed9b48d0e62c7a30da69825ff926aeedbd2. The original
> > CL was reverted because the Blink layout test broke. I have a CL that disables
> > these tests at: https://codereview.chromium.org/1196753003/
> >
> > BUG=N
> > LOG=N
> > R=adamk
> > CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_chromium_rel_ng;tryserver.blink:linux_blink_rel
> >
> > Committed: https://crrev.com/b6d950c979f4348138de0ec54e40dcc48d833926
> > Cr-Commit-Position: refs/heads/master@{#29193}
>
> TBR=adamk@chromium.org,verwaest@chromium.org
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=N
>
> Committed: https://crrev.com/744e4d4fd9316674682bc6ca30ded5866494cc1c
> Cr-Commit-Position: refs/heads/master@{#29495}

TBR=adamk@chromium.org,verwaest@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=N

Review URL: https://codereview.chromium.org/1222363002

Cr-Commit-Position: refs/heads/master@{#29497}

src/v8natives.js
test/mjsunit/function-bind-name.js [new file with mode: 0644]

index d89c12b..72cb8ca 100644 (file)
@@ -21,6 +21,7 @@ var GlobalFunction = global.Function;
 var GlobalNumber = global.Number;
 var GlobalObject = global.Object;
 var InternalArray = utils.InternalArray;
+var SetFunctionName = utils.SetFunctionName;
 
 var MathAbs;
 var ProxyDelegateCallAndConstruct;
@@ -1702,6 +1703,10 @@ function FunctionBind(this_arg) { // Length is 1.
   var result = %FunctionBindArguments(boundFunction, this,
                                       this_arg, new_length);
 
+  var name = this.name;
+  var bound_name = IS_STRING(name) ? name : "";
+  SetFunctionName(result, bound_name, "bound");
+
   // We already have caller and arguments properties on functions,
   // which are non-configurable. It therefore makes no sence to
   // try to redefine these as defined by the spec. The spec says
diff --git a/test/mjsunit/function-bind-name.js b/test/mjsunit/function-bind-name.js
new file mode 100644 (file)
index 0000000..3bebf3e
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function f() {}
+var fb = f.bind({});
+assertEquals('bound f', fb.name);
+assertEquals('function bound f() { [native code] }', fb.toString());
+
+Object.defineProperty(f, 'name', {value: 42});
+var fb2 = f.bind({});
+assertEquals('bound ', fb2.name);
+assertEquals('function bound () { [native code] }', fb2.toString());