mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-26 00:57:30 +09:00
Issue #618: Ignore 'event' and 'for' attributes for module scripts.
Because the spec says so.
This commit is contained in:
parent
34db761758
commit
97617a3ab1
1 changed files with 30 additions and 23 deletions
|
|
@ -299,8 +299,12 @@ ScriptLoader::~ScriptLoader()
|
||||||
// <script for=... event=...> element.
|
// <script for=... event=...> element.
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
IsScriptEventHandler(nsIContent* aScriptElement)
|
IsScriptEventHandler(ScriptKind kind, nsIContent* aScriptElement)
|
||||||
{
|
{
|
||||||
|
if (kind != ScriptKind::Classic) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!aScriptElement->IsHTMLElement()) {
|
if (!aScriptElement->IsHTMLElement()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -1198,35 +1202,38 @@ ScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
|
||||||
|
|
||||||
nsCOMPtr<nsIContent> scriptContent = do_QueryInterface(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
|
// Step 13. Check that the script is not an eventhandler
|
||||||
if (IsScriptEventHandler(scriptContent)) {
|
if (IsScriptEventHandler(scriptKind, scriptContent)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSVersion version = JSVERSION_DEFAULT;
|
JSVersion version = JSVERSION_DEFAULT;
|
||||||
|
|
||||||
// Check the type attribute to determine language and version.
|
// For classic scripts, check the type attribute to determine language and
|
||||||
// If type exists, it trumps the deprecated 'language='
|
// version. If type exists, it trumps the deprecated 'language='
|
||||||
nsAutoString type;
|
if (scriptKind == ScriptKind::Classic) {
|
||||||
bool hasType = aElement->GetScriptType(type);
|
if (!type.IsEmpty()) {
|
||||||
|
|
||||||
ScriptKind scriptKind = ScriptKind::Classic;
|
|
||||||
if (!type.IsEmpty()) {
|
|
||||||
if (ModuleScriptsEnabled() && type.LowerCaseEqualsASCII("module")) {
|
|
||||||
scriptKind = ScriptKind::Module;
|
|
||||||
} else {
|
|
||||||
NS_ENSURE_TRUE(ParseTypeAttribute(type, &version), false);
|
NS_ENSURE_TRUE(ParseTypeAttribute(type, &version), false);
|
||||||
}
|
} else if (!hasType) {
|
||||||
} else if (!hasType) {
|
// no 'type=' element
|
||||||
// no 'type=' element
|
// "language" is a deprecated attribute of HTML, so we check it only for
|
||||||
// "language" is a deprecated attribute of HTML, so we check it only for
|
// HTML script elements.
|
||||||
// HTML script elements.
|
if (scriptContent->IsHTMLElement()) {
|
||||||
if (scriptContent->IsHTMLElement()) {
|
nsAutoString language;
|
||||||
nsAutoString language;
|
scriptContent->GetAttr(kNameSpaceID_None, nsGkAtoms::language, language);
|
||||||
scriptContent->GetAttr(kNameSpaceID_None, nsGkAtoms::language, language);
|
if (!language.IsEmpty()) {
|
||||||
if (!language.IsEmpty()) {
|
if (!nsContentUtils::IsJavaScriptLanguage(language)) {
|
||||||
if (!nsContentUtils::IsJavaScriptLanguage(language)) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue