Title: [292818] trunk/Source/WebInspectorUI
Revision
292818
Author
pan...@apple.com
Date
2022-04-13 11:53:13 -0700 (Wed, 13 Apr 2022)

Log Message

Web Inspector: Clean up `WI.DOMNode` to no longer require the shared `WI.DOMManager` be passed during construction
https://bugs.webkit.org/show_bug.cgi?id=239129

Reviewed by Devin Rousso.

* UserInterface/Controllers/DOMManager.js:
(WI.DOMManager.prototype._setDocument):
(WI.DOMManager.prototype._childNodeInserted):
(WI.DOMManager.prototype._pseudoElementAdded):
- Update to use new syntax for `WI.DOMNode` constructor/`newOrExistingFromPayload`. Additionally, there is no
need to explicitly map node ids to nodes here since `WI.DOMNode`'s constructor does this.

(WI.DOMManager.prototype._setChildNodes):
(WI.DOMManager.prototype._setDetachedRoot): Deleted.
- Inline _setDetachedRoot with a comment instead and update to use `WI.DOMNode.newOrExistingFromPayload` instead
of always creating a new node.

* UserInterface/Models/DOMNode.js:
(WI.DOMNode):
- Remove the _domManager property since it will always be `WI.domManager`, the shared singleton and update the
required arguments to use an options object for non-required parameters.

(WI.DOMNode.prototype.newOrExistingFromPayload):
(WI.DOMNode.prototype._insertChild):
(WI.DOMNode.prototype._setChildrenPayload):
- Update to use new constructor syntax.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (292817 => 292818)


--- trunk/Source/WebInspectorUI/ChangeLog	2022-04-13 18:50:18 UTC (rev 292817)
+++ trunk/Source/WebInspectorUI/ChangeLog	2022-04-13 18:53:13 UTC (rev 292818)
@@ -1,3 +1,33 @@
+2022-04-13  Patrick Angle  <pan...@apple.com>
+
+        Web Inspector: Clean up `WI.DOMNode` to no longer require the shared `WI.DOMManager` be passed during construction
+        https://bugs.webkit.org/show_bug.cgi?id=239129
+
+        Reviewed by Devin Rousso.
+
+        * UserInterface/Controllers/DOMManager.js:
+        (WI.DOMManager.prototype._setDocument):
+        (WI.DOMManager.prototype._childNodeInserted):
+        (WI.DOMManager.prototype._pseudoElementAdded):
+        - Update to use new syntax for `WI.DOMNode` constructor/`newOrExistingFromPayload`. Additionally, there is no
+        need to explicitly map node ids to nodes here since `WI.DOMNode`'s constructor does this.
+        
+        (WI.DOMManager.prototype._setChildNodes):
+        (WI.DOMManager.prototype._setDetachedRoot): Deleted.
+        - Inline _setDetachedRoot with a comment instead and update to use `WI.DOMNode.newOrExistingFromPayload` instead
+        of always creating a new node.
+        
+        * UserInterface/Models/DOMNode.js:
+        (WI.DOMNode):
+        - Remove the _domManager property since it will always be `WI.domManager`, the shared singleton and update the
+        required arguments to use an options object for non-required parameters.
+
+        (WI.DOMNode.prototype.newOrExistingFromPayload):
+        (WI.DOMNode.prototype._insertChild):
+        (WI.DOMNode.prototype._setChildrenPayload):
+        - Update to use new constructor syntax.
+        
+
 2022-04-12  Elliott Williams  <e...@apple.com>
 
         [Xcode] In open-source builds, disable bitcode in xcconfigs instead of build-webkit

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js (292817 => 292818)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js	2022-04-13 18:50:18 UTC (rev 292817)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js	2022-04-13 18:53:13 UTC (rev 292818)
@@ -406,7 +406,7 @@
 
         let newDocument = null;
         if (payload && "nodeId" in payload)
-            newDocument = new WI.DOMNode(this, null, false, payload);
+            newDocument = new WI.DOMNode(payload);
 
         if (this._document === newDocument)
             return;
@@ -422,15 +422,12 @@
         this.dispatchEventToListeners(WI.DOMManager.Event.DocumentUpdated, {document: this._document});
     }
 
-    _setDetachedRoot(payload)
-    {
-        new WI.DOMNode(this, null, false, payload);
-    }
-
     _setChildNodes(parentId, payloads)
     {
         if (!parentId && payloads.length) {
-            this._setDetachedRoot(payloads[0]);
+            // `InspectorDOMAgent::pushNodePathToFrontend` can provide a single child as a detached root node.
+            let node = WI.DOMNode.newOrExistingFromPayload(payloads[0]);
+            console.assert(!node.parentNode);
             return;
         }
 
@@ -459,7 +456,6 @@
         var parent = this._idToDOMNode[parentId];
         var prev = this._idToDOMNode[prevId];
         var node = parent._insertChild(prev, payload);
-        this._idToDOMNode[node.id] = node;
         this.dispatchEventToListeners(WI.DOMManager.Event.NodeInserted, {node, parent});
     }
 
@@ -485,9 +481,8 @@
         if (!parent)
             return;
 
-        let node = WI.DOMNode.newOrExistingFromPayload(parent.ownerDocument, pseudoElement);
+        let node = WI.DOMNode.newOrExistingFromPayload(pseudoElement, {ownerDocument: parent.ownerDocument});
         node.parentNode = parent;
