diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2015-08-27 01:22:42 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2015-08-27 16:59:02 +0200 |
commit | c831c2c0a528b6a04b355cc51169023f8c29b761 (patch) | |
tree | d443f7075709bdb222163aecc8ce1c3b81e107b9 /components/script/dom/htmlscriptelement.rs | |
parent | 1384ff5e9f4d98630d4ec1206049c8fb6d96f187 (diff) | |
download | servo-c831c2c0a528b6a04b355cc51169023f8c29b761.tar.gz servo-c831c2c0a528b6a04b355cc51169023f8c29b761.zip |
Remove helper traits
Now that JSRef<T> is gone, there is no need to have helper traits.
On components/script/*.rs:
# Remove imports.
/^ *use dom::[a-z]+::\{.*Helpers/ {
s/\{(Raw[^L]|[^L][^a])[a-zA-Z]+Helpers, /\{/
s/, (Raw[^L]|[^L][^a])[a-zA-Z]+Helpers([,}])/\2/g
s/\{([a-zA-Z]+)\}/\1/
/\{\}/d
s/::self;$/;/
}
/^ *use dom::[a-z]+::\{?(Raw[^L]|[^L][^a])[a-zA-Z]+Helpers\}?;$/d
On components/script/dom/*.rs:
# Ignore layout things.
/^(pub )?(impl|trait).*Layout.* \{/,/^}$/ { P; D; }
# Delete helpers traits.
/^(pub )?trait ([^L][^ ]|L[^a])[^ ]+Helpers(<'a>)? \{$/,/^\}$/D
# Patch private helpers.
/^impl.*Private.*Helpers/,/^\}$/ {
s/^impl<'a> Private([^L][^ ]|L[^a])[^ ]+Helpers(<'a>)? for &'a ([^ ]+) \{$/impl \3 {/
/^ *(unsafe )?fn .*\(self.*[<&]'a/ {
s/&'a /\&/g
s/<'a, /</g
}
/^ *(unsafe )?fn /s/\(self([,)])/\(\&self\1/
}
# Patch public helpers.
/^impl.*Helpers/,/^\}$/ {
s/^impl(<'a>)? ([^L][^ ]|L[^a])[^ ]+Helpers(<'a>)? for (&'a )?([^ ]+) \{$/impl \5 {/
/^ *(unsafe )?fn .*\(self.*[<&]'a/ {
s/&'a /\&/g
s/<'a, /</g
}
/^ *(unsafe )?fn .*\(&?self[,)]/s/(unsafe )?fn/pub &/
/^ *pub (unsafe )?fn /s/\(self([,)])/\(\&self\1/
}
The few error cases were then fixed by hand.
Diffstat (limited to 'components/script/dom/htmlscriptelement.rs')
-rw-r--r-- | components/script/dom/htmlscriptelement.rs | 69 |
1 files changed, 16 insertions, 53 deletions
diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 64ab605ba40..f4017970087 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -6,7 +6,6 @@ use std::ascii::AsciiExt; use document_loader::LoadType; use dom::attr::Attr; -use dom::attr::AttrHelpers; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; @@ -21,17 +20,16 @@ use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, Root}; use dom::bindings::refcounted::Trusted; use dom::bindings::trace::JSTraceable; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::element::ElementTypeId; use dom::element::{AttributeHandlers, ElementCreator}; -use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers}; +use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{ChildrenMutation, CloneChildrenFlag, Node, NodeHelpers}; +use dom::node::{ChildrenMutation, CloneChildrenFlag, Node}; use dom::node::{NodeTypeId, document_from_node, window_from_node}; -use dom::servohtmlparser::ServoHTMLParserHelpers; use dom::virtualmethods::VirtualMethods; -use dom::window::{WindowHelpers, ScriptHelpers}; +use dom::window::ScriptHelpers; use js::jsapi::RootedValue; use js::jsval::UndefinedValue; use network_listener::{NetworkListener, PreInvoke}; @@ -110,35 +108,6 @@ impl HTMLScriptElement { } } -pub trait HTMLScriptElementHelpers { - /// Prepare a script (<https://www.whatwg.org/html/#prepare-a-script>) - fn prepare(self) -> NextParserState; - - /// [Execute a script block] - /// (https://html.spec.whatwg.org/multipage/#execute-the-script-block) - fn execute(self, load: ScriptOrigin); - - /// Prepare a script, steps 6 and 7. - fn is_javascript(self) -> bool; - - /// Set the "already started" flag (<https://whatwg.org/html/#already-started>) - fn mark_already_started(self); - - // Queues error event - fn queue_error_event(self); - - /// Dispatch beforescriptexecute event. - fn dispatch_before_script_execute_event(self) -> bool; - - /// Dispatch afterscriptexecute event. - fn dispatch_after_script_execute_event(self); - - /// Dispatch load event. - fn dispatch_load_event(self); - - /// Dispatch error event. - fn dispatch_error_event(self); -} /// Supported script types as defined by /// <https://whatwg.org/html/#support-the-scripting-language>. @@ -212,8 +181,8 @@ impl AsyncResponseListener for ScriptContext { impl PreInvoke for ScriptContext {} -impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { - fn prepare(self) -> NextParserState { +impl HTMLScriptElement { + pub fn prepare(&self) -> NextParserState { // https://html.spec.whatwg.org/multipage/#prepare-a-script // Step 1. if self.already_started.get() { @@ -365,7 +334,7 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { NextParserState::Continue } - fn execute(self, load: ScriptOrigin) { + pub fn execute(&self, load: ScriptOrigin) { // Step 1. // TODO: If the element is flagged as "parser-inserted", but the // element's node document is not the Document of the parser that @@ -462,7 +431,7 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { } } - fn queue_error_event(self) { + pub fn queue_error_event(&self) { let window = window_from_node(self); let window = window.r(); let chan = window.script_chan(); @@ -474,31 +443,31 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { chan.send(CommonScriptMsg::RunnableMsg(dispatcher)).unwrap(); } - fn dispatch_before_script_execute_event(self) -> bool { + pub fn dispatch_before_script_execute_event(&self) -> bool { self.dispatch_event("beforescriptexecute".to_owned(), EventBubbles::Bubbles, EventCancelable::Cancelable) } - fn dispatch_after_script_execute_event(self) { + pub fn dispatch_after_script_execute_event(&self) { self.dispatch_event("afterscriptexecute".to_owned(), EventBubbles::Bubbles, EventCancelable::NotCancelable); } - fn dispatch_load_event(self) { + pub fn dispatch_load_event(&self) { self.dispatch_event("load".to_owned(), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable); } - fn dispatch_error_event(self) { + pub fn dispatch_error_event(&self) { self.dispatch_event("error".to_owned(), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable); } - fn is_javascript(self) -> bool { + pub fn is_javascript(&self) -> bool { let element = ElementCast::from_ref(self); match element.get_attribute(&ns!(""), &atom!("type")).map(|s| s.r().Value()) { Some(ref s) if s.is_empty() => { @@ -531,20 +500,14 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { } } - fn mark_already_started(self) { + pub fn mark_already_started(&self) { self.already_started.set(true); } } -trait PrivateHTMLScriptElementHelpers { - fn dispatch_event(self, - type_: DOMString, - bubbles: EventBubbles, - cancelable: EventCancelable) -> bool; -} -impl<'a> PrivateHTMLScriptElementHelpers for &'a HTMLScriptElement { - fn dispatch_event(self, +impl HTMLScriptElement { + fn dispatch_event(&self, type_: DOMString, bubbles: EventBubbles, cancelable: EventCancelable) -> bool { |