Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js

Issue 2450663004: DevTools: do not allow using 'this' before call into super. (Closed)
Patch Set: rebaselined Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js
index afceb870f228dabbc26a53543075cbbc985e44e9..b69f4fdafd9eeb1d9920d8ce07b16846a23f105d 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js
@@ -33,99 +33,28 @@
* @constructor
* @extends {WebInspector.SDKObject}
* @param {!WebInspector.DOMModel} domModel
- * @param {?WebInspector.DOMDocument} doc
- * @param {boolean} isInShadowTree
- * @param {!DOMAgent.Node} payload
*/
-WebInspector.DOMNode = function(domModel, doc, isInShadowTree, payload)
+WebInspector.DOMNode = function(domModel)
{
WebInspector.SDKObject.call(this, domModel.target());
this._domModel = domModel;
- this._agent = domModel._agent;
- this.ownerDocument = doc;
- this._isInShadowTree = isInShadowTree;
-
- this.id = payload.nodeId;
- domModel._idToDOMNode[this.id] = this;
- this._nodeType = payload.nodeType;
- this._nodeName = payload.nodeName;
- this._localName = payload.localName;
- this._nodeValue = payload.nodeValue;
- this._pseudoType = payload.pseudoType;
- this._shadowRootType = payload.shadowRootType;
- this._frameOwnerFrameId = payload.frameId || null;
- this._xmlVersion = payload.xmlVersion;
-
- this._shadowRoots = [];
-
- this._attributes = [];
- this._attributesMap = {};
- if (payload.attributes)
- this._setAttributesPayload(payload.attributes);
-
- /** @type {!Map<string, ?>} */
- this._markers = new Map();
- this._subtreeMarkerCount = 0;
-
- this._childNodeCount = payload.childNodeCount || 0;
- this._children = null;
-
- this.nextSibling = null;
- this.previousSibling = null;
- this.firstChild = null;
- this.lastChild = null;
- this.parentNode = null;
-
- if (payload.shadowRoots) {
- for (var i = 0; i < payload.shadowRoots.length; ++i) {
- var root = payload.shadowRoots[i];
- var node = new WebInspector.DOMNode(this._domModel, this.ownerDocument, true, root);
- this._shadowRoots.push(node);
- node.parentNode = this;
- }
- }
-
- if (payload.templateContent) {
- this._templateContent = new WebInspector.DOMNode(this._domModel, this.ownerDocument, true, payload.templateContent);
- this._templateContent.parentNode = this;
- }
-
- if (payload.importedDocument) {
- this._importedDocument = new WebInspector.DOMNode(this._domModel, this.ownerDocument, true, payload.importedDocument);
- this._importedDocument.parentNode = this;
- }
-
- if (payload.distributedNodes)
- this._setDistributedNodePayloads(payload.distributedNodes);
-
- if (payload.children)
- this._setChildrenPayload(payload.children);
-
- this._setPseudoElements(payload.pseudoElements);
-
- if (payload.contentDocument) {
- this._contentDocument = new WebInspector.DOMDocument(domModel, payload.contentDocument);
- this._children = [this._contentDocument];
- this._renumber();
- }
-
- if (this._nodeType === Node.ELEMENT_NODE) {
- // HTML and BODY from internal iframes should not overwrite top-level ones.
- if (this.ownerDocument && !this.ownerDocument.documentElement && this._nodeName === "HTML")
- this.ownerDocument.documentElement = this;
- if (this.ownerDocument && !this.ownerDocument.body && this._nodeName === "BODY")
- this.ownerDocument.body = this;
- } else if (this._nodeType === Node.DOCUMENT_TYPE_NODE) {
- this.publicId = payload.publicId;
- this.systemId = payload.systemId;
- this.internalSubset = payload.internalSubset;
- } else if (this._nodeType === Node.ATTRIBUTE_NODE) {
- this.name = payload.name;
- this.value = payload.value;
- }
};
/**
+ * @param {!WebInspector.DOMModel} domModel
+ * @param {?WebInspector.DOMDocument} doc
+ * @param {boolean} isInShadowTree
+ * @param {!DOMAgent.Node} payload
+ * @return {!WebInspector.DOMNode}
+ */
+WebInspector.DOMNode.create = function(domModel, doc, isInShadowTree, payload)
+{
+ var node = new WebInspector.DOMNode(domModel);
+ node._init(doc, isInShadowTree, payload);
+ return node;
+}
+
+/**
* @enum {string}
*/
WebInspector.DOMNode.PseudoElementNames = {
@@ -147,6 +76,97 @@ WebInspector.DOMNode.Attribute;
WebInspector.DOMNode.prototype = {
/**
+ * @param {?WebInspector.DOMDocument} doc
+ * @param {boolean} isInShadowTree
+ * @param {!DOMAgent.Node} payload
+ */
+ _init: function(doc, isInShadowTree, payload)
+ {
+ this._agent = this._domModel._agent;
+ this.ownerDocument = doc;
+ this._isInShadowTree = isInShadowTree;
+
+ this.id = payload.nodeId;
+ this._domModel._idToDOMNode[this.id] = this;
+ this._nodeType = payload.nodeType;
+ this._nodeName = payload.nodeName;
+ this._localName = payload.localName;
+ this._nodeValue = payload.nodeValue;
+ this._pseudoType = payload.pseudoType;
+ this._shadowRootType = payload.shadowRootType;
+ this._frameOwnerFrameId = payload.frameId || null;
+ this._xmlVersion = payload.xmlVersion;
+
+ this._shadowRoots = [];
+
+ this._attributes = [];
+ this._attributesMap = {};
+ if (payload.attributes)
+ this._setAttributesPayload(payload.attributes);
+
+ /** @type {!Map<string, ?>} */
+ this._markers = new Map();
+ this._subtreeMarkerCount = 0;
+
+ this._childNodeCount = payload.childNodeCount || 0;
+ this._children = null;
+
+ this.nextSibling = null;
+ this.previousSibling = null;
+ this.firstChild = null;
+ this.lastChild = null;
+ this.parentNode = null;
+
+ if (payload.shadowRoots) {
+ for (var i = 0; i < payload.shadowRoots.length; ++i) {
+ var root = payload.shadowRoots[i];
+ var node = WebInspector.DOMNode.create(this._domModel, this.ownerDocument, true, root);
+ this._shadowRoots.push(node);
+ node.parentNode = this;
+ }
+ }
+
+ if (payload.templateContent) {
+ this._templateContent = WebInspector.DOMNode.create(this._domModel, this.ownerDocument, true, payload.templateContent);
+ this._templateContent.parentNode = this;
+ }
+
+ if (payload.importedDocument) {
+ this._importedDocument = WebInspector.DOMNode.create(this._domModel, this.ownerDocument, true, payload.importedDocument);
+ this._importedDocument.parentNode = this;
+ }
+
+ if (payload.distributedNodes)
+ this._setDistributedNodePayloads(payload.distributedNodes);
+
+ if (payload.children)
+ this._setChildrenPayload(payload.children);
+
+ this._setPseudoElements(payload.pseudoElements);
+
+ if (payload.contentDocument) {
+ this._contentDocument = new WebInspector.DOMDocument(this._domModel, payload.contentDocument);
+ this._children = [this._contentDocument];
+ this._renumber();
+ }
+
+ if (this._nodeType === Node.ELEMENT_NODE) {
+ // HTML and BODY from internal iframes should not overwrite top-level ones.
+ if (this.ownerDocument && !this.ownerDocument.documentElement && this._nodeName === "HTML")
+ this.ownerDocument.documentElement = this;
+ if (this.ownerDocument && !this.ownerDocument.body && this._nodeName === "BODY")
+ this.ownerDocument.body = this;
+ } else if (this._nodeType === Node.DOCUMENT_TYPE_NODE) {
+ this.publicId = payload.publicId;
+ this.systemId = payload.systemId;
+ this.internalSubset = payload.internalSubset;
+ } else if (this._nodeType === Node.ATTRIBUTE_NODE) {
+ this.name = payload.name;
+ this.value = payload.value;
+ }
+ },
+
+ /**
* @return {!WebInspector.DOMModel}
*/
domModel: function()
@@ -642,7 +662,7 @@ WebInspector.DOMNode.prototype = {
*/
_insertChild: function(prev, payload)
{
- var node = new WebInspector.DOMNode(this._domModel, this.ownerDocument, this._isInShadowTree, payload);
+ var node = WebInspector.DOMNode.create(this._domModel, this.ownerDocument, this._isInShadowTree, payload);
this._children.splice(this._children.indexOf(prev) + 1, 0, node);
this._renumber();
return node;
@@ -683,7 +703,7 @@ WebInspector.DOMNode.prototype = {
this._children = [];
for (var i = 0; i < payloads.length; ++i) {
var payload = payloads[i];
- var node = new WebInspector.DOMNode(this._domModel, this.ownerDocument, this._isInShadowTree, payload);
+ var node = WebInspector.DOMNode.create(this._domModel, this.ownerDocument, this._isInShadowTree, payload);
this._children.push(node);
}
this._renumber();
@@ -699,7 +719,7 @@ WebInspector.DOMNode.prototype = {
return;
for (var i = 0; i < payloads.length; ++i) {
- var node = new WebInspector.DOMNode(this._domModel, this.ownerDocument, this._isInShadowTree, payloads[i]);
+ var node = WebInspector.DOMNode.create(this._domModel, this.ownerDocument, this._isInShadowTree, payloads[i]);
node.parentNode = this;
this._pseudoElements.set(node.pseudoType(), node);
}
@@ -1076,7 +1096,8 @@ WebInspector.DOMNodeShortcut = function(target, backendNodeId, nodeType, nodeNam
*/
WebInspector.DOMDocument = function(domModel, payload)
{
- WebInspector.DOMNode.call(this, domModel, this, false, payload);
+ WebInspector.DOMNode.call(this, domModel);
+ this._init(this, false, payload);
this.documentURL = payload.documentURL || "";
this.baseURL = payload.baseURL || "";
this._listeners = {};
@@ -1473,7 +1494,7 @@ WebInspector.DOMModel.prototype = {
if (payload.nodeName === "#document")
new WebInspector.DOMDocument(this, payload);
else
- new WebInspector.DOMNode(this, null, false, payload);
+ WebInspector.DOMNode.create(this, null, false, payload);
},
/**
@@ -1541,7 +1562,7 @@ WebInspector.DOMModel.prototype = {
var host = this._idToDOMNode[hostId];
if (!host)
return;
- var node = new WebInspector.DOMNode(this, host.ownerDocument, true, root);
+ var node = WebInspector.DOMNode.create(this, host.ownerDocument, true, root);
node.parentNode = host;
this._idToDOMNode[node.id] = node;
host._shadowRoots.unshift(node);
@@ -1576,7 +1597,7 @@ WebInspector.DOMModel.prototype = {
var parent = this._idToDOMNode[parentId];
if (!parent)
return;
- var node = new WebInspector.DOMNode(this, parent.ownerDocument, false, pseudoElement);
+ var node = WebInspector.DOMNode.create(this, parent.ownerDocument, false, pseudoElement);
node.parentNode = parent;
this._idToDOMNode[node.id] = node;
console.assert(!parent._pseudoElements.get(node.pseudoType()));

Powered by Google App Engine
This is Rietveld 408576698