mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1407735 - Make the JS loader XPCOM component use a singleton. r=kmag
mozJSComponentLoader is created using XPCOM. However, you can only call it once or it'll crash. This patch fixes that by using a singleton macro. MozReview-Commit-ID: Bq2k7nv9dKA --HG-- extra : rebase_source : d2008da7628edf5db283c8a44c17e741f7ae0a96
This commit is contained in:
parent
f5fb237b0f
commit
cd3f453103
@ -207,8 +207,16 @@ mozJSComponentLoader::mozJSComponentLoader()
|
||||
mLoaderGlobal(dom::RootingCx())
|
||||
{
|
||||
MOZ_ASSERT(!sSelf, "mozJSComponentLoader should be a singleton");
|
||||
}
|
||||
|
||||
sSelf = this;
|
||||
// static
|
||||
already_AddRefed<mozJSComponentLoader>
|
||||
mozJSComponentLoader::GetOrCreate()
|
||||
{
|
||||
if (!sSelf) {
|
||||
sSelf = new mozJSComponentLoader();
|
||||
}
|
||||
return do_AddRef(sSelf);
|
||||
}
|
||||
|
||||
#define ENSURE_DEP(name) { nsresult rv = Ensure##name(); NS_ENSURE_SUCCESS(rv, rv); }
|
||||
|
@ -54,6 +54,8 @@ class mozJSComponentLoader final : public mozilla::ModuleLoader,
|
||||
void FindTargetObject(JSContext* aCx,
|
||||
JS::MutableHandleObject aTargetObject);
|
||||
|
||||
static already_AddRefed<mozJSComponentLoader> GetOrCreate();
|
||||
|
||||
static mozJSComponentLoader* Get() { return sSelf; }
|
||||
|
||||
nsresult Import(const nsACString& aResourceURI, JS::HandleValue aTargetObj,
|
||||
|
@ -24,7 +24,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIXPConnect,
|
||||
nsXPConnect::GetSingleton)
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSComponentLoader)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(mozJSComponentLoader,
|
||||
mozJSComponentLoader::GetOrCreate);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSSubScriptLoader)
|
||||
|
||||
NS_DEFINE_NAMED_CID(NS_JS_ID_CID);
|
||||
|
Loading…
Reference in New Issue
Block a user