diff options
Diffstat (limited to 'dom/script')
-rw-r--r-- | dom/script/ScriptLoader.cpp | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index 9de9a1d03..903822ef5 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; + } } } } |