summaryrefslogtreecommitdiffstats
path: root/dom/script
diff options
context:
space:
mode:
Diffstat (limited to 'dom/script')
-rw-r--r--dom/script/ScriptElement.cpp4
-rw-r--r--dom/script/ScriptLoader.cpp33
-rw-r--r--dom/script/ScriptLoader.h2
-rw-r--r--dom/script/nsIScriptElement.h29
4 files changed, 39 insertions, 29 deletions
diff --git a/dom/script/ScriptElement.cpp b/dom/script/ScriptElement.cpp
index 9cb239c66..eb20dbf32 100644
--- a/dom/script/ScriptElement.cpp
+++ b/dom/script/ScriptElement.cpp
@@ -128,11 +128,11 @@ ScriptElement::MaybeProcessScript()
return false;
}
- FreezeUriAsyncDefer();
+ nsIDocument* ownerDoc = cont->OwnerDoc();
+ FreezeExecutionAttrs(ownerDoc);
mAlreadyStarted = true;
- nsIDocument* ownerDoc = cont->OwnerDoc();
nsCOMPtr<nsIParser> parser = ((nsIScriptElement*) this)->GetCreatorParser();
if (parser) {
nsCOMPtr<nsIContentSink> sink = parser->GetContentSink();
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;
}
diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h
index e9b663acd..ed1e6acbc 100644
--- a/dom/script/ScriptLoader.h
+++ b/dom/script/ScriptLoader.h
@@ -606,8 +606,6 @@ private:
JS::SourceBufferHolder GetScriptSource(ScriptLoadRequest* aRequest,
nsAutoString& inlineData);
- bool ModuleScriptsEnabled();
-
void SetModuleFetchStarted(ModuleLoadRequest *aRequest);
void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest *aRequest,
nsresult aResult);
diff --git a/dom/script/nsIScriptElement.h b/dom/script/nsIScriptElement.h
index 470d51c94..e3e1bc49a 100644
--- a/dom/script/nsIScriptElement.h
+++ b/dom/script/nsIScriptElement.h
@@ -13,6 +13,7 @@
#include "nsIScriptLoaderObserver.h"
#include "nsWeakPtr.h"
#include "nsIParser.h"
+#include "nsIDocument.h"
#include "nsContentCreatorFunctions.h"
#include "nsIDOMHTMLScriptElement.h"
#include "mozilla/CORSMode.h"
@@ -37,6 +38,7 @@ public:
mForceAsync(aFromParser == mozilla::dom::NOT_FROM_PARSER ||
aFromParser == mozilla::dom::FROM_PARSER_FRAGMENT),
mFrozen(false),
+ mIsModule(false),
mDefer(false),
mAsync(false),
mExternal(false),
@@ -73,11 +75,25 @@ public:
virtual void GetScriptCharset(nsAString& charset) = 0;
/**
- * Freezes the return values of GetScriptDeferred(), GetScriptAsync() and
- * GetScriptURI() so that subsequent modifications to the attributes don't
- * change execution behavior.
+ * Freezes the return values of the following methods so that subsequent
+ * modifications to the attributes don't change execution behavior:
+ * - GetScriptIsModule()
+ * - GetScriptDeferred()
+ * - GetScriptAsync()
+ * - GetScriptURI()
+ * - GetScriptExternal()
*/
- virtual void FreezeUriAsyncDefer() = 0;
+ virtual void FreezeExecutionAttrs(nsIDocument* aOwnerDoc) = 0;
+
+ /**
+ * Is the script a module script?
+ * Currently only supported by HTML scripts.
+ */
+ bool GetScriptIsModule()
+ {
+ NS_PRECONDITION(mFrozen, "Execution attributes not yet frozen: Not ready for this call!");
+ return mIsModule;
+ }
/**
* Is the script deferred. Currently only supported by HTML scripts.
@@ -293,6 +309,11 @@ protected:
bool mFrozen;
/**
+ * The effective moduleness.
+ */
+ bool mIsModule;
+
+ /**
* The effective deferredness.
*/
bool mDefer;