diff options
Diffstat (limited to 'components/script/dom/htmlscriptelement.rs')
-rw-r--r-- | components/script/dom/htmlscriptelement.rs | 62 |
1 files changed, 15 insertions, 47 deletions
diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index ed8bdfaa886..e1b23f9b2b2 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -4,7 +4,6 @@ use document_loader::LoadType; use dom::attr::Attr; -use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding::HTMLScriptElementMethods; @@ -17,6 +16,7 @@ use dom::bindings::reflector::DomObject; use dom::bindings::str::DOMString; use dom::document::Document; use dom::element::{AttributeMutation, Element, ElementCreator}; +use dom::element::{cors_setting_for_element, reflect_cross_origin_attribute, set_cross_origin_attribute}; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventdispatcher::EventStatus; use dom::globalscope::GlobalScope; @@ -369,12 +369,7 @@ impl HTMLScriptElement { .unwrap_or_else(|| doc.encoding()); // Step 14. - let cors_setting = match self.GetCrossOrigin() { - Some(ref s) if *s == "anonymous" => Some(CorsSettings::Anonymous), - Some(ref s) if *s == "use-credentials" => Some(CorsSettings::UseCredentials), - None => None, - _ => unreachable!() - }; + let cors_setting = cors_setting_for_element(element); // TODO: Step 15: Module script credentials mode. @@ -486,11 +481,6 @@ impl HTMLScriptElement { Ok(script) => script, }; - // TODO(#12446): beforescriptexecute. - if self.dispatch_before_script_execute_event() == EventStatus::Canceled { - return; - } - // Step 3. let neutralized_doc = if script.external { debug!("loading external script, url = {}", script.url); @@ -523,14 +513,9 @@ impl HTMLScriptElement { doc.decr_ignore_destructive_writes_counter(); } - // TODO(#12446): afterscriptexecute. - self.dispatch_after_script_execute_event(); - // Step 8. if script.external { self.dispatch_load_event(); - } else { - window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("load"), &window); } } @@ -539,18 +524,6 @@ impl HTMLScriptElement { window.dom_manipulation_task_source().queue_simple_event(self.upcast(), atom!("error"), &window); } - pub fn dispatch_before_script_execute_event(&self) -> EventStatus { - self.dispatch_event(atom!("beforescriptexecute"), - EventBubbles::Bubbles, - EventCancelable::Cancelable) - } - - pub fn dispatch_after_script_execute_event(&self) { - self.dispatch_event(atom!("afterscriptexecute"), - EventBubbles::Bubbles, - EventCancelable::NotCancelable); - } - pub fn dispatch_load_event(&self) { self.dispatch_event(atom!("load"), EventBubbles::DoesNotBubble, @@ -688,6 +661,17 @@ impl HTMLScriptElementMethods for HTMLScriptElement { // https://html.spec.whatwg.org/multipage/#dom-script-charset make_setter!(SetCharset, "charset"); + // https://html.spec.whatwg.org/multipage/#dom-script-async + fn Async(&self) -> bool { + self.non_blocking.get() || self.upcast::<Element>().has_attribute(&local_name!("async")) + } + + // https://html.spec.whatwg.org/multipage/#dom-script-async + fn SetAsync(&self, value: bool) { + self.non_blocking.set(false); + self.upcast::<Element>().set_bool_attribute(&local_name!("async"), value); + } + // https://html.spec.whatwg.org/multipage/#dom-script-defer make_bool_getter!(Defer, "defer"); // https://html.spec.whatwg.org/multipage/#dom-script-defer @@ -710,28 +694,12 @@ impl HTMLScriptElementMethods for HTMLScriptElement { // https://html.spec.whatwg.org/multipage/#dom-script-crossorigin fn GetCrossOrigin(&self) -> Option<DOMString> { - let element = self.upcast::<Element>(); - let attr = element.get_attribute(&ns!(), &local_name!("crossorigin")); - - if let Some(mut val) = attr.map(|v| v.Value()) { - val.make_ascii_lowercase(); - if val == "anonymous" || val == "use-credentials" { - return Some(val); - } - return Some(DOMString::from("anonymous")); - } - None + reflect_cross_origin_attribute(self.upcast::<Element>()) } // https://html.spec.whatwg.org/multipage/#dom-script-crossorigin fn SetCrossOrigin(&self, value: Option<DOMString>) { - let element = self.upcast::<Element>(); - match value { - Some(val) => element.set_string_attribute(&local_name!("crossorigin"), val), - None => { - element.remove_attribute(&ns!(), &local_name!("crossorigin")); - } - } + set_cross_origin_attribute(self.upcast::<Element>(), value); } // https://html.spec.whatwg.org/multipage/#dom-script-text |