summaryrefslogtreecommitdiffstats
path: root/dom/html
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/html
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/html')
-rw-r--r--dom/html/HTMLScriptElement.cpp23
-rw-r--r--dom/html/HTMLScriptElement.h2
2 files changed, 16 insertions, 9 deletions
diff --git a/dom/html/HTMLScriptElement.cpp b/dom/html/HTMLScriptElement.cpp
index ddeb925eb..6b0b4be59 100644
--- a/dom/html/HTMLScriptElement.cpp
+++ b/dom/html/HTMLScriptElement.cpp
@@ -279,12 +279,20 @@ HTMLScriptElement::GetScriptCharset(nsAString& charset)
}
void
-HTMLScriptElement::FreezeUriAsyncDefer()
+HTMLScriptElement::FreezeExecutionAttrs(nsIDocument* aOwnerDoc)
{
if (mFrozen) {
return;
}
+ MOZ_ASSERT(!mIsModule && !mAsync && !mDefer && !mExternal);
+
+ // Determine whether this is a classic script or a module script.
+ nsAutoString type;
+ GetScriptType(type);
+ mIsModule = aOwnerDoc->ModuleScriptsEnabled() &&
+ !type.IsEmpty() && type.LowerCaseEqualsASCII("module");
+
// variation of this code in nsSVGScriptElement - check if changes
// need to be transfered when modifying. Note that we don't use GetSrc here
// because it will return the base URL when the attr value is "".
@@ -299,14 +307,13 @@ HTMLScriptElement::FreezeUriAsyncDefer()
// At this point mUri will be null for invalid URLs.
mExternal = true;
-
- bool defer, async;
- GetAsync(&async);
- GetDefer(&defer);
-
- mDefer = !async && defer;
- mAsync = async;
}
+
+ bool defer, async;
+ GetAsync(&async);
+ mAsync = (mExternal || mIsModule) && async;
+ GetDefer(&defer);
+ mDefer = mExternal && !async && defer;
mFrozen = true;
}
diff --git a/dom/html/HTMLScriptElement.h b/dom/html/HTMLScriptElement.h
index 073cf7faf..ffe9d3fbd 100644
--- a/dom/html/HTMLScriptElement.h
+++ b/dom/html/HTMLScriptElement.h
@@ -41,7 +41,7 @@ public:
virtual bool GetScriptType(nsAString& type) override;
virtual void GetScriptText(nsAString& text) override;
virtual void GetScriptCharset(nsAString& charset) override;
- virtual void FreezeUriAsyncDefer() override;
+ virtual void FreezeExecutionAttrs(nsIDocument* aOwnerDoc) override;
virtual CORSMode GetCORSMode() const override;
// nsIContent