summaryrefslogtreecommitdiff
path: root/dom
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-08-13 13:42:52 +0000
committerMoonchild <moonchild@palemoon.org>2020-08-13 13:42:52 +0000
commit4f0d9497f268e79ff47ed4509273204566961199 (patch)
tree0198f8bbe1ecc00c1e986bf61445043778aff0bb /dom
parent11285cd0d6ef7de80d22187b99376602ed547214 (diff)
downloaduxp-4f0d9497f268e79ff47ed4509273204566961199.tar.gz
Issue #618: Ignore 'event' and 'for' attributes for module scripts.
Because the spec says so.
Diffstat (limited to 'dom')
-rw-r--r--dom/script/ScriptLoader.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
index 9de9a1d037..903822ef57 100644
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -299,8 +299,12 @@ ScriptLoader::~ScriptLoader()
// <script for=... event=...> element.
static bool
-IsScriptEventHandler(nsIContent* aScriptElement)
+IsScriptEventHandler(ScriptKind kind, nsIContent* aScriptElement)
{
+ if (kind != ScriptKind::Classic) {
+ return false;
+ }
+
if (!aScriptElement->IsHTMLElement()) {
return false;
}
@@ -1198,35 +1202,38 @@ 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;
+ }
+
// Step 13. Check that the script is not an eventhandler
- if (IsScriptEventHandler(scriptContent)) {
+ if (IsScriptEventHandler(scriptKind, scriptContent)) {
return false;
}
JSVersion version = JSVERSION_DEFAULT;
- // Check the type attribute to determine language and version.
- // If type exists, it trumps the deprecated 'language='
- nsAutoString type;
- bool hasType = aElement->GetScriptType(type);
-
- ScriptKind scriptKind = ScriptKind::Classic;
- if (!type.IsEmpty()) {
- if (ModuleScriptsEnabled() && type.LowerCaseEqualsASCII("module")) {
- scriptKind = ScriptKind::Module;
- } else {
+ // For classic scripts, check the type attribute to determine language and
+ // version. If type exists, it trumps the deprecated 'language='
+ if (scriptKind == ScriptKind::Classic) {
+ if (!type.IsEmpty()) {
NS_ENSURE_TRUE(ParseTypeAttribute(type, &version), false);
- }
- } else if (!hasType) {
- // no 'type=' element
- // "language" is a deprecated attribute of HTML, so we check it only for
- // HTML script elements.
- if (scriptContent->IsHTMLElement()) {
- nsAutoString language;
- scriptContent->GetAttr(kNameSpaceID_None, nsGkAtoms::language, language);
- if (!language.IsEmpty()) {
- if (!nsContentUtils::IsJavaScriptLanguage(language)) {
- return false;
+ } else if (!hasType) {
+ // no 'type=' element
+ // "language" is a deprecated attribute of HTML, so we check it only for
+ // HTML script elements.
+ if (scriptContent->IsHTMLElement()) {
+ nsAutoString language;
+ scriptContent->GetAttr(kNameSpaceID_None, nsGkAtoms::language, language);
+ if (!language.IsEmpty()) {
+ if (!nsContentUtils::IsJavaScriptLanguage(language)) {
+ return false;
+ }
}
}
}