Bug 1446302 - WIP: workaround to avoid reference new nodes while counting draft
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 16 Mar 2018 10:42:55 +0100
changeset 768361 95e1bf7f30a8831edcde77636ff244b729ea5fae
parent 768291 697460b72d8b2d5c339b4e99ed28300161604dc9
push id102869
push userjdescottes@mozilla.com
push dateFri, 16 Mar 2018 09:43:22 +0000
bugs1446302
milestone61.0a1
Bug 1446302 - WIP: workaround to avoid reference new nodes while counting MozReview-Commit-ID: 1INUst56f78
devtools/server/actors/inspector/node.js
devtools/server/actors/inspector/walker.js
--- a/devtools/server/actors/inspector/node.js
+++ b/devtools/server/actors/inspector/node.js
@@ -194,17 +194,17 @@ const NodeActor = protocol.ActorClassWit
     if (numChildren === 0 && (hasContentDocument || hasSVGDocument)) {
       // This might be an iframe with virtual children.
       numChildren = 1;
     }
 
     // Normal counting misses ::before/::after.  Also, some anonymous children
     // may ultimately be skipped, so we have to consult with the walker.
     if (numChildren === 0 || hasAnonChildren) {
-      numChildren = this.walker.children(this).nodes.length;
+      numChildren = this.walker.children(this, { dontwatch: true }).nodes.length;
     }
 
     return numChildren;
   },
 
   get computedStyle() {
     if (!this._computedStyle) {
       this._computedStyle = CssLogic.getComputedStyle(this.rawNode);
--- a/devtools/server/actors/inspector/walker.js
+++ b/devtools/server/actors/inspector/walker.js
@@ -643,30 +643,30 @@ var WalkerActor = protocol.ActorClassWit
 
     let nodes = [];
 
     // Start by reading backward from the starting point if we're centering...
     let backwardWalker = getFilteredWalker(start);
     if (backwardWalker.currentNode != firstChild && options.center) {
       backwardWalker.previousSibling();
       let backwardCount = Math.floor(maxNodes / 2);
-      let backwardNodes = this._readBackward(backwardWalker, backwardCount);
+      let backwardNodes = this._readBackward(backwardWalker, backwardCount, options.dontwatch);
       nodes = backwardNodes;
     }
 
     // Then read forward by any slack left in the max children...
     let forwardWalker = getFilteredWalker(start);
     let forwardCount = maxNodes - nodes.length;
-    nodes = nodes.concat(this._readForward(forwardWalker, forwardCount));
+    nodes = nodes.concat(this._readForward(forwardWalker, forwardCount, options.dontwatch));
 
     // If there's any room left, it means we've run all the way to the end.
     // If we're centering, check if there are more items to read at the front.
     let remaining = maxNodes - nodes.length;
     if (options.center && remaining > 0 && nodes[0].rawNode != firstChild) {
-      let firstNodes = this._readBackward(backwardWalker, remaining);
+      let firstNodes = this._readBackward(backwardWalker, remaining, options.dontwatch);
 
       // Then put it all back together.
       nodes = firstNodes.concat(nodes);
     }
 
     return {
       hasFirst: nodes[0].rawNode == firstChild,
       hasLast: nodes[nodes.length - 1].rawNode == lastChild,
@@ -760,44 +760,44 @@ var WalkerActor = protocol.ActorClassWit
     let sibling = walker.previousSibling();
     return sibling ? this._ref(sibling) : null;
   },
 
   /**
    * Helper function for the `children` method: Read forward in the sibling
    * list into an array with `count` items, including the current node.
    */
-  _readForward: function(walker, count) {
+  _readForward: function(walker, count, dontwatch) {
     let ret = [];
 
     let node = walker.currentNode;
     do {
       if (!walker.isSkippedNode(node)) {
         // The walker can be on a node that would be filtered out if it didn't find any
         // other node to fallback to.
-        ret.push(this._ref(node));
+        ret.push(dontwatch ? node : this._ref(node));
       }
       node = walker.nextSibling();
     } while (node && --count);
     return ret;
   },
 
   /**
    * Helper function for the `children` method: Read backward in the sibling
    * list into an array with `count` items, including the current node.
    */
-  _readBackward: function(walker, count) {
+  _readBackward: function(walker, count, dontwatch) {
     let ret = [];
 
     let node = walker.currentNode;
     do {
       if (!walker.isSkippedNode(node)) {
         // The walker can be on a node that would be filtered out if it didn't find any
         // other node to fallback to.
-        ret.push(this._ref(node));
+        ret.push(dontwatch ? node : this._ref(node));
       }
       node = walker.previousSibling();
     } while (node && --count);
     ret.reverse();
     return ret;
   },
 
   /**