Web Inspector: API View of Native DOM APIs looks poor (TypeErrors for native getters)
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jun 2016 04:19:42 +0000 (04:19 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jun 2016 04:19:42 +0000 (04:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158334
<rdar://problem/26615366>

Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/InjectedScriptSource.js:
(InjectedScript.prototype._getProperties):
(InjectedScript.prototype._propertyDescriptors):
Do not create fake value property descriptors for native accessors
unless requested. This means, getProperties for a native prototype
should return  accessors for native accessors just like it does
for normal non-native accessors (getters/setters).

(InjectedScript.prototype.getProperties):
Do not produce fake value accessors for native accessors.

(InjectedScript.prototype.getDisplayableProperties):
(InjectedScript.RemoteObject.prototype._generatePreview):
Do produce fake value accessors for native accessors.

LayoutTests:

* inspector/runtime/getProperties-expected.txt:
* inspector/runtime/getProperties.html:
Improve output for accessors now that getProperties
returns real accessor descriptors for native accessors
instead of fake value descriptors.

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

LayoutTests/ChangeLog
LayoutTests/inspector/runtime/getProperties-expected.txt
LayoutTests/inspector/runtime/getProperties.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/InjectedScriptSource.js

index 78788c2..ac5ff9d 100644 (file)
@@ -1,5 +1,19 @@
 2016-06-29  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: API View of Native DOM APIs looks poor (TypeErrors for native getters)
+        https://bugs.webkit.org/show_bug.cgi?id=158334
+        <rdar://problem/26615366>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/runtime/getProperties-expected.txt:
+        * inspector/runtime/getProperties.html:
+        Improve output for accessors now that getProperties
+        returns real accessor descriptors for native accessors
+        instead of fake value descriptors.
+
+2016-06-29  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: Wrong function name next to scope
         https://bugs.webkit.org/show_bug.cgi?id=158210
         <rdar://problem/26543093>
index 97ce6d2..84d4db5 100644 (file)
@@ -20,8 +20,8 @@ Properties:
   __proto__ function function () {
     [native code]
 }
-  arguments object TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in strict mode.
-  caller object TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in strict mode.
+  arguments getter setter
+  caller getter setter
   length number 0
   name string bound Number
 Internal properties:
@@ -37,8 +37,8 @@ Properties:
   __proto__ function function () {
     [native code]
 }
-  arguments object TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in strict mode.
-  caller object TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in strict mode.
+  arguments getter setter
+  caller getter setter
   length number 0
   name string bound 
 Internal properties:
index 74de1f9..1fe6e22 100644 (file)
@@ -80,11 +80,13 @@ function test()
         }
 
         function dumpSingleProperty(property) {
-            var {name, value} = property;
+            var {name, value, get, set} = property;
             if (value)
-                ProtocolTest.log("  " + name + " " + value.type + " " + (value.value || value.description));
+                ProtocolTest.log(`  ${name} ${value.type} ${value.value || value.description}`);
+            else if (get || set)
+                ProtocolTest.log(`  ${name} ${get ? "getter" : "-"} ${set ? "setter" : ""}`);
             else
-                ProtocolTest.log("  " + name);
+                ProtocolTest.log(`  ${name}`);
         }
 
         function NamedThingComparator(o1, o2) {
index 053da75..8020553 100644 (file)
@@ -1,3 +1,26 @@
+2016-06-29  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: API View of Native DOM APIs looks poor (TypeErrors for native getters)
+        https://bugs.webkit.org/show_bug.cgi?id=158334
+        <rdar://problem/26615366>
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/InjectedScriptSource.js:
+        (InjectedScript.prototype._getProperties):
+        (InjectedScript.prototype._propertyDescriptors):
+        Do not create fake value property descriptors for native accessors
+        unless requested. This means, getProperties for a native prototype
+        should return  accessors for native accessors just like it does
+        for normal non-native accessors (getters/setters).
+
+        (InjectedScript.prototype.getProperties):
+        Do not produce fake value accessors for native accessors.
+
+        (InjectedScript.prototype.getDisplayableProperties):
+        (InjectedScript.RemoteObject.prototype._generatePreview):
+        Do produce fake value accessors for native accessors.
+
 2016-06-29  Saam barati  <sbarati@apple.com>
 
         JSGlobalLexicalEnvironment needs a toThis implementation
index 1f499d1..08148d3 100644 (file)
@@ -251,7 +251,7 @@ InjectedScript.prototype = {
         return result;
     },
 
-    _getProperties: function(objectId, collectionMode, generatePreview)
+    _getProperties: function(objectId, collectionMode, generatePreview, nativeGettersAsValues)
     {
         var parsedObjectId = this._parseObjectId(objectId);
         var object = this._objectForId(parsedObjectId);
@@ -263,7 +263,7 @@ InjectedScript.prototype = {
         if (isSymbol(object))
             return false;
 
-        var descriptors = this._propertyDescriptors(object, collectionMode);
+        var descriptors = this._propertyDescriptors(object, collectionMode, nativeGettersAsValues);
 
         // Go over properties, wrap object values.
         for (var i = 0; i < descriptors.length; ++i) {
@@ -287,14 +287,16 @@ InjectedScript.prototype = {
 
     getProperties: function(objectId, ownProperties, generatePreview)
     {
+        var nativeGettersAsValues = false;
         var collectionMode = ownProperties ? InjectedScript.CollectionMode.OwnProperties : InjectedScript.CollectionMode.AllProperties;
-        return this._getProperties(objectId, collectionMode, generatePreview);
+        return this._getProperties(objectId, collectionMode, generatePreview, nativeGettersAsValues);
     },
 
     getDisplayableProperties: function(objectId, generatePreview)
     {
+        var nativeGettersAsValues = true;
         var collectionMode = InjectedScript.CollectionMode.OwnProperties | InjectedScript.CollectionMode.NativeGetterProperties;
-        return this._getProperties(objectId, collectionMode, generatePreview);
+        return this._getProperties(objectId, collectionMode, generatePreview, nativeGettersAsValues);
     },
 
     getInternalProperties: function(objectId, generatePreview)
@@ -570,7 +572,7 @@ InjectedScript.prototype = {
         return descriptors;
     },
 
-    _propertyDescriptors: function(object, collectionMode)
+    _propertyDescriptors: function(object, collectionMode, nativeGettersAsValues)
     {
         var descriptors = [];
         var nameProcessed = new Set;
@@ -612,11 +614,7 @@ InjectedScript.prototype = {
 
             // Native Getter properties.
             if (collectionMode & InjectedScript.CollectionMode.NativeGetterProperties) {
-                // FIXME: <https://webkit.org/b/140575> Web Inspector: Native Bindings Descriptors are Incomplete
-                // if (descriptor.hasOwnProperty("get") && descriptor.get && isNativeFunction(descriptor.get)) { ... }
-
                 if (possibleNativeBindingGetter) {
-                    // Possible getter property in the prototype chain.
                     descriptors.push(descriptor);
                     return;
                 }
@@ -644,15 +642,14 @@ InjectedScript.prototype = {
                     continue;
                 }
 
-                if (endsWith(String(descriptor.get), "[native code]\n}") ||
-                     (!descriptor.get && descriptor.hasOwnProperty("get") && !descriptor.set && descriptor.hasOwnProperty("set"))) {
-                    // FIXME: Some Native Bindings Descriptors are Incomplete
-                    // <https://webkit.org/b/141585> Some IDL attributes appear on the instances instead of on prototypes
-                    // Developers may create such a descriptors, so we should be resilient:
-                    // var x = {}; Object.defineProperty(x, "p", {get:undefined}); Object.getOwnPropertyDescriptor(x, "p")
-                    var fakeDescriptor = createFakeValueDescriptor(name, symbol, descriptor, isOwnProperty, true);
-                    processDescriptor(fakeDescriptor, isOwnProperty, true);
-                    continue;
+                if (nativeGettersAsValues) {
+                    if (endsWith(String(descriptor.get), "[native code]\n}") || (!descriptor.get && descriptor.hasOwnProperty("get") && !descriptor.set && descriptor.hasOwnProperty("set"))) {
+                        // Developers may create such a descriptor, so we should be resilient:
+                        // var x = {}; Object.defineProperty(x, "p", {get:undefined}); Object.getOwnPropertyDescriptor(x, "p")
+                        var fakeDescriptor = createFakeValueDescriptor(name, symbol, descriptor, isOwnProperty, true);
+                        processDescriptor(fakeDescriptor, isOwnProperty, true);
+                        continue;
+                    }
                 }
 
                 descriptor.name = name;
@@ -1043,7 +1040,8 @@ InjectedScript.RemoteObject.prototype = {
                 return preview;
 
             // Properties.
-            var descriptors = injectedScript._propertyDescriptors(object, InjectedScript.CollectionMode.AllProperties);
+            var nativeGettersAsValues = true;
+            var descriptors = injectedScript._propertyDescriptors(object, InjectedScript.CollectionMode.AllProperties, nativeGettersAsValues);
             this._appendPropertyPreviews(object, preview, descriptors, false, propertiesThreshold, firstLevelKeys, secondLevelKeys);
             if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0)
                 return preview;