Title: [196033] trunk
Revision
196033
Author
[email protected]
Date
2016-02-02 15:26:08 -0800 (Tue, 02 Feb 2016)

Log Message

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

Reviewed by Mark Lam.

Source/_javascript_Core:

See http://tc39.github.io/ecma262/#sec-function.prototype.bind for details.
What the spec says:
```
function foo() { }
foo.bind(null).name === "bound foo"

(function bar() { }).bind(null).name === "bound bar"
```

* runtime/FunctionPrototype.cpp:
(JSC::functionProtoFuncToString):
* runtime/JSBoundFunction.cpp:
(JSC::hasInstanceBoundFunction):
(JSC::JSBoundFunction::create):
(JSC::JSBoundFunction::visitChildren):
(JSC::JSBoundFunction::toStringName):
* runtime/JSBoundFunction.h:
(JSC::JSBoundFunction::boundThis):
(JSC::JSBoundFunction::boundArgs):
(JSC::JSBoundFunction::createStructure):
* tests/es6.yaml:

LayoutTests:

* inspector/runtime/getProperties-expected.txt:
* platform/mac/http/tests/media/media-source/SourceBuffer-abort-readyState-expected.txt:
* platform/mac/http/tests/media/media-source/SourceBuffer-abort-removed-expected.txt:
* platform/mac/http/tests/media/media-source/SourceBuffer-abort-updating-expected.txt:
* platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (196032 => 196033)


--- trunk/LayoutTests/ChangeLog	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/LayoutTests/ChangeLog	2016-02-02 23:26:08 UTC (rev 196033)
@@ -1,3 +1,16 @@
+2016-02-02  Saam barati  <[email protected]>
+
+        [ES6] bound functions .name property should be "bound " + the target function's name
+        https://bugs.webkit.org/show_bug.cgi?id=153796
+
+        Reviewed by Mark Lam.
+
+        * inspector/runtime/getProperties-expected.txt:
+        * platform/mac/http/tests/media/media-source/SourceBuffer-abort-readyState-expected.txt:
+        * platform/mac/http/tests/media/media-source/SourceBuffer-abort-removed-expected.txt:
+        * platform/mac/http/tests/media/media-source/SourceBuffer-abort-updating-expected.txt:
+        * platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt:
+
 2016-02-02  Ryan Haddad  <[email protected]>
 
         Marking perf/show-hide-table-rows.html as flaky on ios-simulator

Modified: trunk/LayoutTests/inspector/runtime/getProperties-expected.txt (196032 => 196033)


--- trunk/LayoutTests/inspector/runtime/getProperties-expected.txt	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/LayoutTests/inspector/runtime/getProperties-expected.txt	2016-02-02 23:26:08 UTC (rev 196033)
@@ -24,7 +24,7 @@
   arguments object TypeError: Type error
   caller object TypeError: Type error
   length number 0
-  name string Number
+  name string bound Number
 Internal properties:
   boundArgs object Array
   boundThis object Object

Modified: trunk/LayoutTests/platform/mac/http/tests/media/media-source/SourceBuffer-abort-readyState-expected.txt (196032 => 196033)


--- trunk/LayoutTests/platform/mac/http/tests/media/media-source/SourceBuffer-abort-readyState-expected.txt	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/LayoutTests/platform/mac/http/tests/media/media-source/SourceBuffer-abort-readyState-expected.txt	2016-02-02 23:26:08 UTC (rev 196033)
@@ -4,7 +4,7 @@
 http://127.0.0.1:8000/media/media-source/SourceBuffer-abort-readyState.html:20:29
 step@http://127.0.0.1:8000/w3c/resources/testharness.js:1160:30
 isTypeSupported@http://127.0.0.1:8000/media/media-source/SourceBuffer-abort-readyState.html:19:18