-        this._idToDOMNode[node.id] = node;
         console.assert(!parent.pseudoElements().get(node.pseudoType()));
         parent.pseudoElements().set(node.pseudoType(), node);
         this.dispatchEventToListeners(WI.DOMManager.Event.NodeInserted, {node, parent});

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/DOMNode.js (292817 => 292818)


--- trunk/Source/WebInspectorUI/UserInterface/Models/DOMNode.js	2022-04-13 18:50:18 UTC (rev 292817)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/DOMNode.js	2022-04-13 18:53:13 UTC (rev 292818)
@@ -32,18 +32,19 @@
 
 WI.DOMNode = class DOMNode extends WI.Object
 {
-    constructor(domManager, doc, isInShadowTree, payload)
+    constructor(payload, {ownerDocument, isInShadowTree} = {})
     {
         super();
 
         this._destroyed = false;
 
-        this._domManager = domManager;
-        this._isInShadowTree = isInShadowTree;
+        this._isInShadowTree = !!isInShadowTree;
 
         this.id = payload.nodeId;
-        this._domManager._idToDOMNode[this.id] = this;
 
+        console.assert(!(this.id in WI.domManager._idToDOMNode), this);
+        WI.domManager._idToDOMNode[this.id] = this;
+
         this._nodeType = payload.nodeType;
         this._nodeName = payload.nodeName;
         this._localName = payload.localName;
@@ -56,10 +57,8 @@
         this._layoutOverlayShowing = false;
         this._layoutOverlayColorSetting = null;
 
-        if (this._nodeType === Node.DOCUMENT_NODE)
-            this.ownerDocument = this;
-        else
-            this.ownerDocument = doc;
+        this.ownerDocument = this._nodeType === Node.DOCUMENT_NODE ? this : ownerDocument;
+        console.assert(this.ownerDocument, this);
 
         this._frame = null;
 
@@ -94,9 +93,8 @@
         // we have both shadowRoots and child nodes.
         this._shadowRoots = [];
         if (payload.shadowRoots) {
-            for (var i = 0; i < payload.shadowRoots.length; ++i) {
-                var root = payload.shadowRoots[i];
-                var node = new WI.DOMNode(this._domManager, this.ownerDocument, true, root);
+            for (let shadowRootPayload of payload.shadowRoots) {
+                let node = WI.DOMNode.newOrExistingFromPayload(shadowRootPayload, {ownerDocument: this.ownerDocument, isInShadowTree: true});
                 node.parentNode = this;
                 this._shadowRoots.push(node);
             }
@@ -113,14 +111,14 @@
             this._customElementState = null;
 
         if (payload.templateContent) {
-            this._templateContent = new WI.DOMNode(this._domManager, this.ownerDocument, false, payload.templateContent);
+            this._templateContent = WI.DOMNode.newOrExistingFromPayload(payload.templateContent, {ownerDocument: this.ownerDocument});
             this._templateContent.parentNode = this;
         }
 
         this._pseudoElements = new Map;
         if (payload.pseudoElements) {
-            for (var i = 0; i < payload.pseudoElements.length; ++i) {
-                var node = new WI.DOMNode(this._domManager, this.ownerDocument, this._isInShadowTree, payload.pseudoElements[i]);
+            for (let pseudoElementPayload of payload.pseudoElements) {
+                let node = WI.DOMNode.newOrExistingFromPayload(pseudoElementPayload, {ownerDocument: this.ownerDocument, isInShadowTree: this._isInShadowTree});
                 node.parentNode = this;
                 this._pseudoElements.set(node.pseudoType(), node);
             }
@@ -127,7 +125,7 @@
         }
 
         if (payload.contentDocument) {
-            this._contentDocument = new WI.DOMNode(this._domManager, null, false, payload.contentDocument);
+            this._contentDocument = WI.DOMNode.newOrExistingFromPayload(payload.contentDocument);
             this._children = [this._contentDocument];
             this._renumber();
         }
@@ -163,10 +161,10 @@
 
     // Static
 
-    static newOrExistingFromPayload(document, payload, {isInShadowTree} = {})
+    static newOrExistingFromPayload(payload, {ownerDocument, isInShadowTree} = {})
     {
         // FIXME: <webkit.org/b/238947> Don't send node payloads to the frontend for already-bound nodes.
-        return WI.domManager.nodeForId(payload.nodeId) || new WI.DOMNode(WI.domManager, document, !!isInShadowTree, payload);
+        return WI.domManager.nodeForId(payload.nodeId) || new WI.DOMNode(payload, {ownerDocument, isInShadowTree});
     }
 
     static resetDefaultLayoutOverlayConfiguration()
@@ -1074,7 +1072,7 @@
 
     _insertChild(prev, payload)
     {
-        let node = WI.DOMNode.newOrExistingFromPayload(this.ownerDocument, payload, {isInShadowTree: this._isInShadowTree});
+        let node = WI.DOMNode.newOrExistingFromPayload(payload, {ownerDocument: this.ownerDocument, isInShadowTree: this._isInShadowTree});
         if (!prev) {
             if (!this._children) {
                 // First node
@@ -1108,7 +1106,7 @@
 
         this._children = this._shadowRoots.slice();
         for (let payload of payloads)
-            this._children.push(WI.DOMNode.newOrExistingFromPayload(this.ownerDocument, payload, {isInShadowTree: this._isInShadowTree}));
+            this._children.push(WI.DOMNode.newOrExistingFromPayload(payload, {ownerDocument: this.ownerDocument, isInShadowTree: this._isInShadowTree}));
 
         this._renumber();
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to