Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 7bdab9d

Browse files
committed
Bug 1531826 Part 1 - View event handler sources by ID, r=ochameau.
--HG-- extra : rebase_source : 372a529e62b35c985ec8c1bc49ca33e2003fe3a4
1 parent abb2fb9 commit 7bdab9d

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

devtools/client/shared/view-source.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ exports.viewSourceInStyleEditor = async function(toolbox, sourceURL,
5252
exports.viewSourceInDebugger = async function(toolbox, sourceURL, sourceLine, sourceId,
5353
reason = "unknown") {
5454
const dbg = await toolbox.loadTool("jsdebugger");
55-
const source = dbg.getSourceByURL(sourceURL) || dbg.getSourceByActorId(sourceId);
55+
const source =
56+
sourceId ? dbg.getSourceByActorId(sourceId) : dbg.getSourceByURL(sourceURL);
5657
if (source) {
5758
await toolbox.selectTool("jsdebugger", reason);
5859
dbg.selectSource(source.id, sourceLine);

devtools/client/shared/widgets/tooltip/EventTooltipHelper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ EventTooltip.prototype = {
184184
editor: editor,
185185
handler: listener.handler,
186186
uri: listener.origin,
187+
sourceActor: listener.sourceActor,
187188
dom0: listener.DOM0,
188189
native: listener.native,
189190
appended: false,
@@ -263,7 +264,7 @@ EventTooltip.prototype = {
263264
const header = event.currentTarget;
264265
const content = header.nextElementSibling;
265266

266-
const {uri} = this._eventEditors.get(content);
267+
const {sourceActor, uri} = this._eventEditors.get(content);
267268

268269
const location = this._parseLocation(uri);
269270
if (location) {
@@ -272,7 +273,7 @@ EventTooltip.prototype = {
272273

273274
this._tooltip.hide();
274275

275-
toolbox.viewSourceInDebugger(location.url, location.line);
276+
toolbox.viewSourceInDebugger(location.url, location.line, sourceActor);
276277
}
277278
},
278279

devtools/server/actors/inspector/event-collector.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,9 @@ class ReactEventCollector extends MainEventCollector {
708708
* The exposed class responsible for gathering events.
709709
*/
710710
class EventCollector {
711-
constructor() {
711+
constructor(targetActor) {
712+
this.targetActor = targetActor;
713+
712714
// The event collector array. Please preserve the order otherwise there will
713715
// be multiple failing tests.
714716
this.eventCollectors = [
@@ -864,6 +866,7 @@ class EventCollector {
864866
let line = 0;
865867
let native = false;
866868
let url = "";
869+
let sourceActor = "";
867870

868871
// If the listener is an object with a 'handleEvent' method, use that.
869872
if (listenerDO.class === "Object" || /^XUL\w*Element$/.test(listenerDO.class)) {
@@ -900,6 +903,8 @@ class EventCollector {
900903

901904
line = script.startLine;
902905
url = script.url;
906+
const actor = this.targetActor.sources.getOrCreateSourceActor(script.source);
907+
sourceActor = actor ? actor.actorID : null;
903908

904909
// Checking for the string "[native code]" is the only way at this point
905910
// to check for native code. Even if this provides a false positive then
@@ -957,6 +962,7 @@ class EventCollector {
957962
override.capturing : capturing,
958963
hide: typeof override.hide !== "undefined" ? override.hide : hide,
959964
native,
965+
sourceActor,
960966
};
961967

962968
// Hide the debugger icon for DOM0 and native listeners. DOM0 listeners are

devtools/server/actors/inspector/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const NodeActor = protocol.ActorClassWithSpec(nodeSpec, {
4848
protocol.Actor.prototype.initialize.call(this, null);
4949
this.walker = walker;
5050
this.rawNode = node;
51-
this._eventCollector = new EventCollector();
51+
this._eventCollector = new EventCollector(this.walker.targetActor);
5252

5353
// Store the original display type and scrollable state and whether or not the node is
5454
// displayed to track changes when reflows occur.

devtools/server/actors/utils/TabSources.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ TabSources.prototype = {
147147
return sourceActor;
148148
},
149149

150+
getOrCreateSourceActor(source) {
151+
if (this.hasSourceActor(source)) {
152+
return this.getSourceActor(source);
153+
}
154+
return this.createSourceActor(source);
155+
},
156+
150157
getSourceActorByInternalSourceId: function(id) {
151158
if (!this._sourcesByInternalSourceId) {
152159
this._sourcesByInternalSourceId = new Map();
@@ -158,10 +165,7 @@ TabSources.prototype = {
158165
}
159166
const source = this._sourcesByInternalSourceId.get(id);
160167
if (source) {
161-
if (this.hasSourceActor(source)) {
162-
return this.getSourceActor(source);
163-
}
164-
return this.createSourceActor(source);
168+
return this.getOrCreateSourceActor(source);
165169
}
166170
return null;
167171
},

0 commit comments

Comments
 (0)