summaryrefslogtreecommitdiffstats
path: root/dom/script/ScriptLoader.cpp
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-08-25 07:06:43 +0000
committerMoonchild <moonchild@palemoon.org>2020-08-30 09:51:18 +0000
commit77e8ba7eaf3ca00f25d0507cf17de2f50741f335 (patch)
treeb9025ffd0f46746481cd809598cd62142764f225 /dom/script/ScriptLoader.cpp
parente854d58633a2c877778410393914146f7a137495 (diff)
downloadUXP-77e8ba7eaf3ca00f25d0507cf17de2f50741f335.tar
UXP-77e8ba7eaf3ca00f25d0507cf17de2f50741f335.tar.gz
UXP-77e8ba7eaf3ca00f25d0507cf17de2f50741f335.tar.lz
UXP-77e8ba7eaf3ca00f25d0507cf17de2f50741f335.tar.xz
UXP-77e8ba7eaf3ca00f25d0507cf17de2f50741f335.zip
Issue #618 - Implement async attribute for inline module scripts. (uplift)
This commit does several things: - Moves the pref check from ScriptLoader to ns[I]Document so it can be called on the document. - Changes the atrribute freezing function to a better name that takes the document as a parameter. - Sets the proper async/defer attributes on HTML script elements based on keywords and whether they are module scripts or not.
Diffstat (limited to 'dom/script/ScriptLoader.cpp')
-rw-r--r--dom/script/ScriptLoader.cpp33
1 files changed, 12 insertions, 21 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
index 59c4ecae4..989301b91 100644
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -391,19 +391,6 @@ ScriptLoader::CheckContentPolicy(nsIDocument* aDocument,
}
bool
-ScriptLoader::ModuleScriptsEnabled()
-{
- static bool sEnabledForContent = false;
- static bool sCachedPref = false;
- if (!sCachedPref) {
- sCachedPref = true;
- Preferences::AddBoolVarCache(&sEnabledForContent, "dom.moduleScripts.enabled", false);
- }
-
- return nsContentUtils::IsChromeDoc(mDocument) || sEnabledForContent;
-}
-
-bool
ScriptLoader::ModuleMapContainsURL(nsIURI* aURL) const
{
// Returns whether we have fetched, or are currently fetching, a module script
@@ -1227,14 +1214,12 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
nsCOMPtr<nsIContent> scriptContent = do_QueryInterface(aElement);
- // Determine whether this is a classic script or a module script.
nsAutoString type;
bool hasType = aElement->GetScriptType(type);
- ScriptKind scriptKind = ScriptKind::Classic;
- if (ModuleScriptsEnabled() &&
- !type.IsEmpty() && type.LowerCaseEqualsASCII("module")) {
- scriptKind = ScriptKind::Module;
- }
+
+ ScriptKind scriptKind = aElement->GetScriptIsModule() ?
+ ScriptKind::Module :
+ ScriptKind::Classic;
// Step 13. Check that the script is not an eventhandler
if (IsScriptEventHandler(scriptKind, scriptContent)) {
@@ -1268,7 +1253,7 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
// the nomodule attribute will be ignored".
// "The nomodule attribute must not be specified on module scripts (and will
// be ignored if it is)."
- if (ModuleScriptsEnabled() &&
+ if (mDocument->ModuleScriptsEnabled() &&
scriptKind == ScriptKind::Classic &&
scriptContent->IsHTMLElement() &&
scriptContent->HasAttr(kNameSpaceID_None, nsGkAtoms::nomodule)) {
@@ -1480,6 +1465,12 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
request->mIsInline = true;
request->mLineNo = aElement->GetScriptLineNumber();
+ // Only the 'async' attribute is heeded on an inline module script and
+ // inline classic scripts ignore both these attributes.
+ MOZ_ASSERT(!aElement->GetScriptDeferred());
+ MOZ_ASSERT_IF(!request->IsModuleRequest(), !aElement->GetScriptAsync());
+ request->SetScriptMode(false, aElement->GetScriptAsync());
+
if (request->IsModuleRequest()) {
ModuleLoadRequest* modReq = request->AsModuleRequest();
modReq->mBaseURL = mDocument->GetDocBaseURI();
@@ -2601,7 +2592,7 @@ ScriptLoader::PreloadURI(nsIURI *aURI, const nsAString &aCharset,
}
// TODO: Preload module scripts.
- if (ModuleScriptsEnabled() && aType.LowerCaseEqualsASCII("module")) {
+ if (mDocument->ModuleScriptsEnabled() && aType.LowerCaseEqualsASCII("module")) {
return;
}