1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 23:13:55 +00:00

Issue #618 - (async) Implement async attribute for inline module scripts.

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.
This commit is contained in:
Moonchild
2020-08-25 07:06:43 +00:00
committed by Roy Tam
parent 294721687c
commit 3781c4a6dd
11 changed files with 73 additions and 41 deletions
+15 -8
View File
@@ -280,12 +280,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 "".
@@ -300,14 +308,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;
}