Web Inspector: RemoteObject.resolveNode should return a Promise
authormattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Sep 2017 23:14:47 +0000 (23:14 +0000)
committermattbaker@apple.com <mattbaker@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Sep 2017 23:14:47 +0000 (23:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177042

Reviewed by Joseph Pecoraro.

Source/WebInspectorUI:

Update RemoteObject.resolveNode to return a promise instead of taking a
callback. If the promise is fulfilled, `remoteObject` will be non-null.

* UserInterface/Controllers/DOMTreeManager.js:
(WI.DOMTreeManager.prototype.inspectNodeObject.nodeAvailable):
(WI.DOMTreeManager.prototype.inspectNodeObject):
(WI.DOMTreeManager.prototype.getNodeContentFlowInfo.domNodeResolved): Deleted.

* UserInterface/Models/DOMNode.js:
(WI.DOMNode.prototype.toggleClass.WI.RemoteObject.resolveNode.then):
(WI.DOMNode.prototype.toggleClass):
(WI.DOMNode.prototype.scrollIntoView.WI.RemoteObject.resolveNode.then):
(WI.DOMNode.prototype.scrollIntoView):
(WI.DOMNode.prototype.toggleClass.resolvedNode.inspectedPage_node_toggleClass): Deleted.
(WI.DOMNode.prototype.toggleClass.resolvedNode): Deleted.
(WI.DOMNode.prototype.scrollIntoView.resolvedNode.inspectedPage_node_scrollIntoView): Deleted.
(WI.DOMNode.prototype.scrollIntoView.resolvedNode): Deleted.

* UserInterface/Protocol/RemoteObject.js:
(WI.RemoteObject.resolveNode):

* UserInterface/Views/BoxModelDetailsSectionRow.js:
(WI.BoxModelDetailsSectionRow.prototype._applyUserInput.WI.RemoteObject.resolveNode.then):
(WI.BoxModelDetailsSectionRow.prototype._applyUserInput):
(WI.BoxModelDetailsSectionRow.prototype._applyUserInput.resolvedNode.toggleInlineStyleProperty): Deleted.
(WI.BoxModelDetailsSectionRow.prototype._applyUserInput.resolvedNode.didToggle): Deleted.
(WI.BoxModelDetailsSectionRow.prototype._applyUserInput.resolvedNode): Deleted.
* UserInterface/Views/CanvasDetailsSidebarPanel.js:

* UserInterface/Views/ContextMenuUtilities.js:
(WI.appendContextMenuItemsForDOMNode):

* UserInterface/Views/DOMNodeDetailsSidebarPanel.js:
(WI.DOMNodeDetailsSidebarPanel.prototype._refreshProperties.nodeResolved.inspectedPage_node_collectPrototypes): Deleted.
(WI.DOMNodeDetailsSidebarPanel.prototype._refreshProperties.nodeResolved): Deleted.
(WI.DOMNodeDetailsSidebarPanel.prototype._refreshProperties.nodePrototypesReady): Deleted.

* UserInterface/Views/DOMTreeElement.js:
(WI.DOMTreeElement.prototype._createTooltipForNode.WI.RemoteObject.resolveNode.then):
(WI.DOMTreeElement.prototype._createTooltipForNode):
(WI.DOMTreeElement.prototype._createTooltipForNode.resolvedNode.dimensions): Deleted.
(WI.DOMTreeElement.prototype._createTooltipForNode.resolvedNode): Deleted.

* UserInterface/Views/DOMTreeOutline.js:
(WI.DOMTreeOutline.prototype._hideElement.injectStyleAndToggleClass):
(WI.DOMTreeOutline.prototype._hideElement):
(WI.DOMTreeOutline):
(WI.DOMTreeOutline.prototype._hideElement.resolvedNode.injectStyleAndToggleClass): Deleted.
(WI.DOMTreeOutline.prototype._hideElement.resolvedNode): Deleted.

LayoutTests:

Updated tests to use promises instead of callbacks.

* inspector/dom/highlightNode.html:

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

12 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/dom/highlightNode.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/DOMTreeManager.js
Source/WebInspectorUI/UserInterface/Models/DOMNode.js
Source/WebInspectorUI/UserInterface/Protocol/RemoteObject.js
Source/WebInspectorUI/UserInterface/Views/BoxModelDetailsSectionRow.js
Source/WebInspectorUI/UserInterface/Views/CanvasDetailsSidebarPanel.js
Source/WebInspectorUI/UserInterface/Views/ContextMenuUtilities.js
Source/WebInspectorUI/UserInterface/Views/DOMNodeDetailsSidebarPanel.js
Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js
Source/WebInspectorUI/UserInterface/Views/DOMTreeOutline.js

index df5674e..82ef86d 100644 (file)
@@ -1,3 +1,14 @@
+2017-09-18  Matt Baker  <mattbaker@apple.com>
+
+        Web Inspector: RemoteObject.resolveNode should return a Promise
+        https://bugs.webkit.org/show_bug.cgi?id=177042
+
+        Reviewed by Joseph Pecoraro.
+
+        Updated tests to use promises instead of callbacks.
+
+        * inspector/dom/highlightNode.html:
+
 2017-09-18  Devin Rousso  <webkit@devinrousso.com>
 
         Web Inspector: make Canvas recording tests more human readable
index d0d6a45..06fb6d3 100644 (file)
@@ -82,12 +82,13 @@ function test()
         name: "MainFrameNodeViaObjectId",
         description: "Should highlight a node in the main frame using object id.",
         test(resolve, reject) {
-            WI.RemoteObject.resolveNode(mainFrameTargetNode, "test"(remoteObject) => {
+            WI.RemoteObject.resolveNode(mainFrameTargetNode, "test").then((remoteObject) => {
                 DOMAgent.highlightNode(highlightConfig, undefined, remoteObject.objectId, (error) => {
                     InspectorTest.assert(!error, "Should not have an error.");
                     dumpHighlight(resolve);
                 });
-            });
+            })
+            .catch(reject);
         }
     });
 
