servo: Merge #4865 - implementing step 12 of 'prepare a script' algorithm (from psdh:prepscript); r=Ms2ger
authorPrabhjyot Singh Sodhi <prabhjyotsingh95@gmail.com>
Fri, 20 Feb 2015 17:03:53 -0700
changeset 335848 bff2372be73ccb228ccb51c3da7f1d5f861d5129
parent 335847 4dfc8adc273b221372ff67eaf9f24dd30202d7b5
child 335849 bd488eaacfd64714abbdbc0466583e81b9eca0ce
push id86548
push userkwierso@gmail.com
push dateSat, 04 Feb 2017 01:35:21 +0000
treeherdermozilla-inbound@e7b96d015d03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
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
servo/components/script/dom/htmlscriptelement.rs
--- 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.)