Bug 1688879 - Part 6: Acquiring import maps. r=jonco,yulia
Implement https://wicg.github.io/import-maps/#document-acquiring-import-maps Differential Revision: https://phabricator.services.mozilla.com/D142074
This commit is contained in:
@@ -113,6 +113,17 @@ nsresult ModuleLoader::StartFetch(ModuleLoadRequest* aRequest) {
|
||||
nsresult rv = GetScriptLoader()->StartLoadInternal(aRequest, securityFlags);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// https://wicg.github.io/import-maps/#document-acquiring-import-maps
|
||||
//
|
||||
// An import map is accepted if and only if it is added (i.e., its
|
||||
// corresponding script element is added) before the first module load is
|
||||
// started, even if the loading of the import map file doesn’t finish before
|
||||
// the first module load is started.
|
||||
if (!aRequest->GetScriptLoadContext()->IsPreload()) {
|
||||
LOG(("ScriptLoadRequest (%p): SetAcquiringImportMaps false", aRequest));
|
||||
SetAcquiringImportMaps(false);
|
||||
}
|
||||
|
||||
LOG(("ScriptLoadRequest (%p): Start fetching module", aRequest));
|
||||
|
||||
return NS_OK;
|
||||
|
||||
@@ -949,6 +949,15 @@ bool ScriptLoader::ProcessExternalScript(nsIScriptElement* aElement,
|
||||
|
||||
LOG(("ScriptLoadRequest (%p): Using preload request", request.get()));
|
||||
|
||||
// https://wicg.github.io/import-maps/#document-acquiring-import-maps
|
||||
// If this preload request is for a module load, set acquiring import maps
|
||||
// to false.
|
||||
if (request->IsModuleRequest()) {
|
||||
LOG(("ScriptLoadRequest (%p): Set acquiring import maps to false",
|
||||
request.get()));
|
||||
mModuleLoader->SetAcquiringImportMaps(false);
|
||||
}
|
||||
|
||||
// It's possible these attributes changed since we started the preload so
|
||||
// update them here.
|
||||
request->GetScriptLoadContext()->SetScriptMode(
|
||||
@@ -1168,6 +1177,23 @@ bool ScriptLoader::ProcessInlineScript(nsIScriptElement* aElement,
|
||||
}
|
||||
|
||||
if (request->IsImportMapRequest()) {
|
||||
// https://wicg.github.io/import-maps/#integration-prepare-a-script
|
||||
// If the script's type is "importmap":
|
||||
//
|
||||
// Step 1: If the element's node document's acquiring import maps is false,
|
||||
// then queue a task to fire an event named error at the element, and
|
||||
// return.
|
||||
if (!mModuleLoader->GetAcquiringImportMaps()) {
|
||||
NS_WARNING("ScriptLoader: acquiring import maps is false.");
|
||||
NS_DispatchToCurrentThread(
|
||||
NewRunnableMethod("nsIScriptElement::FireErrorEvent", aElement,
|
||||
&nsIScriptElement::FireErrorEvent));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 2: Set the element's node document's acquiring import maps to false.
|
||||
mModuleLoader->SetAcquiringImportMaps(false);
|
||||
|
||||
UniquePtr<ImportMap> importMap = mModuleLoader->ParseImportMap(request);
|
||||
|
||||
// https://wicg.github.io/import-maps/#register-an-import-map
|
||||
|
||||
@@ -151,6 +151,11 @@ class ModuleLoaderBase : public nsISupports {
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> mGlobalObject;
|
||||
|
||||
// https://wicg.github.io/import-maps/#document-acquiring-import-maps
|
||||
//
|
||||
// Each Document has an acquiring import maps boolean. It is initially true.
|
||||
bool mAcquiringImportMaps = true;
|
||||
|
||||
protected:
|
||||
RefPtr<ScriptLoaderInterface> mLoader;
|
||||
|
||||
@@ -242,6 +247,14 @@ class ModuleLoaderBase : public nsISupports {
|
||||
// Implements https://wicg.github.io/import-maps/#register-an-import-map
|
||||
void RegisterImportMap(mozilla::UniquePtr<ImportMap> aImportMap);
|
||||
|
||||
/**
|
||||
* Getter and Setter for mAcquiringImportMaps.
|
||||
*/
|
||||
bool GetAcquiringImportMaps() const { return mAcquiringImportMaps; }
|
||||
void SetAcquiringImportMaps(bool acquiring) {
|
||||
mAcquiringImportMaps = acquiring;
|
||||
}
|
||||
|
||||
// Internal methods.
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user