Bug 1218817 - Fix a bug in WorkerActorList;r=janx

This commit is contained in:
Eddy Bruel 2015-11-26 17:36:28 +01:00
Родитель 3ddc4dcff5
Коммит fc3588dc64
2 изменённых файлов: 27 добавлений и 15 удалений

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

@ -1089,6 +1089,10 @@ TabActor.prototype = {
},
onListWorkers: function BTA_onListWorkers(aRequest) {
if (!this.attached) {
return { error: "wrongState" };
}
if (this._workerActorList === null) {
this._workerActorList = new WorkerActorList({
type: Ci.nsIWorkerDebugger.TYPE_DEDICATED,

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

@ -146,6 +146,7 @@ function WorkerActorList(options) {
WorkerActorList.prototype = {
getList: function () {
// Create a set of debuggers.
let dbgs = new Set();
let e = wdm.getWorkerDebuggerEnumerator();
while (e.hasMoreElements()) {
@ -155,12 +156,14 @@ WorkerActorList.prototype = {
}
}
// Delete each actor for which we don't have a debugger.
for (let [dbg, ] of this._actors) {
if (!dbgs.has(dbg)) {
this._actors.delete(dbg);
}
}
// Create an actor for each debugger for which we don't have one.
for (let dbg of dbgs) {
if (!this._actors.has(dbg)) {
this._actors.set(dbg, new WorkerActor(dbg));
@ -172,8 +175,12 @@ WorkerActorList.prototype = {
actors.push(actor);
}
this._mustNotify = true;
this._checkListening();
if (!this._mustNotify) {
if (this._onListChanged !== null) {
wdm.addListener(this);
}
this._mustNotify = true;
}
return Promise.resolve(actors);
},
@ -187,23 +194,24 @@ WorkerActorList.prototype = {
throw new Error("onListChanged must be either a function or null.");
}
this._onListChanged = onListChanged;
this._checkListening();
},
_checkListening: function () {
if (this._onListChanged !== null && this._mustNotify) {
wdm.addListener(this);
} else {
wdm.removeListener(this);
if (this._mustNotify) {
if (this._onListChanged === null && onListChanged !== null) {
wdm.addListener(this);
}
if (this._onListChanged !== null && onListChanged === null) {
wdm.removeListener(this);
}
}
this._onListChanged = onListChanged;
},
_notifyListChanged: function () {
if (this._mustNotify) {
this._onListChanged();
this._mustNotify = false;
}
this._onListChanged();
if (this._onListChanged !== null) {
wdm.removeListener(this);
}
this._mustNotify = false;
},
onRegister: function (dbg) {