Bug 1550031 - Part 2: Update mutation breakpoint data on DOM Node removal. r=jlast

Differential Revision: https://phabricator.services.mozilla.com/D40717

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Logan Smyth 2019-08-09 01:27:26 +00:00
Родитель 75676e23ac
Коммит 5c440e493a
1 изменённых файлов: 33 добавлений и 41 удалений

Просмотреть файл

@ -188,6 +188,10 @@ const IMMEDIATE_MUTATIONS = [
"frameLoad",
"newRoot",
"pseudoClassLock",
// These should be delivered right away in order to be sure that the
// fronts have not been removed due to other non-throttled mutations.
"mutationBreakpoints",
];
const HIDDEN_CLASS = "__fx-devtools-hide-shortcut__";
@ -301,8 +305,6 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
this.onNodeRemoved[EXCLUDED_LISTENER] = true;
this.onAttributeModified = this.onAttributeModified.bind(this);
this.onAttributeModified[EXCLUDED_LISTENER] = true;
this.onNodeRemovedFromDocument = this.onNodeRemovedFromDocument.bind(this);
this.onNodeRemovedFromDocument[EXCLUDED_LISTENER] = true;
this.onMutations = this.onMutations.bind(this);
this.onSlotchange = this.onSlotchange.bind(this);
@ -1958,7 +1960,14 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
rawDoc,
true /* createIfNeeded */
);
const originalBpsForNode = this._breakpointInfoForNode(rawNode) || {};
let originalBpsForNode = this._breakpointInfoForNode(rawNode);
if (!bpsForNode && !originalBpsForNode) {
return;
}
bpsForNode = bpsForNode || {};
originalBpsForNode = originalBpsForNode || {};
if (Object.values(bpsForNode).some(Boolean)) {
docMutationBreakpoints.nodes.set(rawNode, bpsForNode);
@ -1983,7 +1992,6 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
docMutationBreakpoints.counts.attribute += 1;
}
this._updateNodeMutationListeners(rawNode);
this._updateDocumentMutationListeners(rawDoc);
const actor = this.getNode(rawNode);
@ -1996,30 +2004,6 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
}
},
/**
* Controls whether this DOM node has a listener attached.
*
* @param {Node} rawNode The DOM node.
*/
_updateNodeMutationListeners(rawNode) {
const bpInfo = this._breakpointInfoForNode(rawNode);
if (bpInfo && (bpInfo.subtree || bpInfo.removal || bpInfo.attribute)) {
eventListenerService.addSystemEventListener(
rawNode,
"DOMNodeRemovedFromDocument",
this.onNodeRemovedFromDocument,
true /* capture */
);
} else {
eventListenerService.removeSystemEventListener(
rawNode,
"DOMNodeRemovedFromDocument",
this.onNodeRemovedFromDocument,
true /* capture */
);
}
},
/**
* Controls whether this DOM document has event listeners attached for
* handling of DOM mutation breakpoints.
@ -2050,7 +2034,8 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
if (
docMutationBreakpoints.counts.subtree > 0 ||
docMutationBreakpoints.counts.removal > 0
docMutationBreakpoints.counts.removal > 0 ||
docMutationBreakpoints.counts.attribute > 0
) {
eventListenerService.addSystemEventListener(
rawDoc,
@ -2120,7 +2105,11 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
onNodeRemoved: function(evt) {
const mutationBpInfo = this._breakpointInfoForNode(evt.target);
if (mutationBpInfo && mutationBpInfo.removal) {
const hasNodeRemovalEvent = mutationBpInfo && mutationBpInfo.removal;
this._clearMutationBreakpointsFromSubtree(evt.target);
if (hasNodeRemovalEvent) {
this._breakOnMutation("nodeRemoved");
} else {
this.onSubtreeModified(evt);
@ -2145,12 +2134,19 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
}
},
onNodeRemovedFromDocument: function(evt) {
this._updateMutationBreakpointState(evt.target, {
subtree: false,
removal: false,
attribute: false,
});
_clearMutationBreakpointsFromSubtree: function(targetNode) {
const targetDoc = targetNode.ownerDocument || targetNode;
const docMutationBreakpoints = this._mutationBreakpointsForDoc(targetDoc);
if (!docMutationBreakpoints || docMutationBreakpoints.nodes.size === 0) {
// Bail early for performance. If the doc has no mutation BPs, there is
// no reason to iterate through the children looking for things to detach.
return;
}
const walker = this.getDocumentWalker(targetNode);
do {
this._updateMutationBreakpointState(walker.currentNode, null);
} while (walker.nextNode());
},
/**
@ -2503,11 +2499,7 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
const mutationBps = this._mutationBreakpointsForDoc(doc);
const nodes = mutationBps ? Array.from(mutationBps.nodes.keys()) : [];
for (const node of nodes) {
this._updateMutationBreakpointState(node, {
subtree: false,
removal: false,
attribute: false,
});
this._updateMutationBreakpointState(node, null);
}
if (this.rootDoc === doc) {