/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EventEmitter = require("resource://devtools/shared/event-emitter.js");
if (conn) { this.conn = conn;
} this.label = label;
// Will be individually flipped to true by Actor/Front classes. // Will also only be exposed via Actor/Front::isDestroyed(). this._isDestroyed = false;
}
/** *Poolisthebaseclassforallactors,evenleafnodes. *Ifthechildmapisactuallyreferenced,goaheadandcreate *thestuffneededbythepool.
*/
get _poolMap() { if (this.__poolMap) { returnthis.__poolMap;
} this.__poolMap = new Map(); this.conn.addActorPool(this); returnthis.__poolMap;
}
/** *Addanactorasachildofthispool.
*/
manage(actor) { if (!actor.actorID) {
actor.actorID = this.conn.allocID(actor.typeName);
} else { // If the actor is already registered in a pool, remove it without destroying it. // This happens for example when an addon is reloaded. To see this behavior, take a // look at devtools/server/tests/xpcshell/test_addon_reload.js
const parent = actor.getParent(); if (parent && parent !== this) {
parent.unmanage(actor);
}
} // Duplicate the ID into another field as `actorID` will be cleared on destruction
actor.persistedActorID = actor.actorID;
// Generator that yields each non-self child of the pool.
*poolChildren() { if (!this.__poolMap) { return;
} for (const actor of this.__poolMap.values()) { // Self-owned actors are ok, but don't need visiting twice. if (actor === this) { continue;
}
yield actor;
}
}
isDestroyed() { // Note: _isDestroyed is only flipped from Actor and Front subclasses for // now, so this method should not be called on pure Pool instances. // See Bug 1717811. returnthis._isDestroyed;
}
/** *Destroythisitem,removingitfromaparentifithasone, *anddestroyingallchildrenifnecessary.
*/
destroy() { const parent = this.getParent(); if (parent) {
parent.unmanage(this);
} if (!this.__poolMap) { return;
} // Immediately clear the poolmap so that we bail out early if the code is reentrant. const poolMap = this.__poolMap; this.__poolMap = null;
for (const actor of poolMap.values()) { // Self-owned actors are ok, but don't need destroying twice. if (actor === this) { continue;
}
// Some pool-managed values don't extend Pool and won't have skipDestroy // defined. For instance, the root actor and the lazy actors. if (typeof actor.skipDestroy === "function" && actor.skipDestroy()) { continue;
}
const destroy = actor.destroy; if (destroy) { // Disconnect destroy while we're destroying in case of (misbehaving) // circular ownership.
actor.destroy = null;
destroy.call(actor);
actor.destroy = destroy;
}
}
// `conn` might be null for LazyPool in an unexplained way. if (this.conn) { this.conn.removeActorPool(this); this.conn = null;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.