servo: Merge
#4865 - implementing step 12 of 'prepare a script' algorithm (from psdh:prepscript); r=Ms2ger
#4176
Source-Repo:
https://github.com/servo/servo
Source-Revision:
e39e75865bdcef639b47a6a448a84cf2ca4894cf
--- a/servo/components/script/dom/htmlscriptelement.rs
+++ b/servo/components/script/dom/htmlscriptelement.rs
@@ -165,19 +165,35 @@ impl<'a> HTMLScriptElementHelpers for JS
// TODO: If the element is flagged as "parser-inserted", but the element's node document is
// not the Document of the parser that created the element, then abort these steps.
// Step 11.
// TODO: If scripting is disabled for the script element, then the user agent must abort
// these steps at this point. The script is not executed.
// Step 12.
- // TODO: If the script element has an `event` attribute and a `for` attribute, then run
- // these substeps...
+ match element.get_attribute(ns!(""), &atom!("for")).root() {
+ Some(for_script) => {
+ if for_script.r().Value().to_ascii_lowercase().trim_matches(HTML_SPACE_CHARACTERS) != "window" {
+ return;
+ }
+ }
+ _ => { }
+ }
+ match element.get_attribute(ns!(""), &Atom::from_slice("event")).root() {
+ Some(event) => {
+ let event = event.r().Value().to_ascii_lowercase();
+ let event = event.trim_matches(HTML_SPACE_CHARACTERS);
+ if event != "onload" && event != "onload()" {
+ return;
+ }
+ }
+ _ => { }
+ }
// Step 13.
// TODO: If the script element has a `charset` attribute, then let the script block's
// character encoding for this script element be the result of getting an encoding from the
// value of the `charset` attribute.
// Step 14 and 15.
// TODO: Add support for the `defer` and `async` attributes. (For now, we fetch all
// scripts synchronously and execute them immediately.)