Bug 1466691 - Replace callback style in favor of promise for TabClient methods. r=jryans

MozReview-Commit-ID: 6Is4O8KQhgY

--HG--
extra : rebase_source : 8987e85385bd202a8e9100a230eff1c1fcdcb4f9
This commit is contained in:
Alexandre Poirot 2018-06-05 01:50:40 -07:00
parent 6f1c06f3e9
commit f68f33087a
23 changed files with 128 additions and 249 deletions

View File

@ -523,7 +523,7 @@ Workers.prototype = {
},
_onWorkerSelect: function (workerForm) {
DebuggerController.client.attachWorker(workerForm.actor, (response, workerClient) => {
DebuggerController.client.attachWorker(workerForm.actor).then(([response, workerClient]) => {
let toolbox = gDevTools.showToolbox(TargetFactory.forWorker(workerClient),
"jsdebugger", Toolbox.HostType.WINDOW);
window.emit(EVENTS.WORKER_SELECTED, toolbox);

View File

@ -83,18 +83,12 @@ DebuggerPanel.prototype = {
});
},
openWorkerToolbox: function(worker) {
this.toolbox.target.client.attachWorker(
worker.actor,
(response, workerClient) => {
const workerTarget = TargetFactory.forWorker(workerClient);
gDevTools
.showToolbox(workerTarget, "jsdebugger", Toolbox.HostType.WINDOW)
.then(toolbox => {
toolbox.once("destroy", () => workerClient.detach());
});
}
);
openWorkerToolbox: async function(worker) {
const [response, workerClient] =
await this.toolbox.target.client.attachWorker(worker.actor);
const workerTarget = TargetFactory.forWorker(workerClient);
const toolbox = await gDevTools.showToolbox(workerTarget, "jsdebugger", Toolbox.HostType.WINDOW);
toolbox.once("destroy", () => workerClient.detach());
},
getFrames: function() {

View File

@ -29,14 +29,10 @@ function initDebuggerClient() {
return new DebuggerClient(transport);
}
function attachThread(client, actor) {
return new Promise(resolve => {
client.attachTab(actor, (response, tabClient) => {
tabClient.attachThread(null, (r, threadClient) => {
resolve(threadClient);
});
});
});
async function attachThread(client, actor) {
let [response, tabClient] = await client.attachTab(actor);
let [response2, threadClient] = await tabClient.attachThread(null);
return threadClient;
}
function onNewGlobal() {

View File

@ -46,8 +46,8 @@ function testParentProcessTargetActor() {
gClient.addListener("newGlobal", onNewGlobal);
let actor = aResponse.form.actor;
gClient.attachTab(actor, (response, tabClient) => {
tabClient.attachThread(null, (aResponse, aThreadClient) => {
gClient.attachTab(actor).then(([response, tabClient]) => {
tabClient.attachThread(null).then(([aResponse, aThreadClient]) => {
gThreadClient = aThreadClient;
gThreadClient.addListener("newSource", onNewSource);

View File

@ -183,30 +183,17 @@ function getAddonActorForId(aClient, aAddonId) {
return deferred.promise;
}
function attachTabActorForUrl(aClient, aUrl) {
let deferred = promise.defer();
getTabActorForUrl(aClient, aUrl).then(aGrip => {
aClient.attachTab(aGrip.actor, aResponse => {
deferred.resolve([aGrip, aResponse]);
});
});
return deferred.promise;
async function attachTabActorForUrl(aClient, aUrl) {
let grip = await getTabActorForUrl(aClient, aUrl);
let [ response ] = await aClient.attachTab(grip.actor);
return [grip, response];
}
function attachThreadActorForUrl(aClient, aUrl) {
let deferred = promise.defer();
attachTabActorForUrl(aClient, aUrl).then(([aGrip, aResponse]) => {
aClient.attachThread(aResponse.threadActor, (aResponse, aThreadClient) => {
aThreadClient.resume(aResponse => {
deferred.resolve(aThreadClient);
});
});
});
return deferred.promise;
async function attachThreadActorForUrl(aClient, aUrl) {
let [grip, response] = await attachTabActorForUrl(aClient, aUrl);
let [response2, threadClient] = await aClient.attachThread(response.threadActor);
await threadClient.resume();
return threadClient;
}
// Override once from shared-head, as some tests depend on trying native DOM listeners
@ -679,16 +666,14 @@ AddonDebugger.prototype = {
_attachConsole: function () {
let deferred = promise.defer();
this.client.attachConsole(this.target.form.consoleActor, ["ConsoleAPI"], (aResponse, aWebConsoleClient) => {
if (aResponse.error) {
deferred.reject(aResponse);
}
else {
this.client.attachConsole(this.target.form.consoleActor, ["ConsoleAPI"])
.then(([aResponse, aWebConsoleClient]) => {
this.webConsole = aWebConsoleClient;
this.client.addListener("consoleAPICall", this._onConsoleAPICall);
deferred.resolve();
}
});
}, e => {
deferred.reject(e);
});
return deferred.promise;
},
@ -956,7 +941,7 @@ function attachAddonActorForId(aClient, aAddonId) {
let deferred = promise.defer();
getAddonActorForId(aClient, aAddonId).then(aGrip => {
aClient.attachAddon(aGrip.actor, aResponse => {
aClient.attachAddon(aGrip.actor).then(([aResponse]) => {
deferred.resolve([aGrip, aResponse]);
});
});
@ -1108,11 +1093,7 @@ function findTab(tabs, url) {
function attachTab(client, tab) {
info("Attaching to tab with url '" + tab.url + "'.");
return new Promise(function (resolve) {
client.attachTab(tab.actor, function (response, tabClient) {
resolve([response, tabClient]);
});
});
return client.attachTab(tab.actor);
}
function listWorkers(tabClient) {
@ -1136,11 +1117,7 @@ function findWorker(workers, url) {
function attachWorker(tabClient, worker) {
info("Attaching to worker with url '" + worker.url + "'.");
return new Promise(function (resolve, reject) {
tabClient.attachWorker(worker.actor, function (response, workerClient) {
resolve([response, workerClient]);
});
});
return tabClient.attachWorker(worker.actor);
}
function waitForWorkerListChanged(tabClient) {
@ -1155,11 +1132,7 @@ function waitForWorkerListChanged(tabClient) {
function attachThread(workerClient, options) {
info("Attaching to thread.");
return new Promise(function (resolve, reject) {
workerClient.attachThread(options, function (response, threadClient) {
resolve([response, threadClient]);
});
});
return workerClient.attachThread(options);
}
function waitForWorkerClose(workerClient) {

View File

@ -58,7 +58,7 @@ function attachThread(toolbox) {
const threadOptions = { useSourceMaps, autoBlackBox, ignoreFrameEnvironment };
const handleResponse = (res, threadClient) => {
const handleResponse = ([res, threadClient]) => {
if (res.error) {
deferred.reject(new Error("Couldn't attach to thread: " + res.error));
return;
@ -98,15 +98,15 @@ function attachThread(toolbox) {
if (target.isBrowsingContext) {
// Attaching a tab, a browser process, or a WebExtensions add-on.
target.activeTab.attachThread(threadOptions, handleResponse);
target.activeTab.attachThread(threadOptions).then(handleResponse);
} else if (target.isAddon) {
// Attaching a legacy addon.
target.client.attachAddon(actor, res => {
target.client.attachThread(res.threadActor, handleResponse);
target.client.attachAddon(actor).then(([res]) => {
target.client.attachThread(res.threadActor).then(handleResponse);
});
} else {
// Attaching an old browser debugger or a content process.
target.client.attachThread(chromeDebugger, handleResponse);
target.client.attachThread(chromeDebugger).then(handleResponse);
}
return deferred.promise;

View File

@ -375,14 +375,11 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
* @param {Object} workerTargetActor
* worker actor form to debug
*/
openWorkerToolbox(client, workerTargetActor) {
client.attachWorker(workerTargetActor, (response, workerClient) => {
const workerTarget = TargetFactory.forWorker(workerClient);
gDevTools.showToolbox(workerTarget, null, Toolbox.HostType.WINDOW)
.then(toolbox => {
toolbox.once("destroy", () => workerClient.detach());
});
});
async openWorkerToolbox(client, workerTargetActor) {
const [, workerClient] = await client.attachWorker(workerTargetActor);
const workerTarget = TargetFactory.forWorker(workerClient);
const toolbox = await gDevTools.showToolbox(workerTarget, null, Toolbox.HostType.WINDOW);
toolbox.once("destroy", () => workerClient.detach());
},
/**

View File

@ -439,24 +439,19 @@ TabTarget.prototype = {
this._setupRemoteListeners();
const attachTab = () => {
this._client.attachTab(this._form.actor, (response, tabClient) => {
if (!tabClient) {
this._remote.reject("Unable to attach to the tab");
return;
}
const attachTab = async () => {
try {
const [ response, tabClient ] = await this._client.attachTab(this._form.actor);
this.activeTab = tabClient;
this.threadActor = response.threadActor;
attachConsole();
});
};
const onConsoleAttached = (response, consoleClient) => {
if (!consoleClient) {
this._remote.reject("Unable to attach to the console");
} catch (e) {
this._remote.reject("Unable to attach to the tab: " + e);
return;
}
attachConsole();
};
const onConsoleAttached = ([response, consoleClient]) => {
this.activeConsole = consoleClient;
this._onInspectObject = packet => this.emit("inspect-object", packet);
@ -466,7 +461,11 @@ TabTarget.prototype = {
};
const attachConsole = () => {
this._client.attachConsole(this._form.consoleActor, [], onConsoleAttached);
this._client.attachConsole(this._form.consoleActor, [])
.then(onConsoleAttached, response => {
this._remote.reject(
`Unable to attach to the console [${response.error}]: ${response.message}`);
});
};
if (this.isLocalTab) {

View File

@ -2056,17 +2056,16 @@ ScratchpadTab.prototype = {
this._attach(aSubject).then(aTarget => {
const consoleActor = aTarget.form.consoleActor;
const client = aTarget.client;
client.attachConsole(consoleActor, [], (aResponse, aWebConsoleClient) => {
if (aResponse.error) {
reportError("attachConsole", aResponse);
deferred.reject(aResponse);
} else {
client.attachConsole(consoleActor, [])
.then(([aResponse, aWebConsoleClient]) => {
deferred.resolve({
webConsoleClient: aWebConsoleClient,
debuggerClient: client
});
}
});
}, error => {
reportError("attachConsole", error);
deferred.reject(error);
});
});
return deferred.promise;

View File

@ -179,8 +179,14 @@ WebConsoleConnectionProxy.prototype = {
if (this.target.chrome && !this.target.isAddon) {
listeners.push("ContentProcessMessages");
}
this.client.attachConsole(this._consoleActor, listeners,
this._onAttachConsole);
this.client.attachConsole(this._consoleActor, listeners)
.then(this._onAttachConsole, response => {
if (response.error) {
console.error("attachConsole failed: " + response.error + " " +
response.message);
this._connectDefer.reject(response);
}
});
},
/**
@ -193,14 +199,7 @@ WebConsoleConnectionProxy.prototype = {
* The WebConsoleClient instance for the attached console, for the
* specific tab we work with.
*/
_onAttachConsole: function(response, webConsoleClient) {
if (response.error) {
console.error("attachConsole failed: " + response.error + " " +
response.message);
this._connectDefer.reject(response);
return;
}
_onAttachConsole: function([response, webConsoleClient]) {
this.webConsoleClient = webConsoleClient;
this._hasNativeConsoleAPI = response.nativeConsoleAPI;

View File

@ -85,7 +85,7 @@ function attachToTab() {
let tab = response.tabs[response.selected];
// Attach to the tab.
client.attachTab(tab.actor, (response, tabClient) => {
client.attachTab(tab.actor).then(([response, tabClient]) => {
if (!tabClient) {
return;
}
@ -123,7 +123,7 @@ Once the application is attached to a tab, it can attach to its thread in order
// Assuming the application is already attached to the tab, and response is the first
// argument of the attachTab callback.
client.attachThread(response.threadActor, function(response, threadClient) {
client.attachThread(response.threadActor).then(function([response, threadClient]) {
if (!threadClient) {
return;
}
@ -195,7 +195,7 @@ function debugTab() {
// Find the active tab.
let tab = response.tabs[response.selected];
// Attach to the tab.
client.attachTab(tab.actor, (response, tabClient) => {
client.attachTab(tab.actor).then(([response, tabClient]) => {
if (!tabClient) {
return;
}

View File

@ -67,7 +67,7 @@ function attachURL(url, callback) {
if (tab.url === url) {
window.removeEventListener("message", loadListener);
// eslint-disable-next-line max-nested-callbacks
client.attachTab(tab.actor, function(_response, _tabClient) {
client.attachTab(tab.actor).then(function() {
try {
callback(null, client, tab, win.document);
} catch (ex) {

View File

@ -357,7 +357,9 @@ function getTestTab(client, title, callback) {
// response packet and a TabClient instance referring to that tab.
function attachTestTab(client, title, callback) {
getTestTab(client, title, function(tab) {
client.attachTab(tab.actor, callback);
client.attachTab(tab.actor).then(([response, tabClient]) => {
callback(response, tabClient);
});
});
}
@ -367,13 +369,13 @@ function attachTestTab(client, title, callback) {
// thread.
function attachTestThread(client, title, callback) {
attachTestTab(client, title, function(tabResponse, tabClient) {
function onAttach(response, threadClient) {
function onAttach([response, threadClient]) {
callback(response, tabClient, threadClient, tabResponse);
}
tabClient.attachThread({
useSourceMaps: true,
autoBlackBox: true
}, onAttach);
}).then(onAttach);
});
}

View File

@ -22,7 +22,7 @@ function run_test() {
}
function test_attach(tabClient) {
tabClient.attachThread({}, function(response, threadClient) {
tabClient.attachThread({}).then(function([response, threadClient]) {
Assert.equal(threadClient.state, "paused");
threadClient.resume(cleanup);
});

View File

@ -25,7 +25,7 @@ function run_test() {
function test_threadAttach(threadActorID) {
info("Trying to attach to thread " + threadActorID);
gTabClient.attachThread({}, function(response, threadClient) {
gTabClient.attachThread({}).then(function([response, threadClient]) {
Assert.equal(threadClient.state, "paused");
Assert.equal(threadClient.actor, threadActorID);
threadClient.resume(function() {

View File

@ -21,7 +21,7 @@ function run_test() {
}
function test_attach(response, tabClient) {
tabClient.attachThread({}, function(response, threadClient) {
tabClient.attachThread({}).then(function([response, threadClient]) {
Assert.equal(threadClient.paused, true);
threadClient.resume(function() {
test_interrupt(threadClient);

View File

@ -26,7 +26,7 @@ function run_test() {
}
function test_attach() {
gTabClient.attachThread({}, (response, threadClient) => {
gTabClient.attachThread({}).then(([response, threadClient]) => {
Assert.equal(threadClient.state, "paused");
gThreadClient = threadClient;
threadClient.resume(test_detach);
@ -42,7 +42,7 @@ function test_detach() {
}
function test_reattach() {
gTabClient.attachThread({}, (response, threadClient) => {
gTabClient.attachThread({}).then(([response, threadClient]) => {
Assert.notEqual(gThreadClient, threadClient);
Assert.equal(threadClient.state, "paused");
Assert.equal(gTabClient.thread, threadClient);

View File

@ -22,8 +22,8 @@ function run_test() {
// Even though we have no tabs, listTabs gives us the chromeDebugger.
client.getProcess().then(response => {
const actor = response.form.actor;
client.attachTab(actor, (response, tabClient) => {
tabClient.attachThread(null, (response, threadClient) => {
client.attachTab(actor).then(([response, tabClient]) => {
tabClient.attachThread(null).then(([response, threadClient]) => {
threadClient.addOneTimeListener("paused", (event, packet) => {
equal(packet.why.type, "breakpoint",
"yay - hit the breakpoint at the first line in our script");

View File

@ -29,8 +29,6 @@ loader.lazyRequireGetter(this, "ThreadClient", "devtools/shared/client/thread-cl
loader.lazyRequireGetter(this, "WorkerClient", "devtools/shared/client/worker-client");
loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/object-client");
const noop = () => {};
// Define the minimum officially supported version of Firefox when connecting to a remote
// runtime. (Use ".0a1" to support the very first nightly version)
// This is usually the current ESR version.
@ -330,11 +328,8 @@ DebuggerClient.prototype = {
*
* @param string targetActor
* The target actor ID for the tab to attach.
* @param function onResponse
* Called with the response packet and a TabClient
* (which will be undefined on error).
*/
attachTab: function(targetActor, onResponse = noop) {
attachTab: function(targetActor) {
if (this._clients.has(targetActor)) {
const cachedTab = this._clients.get(targetActor);
const cachedResponse = {
@ -342,7 +337,6 @@ DebuggerClient.prototype = {
javascriptEnabled: cachedTab.javascriptEnabled,
traits: cachedTab.traits,
};
DevToolsUtils.executeSoon(() => onResponse(cachedResponse, cachedTab));
return promise.resolve([cachedResponse, cachedTab]);
}
@ -351,17 +345,13 @@ DebuggerClient.prototype = {
type: "attach"
};
return this.request(packet).then(response => {
let tabClient;
if (!response.error) {
tabClient = new TabClient(this, response);
this.registerClient(tabClient);
}
onResponse(response, tabClient);
const tabClient = new TabClient(this, response);
this.registerClient(tabClient);
return [response, tabClient];
});
},
attachWorker: function(workerTargetActor, onResponse = noop) {
attachWorker: function(workerTargetActor) {
let workerClient = this._clients.get(workerTargetActor);
if (workerClient !== undefined) {
const response = {
@ -369,19 +359,12 @@ DebuggerClient.prototype = {
type: "attached",
url: workerClient.url
};
DevToolsUtils.executeSoon(() => onResponse(response, workerClient));
return promise.resolve([response, workerClient]);
}
return this.request({ to: workerTargetActor, type: "attach" }).then(response => {
if (response.error) {
onResponse(response, null);
return [response, null];
}
workerClient = new WorkerClient(this, response);
this.registerClient(workerClient);
onResponse(response, workerClient);
return [response, workerClient];
});
},
@ -391,23 +374,16 @@ DebuggerClient.prototype = {
*
* @param string addonTargetActor
* The actor ID for the addon to attach.
* @param function onResponse
* Called with the response packet and a AddonClient
* (which will be undefined on error).
*/
attachAddon: function(addonTargetActor, onResponse = noop) {
attachAddon: function(addonTargetActor) {
const packet = {
to: addonTargetActor,
type: "attach"
};
return this.request(packet).then(response => {
let addonClient;
if (!response.error) {
addonClient = new AddonClient(this, addonTargetActor);
this.registerClient(addonClient);
this.activeAddon = addonClient;
}
onResponse(response, addonClient);
const addonClient = new AddonClient(this, addonTargetActor);
this.registerClient(addonClient);
this.activeAddon = addonClient;
return [response, addonClient];
});
},
@ -419,12 +395,8 @@ DebuggerClient.prototype = {
* The ID for the console actor to attach to.
* @param array listeners
* The console listeners you want to start.
* @param function onResponse
* Called with the response packet and a WebConsoleClient
* instance (which will be undefined on error).
*/
attachConsole:
function(consoleActor, listeners, onResponse = noop) {
attachConsole: function(consoleActor, listeners) {
const packet = {
to: consoleActor,
type: "startListeners",
@ -433,15 +405,12 @@ DebuggerClient.prototype = {
return this.request(packet).then(response => {
let consoleClient;
if (!response.error) {
if (this._clients.has(consoleActor)) {
consoleClient = this._clients.get(consoleActor);
} else {
consoleClient = new WebConsoleClient(this, response);
this.registerClient(consoleClient);
}
if (this._clients.has(consoleActor)) {
consoleClient = this._clients.get(consoleActor);
} else {
consoleClient = new WebConsoleClient(this, response);
this.registerClient(consoleClient);
}
onResponse(response, consoleClient);
return [response, consoleClient];
});
},
@ -451,17 +420,13 @@ DebuggerClient.prototype = {
*
* @param string threadActor
* The actor ID for the thread to attach.
* @param function onResponse
* Called with the response packet and a ThreadClient
* (which will be undefined on error).
* @param object options
* Configuration options.
* - useSourceMaps: whether to use source maps or not.
*/
attachThread: function(threadActor, onResponse = noop, options = {}) {
attachThread: function(threadActor, options = {}) {
if (this._clients.has(threadActor)) {
const client = this._clients.get(threadActor);
DevToolsUtils.executeSoon(() => onResponse({}, client));
return promise.resolve([{}, client]);
}
@ -471,12 +436,8 @@ DebuggerClient.prototype = {
options,
};
return this.request(packet).then(response => {
let threadClient;
if (!response.error) {
threadClient = new ThreadClient(this, threadActor);
this.registerClient(threadClient);
}
onResponse(response, threadClient);
const threadClient = new ThreadClient(this, threadActor);
this.registerClient(threadClient);
return [response, threadClient];
});
},
@ -505,9 +466,6 @@ DebuggerClient.prototype = {
*
* @param string actor
* The actor ID to send the request to.
* @param onResponse function
* If specified, will be called with the response packet when
* debugging server responds.
*/
release: DebuggerClient.requester({
to: arg(0),

View File

@ -6,13 +6,10 @@
const promise = require("devtools/shared/deprecated-sync-thenables");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const eventSource = require("devtools/shared/client/event-source");
const {arg, DebuggerClient} = require("devtools/shared/client/debugger-client");
loader.lazyRequireGetter(this, "ThreadClient", "devtools/shared/client/thread-client");
const noop = () => {};
/**
* Creates a tab client for the remote debugging protocol server. This client
* is a front to the tab actor created in the server side, hiding the protocol
@ -49,13 +46,9 @@ TabClient.prototype = {
* @param object options
* Configuration options.
* - useSourceMaps: whether to use source maps or not.
* @param function onResponse
* Called with the response packet and a ThreadClient
* (which will be undefined on error).
*/
attachThread: function(options = {}, onResponse = noop) {
attachThread: function(options = {}) {
if (this.thread) {
DevToolsUtils.executeSoon(() => onResponse({}, this.thread));
return promise.resolve([{}, this.thread]);
}
@ -65,20 +58,14 @@ TabClient.prototype = {
options,
};
return this.request(packet).then(response => {
if (!response.error) {
this.thread = new ThreadClient(this, this._threadActor);
this.client.registerClient(this.thread);
}
onResponse(response, this.thread);
this.thread = new ThreadClient(this, this._threadActor);
this.client.registerClient(this.thread);
return [response, this.thread];
});
},
/**
* Detach the client from the tab actor.
*
* @param function onResponse
* Called with the response packet.
*/
detach: DebuggerClient.requester({
type: "detach"
@ -140,8 +127,6 @@ TabClient.prototype = {
*
* @param object options
* A dictionary object of the new options to use in the tab actor.
* @param function onResponse
* Called with the response packet.
*/
reconfigure: DebuggerClient.requester({
type: "reconfigure",
@ -152,8 +137,8 @@ TabClient.prototype = {
type: "listWorkers"
}),
attachWorker: function(workerTargetActor, onResponse) {
return this.client.attachWorker(workerTargetActor, onResponse);
attachWorker: function(workerTargetActor) {
return this.client.attachWorker(workerTargetActor);
},
};

View File

@ -5,12 +5,9 @@
"use strict";
const {DebuggerClient} = require("devtools/shared/client/debugger-client");
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
const eventSource = require("devtools/shared/client/event-source");
loader.lazyRequireGetter(this, "ThreadClient", "devtools/shared/client/thread-client");
const noop = () => {};
function WorkerClient(client, form) {
this.client = client;
this._actor = form.from;
@ -55,14 +52,13 @@ WorkerClient.prototype = {
},
}),
attachThread: function(options = {}, onResponse = noop) {
attachThread: function(options = {}) {
if (this.thread) {
const response = [{
type: "connected",
threadActor: this.thread._actor,
consoleActor: this.consoleActor,
}, this.thread];
DevToolsUtils.executeSoon(() => onResponse(response));
return response;
}
@ -72,29 +68,17 @@ WorkerClient.prototype = {
type: "connect",
options,
}).then(connectResponse => {
if (connectResponse.error) {
onResponse(connectResponse, null);
return [connectResponse, null];
}
return this.request({
to: connectResponse.threadActor,
type: "attach",
options,
}).then(attachResponse => {
if (attachResponse.error) {
onResponse(attachResponse, null);
}
this.thread = new ThreadClient(this, connectResponse.threadActor);
this.consoleActor = connectResponse.consoleActor;
this.client.registerClient(this.thread);
onResponse(connectResponse, this.thread);
return [connectResponse, this.thread];
});
}, error => {
onResponse(error, null);
});
},

View File

@ -188,21 +188,14 @@ exports.script.useTarget = function(tgt) {
consoleActor = target._form.consoleActor;
var onAttach = function(response, wcc) {
webConsoleClient = wcc;
if (response.error != null) {
reject(response);
}
else {
resolve(response);
}
// TODO: add _onTabNavigated code?
};
var listeners = [ 'PageError', 'ConsoleAPI' ];
client.attachConsole(consoleActor, listeners, onAttach);
client.attachConsole(consoleActor, listeners)
.then(([response, wcc]) => {
webConsoleClient = wcc;
resolve(response);
}, response => {
reject(response);
});
});
});
};

View File

@ -52,16 +52,16 @@ function attachConsoleToWorker(listeners, callback) {
var _attachConsole = async function(
listeners, callback, attachToTab, attachToWorker
) {
function _onAttachConsole(state, response, webConsoleClient) {
if (response.error) {
console.error("attachConsole failed: " + response.error + " " +
response.message);
}
function _onAttachConsole(state, [response, webConsoleClient]) {
state.client = webConsoleClient;
callback(state, response);
}
function _onAttachError(state, response) {
console.error("attachConsole failed: " + response.error + " " +
response.message);
callback(state, response);
}
function waitForMessage(target) {
return new Promise(resolve => {
@ -82,8 +82,8 @@ var _attachConsole = async function(
await state.dbgClient.attachTab(response.form.actor);
const consoleActor = response.form.consoleActor;
state.actor = consoleActor;
state.dbgClient.attachConsole(consoleActor, listeners,
_onAttachConsole.bind(null, state));
state.dbgClient.attachConsole(consoleActor, listeners)
.then(_onAttachConsole.bind(null, state), _onAttachError.bind(null, state));
return;
}
response = await state.dbgClient.listTabs();
@ -120,12 +120,12 @@ var _attachConsole = async function(
}
await workerClient.attachThread({});
state.actor = workerClient.consoleActor;
state.dbgClient.attachConsole(workerClient.consoleActor, listeners,
_onAttachConsole.bind(null, state));
state.dbgClient.attachConsole(workerClient.consoleActor, listeners)
.then(_onAttachConsole.bind(null, state), _onAttachError.bind(null, state));
} else {
state.actor = tab.consoleActor;
state.dbgClient.attachConsole(tab.consoleActor, listeners,
_onAttachConsole.bind(null, state));
state.dbgClient.attachConsole(tab.consoleActor, listeners)
.then(_onAttachConsole.bind(null, state), _onAttachError.bind(null, state));
}
};