Web Inspector: Improved Console Support for Bound Functions
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 20:17:28 +0000 (20:17 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 20:17:28 +0000 (20:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141635

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::getInternalProperties):
Expose internal properties of a JSBoundFunction.

LayoutTests:

* inspector/model/remote-object-get-properties-expected.txt:
* inspector/model/remote-object-get-properties.html:
Show that boundFunction has extra properties (targetFunction, boundThis, boundArgs).

* inspector/model/remote-object-expected.txt:
* inspector/model/remote-object.html:
Include a bound function. Much different from a function now though.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180236 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector-protocol/runtime/getProperties-expected.txt
LayoutTests/inspector-protocol/runtime/getProperties.html
LayoutTests/inspector/model/remote-object-expected.txt
LayoutTests/inspector/model/remote-object-get-properties-expected.txt
LayoutTests/inspector/model/remote-object-get-properties.html
LayoutTests/inspector/model/remote-object.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp

index e27a6dd..ece55b9 100644 (file)
@@ -1,5 +1,20 @@
 2015-02-16  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Improved Console Support for Bound Functions
+        https://bugs.webkit.org/show_bug.cgi?id=141635
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/model/remote-object-get-properties-expected.txt:
+        * inspector/model/remote-object-get-properties.html:
+        Show that boundFunction has extra properties (targetFunction, boundThis, boundArgs).
+
+        * inspector/model/remote-object-expected.txt:
+        * inspector/model/remote-object.html:
+        Include a bound function. Much different from a function now though.
+
+2015-02-16  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: ES6: Improved Console Support for Promise Objects
         https://bugs.webkit.org/show_bug.cgi?id=141634
 
index d1b6e59..16d63f9 100644 (file)
@@ -1,16 +1,24 @@
 Properties of Object(5)
-  __proto__ object undefined
+  __proto__ object Number
   foo string cat
 Properties of array
-  __proto__ object undefined
+  __proto__ object Array[0]
   0 string red
   1 string green
   2 string blue
   length number 3
 Properties of Bound function
-  __proto__ function undefined
+  __proto__ function function () {
+    [native code]
+}
   arguments
   caller
   length number 0
   name string Number
+Internal properties
+  boundArgs object Array[1]
+  boundThis object Object
+  targetFunction function function Number() {
+    [native code]
+}
 
index 5d0b1e5..e9a1220 100644 (file)
@@ -127,7 +127,7 @@ function test()
             var p = propertyArray[i];
             var v = p.value;
             if (v)
-                InspectorTest.log("  " + p.name + " " + v.type + " " + v.value);
+                InspectorTest.log("  " + p.name + " " + v.type + " " + (v.value || v.description));
             else
                 InspectorTest.log("  " + p.name);
         }
@@ -138,7 +138,7 @@ function test()
             for (var i = 0; i < internalPropertyArray.length; i++) {
                 var p = internalPropertyArray[i];
                 var v = p.value;
-                InspectorTest.log("  " + p.name + " " + v.type + " " + v.value);
+                InspectorTest.log("  " + p.name + " " + v.type + " " + (v.value || v.description));
             }
         }
 
index 973d2da..235a463 100644 (file)
@@ -208,6 +208,14 @@ EXPRESSION: function myFunction(a, b) { console.log(a, b); }; myFunction
 }
 
 -----------------------------------------------------
