Bug 1761938 - Part 4: Give module loaders a global object field r=smaug,yulia

This gives the module loader a field for the current global, since a module map
is only associated with a single global.

This adds a method to Document to tell the script loader when its global
changes. I'm not sure of when we do this exactly.

Differential Revision: https://phabricator.services.mozilla.com/D142831
This commit is contained in:
Jon Coppeard
2022-04-11 15:35:29 +00:00
parent 9847491365
commit 95257109ee
8 changed files with 60 additions and 14 deletions

View File

@@ -52,7 +52,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ModuleLoaderBase)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION(ModuleLoaderBase, mFetchedModules,
mDynamicImportRequests, mLoader)
mDynamicImportRequests, mGlobalObject, mLoader)
NS_IMPL_CYCLE_COLLECTING_ADDREF(ModuleLoaderBase)
NS_IMPL_CYCLE_COLLECTING_RELEASE(ModuleLoaderBase)
@@ -255,6 +255,8 @@ ModuleLoaderBase* ModuleLoaderBase::GetCurrentModuleLoader(JSContext* aCx) {
return nullptr;
}
MOZ_ASSERT(loader->mGlobalObject == global);
reportError.release();
return loader;
}
@@ -461,6 +463,8 @@ nsresult ModuleLoaderBase::CreateModuleScript(ModuleLoadRequest* aRequest) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(globalObject == mGlobalObject);
AutoJSAPI jsapi;
if (!jsapi.Init(globalObject)) {
return NS_ERROR_FAILURE;
@@ -832,8 +836,12 @@ void ModuleLoaderBase::FinishDynamicImport(
aRequest->ClearDynamicImport();
}
ModuleLoaderBase::ModuleLoaderBase(ScriptLoaderInterface* aLoader)
: mLoader(aLoader) {
ModuleLoaderBase::ModuleLoaderBase(ScriptLoaderInterface* aLoader,
nsIGlobalObject* aGlobalObject)
: mGlobalObject(aGlobalObject), mLoader(aLoader) {
MOZ_ASSERT(mGlobalObject);
MOZ_ASSERT(mLoader);
EnsureModuleHooksInitialized();
}
@@ -992,6 +1000,7 @@ void ModuleLoaderBase::ProcessDynamicImport(ModuleLoadRequest* aRequest) {
nsresult ModuleLoaderBase::EvaluateModule(nsIGlobalObject* aGlobalObject,
ModuleLoadRequest* aRequest) {
MOZ_ASSERT(aRequest->mLoader == this);
MOZ_ASSERT(aGlobalObject == mGlobalObject);
AUTO_PROFILER_LABEL("ModuleLoaderBase::EvaluateModule", JS);