/* 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";
const { Pool } = require("devtools/shared/protocol");
// The actor for a given actor id stored in this pool
getActorByID(actorID) { if (this.__poolMap) { const entry = this._poolMap.get(actorID); if (entry instanceof LazyActor) { return entry.createActor();
} return entry;
} returnnull;
}
}
exports.LazyPool = LazyPool;
/** *Populate|parent._extraActors|asspecifiedby|registeredActors|,reusingwhatever *actorsarealreadythere.Addallactorsinthefinalextraactorstableto *|pool|._extraActorsistreatedasacacheforlazyactors * *Thetargetactorusesthistoinstantiateactorsthatother *partsofthebrowserhavespecifiedwithActorRegistry.addTargetScopedActor * *@paramfactories *Anobjectwhoseownpropertynamesarethenamesofpropertiestoaddto *somereplypacket(say,atargetactorgriporthe"listTabs"response *form),andwhoseownpropertyvaluesareactorconstructorfunctions,as *documentedforaddTargetScopedActor * *@paramparent *TheparentTargetActorwithwhichthenewactors *willbeassociated.ItshouldsupportwhateverAPIthe|factories| *constructorfunctionsmightbeinterestedin,asitispassedtothem. *ForthesakeofCommonCreateExtraActorsitself,itshouldhaveatleast *thefollowingproperties: * *-_extraActors *Anobjectwhoseownpropertynamesarefactorytable(andpacket) *propertynames,andwhosevaluesareno-argumentactorconstructors, *ofthesortthatonecanaddtoaPool. * *-conn *TheDevToolsServerConnectioninwhichthenewactorswillparticipate. * *-actorID *Theactor'sname,foruseasthenewactors'parentID. *@parampool *Anobjectwhichimplementstheprotocol.jsPoolinterface,andhasthe *followingproperties * *-manage *afunctionwhichaddsagivenactortoanactorpool
*/ function createExtraActors(registeredActors, pool, parent) { // Walk over global actors added by extensions. const nameMap = {}; for (const name in registeredActors) {
let actor = parent._extraActors[name]; if (!actor) { // Register another factory, but this time specific to this connection. // It creates a fake actor that looks like an regular actor in the pool, // but without actually instantiating the actor. // It will only be instantiated on the first request made to the actor.
actor = new LazyActor(registeredActors[name], parent, pool);
parent._extraActors[name] = actor;
}
// If the actor already exists in the pool, it may have been instantiated, // so make sure not to overwrite it by a non-instantiated version. if (!pool.has(actor.actorID)) {
pool.manage(actor);
}
nameMap[name] = actor.actorID;
} return nameMap;
}
// needed for taking a place in a pool this.typeName = factory.name;
}
loadModule(id) { const options = this._options; try { return require(id); // Fetch the actor constructor
} catch (e) { thrownew Error(
`Unable to load actor module '${options.id}'\n${e.message}\n${e.stack}\n`
);
}
}
getConstructor() { const options = this._options; if (options.constructorFun) { // Actor definition registered by testing helpers return options.constructorFun;
} // Lazy actor definition, where options contains all the information // required to load the actor lazily. // Exposes `name` attribute in order to allow removeXXXActor to match // the actor by its actor constructor name. this.name = options.constructorName; const module = this.loadModule(options.id); const constructor = module[options.constructorName]; if (!constructor) { thrownew Error(
`Unable to find actor constructor named '${this.name}'. (Is it exported?)`
);
} return constructor;
}
createActor() { // Fetch the actor constructor const Constructor = this.getConstructor(); // Instantiate a new actor instance const conn = this._parentActor.conn; // this should be taken care of once all actors are moved to protocol.js const instance = new Constructor(conn, this._parentActor);
instance.conn = conn;
// We want the newly-constructed actor to completely replace the factory // actor. Reusing the existing actor ID will make sure Pool.manage // replaces the old actor with the new actor.
instance.actorID = this.actorID;
this._pool.manage(instance);
return instance;
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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.