-isTypeSupported@[native code]
+bound isTypeSupported@[native code]
 http://127.0.0.1:8000/media/media-source/SourceBuffer-abort-readyState.html:42:36
 step@http://127.0.0.1:8000/w3c/resources/testharness.js:1160:30
 async_test@http://127.0.0.1:8000/w3c/resources/testharness.js:460:26

Modified: trunk/LayoutTests/platform/mac/http/tests/media/media-source/SourceBuffer-abort-removed-expected.txt (196032 => 196033)


--- trunk/LayoutTests/platform/mac/http/tests/media/media-source/SourceBuffer-abort-removed-expected.txt	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/LayoutTests/platform/mac/http/tests/media/media-source/SourceBuffer-abort-removed-expected.txt	2016-02-02 23:26:08 UTC (rev 196033)
@@ -4,7 +4,7 @@
 http://127.0.0.1:8000/media/media-source/SourceBuffer-abort-removed.html:19:29
 step@http://127.0.0.1:8000/w3c/resources/testharness.js:1160:30
 isTypeSupported@http://127.0.0.1:8000/media/media-source/SourceBuffer-abort-removed.html:18:18
-isTypeSupported@[native code]
+bound isTypeSupported@[native code]
 http://127.0.0.1:8000/media/media-source/SourceBuffer-abort-removed.html:28:36
 step@http://127.0.0.1:8000/w3c/resources/testharness.js:1160:30
 async_test@http://127.0.0.1:8000/w3c/resources/testharness.js:460:26

Modified: trunk/LayoutTests/platform/mac/http/tests/media/media-source/SourceBuffer-abort-updating-expected.txt (196032 => 196033)


--- trunk/LayoutTests/platform/mac/http/tests/media/media-source/SourceBuffer-abort-updating-expected.txt	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/LayoutTests/platform/mac/http/tests/media/media-source/SourceBuffer-abort-updating-expected.txt	2016-02-02 23:26:08 UTC (rev 196033)
@@ -4,7 +4,7 @@
 http://127.0.0.1:8000/media/media-source/SourceBuffer-abort-updating.html:33:29
 step@http://127.0.0.1:8000/w3c/resources/testharness.js:1160:30
 isTypeSupported@http://127.0.0.1:8000/media/media-source/SourceBuffer-abort-updating.html:32:18
-isTypeSupported@[native code]
+bound isTypeSupported@[native code]
 http://127.0.0.1:8000/media/media-source/SourceBuffer-abort-updating.html:42:36
 step@http://127.0.0.1:8000/w3c/resources/testharness.js:1160:30
 async_test@http://127.0.0.1:8000/w3c/resources/testharness.js:460:26

Modified: trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt (196032 => 196033)


--- trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt	2016-02-02 23:26:08 UTC (rev 196033)
@@ -8,7 +8,7 @@
 assert_throws@http://127.0.0.1:8000/w3c/resources/testharness.js:947:19
 http://127.0.0.1:8000/media/media-source/mediasource-sourcebuffer-mode.html:114:32
 handleWaitCallback_@http://127.0.0.1:8000/media/media-source/mediasource-util.js:97:17
-[native code]
+bound @[native code]
 step@http://127.0.0.1:8000/w3c/resources/testharness.js:1160:30
 http://127.0.0.1:8000/w3c/resources/testharness.js:1189:33)
 

Modified: trunk/Source/_javascript_Core/ChangeLog (196032 => 196033)


