зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1171013 - Extend defineLazyModuleGetter to support user-defined proxy objects. r=mfinkle
This commit is contained in:
Родитель
131cc19b7d
Коммит
fce9fdde80
|
@ -203,6 +203,7 @@ this.DOMApplicationRegistry = {
|
|||
dirKey: DIRECTORY_NAME,
|
||||
|
||||
init: function() {
|
||||
// Keep the messages in sync with the lazy-loading in browser.js (bug 1171013).
|
||||
this.messages = ["Webapps:Install",
|
||||
"Webapps:Uninstall",
|
||||
"Webapps:GetSelf",
|
||||
|
|
|
@ -231,7 +231,9 @@ this.XPCOMUtils = {
|
|||
|
||||
/**
|
||||
* Defines a getter on a specified object for a module. The module will not
|
||||
* be imported until first use.
|
||||
* be imported until first use. The getter allows to execute setup and
|
||||
* teardown code (e.g. to register/unregister to services) and accepts
|
||||
* a proxy object which acts on behalf of the module until it is imported.
|
||||
*
|
||||
* @param aObject
|
||||
* The object to define the lazy getter on.
|
||||
|
@ -242,15 +244,35 @@ this.XPCOMUtils = {
|
|||
* @param aSymbol
|
||||
* The name of the symbol exported by the module.
|
||||
* This parameter is optional and defaults to aName.
|
||||
* @param aPreLambda
|
||||
* A function that is executed when the proxy is set up.
|
||||
* This will only ever be called once.
|
||||
* @param aPostLambda
|
||||
* A function that is executed when the module has been imported to
|
||||
* run optional teardown procedures on the proxy object.
|
||||
* This will only ever be called once.
|
||||
* @param aProxy
|
||||
* An object which acts on behalf of the module to be imported until
|
||||
* the module has been imported.
|
||||
*/
|
||||
defineLazyModuleGetter: function XPCU_defineLazyModuleGetter(aObject, aName,
|
||||
aResource,
|
||||
aSymbol)
|
||||
defineLazyModuleGetter: function XPCU_defineLazyModuleGetter(
|
||||
aObject, aName, aResource, aSymbol,
|
||||
aPreLambda, aPostLambda, aProxy)
|
||||
{
|
||||
let proxy = aProxy || {};
|
||||
|
||||
if (typeof(aPreLambda) === "function") {
|
||||
aPreLambda.apply(proxy);
|
||||
}
|
||||
|
||||
this.defineLazyGetter(aObject, aName, function XPCU_moduleLambda() {
|
||||
var temp = {};
|
||||
try {
|
||||
Cu.import(aResource, temp);
|
||||
|
||||
if (typeof(aPostLambda) === "function") {
|
||||
aPostLambda.apply(proxy);
|
||||
}
|
||||
} catch (ex) {
|
||||
Cu.reportError("Failed to load module " + aResource + ".");
|
||||
throw ex;
|
||||
|
|
Загрузка…
Ссылка в новой задаче