/* 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/. */
/** * Creates a thread front for the remote debugging protocol server. This client * is a front to the thread actor created in the server side, hiding the * protocol details in a traditional JavaScript API. * * @param client DevToolsClient * @param actor string * The actor ID for this thread.
*/ class ThreadFront extends FrontClassWithSpec(threadSpec) {
constructor(client, targetFront, parentFront) { super(client, targetFront, parentFront); this.client = client; this._threadGrips = {}; // Note that this isn't matching ThreadActor state field. // ThreadFront is only using two values: paused or attached. this._state = "attached";
this._beforePaused = this._beforePaused.bind(this); this._beforeResumed = this._beforeResumed.bind(this); this.before("paused", this._beforePaused); this.before("resumed", this._beforeResumed); this.targetFront.on("will-navigate", this._onWillNavigate.bind(this)); // Attribute name from which to retrieve the actorID out of the target actor's form this.formAttributeName = "threadActor";
}
get state() { returnthis._state;
}
get paused() { returnthis._state === "paused";
}
get actor() { returnthis.actorID;
}
_assertPaused(command) { if (!this.paused) { throw Error(
command + " command sent while not paused. Currently " + this._state
);
}
}
/** * Resume a paused thread. If the optional limit parameter is present, then * the thread will also pause when that limit is reached. * * @param [optional] object limit * An object with a type property set to the appropriate limit (next, * step, or finish) per the remote debugging protocol specification. * Use null to specify no limit.
*/
async _doResume(resumeLimit, frameActorID) { this._assertPaused("resume");
// Put the client in a tentative "resuming" state so we can prevent // further requests that should only be sent in the paused state. this._previousState = this._state; this._state = "resuming"; try {
await super.resume(resumeLimit, frameActorID);
} catch (e) { if (this._state == "resuming") { // There was an error resuming, update the state to the new one // reported by the server, if given (only on wrongState), otherwise // reset back to the previous state. if (e.state) { this._state = ThreadStateTypes[e.state];
} else { this._state = this._previousState;
}
}
}
/** * Request the loaded sources for the current thread.
*/
async getSources() {
let sources = []; try {
sources = await super.sources();
} catch (e) { // we may have closed the connection
console.log(`getSources failed. Connection may have closed: ${e}`);
} return { sources };
}
/** * This is only used by tests, which should be migrated to DevToolsClient.createObjectFront
*/
pauseGrip(grip) { returnnew ObjectFront(this.conn, this.targetFront, this, grip);
}
/** * Clear and invalidate all the grip fronts from the given cache. * * @param gripCacheName * The property name of the grip cache we want to clear.
*/
_clearObjectFronts(gripCacheName) { for (const id in this[gripCacheName]) { this[gripCacheName][id].valid = false;
} this[gripCacheName] = {};
}
/** * Handle thread state change by doing necessary cleanup
*/
_onThreadState(packet) { // The debugger UI may not be initialized yet so we want to keep // the packet around so it knows what to pause state to display // when it's initialized this._lastPausePacket = packet;
}
/** * Return an instance of SourceFront for the given source actor form.
*/
source(form) { if (form.actor in this._threadGrips) { returnthis._threadGrips[form.actor];
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.