Bug 1544694 - Convert Source Client to a Front; r=ochameau,jdescottes

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
yulia 2019-04-26 12:51:07 +00:00
Родитель 418c70d897
Коммит 47738413e6
9 изменённых файлов: 59 добавлений и 93 удалений

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

@ -465,7 +465,7 @@ async function getBreakpointPositions(
for (const { thread, actor } of actors) {
const sourceThreadClient = lookupThreadClient(thread);
const sourceClient = sourceThreadClient.source({ actor });
const { positions } = await sourceClient.getBreakpointPositionsCompressed(
const positions = await sourceClient.getBreakpointPositionsCompressed(
range
);

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

@ -324,7 +324,11 @@ const SourceActor = ActorClassWithSpec(sourceSpec, {
},
/**
* Handler for the "source" packet.
* Handler for the "onSource" packet.
* @return Object
* The return of this function contains a field `contentType`, and
* a field `source`. `source` can either be an arrayBufferActor grip,
* or a LongStringActor grip.
*/
onSource: function() {
return Promise.resolve(this._init)

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

@ -746,9 +746,9 @@ function getFrames(threadClient, first, count) {
*/
async function blackBox(sourceClient, range = null) {
dumpn("Black boxing source: " + sourceClient.actor);
const { error, pausedInSource } = await sourceClient.blackBox(range);
Assert.ok(!error, "Should not get an error: " + error);
return {error, pausedInSource};
const pausedInSource = await sourceClient.blackBox(range);
ok(true, "blackBox didn't throw");
return pausedInSource;
}
/**
@ -759,8 +759,8 @@ async function blackBox(sourceClient, range = null) {
*/
async function unBlackBox(sourceClient, range = null) {
dumpn("Un-black boxing source: " + sourceClient.actor);
const {error} = await sourceClient.unblackBox(range);
Assert.ok(!error, "Should not get an error: " + error);
await sourceClient.unblackBox(range);
ok(true, "unblackBox didn't throw");
}
/**

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

@ -71,7 +71,7 @@ function test_black_box_paused() {
sources.filter(s => s.url == BLACK_BOXED_URL)[0]
);
const {pausedInSource} = await blackBox(sourceClient);
const pausedInSource = await blackBox(sourceClient);
Assert.ok(pausedInSource,
"We should be notified that we are currently paused in this source");
finishClient(gClient);

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

@ -22,7 +22,7 @@ add_task(threadClientTest(({ threadClient, debuggee }) => {
threadClient.addOneTimeListener("paused", function(event, packet) {
// Check the return value.
Assert.equal(packet.type, "paused");
Assert.equal(packet.frame.where.actor, source.actor);
Assert.equal(packet.frame.where.actor, source.actorID);
Assert.equal(packet.frame.where.line, location.line);
Assert.equal(packet.why.type, "breakpoint");
// Check that the breakpoint worked.

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

@ -61,9 +61,8 @@ function test_source() {
const sourceClient = gThreadClient.source(source);
response = await sourceClient.getBreakpointPositions();
Assert.ok(!!response);
Assert.ok(!!response.positions);
Assert.deepEqual(
response.positions,
response,
[{
line: 2,
column: 2,
@ -87,9 +86,8 @@ function test_source() {
response = await sourceClient.getBreakpointPositionsCompressed();
Assert.ok(!!response);
Assert.ok(!!response.positions);
Assert.deepEqual(
response.positions,
response,
{
2: [2],
3: [14, 17, 24],

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

@ -4,88 +4,58 @@
"use strict";
const {arg, DebuggerClient} = require("devtools/shared/client/debugger-client");
const { sourceSpec } = require("devtools/shared/specs/source");
const { FrontClassWithSpec, registerFront } = require("devtools/shared/protocol");
/**
* A SourceClient provides a way to access the source text of a script.
* A SourceFront provides a way to access the source text of a script.
*
* @param client ThreadClient
* The thread client parent.
* @param client DebuggerClient
* The Debugger Client instance.
* @param form Object
* The form sent across the remote debugging protocol.
* @param activeThread ThreadClient
* The thread client parent. Used until the SourceFront marshalls LongStringFront
* and ArrayBuffer.
*/
function SourceClient(client, form) {
this._form = form;
this._activeThread = client;
this._client = client.client;
class SourceClient extends FrontClassWithSpec(sourceSpec) {
constructor(client, form, activeThread) {
super(client);
this._url = form.url;
this._activeThread = activeThread;
// this is here for the time being, until the source front is managed
// via protocol.js marshalling
this.actorID = form.actor;
this.manage(this);
}
SourceClient.prototype = {
get actor() {
return this._form.actor;
},
return this.actorID;
}
get url() {
return this._form.url;
},
return this._url;
}
/**
* Black box this SourceClient's source.
*/
blackBox: DebuggerClient.requester(
{
type: "blackbox",
range: arg(0),
},
{
telemetry: "BLACKBOX",
},
),
// Alias for source.blackbox to avoid changing protocol.js packets
blackBox(range) {
return this.blackbox(range);
}
/**
* Un-black box this SourceClient's source.
*/
unblackBox: DebuggerClient.requester(
{
type: "unblackbox",
range: arg(0),
},
{
telemetry: "UNBLACKBOX",
},
),
getBreakpointPositions: function(query) {
const packet = {
to: this._form.actor,
type: "getBreakpointPositions",
query,
};
return this._client.request(packet);
},
getBreakpointPositionsCompressed: function(query) {
const packet = {
to: this._form.actor,
type: "getBreakpointPositionsCompressed",
query,
};
return this._client.request(packet);
},
// Alias for source.unblackbox to avoid changing protocol.js packets
unblackBox() {
return this.unblackbox();
}
/**
* Get a long string grip for this SourceClient's source.
*/
source: function() {
const packet = {
to: this._form.actor,
type: "source",
};
return this._client.request(packet).then(response => {
async source() {
const response = await this.onSource();
return this._onSourceResponse(response);
});
},
}
_onSourceResponse: function(response) {
_onSourceResponse(response) {
if (typeof response.source === "string") {
return response;
}
@ -123,16 +93,8 @@ SourceClient.prototype = {
};
return newResponse;
});
},
}
}
setPausePoints: function(pausePoints) {
const packet = {
to: this._form.actor,
type: "setPausePoints",
pausePoints,
};
return this._client.request(packet);
},
};
module.exports = SourceClient;
exports.SourceClient = SourceClient;
registerFront(SourceClient);

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

@ -12,7 +12,7 @@ const {ThreadStateTypes} = require("devtools/shared/client/constants");
loader.lazyRequireGetter(this, "ArrayBufferClient", "devtools/shared/client/array-buffer-client");
loader.lazyRequireGetter(this, "LongStringClient", "devtools/shared/client/long-string-client");
loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/object-client");
loader.lazyRequireGetter(this, "SourceClient", "devtools/shared/client/source-client");
loader.lazyRequireGetter(this, "SourceClient", "devtools/shared/client/source-client", true);
/**
* Creates a thread client for the remote debugging protocol server. This client
@ -544,7 +544,7 @@ ThreadClient.prototype = {
return this._threadGrips[form.actor];
}
this._threadGrips[form.actor] = new SourceClient(this, form);
this._threadGrips[form.actor] = new SourceClient(this.client, form, this);
return this._threadGrips[form.actor];
},

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

@ -39,6 +39,8 @@ const sourceSpec = generateActorSpec({
},
},
onSource: {
// we are sending the type "source" to be compatible
// with FF67 and older
request: { type: "source" },
response: RetVal("json"),
},