зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1494632 - Convert WorkerClient to protocol.js front. r=jdescottes
MozReview-Commit-ID: BbtEReeG4v9 Depends on D7462 Differential Revision: https://phabricator.services.mozilla.com/D7463 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
86eec944ad
Коммит
6cd123eae4
|
@ -1119,14 +1119,10 @@ function attachThread(workerClient, options) {
|
|||
return workerClient.attachThread(options);
|
||||
}
|
||||
|
||||
function waitForWorkerClose(workerClient) {
|
||||
async function waitForWorkerClose(workerClient) {
|
||||
info("Waiting for worker to close.");
|
||||
return new Promise(function (resolve) {
|
||||
workerClient.addOneTimeListener("close", function () {
|
||||
info("Worker did close.");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
await workerClient.once("close");
|
||||
info("Worker did close.");
|
||||
}
|
||||
|
||||
function resume(threadClient) {
|
||||
|
|
|
@ -123,14 +123,10 @@ function attachThread(workerClient, options) {
|
|||
return workerClient.attachThread(options);
|
||||
}
|
||||
|
||||
function waitForWorkerClose(workerClient) {
|
||||
async function waitForWorkerClose(workerClient) {
|
||||
info("Waiting for worker to close.");
|
||||
return new Promise(function(resolve) {
|
||||
workerClient.addOneTimeListener("close", function() {
|
||||
info("Worker did close.");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
await workerClient.once("close");
|
||||
info("Worker did close.");
|
||||
}
|
||||
|
||||
// Return a promise with a reference to jsterm, opening the split
|
||||
|
|
|
@ -25,8 +25,8 @@ loader.lazyRequireGetter(this, "WebConsoleClient", "devtools/shared/webconsole/c
|
|||
loader.lazyRequireGetter(this, "AddonClient", "devtools/shared/client/addon-client");
|
||||
loader.lazyRequireGetter(this, "RootClient", "devtools/shared/client/root-client");
|
||||
loader.lazyRequireGetter(this, "BrowsingContextFront", "devtools/shared/fronts/targets/browsing-context", true);
|
||||
loader.lazyRequireGetter(this, "WorkerTargetFront", "devtools/shared/fronts/targets/worker", true);
|
||||
loader.lazyRequireGetter(this, "ThreadClient", "devtools/shared/client/thread-client");
|
||||
loader.lazyRequireGetter(this, "WorkerClient", "devtools/shared/client/worker-client");
|
||||
loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/object-client");
|
||||
loader.lazyRequireGetter(this, "Pool", "devtools/shared/protocol", true);
|
||||
loader.lazyRequireGetter(this, "Front", "devtools/shared/protocol", true);
|
||||
|
@ -380,22 +380,15 @@ DebuggerClient.prototype = {
|
|||
return [response, front];
|
||||
},
|
||||
|
||||
attachWorker: function(workerTargetActor) {
|
||||
let workerClient = this._clients.get(workerTargetActor);
|
||||
if (workerClient !== undefined) {
|
||||
const response = {
|
||||
from: workerClient.actor,
|
||||
type: "attached",
|
||||
url: workerClient.url
|
||||
};
|
||||
return promise.resolve([response, workerClient]);
|
||||
attachWorker: async function(workerTargetActor) {
|
||||
let front = this._frontPool.actor(workerTargetActor);
|
||||
if (!front) {
|
||||
front = new WorkerTargetFront(this, { actor: workerTargetActor });
|
||||
this._frontPool.manage(front);
|
||||
}
|
||||
|
||||
return this.request({ to: workerTargetActor, type: "attach" }).then(response => {
|
||||
workerClient = new WorkerClient(this, response);
|
||||
this.registerClient(workerClient);
|
||||
return [response, workerClient];
|
||||
});
|
||||
const response = await front.attach();
|
||||
return [response, front];
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,5 +20,4 @@ DevToolsModules(
|
|||
'source-client.js',
|
||||
'symbol-iterator-client.js',
|
||||
'thread-client.js',
|
||||
'worker-client.js',
|
||||
)
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {DebuggerClient} = require("devtools/shared/client/debugger-client");
|
||||
const eventSource = require("devtools/shared/client/event-source");
|
||||
loader.lazyRequireGetter(this, "ThreadClient", "devtools/shared/client/thread-client");
|
||||
|
||||
function WorkerClient(client, form) {
|
||||
this.client = client;
|
||||
this._actor = form.from;
|
||||
this._isClosed = false;
|
||||
this._url = form.url;
|
||||
|
||||
this._onClose = this._onClose.bind(this);
|
||||
|
||||
this.addListener("close", this._onClose);
|
||||
|
||||
this.traits = {};
|
||||
}
|
||||
|
||||
WorkerClient.prototype = {
|
||||
get _transport() {
|
||||
return this.client._transport;
|
||||
},
|
||||
|
||||
get request() {
|
||||
return this.client.request;
|
||||
},
|
||||
|
||||
get actor() {
|
||||
return this._actor;
|
||||
},
|
||||
|
||||
get url() {
|
||||
return this._url;
|
||||
},
|
||||
|
||||
get isClosed() {
|
||||
return this._isClosed;
|
||||
},
|
||||
|
||||
detach: DebuggerClient.requester({ type: "detach" }, {
|
||||
after: function(response) {
|
||||
if (this.thread) {
|
||||
this.client.unregisterClient(this.thread);
|
||||
}
|
||||
this.client.unregisterClient(this);
|
||||
return response;
|
||||
},
|
||||
}),
|
||||
|
||||
attachThread: function(options = {}) {
|
||||
if (this.thread) {
|
||||
const response = [{
|
||||
type: "connected",
|
||||
threadActor: this.thread._actor,
|
||||
consoleActor: this.consoleActor,
|
||||
}, this.thread];
|
||||
return response;
|
||||
}
|
||||
|
||||
// The connect call on server doesn't attach the thread as of version 44.
|
||||
return this.request({
|
||||
to: this._actor,
|
||||
type: "connect",
|
||||
options,
|
||||
}).then(connectResponse => {
|
||||
return this.request({
|
||||
to: connectResponse.threadActor,
|
||||
type: "attach",
|
||||
options,
|
||||
}).then(attachResponse => {
|
||||
this.thread = new ThreadClient(this, connectResponse.threadActor);
|
||||
this.consoleActor = connectResponse.consoleActor;
|
||||
this.client.registerClient(this.thread);
|
||||
|
||||
return [connectResponse, this.thread];
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
_onClose: function() {
|
||||
this.removeListener("close", this._onClose);
|
||||
|
||||
if (this.thread) {
|
||||
this.client.unregisterClient(this.thread);
|
||||
}
|
||||
this.client.unregisterClient(this);
|
||||
this._isClosed = true;
|
||||
},
|
||||
|
||||
reconfigure: function() {
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
events: ["close"]
|
||||
};
|
||||
|
||||
eventSource(WorkerClient.prototype);
|
||||
|
||||
module.exports = WorkerClient;
|
|
@ -6,4 +6,5 @@
|
|||
|
||||
DevToolsModules(
|
||||
'browsing-context.js',
|
||||
'worker.js',
|
||||
)
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
/* 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/. */
|
||||
"use strict";
|
||||
|
||||
const {workerTargetSpec} = require("devtools/shared/specs/targets/worker");
|
||||
const protocol = require("devtools/shared/protocol");
|
||||
const {custom} = protocol;
|
||||
|
||||
loader.lazyRequireGetter(this, "ThreadClient", "devtools/shared/client/thread-client");
|
||||
|
||||
const WorkerTargetFront = protocol.FrontClassWithSpec(workerTargetSpec, {
|
||||
initialize: function(client, form) {
|
||||
protocol.Front.prototype.initialize.call(this, client, form);
|
||||
|
||||
this.thread = null;
|
||||
this.traits = {};
|
||||
|
||||
// TODO: remove once ThreadClient becomes a front
|
||||
this.client = client;
|
||||
|
||||
this._isClosed = false;
|
||||
|
||||
this.destroy = this.destroy.bind(this);
|
||||
this.on("close", this.destroy);
|
||||
},
|
||||
|
||||
get isClosed() {
|
||||
return this._isClosed;
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
this.off("close", this.destroy);
|
||||
this._isClosed = true;
|
||||
|
||||
if (this.thread) {
|
||||
this.client.unregisterClient(this.thread);
|
||||
}
|
||||
|
||||
this.unmanage(this);
|
||||
|
||||
protocol.Front.prototype.destroy.call(this);
|
||||
},
|
||||
|
||||
attach: custom(async function() {
|
||||
const response = await this._attach();
|
||||
|
||||
this.url = response.url;
|
||||
|
||||
return response;
|
||||
}, {
|
||||
impl: "_attach"
|
||||
}),
|
||||
|
||||
detach: custom(async function() {
|
||||
let response;
|
||||
try {
|
||||
response = await this._detach();
|
||||
} catch (e) {
|
||||
console.warn(`Error while detaching the worker target front: ${e.message}`);
|
||||
}
|
||||
this.destroy();
|
||||
return response;
|
||||
}, {
|
||||
impl: "_detach"
|
||||
}),
|
||||
|
||||
reconfigure: function() {
|
||||
// Toolbox and options panel are calling this method but Worker Target can't be
|
||||
// reconfigured. So we ignore this call here.
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
attachThread: async function(options = {}) {
|
||||
if (this.thread) {
|
||||
const response = [{
|
||||
type: "connected",
|
||||
threadActor: this.thread._actor,
|
||||
consoleActor: this.consoleActor,
|
||||
}, this.thread];
|
||||
return response;
|
||||
}
|
||||
|
||||
// The connect call on server doesn't attach the thread as of version 44.
|
||||
const connectResponse = await this.connect(options);
|
||||
await this.client.request({
|
||||
to: connectResponse.threadActor,
|
||||
type: "attach",
|
||||
options,
|
||||
});
|
||||
this.thread = new ThreadClient(this, connectResponse.threadActor);
|
||||
this.consoleActor = connectResponse.consoleActor;
|
||||
this.client.registerClient(this.thread);
|
||||
|
||||
return [connectResponse, this.thread];
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
exports.WorkerTargetFront = WorkerTargetFront;
|
|
@ -28,6 +28,19 @@ const workerTargetSpec = generateActorSpec({
|
|||
response: RetVal("json")
|
||||
},
|
||||
},
|
||||
|
||||
events: {
|
||||
// WorkerTargetActor still uses old sendActorEvent function,
|
||||
// but it should use emit instead.
|
||||
close: {
|
||||
type: "close",
|
||||
},
|
||||
// newSource is being sent by ThreadActor in the name of its parent,
|
||||
// i.e. WorkerTargetActor
|
||||
newSource: {
|
||||
type: "newSource",
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
exports.workerTargetSpec = workerTargetSpec;
|
||||
|
|
Загрузка…
Ссылка в новой задаче