Skip to content
Permalink
Browse files
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.

Canonical link: https://commits.webkit.org/249598@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@292818 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
patrickangle committed Apr 13, 2022
1 parent a7fc97b commit 855935cdc4402ee3d1a02835ce4cdaf38a1e67b4
Showing 3 changed files with 52 additions and 29 deletions.
@@ -1,3 +1,33 @@
2022-04-13 Patrick Angle <pangle@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 <emw@apple.com>

[Xcode] In open-source builds, disable bitcode in xcconfigs instead of build-webkit
@@ -406,7 +406,7 @@ WI.DOMManager = class DOMManager extends WI.Object

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 @@ WI.DOMManager = class DOMManager extends WI.Object
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 @@ WI.DOMManager = class DOMManager extends WI.Object
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 @@ WI.DOMManager = class DOMManager extends WI.Object
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});
@@ -32,17 +32,18 @@

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;
@@ -56,10 +57,8 @@ WI.DOMNode = class DOMNode extends WI.Object
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 @@ WI.DOMNode = class DOMNode extends WI.Object
// 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,21 +111,21 @@ WI.DOMNode = class DOMNode extends WI.Object
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);
}
}

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 @@ WI.DOMNode = class DOMNode extends WI.Object

// 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 @@ WI.DOMNode = class DOMNode extends WI.Object

_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 @@ WI.DOMNode = class DOMNode extends WI.Object

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();
}

0 comments on commit 855935c

Please sign in to comment.