Reviewers: adamk,

Message:
PTAL

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 commit f2747ed9b48d0e62c7a30da69825ff926aeedbd2.

BUG=N
LOG=N
R=adamk
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_chromium_rel_ng;tryserver.blink:linux_blink_rel


Please review this at https://codereview.chromium.org/1195983002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+18, -0 lines):
  M src/v8natives.js
  A test/mjsunit/function-bind-name.js


Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 0cc50786f96fb2f5205696d22ef48eee888322f4..b002be3461852c65df3962e01354134d75b35f12 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -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;
@@ -1764,6 +1765,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
Index: test/mjsunit/function-bind-name.js
diff --git a/test/mjsunit/function-bind-name.js b/test/mjsunit/function-bind-name.js
new file mode 100644
index 0000000000000000000000000000000000000000..3bebf3e72d9da5c2f11c2c6c3c13a9d918462d95
--- /dev/null
+++ b/test/mjsunit/function-bind-name.js
@@ -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());


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to