+EXPRESSION: function myTarget(a, b) { console.log(a, b); }; myTarget.bind(null)
+{
+  "_type": "function",
+  "_objectId": "<filtered>",
+  "_description": "function myTarget() {\n    [native code]\n}"
+}
+
+-----------------------------------------------------
 EXPRESSION: Array.prototype.push
 {
   "_type": "function",
index 025487c..fa31201 100644 (file)
@@ -178,5 +178,107 @@ ALL PROPERTIES:
     __lookupSetter__
     __proto__
 -----------------------------------------------------
+
+-----------------------------------------------------
+EXPRESSION: window.unboundFunction
+type: function
+description: function () { console.log(arguments); }
+
+OWN PROPERTIES:
+    arguments
+    caller
+    length
+    name
+    prototype
+    __proto__
+
+OWN AND GETTER PROPERTIES:
+    arguments
+    caller
+    length
+    name
+    prototype
+    __proto__
+
+ALL PROPERTIES:
+    arguments
+    caller
+    length
+    name
+    prototype
+    toString
+    apply
+    call
+    bind
+    constructor
+    toLocaleString
+    valueOf
+    hasOwnProperty
+    propertyIsEnumerable
+    isPrototypeOf
+    __defineGetter__
+    __defineSetter__
+    __lookupGetter__
+    __lookupSetter__
+    __proto__
+-----------------------------------------------------
+
+-----------------------------------------------------
+EXPRESSION: window.boundFunction
+type: function
+description: function () {
+    [native code]
+}
+
+OWN PROPERTIES:
+    name
+    length
+    get arguments
+    set arguments
+    get caller
+    set caller
+    __proto__
+    targetFunction
+    boundThis
+    boundArgs
+
+OWN AND GETTER PROPERTIES:
+    name
+    length
+    get arguments
+    set arguments
+    get caller
+    set caller
+    __proto__
+    targetFunction
+    boundThis
+    boundArgs
+
+ALL PROPERTIES:
+    name
+    length
+    get arguments
+    set arguments
+    get caller
+    set caller
+    toString
+    apply
+    call
+    bind
+    constructor
+    toLocaleString
+    valueOf
+    hasOwnProperty
+    propertyIsEnumerable
+    isPrototypeOf
+    __defineGetter__
+    __defineSetter__
+    __lookupGetter__
+    __lookupSetter__
+    __proto__
+    targetFunction
+    boundThis
+    boundArgs
+-----------------------------------------------------
 DONE
 
index e0c0792..4301fe0 100644 (file)
@@ -41,6 +41,8 @@ ClassWithBadGetter.prototype = {
 var simpleObject = {a:1, b:"string"};
 var complexObject = new SuperFoo;
 var badGetterObject = new ClassWithBadGetter;
+var unboundFunction = function() { console.log(arguments); }
+var boundFunction = unboundFunction.bind(document.body, 1, 2, 3);
 
 
 // --------
@@ -55,6 +57,8 @@ function test()
         {expression: "window.loadEvent"},
         {expression: "window.complexObject"},
         {expression: "window.badGetterObject"},
+        {expression: "window.unboundFunction"},
+        {expression: "window.boundFunction"},
     ]
 
     function runNextStep() {
index b83a745..8c4de01 100644 (file)
@@ -49,6 +49,7 @@ function test()
         {expression: "(function(){})"},
         {expression: "function foo(){}; foo"},
         {expression: "function myFunction(a, b) { console.log(a, b); }; myFunction"},
+        {expression: "function myTarget(a, b) { console.log(a, b); }; myTarget.bind(null)"}, // bound function
         {expression: "Array.prototype.push"}, // native (ECMAScript)
         {expression: "window.setTimeout"}, // native (DOM)
         {expression: "Object.getOwnPropertyDescriptor({ get getter() { return 1 } }, 'getter').get"}, // getter
index d86d82a..341e157 100644 (file)
@@ -1,5 +1,16 @@
 2015-02-16  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Improved Console Support for Bound Functions
+        https://bugs.webkit.org/show_bug.cgi?id=141635
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/JSInjectedScriptHost.cpp:
+        (Inspector::JSInjectedScriptHost::getInternalProperties):
+        Expose internal properties of a JSBoundFunction.
+
+2015-02-16  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: ES6: Improved Console Support for Promise Objects
         https://bugs.webkit.org/show_bug.cgi?id=141634
 
index 75df5ea..215784c 100644 (file)
@@ -30,6 +30,7 @@
 #include "Error.h"
 #include "InjectedScriptHost.h"
 #include "JSArray.h"
+#include "JSBoundFunction.h"
 #include "JSCInlines.h"
 #include "JSFunction.h"
 #include "JSInjectedScriptHostPrototype.h"
@@ -208,8 +209,7 @@ JSValue JSInjectedScriptHost::getInternalProperties(ExecState* exec)
 
     JSValue value = exec->uncheckedArgument(0);
 
-    JSPromise* promise = jsDynamicCast<JSPromise*>(value);
-    if (promise) {
+    if (JSPromise* promise = jsDynamicCast<JSPromise*>(value)) {
         unsigned index = 0;
         JSArray* array = constructEmptyArray(exec, nullptr);
         switch (promise->status()) {
@@ -229,6 +229,15 @@ JSValue JSInjectedScriptHost::getInternalProperties(ExecState* exec)
         return array;
     }
 
+    if (JSBoundFunction* boundFunction = jsDynamicCast<JSBoundFunction*>(value)) {
+        unsigned index = 0;
+        JSArray* array = constructEmptyArray(exec, nullptr, 3);
+        array->putDirectIndex(exec, index++, constructInternalProperty(exec, "targetFunction", boundFunction->targetFunction()));
+        array->putDirectIndex(exec, index++, constructInternalProperty(exec, "boundThis", boundFunction->boundThis()));
+        array->putDirectIndex(exec, index++, constructInternalProperty(exec, "boundArgs", boundFunction->boundArgs()));
+        return array;
+    }
+
     return jsUndefined();
 }