mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1673328 - [devtools] Rename TabSources to SourcesManager. r=nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D95042
This commit is contained in:
parent
90a993e0b7
commit
ce474dc715
@ -146,10 +146,10 @@ BreakpointActor.prototype = {
|
||||
hit: function(frame) {
|
||||
// Don't pause if we are currently stepping (in or over) or the frame is
|
||||
// black-boxed.
|
||||
const location = this.threadActor.sources.getFrameLocation(frame);
|
||||
const location = this.threadActor.sourcesManager.getFrameLocation(frame);
|
||||
|
||||
if (
|
||||
this.threadActor.sources.isFrameBlackBoxed(frame) ||
|
||||
this.threadActor.sourcesManager.isFrameBlackBoxed(frame) ||
|
||||
this.threadActor.skipBreakpoints
|
||||
) {
|
||||
return undefined;
|
||||
|
@ -38,7 +38,7 @@ function isValidSavedFrame(threadActor, savedFrame) {
|
||||
);
|
||||
}
|
||||
function getSavedFrameSource(threadActor, savedFrame) {
|
||||
return threadActor.sources.getSourceActorByInternalSourceId(
|
||||
return threadActor.sourcesManager.getSourceActorByInternalSourceId(
|
||||
savedFrame.sourceId
|
||||
);
|
||||
}
|
||||
@ -185,7 +185,9 @@ const FrameActor = ActorClassWithSpec(frameSpec, {
|
||||
form.arguments = this._args();
|
||||
|
||||
if (this.frame.script) {
|
||||
const location = this.threadActor.sources.getFrameLocation(this.frame);
|
||||
const location = this.threadActor.sourcesManager.getFrameLocation(
|
||||
this.frame
|
||||
);
|
||||
form.where = {
|
||||
actor: location.sourceActor.actorID,
|
||||
line: location.line,
|
||||
|
@ -66,7 +66,7 @@ const proto = {
|
||||
* - createValueGrip
|
||||
* Creates a value grip for the given object
|
||||
* - sources
|
||||
* TabSources getter that manages the sources of a thread
|
||||
* SourcesManager getter that manages the sources of a thread
|
||||
* - createEnvironmentActor
|
||||
* Creates and return an environment actor
|
||||
* - getGripDepth
|
||||
|
@ -39,7 +39,7 @@ const {
|
||||
class ConsoleMessageWatcher {
|
||||
async watch(targetActor, { onAvailable }) {
|
||||
// The following code expects the ThreadActor to be instantiated, via:
|
||||
// prepareConsoleMessageForRemote > TabSources.getActorIdForInternalSourceId
|
||||
// prepareConsoleMessageForRemote > SourcesManager.getActorIdForInternalSourceId
|
||||
// The Thread Actor is instantiated via Target.attach, but we should
|
||||
// probably review this and only instantiate the actor instead of attaching the target.
|
||||
if (!targetActor.threadActor) {
|
||||
|
@ -110,8 +110,8 @@ const SourceActor = ActorClassWithSpec(sourceSpec, {
|
||||
get threadActor() {
|
||||
return this._threadActor;
|
||||
},
|
||||
get sources() {
|
||||
return this._threadActor.sources;
|
||||
get sourcesManager() {
|
||||
return this._threadActor.sourcesManager;
|
||||
},
|
||||
get dbg() {
|
||||
return this.threadActor.dbg;
|
||||
@ -172,7 +172,7 @@ const SourceActor = ActorClassWithSpec(sourceSpec, {
|
||||
actor: this.actorID,
|
||||
extensionName: this.extensionName,
|
||||
url: this.url,
|
||||
isBlackBoxed: this.threadActor.sources.isBlackBoxed(this.url),
|
||||
isBlackBoxed: this.sourcesManager.isBlackBoxed(this.url),
|
||||
sourceMapBaseURL: getSourcemapBaseURL(
|
||||
this.url,
|
||||
this.threadActor._parent.window
|
||||
@ -220,7 +220,7 @@ const SourceActor = ActorClassWithSpec(sourceSpec, {
|
||||
};
|
||||
}
|
||||
|
||||
return this.sources.urlContents(
|
||||
return this.sourcesManager.urlContents(
|
||||
this.url,
|
||||
/* partial */ false,
|
||||
/* canUseCache */ this._isInlineSource
|
||||
@ -288,7 +288,7 @@ const SourceActor = ActorClassWithSpec(sourceSpec, {
|
||||
// attaches to an existing page. In this case we don't need to get the
|
||||
// displacement synchronously, so it's OK if we yield to the event loop
|
||||
// while the promise resolves.
|
||||
const fileContents = this.sources.urlContents(
|
||||
const fileContents = this.sourcesManager.urlContents(
|
||||
this.url,
|
||||
/* partial */ true,
|
||||
/* canUseCache */ this._isInlineSource
|
||||
@ -608,7 +608,7 @@ const SourceActor = ActorClassWithSpec(sourceSpec, {
|
||||
* Handler for the "blackbox" packet.
|
||||
*/
|
||||
blackbox: function(range) {
|
||||
this.threadActor.sources.blackBox(this.url, range);
|
||||
this.sourcesManager.blackBox(this.url, range);
|
||||
if (
|
||||
this.threadActor.state == "paused" &&
|
||||
this.threadActor.youngestFrame &&
|
||||
@ -623,7 +623,7 @@ const SourceActor = ActorClassWithSpec(sourceSpec, {
|
||||
* Handler for the "unblackbox" packet.
|
||||
*/
|
||||
unblackbox: function(range) {
|
||||
this.threadActor.sources.unblackBox(this.url, range);
|
||||
this.sourcesManager.unblackBox(this.url, range);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -30,7 +30,9 @@ const ChromeUtils = require("ChromeUtils");
|
||||
var { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
|
||||
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
||||
var { assert } = DevToolsUtils;
|
||||
var { TabSources } = require("devtools/server/actors/utils/TabSources");
|
||||
var {
|
||||
SourcesManager,
|
||||
} = require("devtools/server/actors/utils/sources-manager");
|
||||
var makeDebugger = require("devtools/server/actors/utils/make-debugger");
|
||||
const InspectorUtils = require("InspectorUtils");
|
||||
const Targets = require("devtools/server/actors/targets/index");
|
||||
@ -310,7 +312,7 @@ const browsingContextTargetPrototype = {
|
||||
// filter console messages by addonID), set to an empty (no options) object by default.
|
||||
consoleAPIListenerOptions: {},
|
||||
|
||||
// Optional TabSources filter function (e.g. used by the WebExtensionActor to filter
|
||||
// Optional SourcesManager filter function (e.g. used by the WebExtensionActor to filter
|
||||
// sources by addonID), allow all sources by default.
|
||||
_allowSource() {
|
||||
return true;
|
||||
@ -492,7 +494,7 @@ const browsingContextTargetPrototype = {
|
||||
|
||||
get sources() {
|
||||
if (!this._sources) {
|
||||
this._sources = new TabSources(this.threadActor, this._allowSource);
|
||||
this._sources = new SourcesManager(this.threadActor, this._allowSource);
|
||||
}
|
||||
return this._sources;
|
||||
},
|
||||
|
@ -19,7 +19,9 @@ const { WebConsoleActor } = require("devtools/server/actors/webconsole");
|
||||
const makeDebugger = require("devtools/server/actors/utils/make-debugger");
|
||||
const { Pool } = require("devtools/shared/protocol");
|
||||
const { assert } = require("devtools/shared/DevToolsUtils");
|
||||
const { TabSources } = require("devtools/server/actors/utils/TabSources");
|
||||
const {
|
||||
SourcesManager,
|
||||
} = require("devtools/server/actors/utils/sources-manager");
|
||||
const { Actor } = require("devtools/shared/protocol");
|
||||
const {
|
||||
contentProcessTargetSpec,
|
||||
@ -114,7 +116,7 @@ const ContentProcessTargetActor = TargetActorMixin(
|
||||
this.threadActor,
|
||||
"threadActor should exist when creating sources."
|
||||
);
|
||||
this._sources = new TabSources(this.threadActor);
|
||||
this._sources = new SourcesManager(this.threadActor);
|
||||
}
|
||||
return this._sources;
|
||||
},
|
||||
|
@ -114,7 +114,7 @@ webExtensionTargetPrototype.initialize = function(
|
||||
});
|
||||
|
||||
// Bind the _allowSource helper to this, it is used in the
|
||||
// BrowsingContextTargetActor to lazily create the TabSources instance.
|
||||
// BrowsingContextTargetActor to lazily create the SourcesManager instance.
|
||||
this._allowSource = this._allowSource.bind(this);
|
||||
this._onParentExit = this._onParentExit.bind(this);
|
||||
|
||||
|
@ -12,7 +12,9 @@ const { WebConsoleActor } = require("devtools/server/actors/webconsole");
|
||||
const Targets = require("devtools/server/actors/targets/index");
|
||||
|
||||
const makeDebuggerUtil = require("devtools/server/actors/utils/make-debugger");
|
||||
const { TabSources } = require("devtools/server/actors/utils/TabSources");
|
||||
const {
|
||||
SourcesManager,
|
||||
} = require("devtools/server/actors/utils/sources-manager");
|
||||
|
||||
const TargetActorMixin = require("devtools/server/actors/targets/target-actor-mixin");
|
||||
|
||||
@ -83,7 +85,7 @@ exports.WorkerTargetActor = TargetActorMixin(
|
||||
|
||||
get sources() {
|
||||
if (this._sources === null) {
|
||||
this._sources = new TabSources(this.threadActor);
|
||||
this._sources = new SourcesManager(this.threadActor);
|
||||
}
|
||||
|
||||
return this._sources;
|
||||
|
@ -272,7 +272,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
return createValueGrip(value, this.threadLifetimePool, this.objectGrip);
|
||||
},
|
||||
|
||||
get sources() {
|
||||
get sourcesManager() {
|
||||
return this._parent.sources;
|
||||
},
|
||||
|
||||
@ -326,7 +326,6 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
if (this._dbg) {
|
||||
this.dbg.removeAllDebuggees();
|
||||
}
|
||||
this._sources = null;
|
||||
this._scripts = null;
|
||||
},
|
||||
|
||||
@ -363,7 +362,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
this._parent.off("will-navigate", this._onWillNavigate);
|
||||
this._parent.off("navigate", this._onNavigate);
|
||||
|
||||
this.sources.off("newSource", this.onNewSourceEvent);
|
||||
this.sourcesManager.off("newSource", this.onNewSourceEvent);
|
||||
this.clearDebuggees();
|
||||
this._threadLifetimePool.destroy();
|
||||
this._threadLifetimePool = null;
|
||||
@ -397,7 +396,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
this._debuggerSourcesSeen = new WeakSet();
|
||||
|
||||
this._options = { ...this._options, ...options };
|
||||
this.sources.on("newSource", this.onNewSourceEvent);
|
||||
this.sourcesManager.on("newSource", this.onNewSourceEvent);
|
||||
|
||||
// Initialize an event loop stack. This can't be done in the constructor,
|
||||
// because this.conn is not yet initialized by the actor pool at that time.
|
||||
@ -548,14 +547,16 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
if (location.sourceUrl) {
|
||||
// There can be multiple source actors for a URL if there are multiple
|
||||
// inline sources on an HTML page.
|
||||
const sourceActors = this.sources.getSourceActorsByURL(
|
||||
const sourceActors = this.sourcesManager.getSourceActorsByURL(
|
||||
location.sourceUrl
|
||||
);
|
||||
for (const sourceActor of sourceActors) {
|
||||
await sourceActor.applyBreakpoint(actor);
|
||||
}
|
||||
} else {
|
||||
const sourceActor = this.sources.getSourceActorById(location.sourceId);
|
||||
const sourceActor = this.sourcesManager.getSourceActorById(
|
||||
location.sourceId
|
||||
);
|
||||
if (sourceActor) {
|
||||
await sourceActor.applyBreakpoint(actor);
|
||||
}
|
||||
@ -809,7 +810,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
} else if (!notification.phase && !this._activeEventPause) {
|
||||
const frame = this.dbg.getNewestFrame();
|
||||
if (frame) {
|
||||
if (this.sources.isFrameBlackBoxed(frame)) {
|
||||
if (this.sourcesManager.isFrameBlackBoxed(frame)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -820,7 +821,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
|
||||
_makeEventBreakpointEnterFrame(eventBreakpoint) {
|
||||
return frame => {
|
||||
if (this.sources.isFrameBlackBoxed(frame)) {
|
||||
if (this.sourcesManager.isFrameBlackBoxed(frame)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -886,9 +887,11 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { sourceActor, line, column } = this.sources.getFrameLocation(
|
||||
frame
|
||||
);
|
||||
const {
|
||||
sourceActor,
|
||||
line,
|
||||
column,
|
||||
} = this.sourcesManager.getFrameLocation(frame);
|
||||
|
||||
packet.why = reason;
|
||||
|
||||
@ -944,7 +947,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
steppingType: "next",
|
||||
});
|
||||
|
||||
if (this.sources.isFrameBlackBoxed(frame)) {
|
||||
if (this.sourcesManager.isFrameBlackBoxed(frame)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -976,7 +979,10 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
// on the next pause.
|
||||
thread.suspendedFrame = this;
|
||||
|
||||
if (steppingType != "finish" && !thread.sources.isFrameBlackBoxed(this)) {
|
||||
if (
|
||||
steppingType != "finish" &&
|
||||
!thread.sourcesManager.isFrameBlackBoxed(this)
|
||||
) {
|
||||
const pauseAndRespValue = pauseAndRespond(this, packet =>
|
||||
thread.createCompletionGrip(packet, completion)
|
||||
);
|
||||
@ -1014,7 +1020,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
},
|
||||
|
||||
hasMoved: function(frame, newType) {
|
||||
const newLocation = this.sources.getFrameLocation(frame);
|
||||
const newLocation = this.sourcesManager.getFrameLocation(frame);
|
||||
|
||||
if (!this._priorPause) {
|
||||
return true;
|
||||
@ -1061,7 +1067,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
// 3. we have not moved since the last pause
|
||||
if (
|
||||
!meta.isBreakpoint ||
|
||||
this.sources.isFrameBlackBoxed(frame) ||
|
||||
this.sourcesManager.isFrameBlackBoxed(frame) ||
|
||||
!this.hasMoved(frame)
|
||||
) {
|
||||
return false;
|
||||
@ -1074,7 +1080,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
},
|
||||
|
||||
atBreakpointLocation(frame) {
|
||||
const location = this.sources.getFrameLocation(frame);
|
||||
const location = this.sourcesManager.getFrameLocation(frame);
|
||||
return !!this.breakpointActorMap.get(location);
|
||||
},
|
||||
|
||||
@ -1194,7 +1200,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
case "break":
|
||||
case "next":
|
||||
if (stepFrame.script) {
|
||||
if (!this.sources.isFrameBlackBoxed(stepFrame)) {
|
||||
if (!this.sourcesManager.isFrameBlackBoxed(stepFrame)) {
|
||||
stepFrame.onStep = onStep;
|
||||
}
|
||||
}
|
||||
@ -1428,7 +1434,9 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
// there is an active Debugger.Source that represents the SaveFrame's
|
||||
// source, it will have already been created in the server.
|
||||
if (frame instanceof Debugger.Frame) {
|
||||
const sourceActor = this.sources.createSourceActor(frame.script.source);
|
||||
const sourceActor = this.sourcesManager.createSourceActor(
|
||||
frame.script.source
|
||||
);
|
||||
if (!sourceActor) {
|
||||
continue;
|
||||
}
|
||||
@ -1485,7 +1493,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
// timeout flush the buffered packets.
|
||||
|
||||
return {
|
||||
sources: this.sources.iter().map(s => s.form()),
|
||||
sources: this.sourcesManager.iter().map(s => s.form()),
|
||||
};
|
||||
},
|
||||
|
||||
@ -1738,7 +1746,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
|
||||
return createValueGrip(v, this.threadLifetimePool, this.objectGrip);
|
||||
},
|
||||
sources: () => this.sources,
|
||||
sources: () => this.sourcesManager,
|
||||
createEnvironmentActor: (e, p) => this.createEnvironmentActor(e, p),
|
||||
promote: () => this.threadObjectGrip(actor),
|
||||
isThreadLifetimePool: () =>
|
||||
@ -1778,7 +1786,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
|
||||
_onWindowReady: function({ isTopLevel, isBFCache, window }) {
|
||||
if (isTopLevel && this.state != "detached") {
|
||||
this.sources.reset();
|
||||
this.sourcesManager.reset();
|
||||
this.clearDebuggees();
|
||||
this.dbg.enable();
|
||||
this.maybePauseOnExceptions();
|
||||
@ -1843,7 +1851,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (this.skipBreakpoints || this.sources.isFrameBlackBoxed(frame)) {
|
||||
if (this.skipBreakpoints || this.sourcesManager.isFrameBlackBoxed(frame)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -1962,7 +1970,10 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (this.skipBreakpoints || this.sources.isFrameBlackBoxed(youngestFrame)) {
|
||||
if (
|
||||
this.skipBreakpoints ||
|
||||
this.sourcesManager.isFrameBlackBoxed(youngestFrame)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -2033,7 +2044,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
* @returns true, if the source was added; false otherwise.
|
||||
*/
|
||||
_addSource: function(source) {
|
||||
if (!this.sources.allowSource(source)) {
|
||||
if (!this.sourcesManager.allowSource(source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2044,12 +2055,12 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
let sourceActor;
|
||||
if (
|
||||
this._debuggerSourcesSeen.has(source) &&
|
||||
this.sources.hasSourceActor(source)
|
||||
this.sourcesManager.hasSourceActor(source)
|
||||
) {
|
||||
sourceActor = this.sources.getSourceActor(source);
|
||||
sourceActor = this.sourcesManager.getSourceActor(source);
|
||||
sourceActor.resetDebuggeeScripts();
|
||||
} else {
|
||||
sourceActor = this.sources.createSourceActor(source);
|
||||
sourceActor = this.sourcesManager.createSourceActor(source);
|
||||
}
|
||||
|
||||
const sourceUrl = sourceActor.url;
|
||||
@ -2079,7 +2090,11 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
* @param url The URL string to fetch.
|
||||
*/
|
||||
_resurrectSource: async function(url) {
|
||||
let { content, contentType, sourceMapURL } = await this.sources.urlContents(
|
||||
let {
|
||||
content,
|
||||
contentType,
|
||||
sourceMapURL,
|
||||
} = await this.sourcesManager.urlContents(
|
||||
url,
|
||||
/* partial */ false,
|
||||
/* canUseCache */ true
|
||||
@ -2180,7 +2195,7 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
|
||||
},
|
||||
|
||||
logLocation: function(prefix, frame) {
|
||||
const loc = this.sources.getFrameLocation(frame);
|
||||
const loc = this.sourcesManager.getFrameLocation(frame);
|
||||
dump(`${prefix} (${loc.line}, ${loc.column})\n`);
|
||||
},
|
||||
});
|
||||
|
@ -26,9 +26,11 @@ function getThrownMessage(completion) {
|
||||
module.exports.getThrownMessage = getThrownMessage;
|
||||
|
||||
function logEvent({ threadActor, frame, level, expression, bindings }) {
|
||||
const { sourceActor, line, column } = threadActor.sources.getFrameLocation(
|
||||
frame
|
||||
);
|
||||
const {
|
||||
sourceActor,
|
||||
line,
|
||||
column,
|
||||
} = threadActor.sourcesManager.getFrameLocation(frame);
|
||||
const displayName = formatDisplayName(frame);
|
||||
|
||||
// TODO remove this branch when (#1592584) lands (#1609540)
|
||||
|
@ -18,8 +18,8 @@ DevToolsModules(
|
||||
"shapes-utils.js",
|
||||
"source-map-utils.js",
|
||||
"source-url.js",
|
||||
"sources-manager.js",
|
||||
"stack.js",
|
||||
"TabSources.js",
|
||||
"track-change-emitter.js",
|
||||
"walker-search.js",
|
||||
"watchpoint-map.js",
|
||||
|
@ -18,47 +18,6 @@ loader.lazyRequireGetter(
|
||||
true
|
||||
);
|
||||
|
||||
/**
|
||||
* Manages the sources for a thread. Handles URL contents, locations in
|
||||
* the sources, etc for ThreadActors.
|
||||
*/
|
||||
function TabSources(threadActor, allowSourceFn = () => true) {
|
||||
EventEmitter.decorate(this);
|
||||
|
||||
this._thread = threadActor;
|
||||
this.allowSource = source => {
|
||||
return !isHiddenSource(source) && allowSourceFn(source);
|
||||
};
|
||||
|
||||
this.blackBoxedSources = new Map();
|
||||
|
||||
// Debugger.Source -> SourceActor
|
||||
this._sourceActors = new Map();
|
||||
|
||||
// URL -> content
|
||||
//
|
||||
// Any possibly incomplete content that has been loaded for each URL.
|
||||
this._urlContents = new Map();
|
||||
|
||||
// URL -> Promise[]
|
||||
//
|
||||
// Any promises waiting on a URL to be completely loaded.
|
||||
this._urlWaiters = new Map();
|
||||
|
||||
// Debugger.Source.id -> Debugger.Source
|
||||
//
|
||||
// The IDs associated with ScriptSources and available via DebuggerSource.id
|
||||
// are internal to this process and should not be exposed to the client. This
|
||||
// map associates these IDs with the corresponding source, provided the source
|
||||
// has not been GC'ed and the actor has been created. This is lazily populated
|
||||
// the first time it is needed.
|
||||
this._sourcesByInternalSourceId = null;
|
||||
|
||||
if (!isWorker) {
|
||||
Services.obs.addObserver(this, "devtools-html-content");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches strings of the form "foo.min.js" or "foo-min.js", etc. If the regular
|
||||
* expression matches, we can be fairly sure that the source is minified, and
|
||||
@ -66,22 +25,62 @@ function TabSources(threadActor, allowSourceFn = () => true) {
|
||||
*/
|
||||
const MINIFIED_SOURCE_REGEXP = /\bmin\.js$/;
|
||||
|
||||
TabSources.prototype = {
|
||||
/**
|
||||
* Manages the sources for a thread. Handles URL contents, locations in
|
||||
* the sources, etc for ThreadActors.
|
||||
*/
|
||||
class SourcesManager extends EventEmitter {
|
||||
constructor(threadActor, allowSourceFn = () => true) {
|
||||
super();
|
||||
this._thread = threadActor;
|
||||
this.allowSource = source => {
|
||||
return !isHiddenSource(source) && allowSourceFn(source);
|
||||
};
|
||||
|
||||
this.blackBoxedSources = new Map();
|
||||
|
||||
// Debugger.Source -> SourceActor
|
||||
this._sourceActors = new Map();
|
||||
|
||||
// URL -> content
|
||||
//
|
||||
// Any possibly incomplete content that has been loaded for each URL.
|
||||
this._urlContents = new Map();
|
||||
|
||||
// URL -> Promise[]
|
||||
//
|
||||
// Any promises waiting on a URL to be completely loaded.
|
||||
this._urlWaiters = new Map();
|
||||
|
||||
// Debugger.Source.id -> Debugger.Source
|
||||
//
|
||||
// The IDs associated with ScriptSources and available via DebuggerSource.id
|
||||
// are internal to this process and should not be exposed to the client. This
|
||||
// map associates these IDs with the corresponding source, provided the source
|
||||
// has not been GC'ed and the actor has been created. This is lazily populated
|
||||
// the first time it is needed.
|
||||
this._sourcesByInternalSourceId = null;
|
||||
|
||||
if (!isWorker) {
|
||||
Services.obs.addObserver(this, "devtools-html-content");
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
if (!isWorker) {
|
||||
Services.obs.removeObserver(this, "devtools-html-content");
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear existing sources so they are recreated on the next access.
|
||||
*/
|
||||
reset: function() {
|
||||
reset() {
|
||||
this._sourceActors = new Map();
|
||||
this._urlContents = new Map();
|
||||
this._urlWaiters = new Map();
|
||||
this._sourcesByInternalSourceId = null;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a source actor representing this source.
|
||||
@ -90,8 +89,8 @@ TabSources.prototype = {
|
||||
* The source to make an actor for.
|
||||
* @returns a SourceActor representing the source or null.
|
||||
*/
|
||||
createSourceActor: function(source) {
|
||||
assert(source, "TabSources.prototype.source needs a source");
|
||||
createSourceActor(source) {
|
||||
assert(source, "SourcesManager.prototype.source needs a source");
|
||||
|
||||
if (!this.allowSource(source)) {
|
||||
return null;
|
||||
@ -115,21 +114,21 @@ TabSources.prototype = {
|
||||
|
||||
this.emit("newSource", actor);
|
||||
return actor;
|
||||
},
|
||||
}
|
||||
|
||||
_getSourceActor: function(source) {
|
||||
_getSourceActor(source) {
|
||||
if (this._sourceActors.has(source)) {
|
||||
return this._sourceActors.get(source);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
}
|
||||
|
||||
hasSourceActor: function(source) {
|
||||
hasSourceActor(source) {
|
||||
return !!this._getSourceActor(source);
|
||||
},
|
||||
}
|
||||
|
||||
getSourceActor: function(source) {
|
||||
getSourceActor(source) {
|
||||
const sourceActor = this._getSourceActor(source);
|
||||
|
||||
if (!sourceActor) {
|
||||
@ -139,7 +138,7 @@ TabSources.prototype = {
|
||||
}
|
||||
|
||||
return sourceActor;
|
||||
},
|
||||
}
|
||||
|
||||
getOrCreateSourceActor(source) {
|
||||
// Tolerate the source coming from a different Debugger than the one
|
||||
@ -159,9 +158,9 @@ TabSources.prototype = {
|
||||
return this.getSourceActor(source);
|
||||
}
|
||||
return this.createSourceActor(source);
|
||||
},
|
||||
}
|
||||
|
||||
getSourceActorByInternalSourceId: function(id) {
|
||||
getSourceActorByInternalSourceId(id) {
|
||||
if (!this._sourcesByInternalSourceId) {
|
||||
this._sourcesByInternalSourceId = new Map();
|
||||
for (const source of this._thread.dbg.findSources()) {
|
||||
@ -175,9 +174,9 @@ TabSources.prototype = {
|
||||
return this.getOrCreateSourceActor(source);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
}
|
||||
|
||||
getSourceActorsByURL: function(url) {
|
||||
getSourceActorsByURL(url) {
|
||||
const rv = [];
|
||||
if (url) {
|
||||
for (const [, actor] of this._sourceActors) {
|
||||
@ -187,7 +186,7 @@ TabSources.prototype = {
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
},
|
||||
}
|
||||
|
||||
getSourceActorById(actorId) {
|
||||
for (const [, actor] of this._sourceActors) {
|
||||
@ -196,7 +195,7 @@ TabSources.prototype = {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the URL likely points to a minified resource, false
|
||||
@ -206,7 +205,7 @@ TabSources.prototype = {
|
||||
* The url to test.
|
||||
* @returns Boolean
|
||||
*/
|
||||
_isMinifiedURL: function(uri) {
|
||||
_isMinifiedURL(uri) {
|
||||
if (!uri) {
|
||||
return false;
|
||||
}
|
||||
@ -222,7 +221,7 @@ TabSources.prototype = {
|
||||
// whole thing with the minified source regexp.
|
||||
return MINIFIED_SOURCE_REGEXP.test(uri);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the non-source-mapped location of an offset in a script.
|
||||
@ -234,14 +233,14 @@ TabSources.prototype = {
|
||||
* @returns Object
|
||||
* Returns an object of the form { source, line, column }
|
||||
*/
|
||||
getScriptOffsetLocation: function(script, offset) {
|
||||
getScriptOffsetLocation(script, offset) {
|
||||
const { lineNumber, columnNumber } = script.getOffsetMetadata(offset);
|
||||
return new SourceLocation(
|
||||
this.createSourceActor(script.source),
|
||||
lineNumber,
|
||||
columnNumber
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the non-source-mapped location of the given Debugger.Frame. If the
|
||||
@ -252,12 +251,12 @@ TabSources.prototype = {
|
||||
* @returns Object
|
||||
* Returns an object of the form { source, line, column }
|
||||
*/
|
||||
getFrameLocation: function(frame) {
|
||||
getFrameLocation(frame) {
|
||||
if (!frame || !frame.script) {
|
||||
return new SourceLocation();
|
||||
}
|
||||
return this.getScriptOffsetLocation(frame.script, frame.offset);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if URL for the given source is black boxed.
|
||||
@ -266,7 +265,7 @@ TabSources.prototype = {
|
||||
* The URL of the source which we are checking whether it is black
|
||||
* boxed or not.
|
||||
*/
|
||||
isBlackBoxed: function(url, line, column) {
|
||||
isBlackBoxed(url, line, column) {
|
||||
const ranges = this.blackBoxedSources.get(url);
|
||||
if (!ranges) {
|
||||
return this.blackBoxedSources.has(url);
|
||||
@ -274,12 +273,12 @@ TabSources.prototype = {
|
||||
|
||||
const range = ranges.find(r => isLocationInRange({ line, column }, r));
|
||||
return !!range;
|
||||
},
|
||||
}
|
||||
|
||||
isFrameBlackBoxed: function(frame) {
|
||||
isFrameBlackBoxed(frame) {
|
||||
const { url, line, column } = this.getFrameLocation(frame);
|
||||
return this.isBlackBoxed(url, line, column);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given source URL to the set of sources that are black boxed.
|
||||
@ -287,7 +286,7 @@ TabSources.prototype = {
|
||||
* @param url String
|
||||
* The URL of the source which we are black boxing.
|
||||
*/
|
||||
blackBox: function(url, range) {
|
||||
blackBox(url, range) {
|
||||
if (!range) {
|
||||
// blackbox the whole source
|
||||
return this.blackBoxedSources.set(url, null);
|
||||
@ -302,7 +301,7 @@ TabSources.prototype = {
|
||||
ranges.splice(index + 1, 0, range);
|
||||
this.blackBoxedSources.set(url, ranges);
|
||||
return true;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given source URL to the set of sources that are black boxed.
|
||||
@ -310,7 +309,7 @@ TabSources.prototype = {
|
||||
* @param url String
|
||||
* The URL of the source which we are no longer black boxing.
|
||||
*/
|
||||
unblackBox: function(url, range) {
|
||||
unblackBox(url, range) {
|
||||
if (!range) {
|
||||
return this.blackBoxedSources.delete(url);
|
||||
}
|
||||
@ -333,11 +332,11 @@ TabSources.prototype = {
|
||||
}
|
||||
|
||||
return this.blackBoxedSources.set(url, ranges);
|
||||
},
|
||||
}
|
||||
|
||||
iter: function() {
|
||||
iter() {
|
||||
return [...this._sourceActors.values()];
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for new HTML content.
|
||||
@ -374,7 +373,7 @@ TabSources.prototype = {
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of a URL, fetching it if necessary. If partial is set and
|
||||
@ -405,9 +404,9 @@ TabSources.prototype = {
|
||||
}
|
||||
|
||||
return this._fetchURLContents(url, partial, canUseCache);
|
||||
},
|
||||
}
|
||||
|
||||
_fetchURLContents: async function(url, partial, canUseCache) {
|
||||
async _fetchURLContents(url, partial, canUseCache) {
|
||||
// Only try the cache if it is currently enabled for the document.
|
||||
// Without this check, the cache may return stale data that doesn't match
|
||||
// the document shown in the browser.
|
||||
@ -469,9 +468,9 @@ TabSources.prototype = {
|
||||
this._urlContents.set(url, { ...result, complete: true });
|
||||
|
||||
return result;
|
||||
},
|
||||
}
|
||||
|
||||
_reportLoadSourceError: function(error) {
|
||||
_reportLoadSourceError(error) {
|
||||
try {
|
||||
DevToolsUtils.reportException("SourceActor", error);
|
||||
|
||||
@ -480,8 +479,8 @@ TabSources.prototype = {
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks if a source should never be displayed to the user because
|
||||
@ -500,5 +499,5 @@ function isLocationInRange({ line, column }, range) {
|
||||
);
|
||||
}
|
||||
|
||||
exports.TabSources = TabSources;
|
||||
exports.SourcesManager = SourcesManager;
|
||||
exports.isHiddenSource = isHiddenSource;
|
@ -5,8 +5,8 @@
|
||||
"use strict";
|
||||
|
||||
class WatchpointMap {
|
||||
constructor(thread) {
|
||||
this.thread = thread;
|
||||
constructor(threadActor) {
|
||||
this.threadActor = threadActor;
|
||||
this._watchpoints = new Map();
|
||||
}
|
||||
|
||||
@ -31,17 +31,17 @@ class WatchpointMap {
|
||||
}
|
||||
|
||||
const maybeHandlePause = type => {
|
||||
const frame = this.thread.dbg.getNewestFrame();
|
||||
const frame = this.threadActor.dbg.getNewestFrame();
|
||||
|
||||
if (
|
||||
!this.thread.hasMoved(frame, type) ||
|
||||
this.thread.skipBreakpoints ||
|
||||
this.thread.sources.isFrameBlackBoxed(frame)
|
||||
!this.threadActor.hasMoved(frame, type) ||
|
||||
this.threadActor.sourcesManager.isFrameBlackBoxed(frame)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.thread._pauseAndRespond(frame, {
|
||||
this.threadActor._pauseAndRespond(frame, {
|
||||
type: type,
|
||||
message: label,
|
||||
});
|
||||
|
@ -13,7 +13,9 @@ const { DevToolsServer } = require("devtools/server/devtools-server");
|
||||
const {
|
||||
ActorRegistry,
|
||||
} = require("devtools/server/actors/utils/actor-registry");
|
||||
const { TabSources } = require("devtools/server/actors/utils/TabSources");
|
||||
const {
|
||||
SourcesManager,
|
||||
} = require("devtools/server/actors/utils/sources-manager");
|
||||
const makeDebugger = require("devtools/server/actors/utils/make-debugger");
|
||||
const protocol = require("devtools/shared/protocol");
|
||||
const {
|
||||
@ -184,7 +186,7 @@ const TestTargetActor = protocol.ActorClassWithSpec(browsingContextTargetSpec, {
|
||||
|
||||
get sources() {
|
||||
if (!this._sources) {
|
||||
this._sources = new TabSources(this.threadActor);
|
||||
this._sources = new SourcesManager(this.threadActor);
|
||||
}
|
||||
return this._sources;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user