diff --git a/devtools/client/debugger/src/client/firefox/commands.js b/devtools/client/debugger/src/client/firefox/commands.js index 52baf9eb9fab..211d4db6198a 100644 --- a/devtools/client/debugger/src/client/firefox/commands.js +++ b/devtools/client/debugger/src/client/firefox/commands.js @@ -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 ); diff --git a/devtools/server/actors/source.js b/devtools/server/actors/source.js index 1420dbbd9eb0..dd9aa8d95183 100644 --- a/devtools/server/actors/source.js +++ b/devtools/server/actors/source.js @@ -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) diff --git a/devtools/server/tests/unit/head_dbg.js b/devtools/server/tests/unit/head_dbg.js index 94ff272eb4ea..68301d1afe15 100644 --- a/devtools/server/tests/unit/head_dbg.js +++ b/devtools/server/tests/unit/head_dbg.js @@ -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"); } /** diff --git a/devtools/server/tests/unit/test_blackboxing-04.js b/devtools/server/tests/unit/test_blackboxing-04.js index bfef2747b3ee..127670e03377 100644 --- a/devtools/server/tests/unit/test_blackboxing-04.js +++ b/devtools/server/tests/unit/test_blackboxing-04.js @@ -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); diff --git a/devtools/server/tests/unit/test_breakpoint-09.js b/devtools/server/tests/unit/test_breakpoint-09.js index b4af4e4ee525..5b1e4f9b72ad 100644 --- a/devtools/server/tests/unit/test_breakpoint-09.js +++ b/devtools/server/tests/unit/test_breakpoint-09.js @@ -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. diff --git a/devtools/server/tests/unit/test_source-02.js b/devtools/server/tests/unit/test_source-02.js index 358c04cac3a3..87dc7f5890b4 100644 --- a/devtools/server/tests/unit/test_source-02.js +++ b/devtools/server/tests/unit/test_source-02.js @@ -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], diff --git a/devtools/shared/client/source-client.js b/devtools/shared/client/source-client.js index 7e962eb0f933..750615de9d72 100644 --- a/devtools/shared/client/source-client.js +++ b/devtools/shared/client/source-client.js @@ -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 => { - return this._onSourceResponse(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); diff --git a/devtools/shared/client/thread-client.js b/devtools/shared/client/thread-client.js index 7e946f357b62..f8186ccaa14a 100644 --- a/devtools/shared/client/thread-client.js +++ b/devtools/shared/client/thread-client.js @@ -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]; }, diff --git a/devtools/shared/specs/source.js b/devtools/shared/specs/source.js index 61d2ef3a9c25..dd0d788c216b 100644 --- a/devtools/shared/specs/source.js +++ b/devtools/shared/specs/source.js @@ -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"), },