Bug 1561707 - Support excluding listeners from the event collector list. r=gl

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Logan Smyth 2019-06-27 06:23:54 +00:00
Родитель 638fd4ee57
Коммит e572b4c130
4 изменённых файлов: 38 добавлений и 2 удалений

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

@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* Any event listener flagged with this symbol will not be considered when
* the EventCollector class enumerates listeners for nodes. For example:
*
* const someListener = () => {};
* someListener[EXCLUDED_LISTENER] = true;
* eventListenerService.addSystemEventListener(node, "event", someListener);
*/
const EXCLUDED_LISTENER = Symbol("event-collector-excluded-listener");
exports.EXCLUDED_LISTENER = EXCLUDED_LISTENER;

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

@ -17,6 +17,9 @@ const {
} = require("devtools/shared/layout/utils");
const Debugger = require("Debugger");
const ReplayInspector = require("devtools/server/actors/replay/inspector");
const {
EXCLUDED_LISTENER,
} = require("devtools/server/actors/inspector/constants");
// eslint-disable-next-line
const JQUERY_LIVE_REGEX = /return typeof \w+.*.event\.triggered[\s\S]*\.event\.(dispatch|handle).*arguments/;
@ -253,6 +256,7 @@ class MainEventCollector {
* An array of unfiltered event listeners or an empty array
*/
getDOMListeners(node) {
let listeners;
if (typeof node.nodeName !== "undefined" && node.nodeName.toLowerCase() === "html") {
const winListeners =
Services.els.getListenerInfoFor(node.ownerGlobal) || [];
@ -261,9 +265,15 @@ class MainEventCollector {
const docListeners =
Services.els.getListenerInfoFor(node.parentNode) || [];
return [...winListeners, ...docElementListeners, ...docListeners];
listeners = [...winListeners, ...docElementListeners, ...docListeners];
} else {
listeners = Services.els.getListenerInfoFor(node) || [];
}
return Services.els.getListenerInfoFor(node) || [];
return listeners.filter(listener => {
const obj = this.unwrap(listener.listenerObject);
return !obj || !obj[EXCLUDED_LISTENER];
});
}
getJQuery(node) {

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

@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DevToolsModules(
'constants.js',
'css-logic.js',
'custom-element-watcher.js',
'document-walker.js',

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

@ -12,6 +12,9 @@ const {walkerSpec} = require("devtools/shared/specs/inspector");
const {LongStringActor} = require("devtools/server/actors/string");
const InspectorUtils = require("InspectorUtils");
const ReplayInspector = require("devtools/server/actors/replay/inspector");
const {
EXCLUDED_LISTENER,
} = require("devtools/server/actors/inspector/constants");
loader.lazyRequireGetter(this, "getFrameElement", "devtools/shared/layout/utils", true);
loader.lazyRequireGetter(this, "isAfterPseudoElement", "devtools/shared/layout/utils", true);
@ -160,9 +163,14 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
this._retainedOrphans = new Set();
this.onNodeInserted = this.onNodeInserted.bind(this);
this.onNodeInserted[EXCLUDED_LISTENER] = true;
this.onNodeRemoved = this.onNodeRemoved.bind(this);
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);
this.onShadowrootattached = this.onShadowrootattached.bind(this);