@@ -95,12 +96,13 @@ function test()
         name: "ChildFrameNodeViaObjectId",
         description: "Should highlight a node in the child frame using object id.",
         test(resolve, reject) {
-            WI.RemoteObject.resolveNode(childFrameTargetNode, "test"(remoteObject) => {
+            WI.RemoteObject.resolveNode(childFrameTargetNode, "test").then((remoteObject) => {
                 DOMAgent.highlightNode(highlightConfig, undefined, remoteObject.objectId, (error) => {
                     InspectorTest.assert(!error, "Should not have an error.");
                     dumpHighlight(resolve);
                 });
-            });
+            })
+            .catch(reject);
         }
     });
 
index 10338f3..613ea4b 100644 (file)
@@ -1,3 +1,60 @@
+2017-09-18  Matt Baker  <mattbaker@apple.com>
+
+        Web Inspector: RemoteObject.resolveNode should return a Promise
+        https://bugs.webkit.org/show_bug.cgi?id=177042
+
+        Reviewed by Joseph Pecoraro.
+
+        Update RemoteObject.resolveNode to return a promise instead of taking a
+        callback. If the promise is fulfilled, `remoteObject` will be non-null.
+
+        * UserInterface/Controllers/DOMTreeManager.js:
+        (WI.DOMTreeManager.prototype.inspectNodeObject.nodeAvailable):
+        (WI.DOMTreeManager.prototype.inspectNodeObject):
+        (WI.DOMTreeManager.prototype.getNodeContentFlowInfo.domNodeResolved): Deleted.
+
+        * UserInterface/Models/DOMNode.js:
+        (WI.DOMNode.prototype.toggleClass.WI.RemoteObject.resolveNode.then):
+        (WI.DOMNode.prototype.toggleClass):
+        (WI.DOMNode.prototype.scrollIntoView.WI.RemoteObject.resolveNode.then):
+        (WI.DOMNode.prototype.scrollIntoView):
+        (WI.DOMNode.prototype.toggleClass.resolvedNode.inspectedPage_node_toggleClass): Deleted.
+        (WI.DOMNode.prototype.toggleClass.resolvedNode): Deleted.
+        (WI.DOMNode.prototype.scrollIntoView.resolvedNode.inspectedPage_node_scrollIntoView): Deleted.
+        (WI.DOMNode.prototype.scrollIntoView.resolvedNode): Deleted.
+
+        * UserInterface/Protocol/RemoteObject.js:
+        (WI.RemoteObject.resolveNode):
+
+        * UserInterface/Views/BoxModelDetailsSectionRow.js:
+        (WI.BoxModelDetailsSectionRow.prototype._applyUserInput.WI.RemoteObject.resolveNode.then):
+        (WI.BoxModelDetailsSectionRow.prototype._applyUserInput):
+        (WI.BoxModelDetailsSectionRow.prototype._applyUserInput.resolvedNode.toggleInlineStyleProperty): Deleted.
+        (WI.BoxModelDetailsSectionRow.prototype._applyUserInput.resolvedNode.didToggle): Deleted.
+        (WI.BoxModelDetailsSectionRow.prototype._applyUserInput.resolvedNode): Deleted.
+        * UserInterface/Views/CanvasDetailsSidebarPanel.js:
+
+        * UserInterface/Views/ContextMenuUtilities.js:
+        (WI.appendContextMenuItemsForDOMNode):
+
+        * UserInterface/Views/DOMNodeDetailsSidebarPanel.js:
+        (WI.DOMNodeDetailsSidebarPanel.prototype._refreshProperties.nodeResolved.inspectedPage_node_collectPrototypes): Deleted.
+        (WI.DOMNodeDetailsSidebarPanel.prototype._refreshProperties.nodeResolved): Deleted.
+        (WI.DOMNodeDetailsSidebarPanel.prototype._refreshProperties.nodePrototypesReady): Deleted.
+
+        * UserInterface/Views/DOMTreeElement.js:
+        (WI.DOMTreeElement.prototype._createTooltipForNode.WI.RemoteObject.resolveNode.then):
+        (WI.DOMTreeElement.prototype._createTooltipForNode):
+        (WI.DOMTreeElement.prototype._createTooltipForNode.resolvedNode.dimensions): Deleted.
+        (WI.DOMTreeElement.prototype._createTooltipForNode.resolvedNode): Deleted.
+
+        * UserInterface/Views/DOMTreeOutline.js:
+        (WI.DOMTreeOutline.prototype._hideElement.injectStyleAndToggleClass):
+        (WI.DOMTreeOutline.prototype._hideElement):
+        (WI.DOMTreeOutline):
+        (WI.DOMTreeOutline.prototype._hideElement.resolvedNode.injectStyleAndToggleClass): Deleted.
+        (WI.DOMTreeOutline.prototype._hideElement.resolvedNode): Deleted.
+
 2017-09-18  Brian Burg  <bburg@apple.com>
 
         Web Inspector: introduce an AppController class and shared instance of it
