Web Inspector: Clean up and modernize DOMTreeManager
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Sep 2015 21:07:37 +0000 (21:07 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Sep 2015 21:07:37 +0000 (21:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148821

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-09-04
Reviewed by Timothy Hatcher.

* UserInterface/Controllers/DOMTreeManager.js:
(WebInspector.DOMTreeManager.prototype.requestDocument.onDocumentAvailable):
(WebInspector.DOMTreeManager.prototype.requestDocument):
(WebInspector.DOMTreeManager.prototype.pushNodeByPathToFrontend):
(WebInspector.DOMTreeManager.prototype._wrapClientCallback):
(WebInspector.DOMTreeManager.prototype._attributeModified):
(WebInspector.DOMTreeManager.prototype._attributeRemoved):
(WebInspector.DOMTreeManager.prototype._inlineStyleInvalidated):
(WebInspector.DOMTreeManager.prototype._loadNodeAttributes):
(WebInspector.DOMTreeManager.prototype.cancelSearch):
(WebInspector.DOMTreeManager.prototype.querySelector):
(WebInspector.DOMTreeManager.prototype.querySelectorAll):
(WebInspector.DOMTreeManager.prototype.highlightDOMNode):
(WebInspector.DOMTreeManager.prototype._buildHighlightConfig):
Cleanup and modernize where appropriate.

* UserInterface/Views/SearchSidebarPanel.js:
(WebInspector.SearchSidebarPanel.prototype.performSearch):
Callback is now required.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/DOMTreeManager.js
Source/WebInspectorUI/UserInterface/Views/SearchSidebarPanel.js

index 141b212..fd91ce7 100644 (file)
@@ -1,3 +1,30 @@
+2015-09-04  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Clean up and modernize DOMTreeManager
+        https://bugs.webkit.org/show_bug.cgi?id=148821
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Controllers/DOMTreeManager.js:
+        (WebInspector.DOMTreeManager.prototype.requestDocument.onDocumentAvailable):
+        (WebInspector.DOMTreeManager.prototype.requestDocument):
+        (WebInspector.DOMTreeManager.prototype.pushNodeByPathToFrontend):
+        (WebInspector.DOMTreeManager.prototype._wrapClientCallback):
+        (WebInspector.DOMTreeManager.prototype._attributeModified):
+        (WebInspector.DOMTreeManager.prototype._attributeRemoved):
+        (WebInspector.DOMTreeManager.prototype._inlineStyleInvalidated):
+        (WebInspector.DOMTreeManager.prototype._loadNodeAttributes):
+        (WebInspector.DOMTreeManager.prototype.cancelSearch):
+        (WebInspector.DOMTreeManager.prototype.querySelector):
+        (WebInspector.DOMTreeManager.prototype.querySelectorAll):
+        (WebInspector.DOMTreeManager.prototype.highlightDOMNode):
+        (WebInspector.DOMTreeManager.prototype._buildHighlightConfig):
+        Cleanup and modernize where appropriate.
+
+        * UserInterface/Views/SearchSidebarPanel.js:
+        (WebInspector.SearchSidebarPanel.prototype.performSearch):
+        Callback is now required.
+
 2015-09-04  Matt Baker  <mattbaker@apple.com>
 
         Web Inspector: Render Frames "Other" task filter checkbox misaligned with text
index 9b5faff..6231beb 100644 (file)
@@ -59,8 +59,7 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
     requestDocument(callback)
     {
         if (this._document) {
-            if (callback)
-                callback(this._document);
+            callback(this._document);
             return;
         }
 
@@ -76,12 +75,10 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
             if (!error)
                 this._setDocument(root);
 
-            for (var i = 0; i < this._pendingDocumentRequestCallbacks.length; ++i) {
-                var callback = this._pendingDocumentRequestCallbacks[i];
-                if (callback)
-                    callback(this._document);
-            }
-            delete this._pendingDocumentRequestCallbacks;
+            for (let callback of this._pendingDocumentRequestCallbacks)
+                callback(this._document);
+
+            this._pendingDocumentRequestCallbacks = null;
         }
 
         DOMAgent.getDocument(onDocumentAvailable.bind(this));
@@ -94,8 +91,7 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
 
     pushNodeByPathToFrontend(path, callback)
     {
-        var callbackCast = callback;
-        this._dispatchWhenDocumentAvailable(DOMAgent.pushNodeByPathToFrontend.bind(DOMAgent, path), callbackCast);
+        this._dispatchWhenDocumentAvailable(DOMAgent.pushNodeByPathToFrontend.bind(DOMAgent, path), callback);
     }
 
     // Private
@@ -103,7 +99,8 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
     _wrapClientCallback(callback)
     {
         if (!callback)
-            return;
+            return null;
+
         return function(error, result) {
             if (error)
                 console.error("Error during DOMAgent operation: " + error);
@@ -132,6 +129,7 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
         var node = this._idToDOMNode[nodeId];
         if (!node)
             return;
+
         node._setAttribute(name, value);
         this.dispatchEventToListeners(WebInspector.DOMTreeManager.Event.AttributeModified, {node, name});
         node.dispatchEventToListeners(WebInspector.DOMNode.Event.AttributeModified, {name});
@@ -142,6 +140,7 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
         var node = this._idToDOMNode[nodeId];
         if (!node)
             return;
+
         node._removeAttribute(name);
         this.dispatchEventToListeners(WebInspector.DOMTreeManager.Event.AttributeRemoved, {node, name});
         node.dispatchEventToListeners(WebInspector.DOMNode.Event.AttributeRemoved, {name});
@@ -149,8 +148,8 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
 
     _inlineStyleInvalidated(nodeIds)
     {
-        for (var i = 0; i < nodeIds.length; ++i)
-            this._attributeLoadNodeIds[nodeIds[i]] = true;
+        for (var nodeId of nodeIds)
+            this._attributeLoadNodeIds[nodeId] = true;
         if ("_loadNodeAttributesTimeout" in this)
             return;
         this._loadNodeAttributesTimeout = setTimeout(this._loadNodeAttributes.bind(this), 0);
@@ -172,10 +171,10 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
             }
         }
 
-        delete this._loadNodeAttributesTimeout;
+        this._loadNodeAttributesTimeout = undefined;
 
         for (var nodeId in this._attributeLoadNodeIds) {
-            var nodeIdAsNumber = parseInt(nodeId, 10);
+            var nodeIdAsNumber = parseInt(nodeId);
             DOMAgent.getAttributes(nodeIdAsNumber, callback.bind(this, nodeIdAsNumber));
         }
         this._attributeLoadNodeIds = {};
@@ -371,27 +370,25 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
     {
         if (this._searchId) {
             DOMAgent.discardSearchResults(this._searchId);
-            delete this._searchId;
+            this._searchId = undefined;
         }
     }
 
     querySelector(nodeId, selectors, callback)
     {
-        var callbackCast = callback;
-        DOMAgent.querySelector(nodeId, selectors, this._wrapClientCallback(callbackCast));
+        DOMAgent.querySelector(nodeId, selectors, this._wrapClientCallback(callback));
     }
 
     querySelectorAll(nodeId, selectors, callback)
     {
-        var callbackCast = callback;
-        DOMAgent.querySelectorAll(nodeId, selectors, this._wrapClientCallback(callbackCast));
+        DOMAgent.querySelectorAll(nodeId, selectors, this._wrapClientCallback(callback));
     }
 
     highlightDOMNode(nodeId, mode)
     {
         if (this._hideDOMNodeHighlightTimeout) {
             clearTimeout(this._hideDOMNodeHighlightTimeout);
-            delete this._hideDOMNodeHighlightTimeout;
+            this._hideDOMNodeHighlightTimeout = undefined;
         }
 
         this._highlightedDOMNodeId = nodeId;
@@ -450,10 +447,10 @@ WebInspector.DOMTreeManager = class DOMTreeManager extends WebInspector.Object
         DOMAgent.setInspectModeEnabled(enabled, this._buildHighlightConfig(), callback.bind(this));
     }
 
-    _buildHighlightConfig(mode)
+    _buildHighlightConfig(mode = "all")
     {
-        mode = mode || "all";
-        var highlightConfig = { showInfo: mode === "all" };
+        let highlightConfig = {showInfo: mode === "all"};
+
         if (mode === "all" || mode === "content")
             highlightConfig.contentColor = {r: 111, g: 168, b: 220, a: 0.66};
 
index 46f6b60..1a1b168 100644 (file)
@@ -268,7 +268,7 @@ WebInspector.SearchSidebarPanel = class SearchSidebarPanel extends WebInspector.
         }
 
         if (window.DOMAgent)
-            WebInspector.domTreeManager.requestDocument();
+            WebInspector.domTreeManager.requestDocument(function(){});
 
         if (window.PageAgent)
             PageAgent.searchInResources(searchQuery, isCaseSensitive, isRegex, resourcesCallback.bind(this));