зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1655442 - Make usage of nsIWorkerDebugger.addListener more explicit. r=loganfsmyth
Declare separate listener objects instead of relying on the presence of the listener method in a broader class. Differential Revision: https://phabricator.services.mozilla.com/D84964
This commit is contained in:
Родитель
6d68ed9957
Коммит
be3c8ebd18
|
@ -40,6 +40,11 @@ const WorkerTargetActor = protocol.ActorClassWithSpec(workerTargetSpec, {
|
|||
this._attached = false;
|
||||
this._threadActor = null;
|
||||
this._transport = null;
|
||||
|
||||
this._dbgListener = {
|
||||
onClose: this._onWorkerClose.bind(this),
|
||||
onError: this._onWorkerError.bind(this),
|
||||
};
|
||||
},
|
||||
|
||||
form() {
|
||||
|
@ -83,7 +88,7 @@ const WorkerTargetActor = protocol.ActorClassWithSpec(workerTargetSpec, {
|
|||
if (isServiceWorker) {
|
||||
this._preventServiceWorkerShutdown();
|
||||
}
|
||||
this._dbg.addListener(this);
|
||||
this._dbg.addListener(this._dbgListener);
|
||||
this._attached = true;
|
||||
}
|
||||
|
||||
|
@ -152,7 +157,7 @@ const WorkerTargetActor = protocol.ActorClassWithSpec(workerTargetSpec, {
|
|||
return { type: "pushed" };
|
||||
},
|
||||
|
||||
onClose() {
|
||||
_onWorkerClose() {
|
||||
if (this._attached) {
|
||||
this._detach();
|
||||
}
|
||||
|
@ -160,7 +165,7 @@ const WorkerTargetActor = protocol.ActorClassWithSpec(workerTargetSpec, {
|
|||
this.conn.sendActorEvent(this.actorID, "close");
|
||||
},
|
||||
|
||||
onError(filename, lineno, message) {
|
||||
_onWorkerError(filename, lineno, message) {
|
||||
reportError("ERROR:" + filename + ":" + lineno + ":" + message + "\n");
|
||||
},
|
||||
|
||||
|
@ -194,7 +199,7 @@ const WorkerTargetActor = protocol.ActorClassWithSpec(workerTargetSpec, {
|
|||
this._allowServiceWorkerShutdown();
|
||||
}
|
||||
|
||||
this._dbg.removeListener(this);
|
||||
this._dbg.removeListener(this._dbgListener);
|
||||
this._attached = false;
|
||||
},
|
||||
|
||||
|
|
|
@ -13,27 +13,28 @@
|
|||
* A transport that uses a WorkerDebugger to send packets from the main
|
||||
* thread to a worker thread.
|
||||
*/
|
||||
function MainThreadWorkerDebuggerTransport(dbg, id) {
|
||||
this._dbg = dbg;
|
||||
this._id = id;
|
||||
this.onMessage = this._onMessage.bind(this);
|
||||
}
|
||||
class MainThreadWorkerDebuggerTransport {
|
||||
constructor(dbg, id) {
|
||||
this._dbg = dbg;
|
||||
this._id = id;
|
||||
|
||||
MainThreadWorkerDebuggerTransport.prototype = {
|
||||
constructor: MainThreadWorkerDebuggerTransport,
|
||||
this._dbgListener = {
|
||||
onMessage: this._onMessage.bind(this),
|
||||
};
|
||||
}
|
||||
|
||||
ready: function() {
|
||||
this._dbg.addListener(this);
|
||||
},
|
||||
ready() {
|
||||
this._dbg.addListener(this._dbgListener);
|
||||
}
|
||||
|
||||
close: function() {
|
||||
this._dbg.removeListener(this);
|
||||
close() {
|
||||
this._dbg.removeListener(this._dbgListener);
|
||||
if (this.hooks) {
|
||||
this.hooks.onClosed();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
send: function(packet) {
|
||||
send(packet) {
|
||||
this._dbg.postMessage(
|
||||
JSON.stringify({
|
||||
type: "message",
|
||||
|
@ -41,23 +42,21 @@ MainThreadWorkerDebuggerTransport.prototype = {
|
|||
message: packet,
|
||||
})
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
startBulkSend: function() {
|
||||
startBulkSend() {
|
||||
throw new Error("Can't send bulk data from worker threads!");
|
||||
},
|
||||
}
|
||||
|
||||
_onMessage: function(message) {
|
||||
_onMessage(message) {
|
||||
const packet = JSON.parse(message);
|
||||
if (packet.type !== "message" || packet.id !== this._id) {
|
||||
if (packet.type !== "message" || packet.id !== this._id || !this.hooks) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.hooks) {
|
||||
this.hooks.onPacket(packet.message);
|
||||
}
|
||||
},
|
||||
};
|
||||
this.hooks.onPacket(packet.message);
|
||||
}
|
||||
}
|
||||
|
||||
exports.MainThreadWorkerDebuggerTransport = MainThreadWorkerDebuggerTransport;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче