Title: [196243] trunk
Revision
196243
Author
sbar...@apple.com
Date
2016-02-07 15:16:20 -0800 (Sun, 07 Feb 2016)

Log Message

Source/_javascript_Core:
Follow up patch to: [ES6] bound functions .name property should be "bound " + the target function's name
https://bugs.webkit.org/show_bug.cgi?id=153796

Reviewed by Darin Adler.

This follow-up patch addresses some comments/suggestions by
Ryosuke, Darin, and Joe. It simplifies JSBoundFunction::toStringName
and adds some tests for bound names.

* runtime/JSBoundFunction.cpp:
(JSC::hasInstanceBoundFunction):
(JSC::JSBoundFunction::create):
(JSC::JSBoundFunction::toStringName):

LayoutTests:
[ES6] bound functions .name property should be "bound " + the target function's name
https://bugs.webkit.org/show_bug.cgi?id=153796

Reviewed by Darin Adler.

* js/bound-function-name-expected.txt: Added.
* js/bound-function-name.html: Added.
* js/script-tests/bound-function-name.js: Added.
(assert):
(assert.foo):
(bar):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (196242 => 196243)


--- trunk/LayoutTests/ChangeLog	2016-02-07 22:26:46 UTC (rev 196242)
+++ trunk/LayoutTests/ChangeLog	2016-02-07 23:16:20 UTC (rev 196243)
@@ -1,3 +1,17 @@
+2016-02-07  Saam barati  <sbar...@apple.com>
+
+        [ES6] bound functions .name property should be "bound " + the target function's name
+        https://bugs.webkit.org/show_bug.cgi?id=153796
+
+        Reviewed by Darin Adler.
+
+        * js/bound-function-name-expected.txt: Added.
+        * js/bound-function-name.html: Added.
+        * js/script-tests/bound-function-name.js: Added.
+        (assert):
+        (assert.foo):
+        (bar):
+
 2016-02-07  Daniel Bates  <daba...@apple.com>
 
         CSP: Allow Web Workers initiated from an isolated world to bypass the main world Content Security Policy

Added: trunk/LayoutTests/js/bound-function-name-expected.txt (0 => 196243)


--- trunk/LayoutTests/js/bound-function-name-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/bound-function-name-expected.txt	2016-02-07 23:16:20 UTC (rev 196243)
@@ -0,0 +1,16 @@
+Bound Function Names
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Anonymous function bound name.
+PASS Function bound name should be foo.
+PASS Function bound name should be bar.
+PASS Function double bound name should be bar.
+Test InternalFunction names.
+PASS Function bound name should be Error.
+PASS Function bound name should be Function.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/js/bound-function-name.html (0 => 196243)


--- trunk/LayoutTests/js/bound-function-name.html	                        (rev 0)
+++ trunk/LayoutTests/js/bound-function-name.html	2016-02-07 23:16:20 UTC (rev 196243)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/js/script-tests/bound-function-name.js (0 => 196243)


--- trunk/LayoutTests/js/script-tests/bound-function-name.js	                        (rev 0)
+++ trunk/LayoutTests/js/script-tests/bound-function-name.js	2016-02-07 23:16:20 UTC (rev 196243)
@@ -0,0 +1,19 @@
+description("Bound Function Names");
+
+function assert(b, text) {
+    if (b)
+        testPassed(text);
+    else
+        testFailed(`Bad result: ${text}`);
+
+}
+assert((function() {}).bind().name === "bound ", "Anonymous function bound name.");
+assert((function foo() {}).bind().name === "bound foo", "Function bound name should be foo.");
+
+function bar() { }
+assert(bar.bind().name === "bound bar", "Function bound name should be bar.");
+assert(bar.bind().bind().name === "bound bound bar", "Function double bound name should be bar.");
+
+debug("Test InternalFunction names.");
+assert(Error.bind().name === "bound Error", "Function bound name should be Error.");
+assert(Function.bind().name === "bound Function", "Function bound name should be Function.");

Modified: trunk/Source/_javascript_Core/ChangeLog (196242 => 196243)


--- trunk/Source/_javascript_Core/ChangeLog	2016-02-07 22:26:46 UTC (rev 196242)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-02-07 23:16:20 UTC (rev 196243)
@@ -1,3 +1,19 @@
+2016-02-07  Saam barati  <sbar...@apple.com>
+
+        Follow up patch to: [ES6] bound functions .name property should be "bound " + the target function's name 
+        https://bugs.webkit.org/show_bug.cgi?id=153796
+
+        Reviewed by Darin Adler.
+
+        This follow-up patch addresses some comments/suggestions by
+        Ryosuke, Darin, and Joe. It simplifies JSBoundFunction::toStringName
+        and adds some tests for bound names.
+
+        * runtime/JSBoundFunction.cpp:
+        (JSC::hasInstanceBoundFunction):
+        (JSC::JSBoundFunction::create):
+        (JSC::JSBoundFunction::toStringName):
+
 2016-02-07  Filip Pizlo  <fpi...@apple.com>
 
         String.match should defend against matches that would crash the VM

Modified: trunk/Source/_javascript_Core/runtime/JSBoundFunction.cpp (196242 => 196243)


--- trunk/Source/_javascript_Core/runtime/JSBoundFunction.cpp	2016-02-07 22:26:46 UTC (rev 196242)
+++ trunk/Source/_javascript_Core/runtime/JSBoundFunction.cpp	2016-02-07 23:16:20 UTC (rev 196243)
@@ -87,8 +87,6 @@
     return JSValue::encode(jsBoolean(boundObject->targetFunction()->hasInstance(exec, value)));
 }
 
-static const char* const boundPrefix = "bound ";
-
 JSBoundFunction* JSBoundFunction::create(VM& vm, JSGlobalObject* globalObject, JSObject* targetFunction, JSValue boundThis, JSValue boundArgs, int length, const String& name)
 {
     ConstructData constructData;
@@ -97,7 +95,7 @@
     NativeExecutable* executable = vm.getHostFunction(boundFunctionCall, canConstruct ? boundFunctionConstruct : callHostFunctionAsConstructor, ASCIILiteral("Function.prototype.bind result"));
     JSBoundFunction* function = new (NotNull, allocateCell<JSBoundFunction>(vm.heap)) JSBoundFunction(vm, globalObject, globalObject->boundFunctionStructure(), targetFunction, boundThis, boundArgs);
 
-    function->finishCreation(vm, executable, length, makeString(ASCIILiteral(boundPrefix), name));
+    function->finishCreation(vm, executable, length, makeString("bound ", name));
     return function;
 }
 
@@ -136,10 +134,7 @@
 
 String JSBoundFunction::toStringName(ExecState* exec)
 {
-    String result = name(exec);
-    ASSERT(result.find(ASCIILiteral(boundPrefix)) == 0);
-    static const size_t boundPrefixLength = 6;
-    return result.substring(boundPrefixLength);
+    return m_targetFunction->get(exec, exec->vm().propertyNames->name).toWTFString(exec);
 }
 
 } // namespace JSC
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to