--- trunk/Source/_javascript_Core/ChangeLog	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-02-02 23:26:08 UTC (rev 196033)
@@ -1,3 +1,32 @@
+2016-02-02  Saam barati  <[email protected]>
+
+        [ES6] bound functions .name property should be "bound " + the target function's name
+        https://bugs.webkit.org/show_bug.cgi?id=153796
+
+        Reviewed by Mark Lam.
+
+        See http://tc39.github.io/ecma262/#sec-function.prototype.bind for details.
+        What the spec says:
+        ```
+        function foo() { }
+        foo.bind(null).name === "bound foo"
+
+        (function bar() { }).bind(null).name === "bound bar"
+        ```
+
+        * runtime/FunctionPrototype.cpp:
+        (JSC::functionProtoFuncToString):
+        * runtime/JSBoundFunction.cpp:
+        (JSC::hasInstanceBoundFunction):
+        (JSC::JSBoundFunction::create):
+        (JSC::JSBoundFunction::visitChildren):
+        (JSC::JSBoundFunction::toStringName):
+        * runtime/JSBoundFunction.h:
+        (JSC::JSBoundFunction::boundThis):
+        (JSC::JSBoundFunction::boundArgs):
+        (JSC::JSBoundFunction::createStructure):
+        * tests/es6.yaml:
+
 2016-02-02  Filip Pizlo  <[email protected]>
 
         Get rid of anonymous stack slots

Modified: trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp (196032 => 196033)


--- trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp	2016-02-02 23:26:08 UTC (rev 196033)
@@ -85,8 +85,14 @@
     JSValue thisValue = exec->thisValue();
     if (thisValue.inherits(JSFunction::info())) {
         JSFunction* function = jsCast<JSFunction*>(thisValue);
-        if (function->isHostOrBuiltinFunction())
-            return JSValue::encode(jsMakeNontrivialString(exec, "function ", function->name(exec), "() {\n    [native code]\n}"));
+        if (function->isHostOrBuiltinFunction()) {
+            String name;
+            if (JSBoundFunction* boundFunction = jsDynamicCast<JSBoundFunction*>(function))
+                name = boundFunction->toStringName(exec);
+            else
+                name = function->name(exec);
+            return JSValue::encode(jsMakeNontrivialString(exec, "function ", name, "() {\n    [native code]\n}"));
+        }
 
         FunctionExecutable* executable = function->jsExecutable();
         

Modified: trunk/Source/_javascript_Core/runtime/JSBoundFunction.cpp (196032 => 196033)


--- trunk/Source/_javascript_Core/runtime/JSBoundFunction.cpp	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/Source/_javascript_Core/runtime/JSBoundFunction.cpp	2016-02-02 23:26:08 UTC (rev 196033)
@@ -87,16 +87,17 @@
     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;
     ConstructType constructType = JSC::getConstructData(targetFunction, constructData);
     bool canConstruct = constructType != ConstructTypeNone;
-    NativeExecutable* executable = vm.getHostFunction(boundFunctionCall, canConstruct ? boundFunctionConstruct : callHostFunctionAsConstructor, name);
+    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, name);
+    function->finishCreation(vm, executable, length, makeString(ASCIILiteral(boundPrefix), name));
     return function;
 }
 
@@ -133,4 +134,12 @@
     visitor.append(&thisObject->m_boundArgs);
 }
 
+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);
+}
+
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/JSBoundFunction.h (196032 => 196033)


--- trunk/Source/_javascript_Core/runtime/JSBoundFunction.h	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/Source/_javascript_Core/runtime/JSBoundFunction.h	2016-02-02 23:26:08 UTC (rev 196033)
@@ -48,6 +48,8 @@
     JSValue boundThis() { return m_boundThis.get(); }
     JSValue boundArgs() { return m_boundArgs.get(); }
 
+    String toStringName(ExecState*);
+
     static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) 
     {
         ASSERT(globalObject);

Modified: trunk/Source/_javascript_Core/tests/es6.yaml (196032 => 196033)


--- trunk/Source/_javascript_Core/tests/es6.yaml	2016-02-02 23:21:12 UTC (rev 196032)
+++ trunk/Source/_javascript_Core/tests/es6.yaml	2016-02-02 23:26:08 UTC (rev 196033)
@@ -793,7 +793,7 @@
 - path: es6/function_name_property_accessor_properties.js
   cmd: runES6 :fail
 - path: es6/function_name_property_bound_functions.js
-  cmd: runES6 :fail
+  cmd: runES6 :normal
 - path: es6/function_name_property_class_expressions.js
   cmd: runES6 :fail
 - path: es6/function_name_property_class_statements.js
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to