index 0e2bd49..547d8ea 100644 (file)
@@ -371,11 +371,9 @@ WI.DOMTreeManager = class DOMTreeManager extends WI.Object
 
             // Re-resolve the node in the console's object group when adding to the console.
             let domNode = this.nodeForId(nodeId);
-            WI.RemoteObject.resolveNode(domNode, WI.RuntimeManager.ConsoleObjectGroup, function(remoteObject) {
-                if (!remoteObject)
-                    return;
-                let specialLogStyles = true;
-                let shouldRevealConsole = false;
+            WI.RemoteObject.resolveNode(domNode, WI.RuntimeManager.ConsoleObjectGroup).then((remoteObject) => {
+                const specialLogStyles = true;
+                const shouldRevealConsole = false;
                 WI.consoleLogViewController.appendImmediateExecutionWithResult(WI.UIString("Selected Element"), remoteObject, specialLogStyles, shouldRevealConsole);
             });
         }
@@ -700,16 +698,8 @@ WI.DOMTreeManager = class DOMTreeManager extends WI.Object
 
     getNodeContentFlowInfo(domNode, resultReadyCallback)
     {
-        DOMAgent.resolveNode(domNode.id, domNodeResolved.bind(this));
-
-        function domNodeResolved(error, remoteObject)
-        {
-            if (error) {
-                resultReadyCallback(error);
-                return;
-            }
-
-            var evalParameters = {
+        WI.RemoteObject.resolveNode(domNode).then((remoteObject) => {
+            let evalParameters = {
                 objectId: remoteObject.objectId,
                 functionDeclaration: appendWebInspectorSourceURL(inspectedPage_node_getFlowInfo.toString()),
                 doNotPauseOnExceptionsAndMuteConsole: true,
@@ -717,7 +707,7 @@ WI.DOMTreeManager = class DOMTreeManager extends WI.Object
                 generatePreview: false
             };
             RuntimeAgent.callFunctionOn.invoke(evalParameters, regionNodesAvailable.bind(this));
-        }
+        }).catch(resultReadyCallback);
 
         function regionNodesAvailable(error, remoteObject, wasThrown)
         {
index 07fafd5..5a89e78 100644 (file)
@@ -441,40 +441,26 @@ WI.DOMNode = class DOMNode extends WI.Object
         if (this.nodeType() !== Node.ELEMENT_NODE)
             return;
 
-        function resolvedNode(object)
-        {
-            if (!object)
-                return;
-
-            function inspectedPage_node_toggleClass(className, flag)
-            {
+        WI.RemoteObject.resolveNode(this).then((object) => {
+            function inspectedPage_node_toggleClass(className, flag) {
                 this.classList.toggle(className, flag);
             }
 
             object.callFunction(inspectedPage_node_toggleClass, [className, flag]);
             object.release();
-        }
-
-        WI.RemoteObject.resolveNode(this, "", resolvedNode);
+        });
     }
 
     scrollIntoView()
     {
-        function resolvedNode(object)
-        {
-            if (!object)
-                return;
-
-            function inspectedPage_node_scrollIntoView()
-            {
+        WI.RemoteObject.resolveNode(this).then((object) => {
+            function inspectedPage_node_scrollIntoView() {
                 this.scrollIntoViewIfNeeded(true);
             }
 
             object.callFunction(inspectedPage_node_scrollIntoView);
             object.release();
-        }
-
-        WI.RemoteObject.resolveNode(this, "", resolvedNode);
+        });
     }
 
     getChildNodes(callback)
index 8c17c87..c5abd05 100644 (file)
@@ -125,17 +125,10 @@ WI.RemoteObject = class RemoteObject
         return {value: valueOrObject};
     }
 
-    static resolveNode(node, objectGroup, callback)
+    static resolveNode(node, objectGroup)
     {
-        DOMAgent.resolveNode(node.id, objectGroup, function(error, object) {
-            if (!callback)
-                return;
-
-            if (error || !object)
-                callback(null);
-            else
-                callback(WI.RemoteObject.fromPayload(object, WI.mainTarget));
-        });
+        return DOMAgent.resolveNode(node.id, objectGroup)
+            .then(({object}) => WI.RemoteObject.fromPayload(object, WI.mainTarget));
     }
 
     static resolveWebSocket(webSocketResource, objectGroup, callback)
index 52d744a..b1261f2 100644 (file)
@@ -404,26 +404,18 @@ WI.BoxModelDetailsSectionRow = class BoxModelDetailsSectionRow extends WI.Detail
             userInput = userValuePx + "px";
         }
 
-        function resolvedNode(object)
-        {
-            if (!object)
-                return;
-
-            function toggleInlineStyleProperty(property, value)
-            {
+        WI.RemoteObject.resolveNode(this._nodeStyles.node).then((object) => {
+            function inspectedPage_node_toggleInlineStyleProperty(property, value) {
                 this.style.setProperty(property, value, "important");
             }
 
-            function didToggle()
-            {
+            let didToggle = () => {
                 this._nodeStyles.refresh();
-            }
+            };
 
-            object.callFunction(toggleInlineStyleProperty, [styleProperty, userInput], false, didToggle.bind(this));
+            object.callFunction(inspectedPage_node_toggleInlineStyleProperty, [styleProperty, userInput], false, didToggle);
             object.release();
-        }
-
-        WI.RemoteObject.resolveNode(this._nodeStyles.node, "", resolvedNode.bind(this));
+        });
     }
 
     _editingCommitted(element, userInput, previousContent, context)
index 4bd5ea2..84b5719 100644 (file)
@@ -198,10 +198,7 @@ WI.CanvasDetailsSidebarPanel = class CanvasDetailsSidebarPanel extends WI.Detail
                 // attributes, we need to invoke the getter for each to get the actual value.
                 //  - https://html.spec.whatwg.org/multipage/canvas.html#attr-canvas-width
                 //  - https://html.spec.whatwg.org/multipage/canvas.html#attr-canvas-height
-                WI.RemoteObject.resolveNode(node, "", (remoteObject) => {
-                    if (!remoteObject)
-                        return;
-
+                WI.RemoteObject.resolveNode(node).then((remoteObject) => {
                     function setRowValueToPropertyValue(row, property) {
                         remoteObject.getProperty(property, (error, result, wasThrown) => {
                             if (!error && result.type === "number")
index d833a81..630fe1d 100644 (file)
@@ -159,15 +159,10 @@ WI.appendContextMenuItemsForDOMNode = function(contextMenu, domNode, options = {
                 result.release();
             }
 
-            function didResolveNode(remoteObject) {
-                if (!remoteObject)
-                    return;
-
+            WI.RemoteObject.resolveNode(domNode).then((remoteObject) => {
                 remoteObject.getProperty("constructor", didGetProperty);
                 remoteObject.release();
-            }
-
-            WI.RemoteObject.resolveNode(domNode, "", didResolveNode);
+            });
         });
     }
 
@@ -189,10 +184,7 @@ WI.appendContextMenuItemsForDOMNode = function(contextMenu, domNode, options = {
     if (!options.excludeLogElement && !domNode.isInUserAgentShadowTree() && !domNode.isPseudoElement()) {
         let label = isElement ? WI.UIString("Log Element") : WI.UIString("Log Node");
         contextMenu.appendItem(label, () => {
-            WI.RemoteObject.resolveNode(domNode, WI.RuntimeManager.ConsoleObjectGroup, (remoteObject) => {
-                if (!remoteObject)
-                    return;
-
+            WI.RemoteObject.resolveNode(domNode, WI.RuntimeManager.ConsoleObjectGroup).then((remoteObject) => {
                 let text = isElement ? WI.UIString("Selected Element") : WI.UIString("Selected Node");
                 const addSpecialUserLogClass = true;
                 WI.consoleLogViewController.appendImmediateExecutionWithResult(text, remoteObject, addSpecialUserLogClass);
index 422670a..3430116 100644 (file)
@@ -218,13 +218,8 @@ WI.DOMNodeDetailsSidebarPanel = class DOMNodeDetailsSidebarPanel extends WI.DOMD
 
         let domNode = this.domNode;
         RuntimeAgent.releaseObjectGroup(WI.DOMNodeDetailsSidebarPanel.PropertiesObjectGroupName);
-        WI.RemoteObject.resolveNode(domNode, WI.DOMNodeDetailsSidebarPanel.PropertiesObjectGroupName, nodeResolved.bind(this));
-
-        function nodeResolved(object)
-        {
-            if (!object)
-                return;
 
+        WI.RemoteObject.resolveNode(domNode, WI.DOMNodeDetailsSidebarPanel.PropertiesObjectGroupName).then((object) => {
             // Bail if the DOM node changed while we were waiting for the async response.
             if (this.domNode !== domNode)
                 return;
@@ -251,7 +246,7 @@ WI.DOMNodeDetailsSidebarPanel = class DOMNodeDetailsSidebarPanel extends WI.DOMD
             const args = undefined;
             const generatePreview = false;
             object.callFunction(inspectedPage_node_collectPrototypes, args, generatePreview, nodePrototypesReady.bind(this));
-        }
+        });
 
         function nodePrototypesReady(error, object, wasThrown)
         {
index c9ed78a..5a9235a 100644 (file)
@@ -309,20 +309,14 @@ WI.DOMTreeElement = class DOMTreeElement extends WI.TreeElement
             }
         }
 
-        function resolvedNode(object)
-        {
-            if (!object)
-                return;
-
-            function dimensions()
-            {
+        WI.RemoteObject.resolveNode(node).then((object) => {
+            function inspectedPage_node_dimensions() {
                 return "[" + this.offsetWidth + "," + this.offsetHeight + "," + this.naturalWidth + "," + this.naturalHeight + "]";
             }
 
-            object.callFunction(dimensions, undefined, false, setTooltip.bind(this));
+            object.callFunction(inspectedPage_node_dimensions, undefined, false, setTooltip.bind(this));
             object.release();
-        }
-        WI.RemoteObject.resolveNode(node, "", resolvedNode.bind(this));
+        });
     }
 
     updateSelectionArea()
index d713bfc..f03265f 100644 (file)
@@ -505,30 +505,23 @@ WI.DOMTreeOutline = class DOMTreeOutline extends WI.TreeOutline
         if (effectiveNode.nodeType() !== Node.ELEMENT_NODE)
             return;
 
-        function resolvedNode(object)
-        {
-            if (!object)
-                return;
-
-            function injectStyleAndToggleClass()
-            {
-                var hideElementStyleSheetIdOrClassName = "__WebInspectorHideElement__";
-                var styleElement = document.getElementById(hideElementStyleSheetIdOrClassName);
-                if (!styleElement) {
-                    styleElement = document.createElement("style");
-                    styleElement.id = hideElementStyleSheetIdOrClassName;
-                    styleElement.textContent = "." + hideElementStyleSheetIdOrClassName + " { visibility: hidden !important; }";
-                    document.head.appendChild(styleElement);
-                }
-
-                this.classList.toggle(hideElementStyleSheetIdOrClassName);
+        function inspectedPage_node_injectStyleAndToggleClass() {
+            let hideElementStyleSheetIdOrClassName = "__WebInspectorHideElement__";
+            let styleElement = document.getElementById(hideElementStyleSheetIdOrClassName);
+            if (!styleElement) {
+                styleElement = document.createElement("style");
+                styleElement.id = hideElementStyleSheetIdOrClassName;
+                styleElement.textContent = "." + hideElementStyleSheetIdOrClassName + " { visibility: hidden !important; }";
+                document.head.appendChild(styleElement);
             }
 
-            object.callFunction(injectStyleAndToggleClass, undefined, false, function(){});
-            object.release();
+            this.classList.toggle(hideElementStyleSheetIdOrClassName);
         }
 
-        WI.RemoteObject.resolveNode(effectiveNode, "", resolvedNode);
+        WI.RemoteObject.resolveNode(effectiveNode).then((object) => {
+            object.callFunction(inspectedPage_node_injectStyleAndToggleClass, undefined, false, () => { });
+            object.release();
+        });
     }
 };