/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
void ScriptElement::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
nsAtom* aAttribute, int32_t aModType, const nsAttrValue* aOldValue) { // https://html.spec.whatwg.org/#script-processing-model // When a script element el that is not parser-inserted experiences one of the // events listed in the following list, the user agent must immediately // prepare the script element el: // - The script element is connected and has a src attribute set where // previously the element had no such attribute. if (aElement->IsSVGElement() && ((aNameSpaceID != kNameSpaceID_XLink &&
aNameSpaceID != kNameSpaceID_None) ||
aAttribute != nsGkAtoms::href)) { return;
} if (aElement->IsHTMLElement() &&
(aNameSpaceID != kNameSpaceID_None || aAttribute != nsGkAtoms::src)) { return;
} if (mParserCreated == NOT_FROM_PARSER &&
aModType == MutationEvent_Binding::ADDITION) { auto* cont = GetAsContent(); if (cont->IsInComposedDoc()) {
MaybeProcessScript();
}
}
}
NS_ASSERTION(cont->DebugGetSlots()->mMutationObservers.contains(this), "You forgot to add self as observer");
// https://html.spec.whatwg.org/#parsing-main-incdata // An end tag whose tag name is "script" // - If the active speculative HTML parser is null and the JavaScript // execution context stack is empty, then perform a microtask checkpoint.
nsContentUtils::AddScriptRunner(NS_NewRunnableFunction( "ScriptElement::MaybeProcessScript", []() { nsAutoMicroTask mt; }));
if (!HasScriptContent()) { // In the case of an empty, non-external classic script, there is nothing // to process. However, we must perform a microtask checkpoint afterwards, // as per https://html.spec.whatwg.org/#clean-up-after-running-script if (mKind == JS::loader::ScriptKind::eClassic && !mExternal) {
nsContentUtils::AddScriptRunner(NS_NewRunnableFunction( "ScriptElement::MaybeProcessScript", []() { nsAutoMicroTask mt; }));
} returnfalse;
}
// Check the type attribute to determine language and version. If type exists, // it trumps the deprecated 'language='.
nsAutoString type; bool hasType = GetScriptType(type); if (!type.IsEmpty()) { if (!nsContentUtils::IsJavascriptMIMEType(type) &&
!type.LowerCaseEqualsASCII("module") &&
!type.LowerCaseEqualsASCII("importmap")) { #ifdef DEBUG // There is a WebGL convention to store strings they need inside script // tags with these specific unknown script types, so don't warn for them. // "text/something-not-javascript" only seems to be used in the WebGL // conformance tests, but it is also clearly deliberately invalid, so // skip warning for it, too, to reduce warning spam. if (!type.LowerCaseEqualsASCII("x-shader/x-vertex") &&
!type.LowerCaseEqualsASCII("x-shader/x-fragment") &&
!type.LowerCaseEqualsASCII("text/something-not-javascript")) {
NS_WARNING(nsPrintfCString("Unknown script type '%s'",
NS_ConvertUTF16toUTF8(type).get())
.get());
} #endif// #ifdef DEBUG returnfalse;
}
} elseif (!hasType) { // "language" is a deprecated attribute of HTML, so we check it only for // HTML script elements. if (cont->IsHTMLElement()) {
nsAutoString language;
cont->AsElement()->GetAttr(nsGkAtoms::language, language); if (!language.IsEmpty() &&
!nsContentUtils::IsJavaScriptLanguage(language)) { returnfalse;
}
}
}
// If the value before trim was not empty and the value is now empty, do not // trim as we want to retain pure whitespace (by restoring original value) // because we need to treat "" and " " (etc) differently. if (!wasEmptyBeforeTrim && type.IsEmpty()) { return element->GetAttr(nsGkAtoms::type, aType);
}
aType.Assign(type); returntrue;
}
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.