diff options
Diffstat (limited to 'components/script/dom')
39 files changed, 212 insertions, 156 deletions
diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs index 6299abaa672..78e3d6cd4bb 100644 --- a/components/script/dom/activation.rs +++ b/components/script/dom/activation.rs @@ -11,6 +11,7 @@ use dom::eventtarget::{EventTarget, EventTargetHelpers}; use dom::mouseevent::MouseEvent; use dom::node::window_from_node; +use std::borrow::ToOwned; /// Trait for elements with defined activation behavior pub trait Activatable : Copy { @@ -44,7 +45,7 @@ pub trait Activatable : Copy { // https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-mouse-event let win = window_from_node(element.r()).root(); let target: JSRef<EventTarget> = EventTargetCast::from_ref(element.r()); - let mouse = MouseEvent::new(win.r(), "click".into_string(), + let mouse = MouseEvent::new(win.r(), "click".to_owned(), false, false, Some(win.r()), 1, 0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey, 0, None).root(); diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 9a062679a4f..789e5f925d6 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -20,6 +20,7 @@ use servo_util::str::{DOMString, split_html_space_chars}; use string_cache::{Atom, Namespace}; +use std::borrow::ToOwned; use std::cell::Ref; use std::mem; @@ -138,11 +139,11 @@ impl Attr { impl<'a> AttrMethods for JSRef<'a, Attr> { fn LocalName(self) -> DOMString { - self.local_name().as_slice().into_string() + self.local_name().as_slice().to_owned() } fn Value(self) -> DOMString { - self.value().as_slice().into_string() + self.value().as_slice().to_owned() } fn SetValue(self, value: DOMString) { @@ -175,14 +176,14 @@ impl<'a> AttrMethods for JSRef<'a, Attr> { } fn Name(self) -> DOMString { - self.name.as_slice().into_string() + self.name.as_slice().to_owned() } fn GetNamespaceURI(self) -> Option<DOMString> { let Namespace(ref atom) = self.namespace; match atom.as_slice() { "" => None, - url => Some(url.into_string()), + url => Some(url.to_owned()), } } @@ -237,7 +238,7 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> { fn summarize(self) -> AttrInfo { let Namespace(ref ns) = self.namespace; AttrInfo { - namespace: ns.as_slice().into_string(), + namespace: ns.as_slice().to_owned(), name: self.Name(), value: self.Value(), } diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 3d28cf2bdc9..e1e5bee2036 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -674,7 +674,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, default = "None" else: assert defaultValue.type.tag() == IDLType.Tags.domstring - value = "str::from_utf8(&data).unwrap().into_string()" + value = "str::from_utf8(&data).unwrap().to_owned()" if type.nullable(): value = "Some(%s)" % value @@ -4584,6 +4584,7 @@ class CGBindingRoot(CGThing): 'page::JSPageInfo', 'libc', 'servo_util::str::DOMString', + 'std::borrow::ToOwned', 'std::cmp', 'std::iter::repeat', 'std::mem', diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 8e9e656b0c4..8447b9e9554 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -28,6 +28,7 @@ use js::jsval::{UndefinedValue, NullValue, BooleanValue, Int32Value, UInt32Value use js::jsval::{StringValue, ObjectValue, ObjectOrNullValue}; use libc; +use std::borrow::ToOwned; use std::default; use std::slice; @@ -289,7 +290,7 @@ pub fn jsid_to_str(cx: *mut JSContext, id: jsid) -> DOMString { impl FromJSValConvertible<StringificationBehavior> for DOMString { fn from_jsval(cx: *mut JSContext, value: JSVal, nullBehavior: StringificationBehavior) -> Result<DOMString, ()> { if nullBehavior == StringificationBehavior::Empty && value.is_null() { - Ok("".into_string()) + Ok("".to_owned()) } else { let jsstr = unsafe { JS_ValueToString(cx, value) }; if jsstr.is_null() { diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index c252a8a3e21..e67c8ac7d6a 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -6,6 +6,7 @@ //! The `ByteString` struct. +use std::borrow::ToOwned; use std::hash::{Hash, sip}; use std::str; use std::str::FromStr; @@ -154,6 +155,6 @@ impl Hash for ByteString { impl FromStr for ByteString { fn from_str(s: &str) -> Option<ByteString> { - Some(ByteString::new(s.into_string().into_bytes())) + Some(ByteString::new(s.to_owned().into_bytes())) } } diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index f4794d9f6fe..782fff57c9d 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -11,6 +11,7 @@ use dom::bindings::codegen::Bindings::BlobBinding; use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; use servo_util::str::DOMString; +use std::borrow::ToOwned; use std::cmp::{min, max}; use std::ascii::AsciiExt; @@ -43,7 +44,7 @@ impl Blob { reflector_: Reflector::new(), type_: type_, bytes: bytes, - typeString: typeString.into_string(), + typeString: typeString.to_owned(), global: GlobalField::from_rooted(&global) //isClosed_: false } @@ -109,12 +110,12 @@ impl<'a> BlobMethods for JSRef<'a, Blob> { } }; let relativeContentType = match contentType { - None => "".into_string(), + None => "".to_owned(), Some(str) => { if is_ascii_printable(&str) { - str.as_slice().to_ascii_lower().into_string() + str.as_slice().to_ascii_lower().to_owned() } else { - "".into_string() + "".to_owned() } } }; diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index 55e4ab5f551..bdc56530e7d 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -16,6 +16,7 @@ use dom::node::{Node, NodeHelpers, NodeTypeId}; use servo_util::str::DOMString; +use std::borrow::ToOwned; use std::cell::Ref; #[dom_struct] @@ -80,7 +81,7 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { } fn SubstringData(self, offset: u32, count: u32) -> Fallible<DOMString> { - Ok(self.data.borrow().as_slice().slice(offset as uint, count as uint).into_string()) + Ok(self.data.borrow().as_slice().slice(offset as uint, count as uint).to_owned()) } fn AppendData(self, arg: DOMString) -> ErrorResult { @@ -93,7 +94,7 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { } fn DeleteData(self, offset: u32, count: u32) -> ErrorResult { - self.ReplaceData(offset, count, "".into_string()) + self.ReplaceData(offset, count, "".to_owned()) } fn ReplaceData(self, offset: u32, count: u32, arg: DOMString) -> ErrorResult { @@ -106,7 +107,7 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { } else { count }; - let mut data = self.data.borrow().as_slice().slice(0, offset as uint).into_string(); + let mut data = self.data.borrow().as_slice().slice(0, offset as uint).to_owned(); data.push_str(arg.as_slice()); data.push_str(self.data.borrow().as_slice().slice((offset + count) as uint, length as uint)); *self.data.borrow_mut() = data; diff --git a/components/script/dom/create.rs b/components/script/dom/create.rs index 4f8d3b9f846..73e39768f6e 100644 --- a/components/script/dom/create.rs +++ b/components/script/dom/create.rs @@ -79,16 +79,18 @@ use servo_util::str::DOMString; use string_cache::QualName; +use std::borrow::ToOwned; + pub fn create_element(name: QualName, prefix: Option<DOMString>, document: JSRef<Document>, creator: ElementCreator) -> Temporary<Element> { if name.ns != ns!(HTML) { - return Element::new(name.local.as_slice().into_string(), name.ns, prefix, document); + return Element::new(name.local.as_slice().to_owned(), name.ns, prefix, document); } macro_rules! make( ($ctor:ident $(, $arg:expr)*) => ({ - let obj = $ctor::new(name.local.as_slice().into_string(), prefix, document $(, $arg)*); + let obj = $ctor::new(name.local.as_slice().to_owned(), prefix, document $(, $arg)*); ElementCast::from_temporary(obj) }) ) diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index b95df387901..32f7f174433 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -21,6 +21,7 @@ use style::{is_supported_property, longhands_from_shorthand, parse_style_attribu use style::PropertyDeclaration; use std::ascii::AsciiExt; +use std::borrow::ToOwned; #[dom_struct] pub struct CSSStyleDeclaration { @@ -39,10 +40,10 @@ macro_rules! css_properties( ( $([$getter:ident, $setter:ident, $cssprop:expr]),* ) => ( $( fn $getter(self) -> DOMString { - self.GetPropertyValue($cssprop.into_string()) + self.GetPropertyValue($cssprop.to_owned()) } fn $setter(self, value: DOMString) { - self.SetPropertyValue($cssprop.into_string(), value).unwrap(); + self.SetPropertyValue($cssprop.to_owned(), value).unwrap(); } )* ); @@ -123,7 +124,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { } }); - result.unwrap_or("".into_string()) + result.unwrap_or("".to_owned()) } // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue @@ -145,7 +146,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { // Step 2.2.2 & 2.2.3 match declaration { Some(declaration) => list.push(declaration), - None => return "".into_string(), + None => return "".to_owned(), } } @@ -157,7 +158,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { if let Some(ref declaration) = self.get_declaration(&property) { serialize_value(declaration) } else { - "".into_string() + "".to_owned() } } @@ -174,15 +175,15 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { .map(|longhand| self.GetPropertyPriority(longhand.clone())) .all(|priority| priority.as_slice() == "important") { - return "important".into_string(); + return "important".to_owned(); } // Step 3 } else if self.get_important_declaration(&property).is_some() { - return "important".into_string(); + return "important".to_owned(); } // Step 4 - "".into_string() + "".to_owned() } // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setproperty @@ -289,7 +290,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setpropertyvalue fn SetPropertyValue(self, property: DOMString, value: DOMString) -> ErrorResult { - self.SetProperty(property, value, "".into_string()) + self.SetProperty(property, value, "".to_owned()) } // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-removeproperty @@ -328,12 +329,12 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-cssfloat fn CssFloat(self) -> DOMString { - self.GetPropertyValue("float".into_string()) + self.GetPropertyValue("float".to_owned()) } // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-cssfloat fn SetCssFloat(self, value: DOMString) -> ErrorResult { - self.SetPropertyValue("float".into_string(), value) + self.SetPropertyValue("float".to_owned(), value) } fn IndexedGetter(self, index: u32, found: &mut bool) -> DOMString { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index f01dc20a7e1..d20dcda10e7 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -63,6 +63,7 @@ use layout_interface::{LayoutChan, Msg}; use string_cache::{Atom, QualName}; use url::Url; +use std::borrow::ToOwned; use std::collections::HashMap; use std::collections::hash_map::{Vacant, Occupied}; use std::ascii::AsciiExt; @@ -339,7 +340,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { self.ready_state.set(state); let window = self.window.root(); - let event = Event::new(GlobalRef::Window(window.r()), "readystatechange".into_string(), + let event = Event::new(GlobalRef::Window(window.r()), "readystatechange".to_owned(), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable).root(); let target: JSRef<EventTarget> = EventTargetCast::from_ref(self); @@ -425,9 +426,9 @@ impl Document { Some(string) => string.clone(), None => match is_html_document { // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument - IsHTMLDocument::HTMLDocument => "text/html".into_string(), + IsHTMLDocument::HTMLDocument => "text/html".to_owned(), // http://dom.spec.whatwg.org/#concept-document-content-type - IsHTMLDocument::NonHTMLDocument => "application/xml".into_string() + IsHTMLDocument::NonHTMLDocument => "application/xml".to_owned() } }, last_modified: DOMRefCell::new(None), @@ -435,7 +436,7 @@ impl Document { // http://dom.spec.whatwg.org/#concept-document-quirks quirks_mode: Cell::new(NoQuirks), // http://dom.spec.whatwg.org/#concept-document-encoding - encoding_name: DOMRefCell::new("UTF-8".into_string()), + encoding_name: DOMRefCell::new("UTF-8".to_owned()), is_html_document: is_html_document == IsHTMLDocument::HTMLDocument, images: Default::default(), embeds: Default::default(), @@ -520,8 +521,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-compatmode fn CompatMode(self) -> DOMString { match self.quirks_mode.get() { - LimitedQuirks | NoQuirks => "CSS1Compat".into_string(), - Quirks => "BackCompat".into_string() + LimitedQuirks | NoQuirks => "CSS1Compat".to_owned(), + Quirks => "BackCompat".to_owned() } } @@ -639,7 +640,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } let name = QualName::new(ns, Atom::from_slice(local_name_from_qname)); - Ok(Element::create(name, prefix_from_qname.map(|s| s.into_string()), self, + Ok(Element::create(name, prefix_from_qname.map(|s| s.to_owned()), self, ElementCreator::ScriptCreated)) } @@ -654,7 +655,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { let name = Atom::from_slice(local_name.as_slice()); // repetition used because string_cache::atom::Atom is non-copyable let l_name = Atom::from_slice(local_name.as_slice()); - let value = AttrValue::String("".into_string()); + let value = AttrValue::String("".to_owned()); Ok(Attr::new(window.r(), name, value, l_name, ns!(""), None, None)) } @@ -802,7 +803,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } }, None => { - let new_title = HTMLTitleElement::new("title".into_string(), None, self).root(); + let new_title = HTMLTitleElement::new("title".to_owned(), None, self).root(); let new_title: JSRef<Node> = NodeCast::from_ref(new_title.r()); if !title.is_empty() { diff --git a/components/script/dom/documenttype.rs b/components/script/dom/documenttype.rs index 2fe9e340987..fc9407c5dd0 100644 --- a/components/script/dom/documenttype.rs +++ b/components/script/dom/documenttype.rs @@ -11,6 +11,8 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::node::{Node, NodeHelpers, NodeTypeId}; use servo_util::str::DOMString; +use std::borrow::ToOwned; + /// The `DOCTYPE` tag. #[dom_struct] pub struct DocumentType { @@ -35,8 +37,8 @@ impl DocumentType { DocumentType { node: Node::new_inherited(NodeTypeId::DocumentType, document), name: name, - public_id: public_id.unwrap_or("".into_string()), - system_id: system_id.unwrap_or("".into_string()) + public_id: public_id.unwrap_or("".to_owned()), + system_id: system_id.unwrap_or("".to_owned()) } } #[allow(unrooted_must_root)] diff --git a/components/script/dom/domexception.rs b/components/script/dom/domexception.rs index 0af98e21e81..112dcedf4b2 100644 --- a/components/script/dom/domexception.rs +++ b/components/script/dom/domexception.rs @@ -11,6 +11,8 @@ use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::utils::{Reflector, reflect_dom_object}; use servo_util::str::DOMString; +use std::borrow::ToOwned; + #[repr(uint)] #[deriving(Copy, Show)] #[jstraceable] @@ -125,6 +127,6 @@ impl<'a> DOMExceptionMethods for JSRef<'a, DOMException> { DOMErrorName::EncodingError => "The encoding operation (either encoded or decoding) failed." }; - message.into_string() + message.to_owned() } } diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index e298d275f47..285b86967e8 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -25,6 +25,8 @@ use dom::node::Node; use dom::text::Text; use servo_util::str::DOMString; +use std::borrow::ToOwned; + #[dom_struct] pub struct DOMImplementation { reflector_: Reflector, @@ -123,18 +125,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { { // Step 3. - let doc_type = DocumentType::new("html".into_string(), None, None, doc.r()).root(); + let doc_type = DocumentType::new("html".to_owned(), None, None, doc.r()).root(); assert!(doc_node.AppendChild(NodeCast::from_ref(doc_type.r())).is_ok()); } { // Step 4. - let doc_html: Root<Node> = NodeCast::from_temporary(HTMLHtmlElement::new("html".into_string(), None, doc.r())).root(); + let doc_html: Root<Node> = NodeCast::from_temporary(HTMLHtmlElement::new("html".to_owned(), None, doc.r())).root(); assert!(doc_node.AppendChild(doc_html.r()).is_ok()); { // Step 5. - let doc_head: Root<Node> = NodeCast::from_temporary(HTMLHeadElement::new("head".into_string(), None, doc.r())).root(); + let doc_head: Root<Node> = NodeCast::from_temporary(HTMLHeadElement::new("head".to_owned(), None, doc.r())).root(); assert!(doc_html.r().AppendChild(doc_head.r()).is_ok()); // Step 6. @@ -142,7 +144,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { None => (), Some(title_str) => { // Step 6.1. - let doc_title: Root<Node> = NodeCast::from_temporary(HTMLTitleElement::new("title".into_string(), None, doc.r())).root(); + let doc_title: Root<Node> = NodeCast::from_temporary(HTMLTitleElement::new("title".to_owned(), None, doc.r())).root(); assert!(doc_head.r().AppendChild(doc_title.r()).is_ok()); // Step 6.2. @@ -153,7 +155,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { } // Step 7. - let doc_body: Root<HTMLBodyElement> = HTMLBodyElement::new("body".into_string(), None, doc.r()).root(); + let doc_body: Root<HTMLBodyElement> = HTMLBodyElement::new("body".to_owned(), None, doc.r()).root(); assert!(doc_html.r().AppendChild(NodeCast::from_ref(doc_body.r())).is_ok()); } diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs index 4b473ed8ced..a3a7db0b1ca 100644 --- a/components/script/dom/domparser.rs +++ b/components/script/dom/domparser.rs @@ -17,6 +17,8 @@ use dom::window::Window; use parse::html::{HTMLInput, parse_html}; use servo_util::str::DOMString; +use std::borrow::ToOwned; + #[dom_struct] pub struct DOMParser { reflector_: Reflector, @@ -49,7 +51,7 @@ impl<'a> DOMParserMethods for JSRef<'a, DOMParser> { -> Fallible<Temporary<Document>> { let window = self.window.root(); let url = window.r().get_url(); - let content_type = DOMParserBinding::SupportedTypeValues::strings[ty as uint].into_string(); + let content_type = DOMParserBinding::SupportedTypeValues::strings[ty as uint].to_owned(); match ty { Text_html => { let document = Document::new(window.r(), Some(url.clone()), diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index c681dc7d710..3ae0a4f09de 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -16,6 +16,8 @@ use dom::node::window_from_node; use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS}; use string_cache::Atom; +use std::borrow::ToOwned; + #[dom_struct] pub struct DOMTokenList { reflector_: Reflector, @@ -72,7 +74,7 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> { // http://dom.spec.whatwg.org/#dom-domtokenlist-item fn Item(self, index: u32) -> Option<DOMString> { self.attribute().root().and_then(|attr| attr.r().value().tokens().and_then(|tokens| { - tokens.get(index as uint).map(|token| token.as_slice().into_string()) + tokens.get(index as uint).map(|token| token.as_slice().to_owned()) })) } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 0735e19299f..b684b90579e 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -59,6 +59,7 @@ use html5ever::tree_builder::{NoQuirks, LimitedQuirks, Quirks}; use cssparser::RGBA; use std::ascii::AsciiExt; +use std::borrow::ToOwned; use std::cell::{Ref, RefMut}; use std::default::Default; use std::mem; @@ -761,7 +762,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { fn get_url_attribute(self, name: &Atom) -> DOMString { assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice()); if !self.has_attribute(name) { - return "".into_string(); + return "".to_owned(); } let url = self.get_string_attribute(name); let doc = document_from_node(self).root(); @@ -770,7 +771,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { // XXXManishearth this doesn't handle `javascript:` urls properly match UrlParser::new().base_url(base).parse(url.as_slice()) { Ok(parsed) => parsed.serialize(), - Err(_) => "".into_string() + Err(_) => "".to_owned() } } fn set_url_attribute(self, name: &Atom, value: DOMString) { @@ -780,7 +781,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { fn get_string_attribute(self, name: &Atom) -> DOMString { match self.get_attribute(ns!(""), name) { Some(x) => x.root().r().Value(), - None => "".into_string() + None => "".to_owned() } } fn set_string_attribute(self, name: &Atom, value: DOMString) { @@ -835,12 +836,12 @@ impl<'a> ElementMethods for JSRef<'a, Element> { fn GetNamespaceURI(self) -> Option<DOMString> { match self.namespace { ns!("") => None, - Namespace(ref ns) => Some(ns.as_slice().into_string()) + Namespace(ref ns) => Some(ns.as_slice().to_owned()) } } fn LocalName(self) -> DOMString { - self.local_name.as_slice().into_string() + self.local_name.as_slice().to_owned() } // http://dom.spec.whatwg.org/#dom-element-prefix @@ -996,7 +997,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // Step 9. let value = self.parse_attribute(&namespace, &local_name, value); self.do_set_attribute(local_name.clone(), value, name, - namespace.clone(), prefix.map(|s| s.into_string()), + namespace.clone(), prefix.map(|s| s.to_owned()), |attr| { *attr.local_name() == local_name && *attr.namespace() == namespace diff --git a/components/script/dom/errorevent.rs b/components/script/dom/errorevent.rs index 51a86165cbe..2ae0eec9a18 100644 --- a/components/script/dom/errorevent.rs +++ b/components/script/dom/errorevent.rs @@ -17,6 +17,7 @@ use dom::event::{Event, EventTypeId, EventBubbles, EventCancelable}; use servo_util::str::DOMString; use dom::bindings::cell::DOMRefCell; +use std::borrow::ToOwned; use std::cell::{Cell}; use js::jsval::{JSVal, NullValue}; @@ -40,8 +41,8 @@ impl ErrorEvent { fn new_inherited(type_id: EventTypeId) -> ErrorEvent { ErrorEvent { event: Event::new_inherited(type_id), - message: DOMRefCell::new("".into_string()), - filename: DOMRefCell::new("".into_string()), + message: DOMRefCell::new("".to_owned()), + filename: DOMRefCell::new("".to_owned()), lineno: Cell::new(0), colno: Cell::new(0), error: MutHeap::new(NullValue()) @@ -80,11 +81,11 @@ impl ErrorEvent { init: &ErrorEventBinding::ErrorEventInit) -> Fallible<Temporary<ErrorEvent>>{ let msg = match init.message.as_ref() { Some(message) => message.clone(), - None => "".into_string(), + None => "".to_owned(), }; let file_name = match init.filename.as_ref() { - None => "".into_string(), + None => "".to_owned(), Some(filename) => filename.clone(), }; diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index 0f084288c7b..eda8690e48d 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -11,6 +11,8 @@ use dom::bindings::js::{MutNullableJS, JSRef, Temporary}; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::eventtarget::EventTarget; use servo_util::str::DOMString; + +use std::borrow::ToOwned; use std::cell::Cell; use std::default::Default; @@ -77,7 +79,7 @@ impl Event { current_target: Default::default(), target: Default::default(), phase: Cell::new(EventPhase::None), - type_: DOMRefCell::new("".into_string()), + type_: DOMRefCell::new("".to_owned()), canceled: Cell::new(false), cancelable: Cell::new(false), bubbles: Cell::new(false), diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index 71203d386a2..fd7de4c64d6 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -22,6 +22,7 @@ use js::jsapi::{JSContext, JSObject}; use servo_util::fnv::FnvHasher; use servo_util::str::DOMString; use libc::{c_char, size_t}; +use std::borrow::ToOwned; use std::collections::hash_map::{Occupied, Vacant}; use std::ptr; use url::Url; @@ -231,11 +232,11 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { { let event_listener = listener.map(|listener| EventListener::new(listener.callback())); - self.set_inline_event_listener(ty.into_string(), event_listener); + self.set_inline_event_listener(ty.to_owned(), event_listener); } fn get_event_handler_common<T: CallbackContainer>(self, ty: &str) -> Option<T> { - let listener = self.get_inline_event_listener(ty.into_string()); + let listener = self.get_inline_event_listener(ty.to_owned()); listener.map(|listener| CallbackContainer::new(listener.parent.callback())) } diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index bcac91da97e..9687bf6d9e5 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -16,6 +16,8 @@ use dom::blob::Blob; use dom::file::File; use dom::htmlformelement::HTMLFormElement; use servo_util::str::DOMString; + +use std::borrow::ToOwned; use std::collections::HashMap; use std::collections::hash_map::{Occupied, Vacant}; @@ -115,7 +117,7 @@ impl PrivateFormDataHelpers for FormData { fn get_file_from_blob(&self, value: JSRef<Blob>, filename: Option<DOMString>) -> Temporary<File> { let global = self.global.root(); let f: Option<JSRef<File>> = FileCast::to_ref(value); - let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or("blob".into_string())); + let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or("blob".to_owned())); File::new(global.r(), value, name) } } diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 220578d0282..c398d605abd 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -19,6 +19,8 @@ use dom::virtualmethods::VirtualMethods; use cssparser::RGBA; use servo_util::str::{mod, DOMString}; + +use std::borrow::ToOwned; use std::cell::Cell; #[dom_struct] @@ -106,7 +108,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> { }; evtarget.set_event_handler_uncompiled(cx, url, reflector, name.slice_from(2), - attr.value().as_slice().into_string()); + attr.value().as_slice().to_owned()); } match attr.local_name() { diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index dfc0309cc19..3dd5026a5a0 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -19,6 +19,7 @@ use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; use std::ascii::OwnedAsciiExt; +use std::borrow::ToOwned; use servo_util::str::DOMString; use string_cache::Atom; @@ -66,7 +67,7 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { // https://html.spec.whatwg.org/multipage/forms.html#attr-button-type match ty.as_slice() { "reset" | "button" | "menu" => ty, - _ => "submit".into_string() + _ => "submit".to_owned() } } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index d60591bb390..d5fae8353be 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -30,6 +30,7 @@ use servo_util::str::DOMString; use string_cache::Atom; +use std::borrow::ToOwned; use std::default::Default; #[dom_struct] @@ -141,7 +142,7 @@ pub trait HTMLElementCustomAttributeHelpers { } fn to_snake_case(name: DOMString) -> DOMString { - let mut attr_name = "data-".into_string(); + let mut attr_name = "data-".to_owned(); for ch in name.as_slice().chars() { if ch.is_uppercase() { attr_name.push('\x2d'); @@ -168,7 +169,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> { let element: JSRef<Element> = ElementCast::from_ref(self); element.get_attribute(ns!(""), &Atom::from_slice(to_snake_case(name).as_slice())).map(|attr| { let attr = attr.root(); - attr.r().value().as_slice().into_string() + attr.r().value().as_slice().to_owned() }) } @@ -199,7 +200,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLElement> { let evtarget: JSRef<EventTarget> = EventTargetCast::from_ref(*self); evtarget.set_event_handler_uncompiled(cx, url, reflector, name.slice_from(2), - attr.value().as_slice().into_string()); + attr.value().as_slice().to_owned()); } } } diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index fc8f9879c7b..7890dc1eb99 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -30,6 +30,7 @@ use url::UrlParser; use url::form_urlencoded::serialize; use string_cache::Atom; +use std::borrow::ToOwned; use std::cell::Cell; #[dom_struct] @@ -159,7 +160,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> { // TODO: Handle browsing contexts // TODO: Handle validation let event = Event::new(GlobalRef::Window(win.r()), - "submit".into_string(), + "submit".to_owned(), EventBubbles::Bubbles, EventCancelable::Cancelable).root(); event.r().set_trusted(true); @@ -187,7 +188,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> { let parsed_data = match enctype { FormEncType::UrlEncoded => serialize(form_data.iter().map(|d| (d.name.as_slice(), d.value.as_slice()))), - _ => "".into_string() // TODO: Add serializers for the other encoding types + _ => "".to_owned() // TODO: Add serializers for the other encoding types }; let mut load_data = LoadData::new(action_components); @@ -214,7 +215,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> { fn clean_crlf(s: &str) -> DOMString { // https://html.spec.whatwg.org/multipage/forms.html#constructing-the-form-data-set // Step 4 - let mut buf = "".into_string(); + let mut buf = "".to_owned(); let mut prev = ' '; for ch in s.chars() { match ch { @@ -284,7 +285,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> { "image" => None, // Unimplemented "radio" | "checkbox" => { if value.is_empty() { - value = "on".into_string(); + value = "on".to_owned(); } Some(FormDatum { ty: ty, @@ -346,7 +347,7 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> { let win = window_from_node(self).root(); let event = Event::new(GlobalRef::Window(win.r()), - "reset".into_string(), + "reset".to_owned(), EventBubbles::Bubbles, EventCancelable::Cancelable).root(); let target: JSRef<EventTarget> = EventTargetCast::from_ref(self); @@ -513,7 +514,7 @@ pub trait FormControl<'a> : Copy { if self.to_element().has_attribute(attr) { input(self) } else { - self.form_owner().map_or("".into_string(), |t| owner(t.root().r())) + self.form_owner().map_or("".to_owned(), |t| owner(t.root().r())) } } fn to_element(self) -> JSRef<'a, Element>; diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 0fb926666fa..3d6b8d28c7c 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -24,6 +24,8 @@ use string_cache::Atom; use url::{Url, UrlParser}; +use std::borrow::ToOwned; + #[dom_struct] pub struct HTMLImageElement { htmlelement: HTMLElement, @@ -189,7 +191,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { &atom!("src") => { let window = window_from_node(*self).root(); let url = window.r().get_url(); - self.update_image(Some((attr.value().as_slice().into_string(), &url))); + self.update_image(Some((attr.value().as_slice().to_owned(), &url))); }, _ => () } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 22da5bb20d7..55f7a102ce3 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -38,6 +38,7 @@ use servo_util::str::DOMString; use string_cache::Atom; use std::ascii::OwnedAsciiExt; +use std::borrow::ToOwned; use std::cell::Cell; use std::default::Default; @@ -116,7 +117,7 @@ impl HTMLInputElement { checked_changed: Cell::new(false), value_changed: Cell::new(false), size: Cell::new(DEFAULT_INPUT_SIZE), - textinput: DOMRefCell::new(TextInput::new(Single, "".into_string())), + textinput: DOMRefCell::new(TextInput::new(Single, "".to_owned())), activation_state: DOMRefCell::new(InputActivationState::new()) } } @@ -149,15 +150,15 @@ impl LayoutHTMLInputElementHelpers for JS<HTMLInputElement> { unsafe fn get_raw_attr_value(input: JS<HTMLInputElement>) -> Option<String> { let elem: JS<Element> = input.transmute_copy(); (*elem.unsafe_get()).get_attr_val_for_layout(&ns!(""), &atom!("value")) - .map(|s| s.into_string()) + .map(|s| s.to_owned()) } match (*self.unsafe_get()).input_type.get() { - InputType::InputCheckbox | InputType::InputRadio => "".into_string(), - InputType::InputFile | InputType::InputImage => "".into_string(), - InputType::InputButton => get_raw_attr_value(self).unwrap_or_else(|| "".into_string()), - InputType::InputSubmit => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_SUBMIT_VALUE.into_string()), - InputType::InputReset => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_RESET_VALUE.into_string()), + InputType::InputCheckbox | InputType::InputRadio => "".to_owned(), + InputType::InputFile | InputType::InputImage => "".to_owned(), + InputType::InputButton => get_raw_attr_value(self).unwrap_or_else(|| "".to_owned()), + InputType::InputSubmit => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_SUBMIT_VALUE.to_owned()), + InputType::InputReset => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_RESET_VALUE.to_owned()), InputType::InputPassword => { let raw = get_raw_textinput_value(self); String::from_char(raw.char_len(), '●') @@ -313,7 +314,7 @@ fn broadcast_radio_checked(broadcaster: JSRef<HTMLInputElement>, group: Option<& // There is no DOM tree manipulation here, so this is safe let mut iter = unsafe { - doc_node.query_selector_iter("input[type=radio]".into_string()).unwrap() + doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap() .filter_map(|t| HTMLInputElementCast::to_ref(t)) .filter(|&r| in_same_group(r, owner.r(), group) && broadcaster != r) }; @@ -439,7 +440,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { } &atom!("value") => { if !self.value_changed.get() { - self.textinput.borrow_mut().set_content(attr.value().as_slice().into_string()); + self.textinput.borrow_mut().set_content(attr.value().as_slice().to_owned()); self.force_relayout(); } } @@ -488,7 +489,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { } &atom!("value") => { if !self.value_changed.get() { - self.textinput.borrow_mut().set_content("".into_string()); + self.textinput.borrow_mut().set_content("".to_owned()); self.force_relayout(); } } @@ -639,7 +640,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { // Safe since we only manipulate the DOM tree after finding an element let checked_member = unsafe { - doc_node.query_selector_iter("input[type=radio]".into_string()).unwrap() + doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap() .filter_map(|t| HTMLInputElementCast::to_ref(t)) .filter(|&r| in_same_group(r, owner.r(), group.as_ref().map(|gr| gr.as_slice()))) @@ -739,7 +740,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { if self.mutable() { let win = window_from_node(*self).root(); let event = Event::new(GlobalRef::Window(win.r()), - "input".into_string(), + "input".to_owned(), EventBubbles::Bubbles, EventCancelable::NotCancelable).root(); event.r().set_trusted(true); @@ -747,7 +748,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { target.DispatchEvent(event.r()).ok(); let event = Event::new(GlobalRef::Window(win.r()), - "change".into_string(), + "change".to_owned(), EventBubbles::Bubbles, EventCancelable::NotCancelable).root(); event.r().set_trusted(true); @@ -771,7 +772,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { // This is safe because we are stopping after finding the first element // and only then performing actions which may modify the DOM tree unsafe { - node.query_selector_iter("input[type=submit]".into_string()).unwrap() + node.query_selector_iter("input[type=submit]".to_owned()).unwrap() .filter_map(|t| HTMLInputElementCast::to_ref(t)) .find(|r| r.form_owner() == owner) .map(|s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey)); diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index e4febefa004..49018903a5a 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -21,6 +21,7 @@ use layout_interface::{LayoutChan, Msg}; use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS}; use std::ascii::AsciiExt; +use std::borrow::ToOwned; use std::default::Default; use url::UrlParser; use string_cache::Atom; @@ -54,7 +55,7 @@ impl HTMLLinkElement { fn get_attr(element: JSRef<Element>, name: &Atom) -> Option<String> { let elem = element.get_attribute(ns!(""), name).root(); - elem.map(|e| e.r().value().as_slice().into_string()) + elem.map(|e| e.r().value().as_slice().to_owned()) } fn is_stylesheet(value: &Option<String>) -> bool { diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index c2af3ae9f6a..317769d23db 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -31,6 +31,7 @@ use encoding::all::UTF_8; use encoding::types::{Encoding, DecoderTrap}; use servo_net::resource_task::load_whole_resource; use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS, StaticStringVec}; +use std::borrow::ToOwned; use std::cell::Cell; use string_cache::Atom; use url::UrlParser; @@ -239,7 +240,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { let window = window_from_node(self).root(); let window = window.r(); let event = Event::new(GlobalRef::Window(window), - "load".into_string(), + "load".to_owned(), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable).root(); event.r().set_trusted(true); diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs index dcef30bf1ac..fce7277d6a9 100644 --- a/components/script/dom/htmlselectelement.rs +++ b/components/script/dom/htmlselectelement.rs @@ -23,6 +23,8 @@ use dom::virtualmethods::VirtualMethods; use servo_util::str::DOMString; use string_cache::Atom; +use std::borrow::ToOwned; + #[dom_struct] pub struct HTMLSelectElement { htmlelement: HTMLElement @@ -68,9 +70,9 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> { fn Type(self) -> DOMString { let elem: JSRef<Element> = ElementCast::from_ref(self); if elem.has_attribute(&atom!("multiple")) { - "select-multiple".into_string() + "select-multiple".to_owned() } else { - "select-one".into_string() + "select-one".to_owned() } } } diff --git a/components/script/dom/htmlserializer.rs b/components/script/dom/htmlserializer.rs index b4c3662fd30..a0ab5b82d03 100644 --- a/components/script/dom/htmlserializer.rs +++ b/components/script/dom/htmlserializer.rs @@ -15,6 +15,8 @@ use dom::node::{Node, NodeHelpers, NodeTypeId, NodeIterator}; use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; +use std::borrow::ToOwned; + #[allow(unrooted_must_root)] pub fn serialize(iterator: &mut NodeIterator) -> String { let mut html = String::new(); @@ -126,7 +128,7 @@ fn serialize_elem(elem: JSRef<Element>, open_elements: &mut Vec<String>, html: & } if !(elem.is_void()) { - open_elements.push(elem.local_name().as_slice().into_string()); + open_elements.push(elem.local_name().as_slice().to_owned()); } } diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index c5d3c1593c1..8ede6e716ae 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -29,6 +29,7 @@ use dom::virtualmethods::VirtualMethods; use servo_util::str::DOMString; use string_cache::Atom; +use std::borrow::ToOwned; use std::cell::Cell; #[dom_struct] @@ -83,7 +84,7 @@ impl HTMLTextAreaElement { fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLTextAreaElement { HTMLTextAreaElement { htmlelement: HTMLElement::new_inherited(HTMLElementTypeId::HTMLTextAreaElement, localName, prefix, document), - textinput: DOMRefCell::new(TextInput::new(Lines::Multiple, "".into_string())), + textinput: DOMRefCell::new(TextInput::new(Lines::Multiple, "".to_owned())), cols: Cell::new(DEFAULT_COLS), rows: Cell::new(DEFAULT_ROWS), value_changed: Cell::new(false), @@ -151,7 +152,7 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> { // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-type fn Type(self) -> DOMString { - "textarea".into_string() + "textarea".to_owned() } // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-defaultvalue diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs index e28f1c90c6c..cf4cadca3a1 100644 --- a/components/script/dom/keyboardevent.rs +++ b/components/script/dom/keyboardevent.rs @@ -15,6 +15,8 @@ use dom::uievent::UIEvent; use dom::window::Window; use servo_msg::constellation_msg; use servo_util::str::DOMString; + +use std::borrow::ToOwned; use std::cell::{RefCell, Cell}; #[jstraceable] @@ -44,8 +46,8 @@ impl KeyboardEvent { fn new_inherited() -> KeyboardEvent { KeyboardEvent { uievent: UIEvent::new_inherited(EventTypeId::KeyboardEvent), - key: RefCell::new("".into_string()), - code: RefCell::new("".into_string()), + key: RefCell::new("".to_owned()), + code: RefCell::new("".to_owned()), location: Cell::new(0), ctrl: Cell::new(false), alt: Cell::new(false), @@ -83,7 +85,7 @@ impl KeyboardEvent { key_code: u32) -> Temporary<KeyboardEvent> { let ev = KeyboardEvent::new_uninitialized(window).root(); ev.r().InitKeyboardEvent(type_, canBubble, cancelable, view, key, location, - "".into_string(), repeat, "".into_string()); + "".to_owned(), repeat, "".to_owned()); *ev.r().code.borrow_mut() = code; ev.r().ctrl.set(ctrlKey); ev.r().alt.set(altKey); diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index e67f04b30ba..646baabf785 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -106,13 +106,14 @@ macro_rules! make_enumerated_getter( use dom::bindings::codegen::InheritTypes::ElementCast; #[allow(unused_imports)] use std::ascii::AsciiExt; + use std::borrow::ToOwned; let element: JSRef<Element> = ElementCast::from_ref(self); let val = element.get_string_attribute(&Atom::from_slice($htmlname)) .into_ascii_lower(); // https://html.spec.whatwg.org/multipage/forms.html#attr-fs-method match val.as_slice() { $($choices)|+ => val, - _ => $default.into_string() + _ => $default.to_owned() } } ); diff --git a/components/script/dom/messageevent.rs b/components/script/dom/messageevent.rs index 976c7520378..7cae6302073 100644 --- a/components/script/dom/messageevent.rs +++ b/components/script/dom/messageevent.rs @@ -18,6 +18,8 @@ use servo_util::str::DOMString; use js::jsapi::JSContext; use js::jsval::{JSVal, UndefinedValue}; +use std::borrow::ToOwned; + #[dom_struct] pub struct MessageEvent { event: Event, @@ -44,7 +46,7 @@ impl MessageEvent { } pub fn new_uninitialized(global: GlobalRef) -> Temporary<MessageEvent> { - MessageEvent::new_initialized(global, UndefinedValue(), "".into_string(), "".into_string()) + MessageEvent::new_initialized(global, UndefinedValue(), "".to_owned(), "".to_owned()) } pub fn new_initialized(global: GlobalRef, data: JSVal, origin: DOMString, lastEventId: DOMString) -> Temporary<MessageEvent> { @@ -78,8 +80,8 @@ impl MessageEvent { scope: GlobalRef, message: JSVal) { let messageevent = MessageEvent::new( - scope, "message".into_string(), false, false, message, - "".into_string(), "".into_string()).root(); + scope, "message".to_owned(), false, false, message, + "".to_owned(), "".to_owned()).root(); let event: JSRef<Event> = EventCast::from_ref(messageevent.r()); target.dispatch_event(event); } diff --git a/components/script/dom/navigatorinfo.rs b/components/script/dom/navigatorinfo.rs index 0dff42d88ea..b8fabd01acf 100644 --- a/components/script/dom/navigatorinfo.rs +++ b/components/script/dom/navigatorinfo.rs @@ -5,8 +5,10 @@ use servo_util::str::DOMString; use servo_util::opts; +use std::borrow::ToOwned; + pub fn Product() -> DOMString { - "Gecko".into_string() + "Gecko".to_owned() } pub fn TaintEnabled() -> bool { @@ -14,20 +16,20 @@ pub fn TaintEnabled() -> bool { } pub fn AppName() -> DOMString { - "Netscape".into_string() // Like Gecko/Webkit + "Netscape".to_owned() // Like Gecko/Webkit } pub fn AppCodeName() -> DOMString { - "Mozilla".into_string() + "Mozilla".to_owned() } pub fn Platform() -> DOMString { - "".into_string() + "".to_owned() } pub fn UserAgent() -> DOMString { match opts::get().user_agent { Some(ref user_agent) => user_agent.clone(), - None => "".into_string(), + None => "".to_owned(), } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 83c14208cbb..d65a82880c5 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -54,6 +54,7 @@ use js::jsapi::{JSContext, JSObject, JSTracer, JSRuntime}; use js::jsfriendapi; use libc; use libc::{uintptr_t, c_void}; +use std::borrow::ToOwned; use std::cell::{Cell, RefCell, Ref, RefMut}; use std::default::Default; use std::iter::{FilterMap, Peekable}; @@ -854,17 +855,17 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { NodeInfo { uniqueId: self.unique_id.borrow().clone(), - baseURI: self.GetBaseURI().unwrap_or("".into_string()), - parent: self.GetParentNode().root().map(|node| node.r().get_unique_id()).unwrap_or("".into_string()), + baseURI: self.GetBaseURI().unwrap_or("".to_owned()), + parent: self.GetParentNode().root().map(|node| node.r().get_unique_id()).unwrap_or("".to_owned()), nodeType: self.NodeType() as uint, - namespaceURI: "".into_string(), //FIXME + namespaceURI: "".to_owned(), //FIXME nodeName: self.NodeName(), numChildren: self.ChildNodes().root().r().Length() as uint, //FIXME doctype nodes only - name: "".into_string(), - publicId: "".into_string(), - systemId: "".into_string(), + name: "".to_owned(), + publicId: "".to_owned(), + systemId: "".to_owned(), attrs: match ElementCast::to_ref(self) { Some(element) => element.summarize(), @@ -878,7 +879,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { .map(|elem| NodeCast::from_ref(elem.root().r()) == self) .unwrap_or(false), - shortValue: self.GetNodeValue().unwrap_or("".into_string()), //FIXME: truncate + shortValue: self.GetNodeValue().unwrap_or("".to_owned()), //FIXME: truncate incompleteValue: false, //FIXME: reflect truncation } } @@ -1567,7 +1568,7 @@ impl Node { local: element.local_name().clone() }; let element = Element::create(name, - element.prefix().as_ref().map(|p| p.as_slice().into_string()), + element.prefix().as_ref().map(|p| p.as_slice().to_owned()), document.r(), ElementCreator::ScriptCreated); NodeCast::from_temporary(element) }, @@ -1680,19 +1681,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> { let elem: JSRef<Element> = ElementCast::to_ref(self).unwrap(); elem.TagName() } - NodeTypeId::Text => "#text".into_string(), + NodeTypeId::Text => "#text".to_owned(), NodeTypeId::ProcessingInstruction => { let processing_instruction: JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(self).unwrap(); processing_instruction.Target() } - NodeTypeId::Comment => "#comment".into_string(), + NodeTypeId::Comment => "#comment".to_owned(), NodeTypeId::DocumentType => { let doctype: JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap(); doctype.name().clone() }, - NodeTypeId::DocumentFragment => "#document-fragment".into_string(), - NodeTypeId::Document => "#document".into_string() + NodeTypeId::DocumentFragment => "#document-fragment".to_owned(), + NodeTypeId::Document => "#document".to_owned() } } diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index fc222a4f604..2d0b58ec923 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -22,6 +22,8 @@ use servo_util::str::DOMString; use js::jsapi::{JSContext, JSObject}; use js::jsval::{JSVal, NullValue}; +use std::borrow::ToOwned; + #[dom_struct] pub struct TestBinding { reflector: Reflector, @@ -51,7 +53,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn SetFloatAttribute(self, _: f32) {} fn DoubleAttribute(self) -> f64 { 0. } fn SetDoubleAttribute(self, _: f64) {} - fn StringAttribute(self) -> DOMString { "".into_string() } + fn StringAttribute(self) -> DOMString { "".to_owned() } fn SetStringAttribute(self, _: DOMString) {} fn ByteStringAttribute(self) -> ByteString { ByteString::new(vec!()) } fn SetByteStringAttribute(self, _: ByteString) {} @@ -64,7 +66,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn SetInterfaceAttribute(self, _: JSRef<Blob>) {} fn UnionAttribute(self) -> HTMLElementOrLong { eLong(0) } fn SetUnionAttribute(self, _: HTMLElementOrLong) {} - fn Union2Attribute(self) -> EventOrString { eString("".into_string()) } + fn Union2Attribute(self) -> EventOrString { eString("".to_owned()) } fn SetUnion2Attribute(self, _: EventOrString) {} fn ArrayAttribute(self, _: *mut JSContext) -> *mut JSObject { NullValue().to_object_or_null() } fn AnyAttribute(self, _: *mut JSContext) -> JSVal { NullValue() } @@ -94,7 +96,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn SetDoubleAttributeNullable(self, _: Option<f64>) {} fn GetByteStringAttributeNullable(self) -> Option<ByteString> { Some(ByteString::new(vec!())) } fn SetByteStringAttributeNullable(self, _: Option<ByteString>) {} - fn GetStringAttributeNullable(self) -> Option<DOMString> { Some("".into_string()) } + fn GetStringAttributeNullable(self) -> Option<DOMString> { Some("".to_owned()) } fn SetStringAttributeNullable(self, _: Option<DOMString>) {} fn GetEnumAttributeNullable(self) -> Option<TestEnum> { Some(_empty) } fn GetInterfaceAttributeNullable(self) -> Option<Temporary<Blob>> { @@ -104,7 +106,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn SetInterfaceAttributeNullable(self, _: Option<JSRef<Blob>>) {} fn GetUnionAttributeNullable(self) -> Option<HTMLElementOrLong> { Some(eLong(0)) } fn SetUnionAttributeNullable(self, _: Option<HTMLElementOrLong>) {} - fn GetUnion2AttributeNullable(self) -> Option<EventOrString> { Some(eString("".into_string())) } + fn GetUnion2AttributeNullable(self) -> Option<EventOrString> { Some(eString("".to_owned())) } fn SetUnion2AttributeNullable(self, _: Option<EventOrString>) {} fn ReceiveVoid(self) -> () {} fn ReceiveBoolean(self) -> bool { false } @@ -118,7 +120,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn ReceiveUnsignedLongLong(self) -> u64 { 0 } fn ReceiveFloat(self) -> f32 { 0. } fn ReceiveDouble(self) -> f64 { 0. } - fn ReceiveString(self) -> DOMString { "".into_string() } + fn ReceiveString(self) -> DOMString { "".to_owned() } fn ReceiveByteString(self) -> ByteString { ByteString::new(vec!()) } fn ReceiveEnum(self) -> TestEnum { _empty } fn ReceiveInterface(self) -> Temporary<Blob> { @@ -127,7 +129,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { } fn ReceiveAny(self, _: *mut JSContext) -> JSVal { NullValue() } fn ReceiveUnion(self) -> HTMLElementOrLong { eLong(0) } - fn ReceiveUnion2(self) -> EventOrString { eString("".into_string()) } + fn ReceiveUnion2(self) -> EventOrString { eString("".to_owned()) } fn ReceiveNullableBoolean(self) -> Option<bool> { Some(false) } fn ReceiveNullableByte(self) -> Option<i8> { Some(0) } @@ -140,7 +142,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { fn ReceiveNullableUnsignedLongLong(self) -> Option<u64> { Some(0) } fn ReceiveNullableFloat(self) -> Option<f32> { Some(0.) } fn ReceiveNullableDouble(self) -> Option<f64> { Some(0.) } - fn ReceiveNullableString(self) -> Option<DOMString> { Some("".into_string()) } + fn ReceiveNullableString(self) -> Option<DOMString> { Some("".to_owned()) } fn ReceiveNullableByteString(self) -> Option<ByteString> { Some(ByteString::new(vec!())) } fn ReceiveNullableEnum(self) -> Option<TestEnum> { Some(_empty) } fn ReceiveNullableInterface(self) -> Option<Temporary<Blob>> { @@ -148,7 +150,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> { Some(Blob::new(global.r(), None, "")) } fn ReceiveNullableUnion(self) -> Option<HTMLElementOrLong> { Some(eLong(0)) } - fn ReceiveNullableUnion2(self) -> Option<EventOrString> { Some(eString("".into_string())) } + fn ReceiveNullableUnion2(self) -> Option<EventOrString> { Some(eString("".to_owned())) } fn PassBoolean(self, _: bool) {} fn PassByte(self, _: i8) {} diff --git a/components/script/dom/urlhelper.rs b/components/script/dom/urlhelper.rs index 8f3a005127d..290fede857c 100644 --- a/components/script/dom/urlhelper.rs +++ b/components/script/dom/urlhelper.rs @@ -5,6 +5,8 @@ use servo_util::str::DOMString; use url::Url; +use std::borrow::ToOwned; + pub struct UrlHelper; impl UrlHelper { @@ -14,16 +16,16 @@ impl UrlHelper { pub fn Search(url: &Url) -> DOMString { match url.query { - None => "".into_string(), - Some(ref query) if query.as_slice() == "" => "".into_string(), + None => "".to_owned(), + Some(ref query) if query.as_slice() == "" => "".to_owned(), Some(ref query) => format!("?{}", query) } } pub fn Hash(url: &Url) -> DOMString { match url.fragment { - None => "".into_string(), - Some(ref hash) if hash.as_slice() == "" => "".into_string(), + None => "".to_owned(), + Some(ref hash) if hash.as_slice() == "" => "".to_owned(), Some(ref hash) => format!("#{}", hash) } } diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index a5d5c767a72..4572d3221c7 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -50,6 +50,7 @@ use servo_util::str::DOMString; use servo_util::task::spawn_named; use std::ascii::AsciiExt; +use std::borrow::ToOwned; use std::cell::Cell; use std::comm::{Sender, Receiver, channel}; use std::default::Default; @@ -168,7 +169,7 @@ impl XMLHttpRequest { timeout: Cell::new(0u32), with_credentials: Cell::new(false), upload: JS::from_rooted(XMLHttpRequestUpload::new(global)), - response_url: "".into_string(), + response_url: "".to_owned(), status: Cell::new(0), status_text: DOMRefCell::new(ByteString::new(vec!())), response: DOMRefCell::new(ByteString::new(vec!())), @@ -454,7 +455,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { None => {} } - headers.set_raw(name_str.into_string(), vec![value.as_slice().to_vec()]); + headers.set_raw(name_str.to_owned(), vec![value.as_slice().to_vec()]); Ok(()) } fn Timeout(self) -> u32 { @@ -525,12 +526,12 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { // If one of the event handlers below aborts the fetch by calling // abort or open we will need the current generation id to detect it. let gen_id = self.generation_id.get(); - self.dispatch_response_progress_event("loadstart".into_string()); + self.dispatch_response_progress_event("loadstart".to_owned()); if self.generation_id.get() != gen_id { return Ok(()); } if !self.upload_complete.get() { - self.dispatch_upload_progress_event("loadstart".into_string(), Some(0)); + self.dispatch_upload_progress_event("loadstart".to_owned(), Some(0)); if self.generation_id.get() != gen_id { return Ok(()); } @@ -562,10 +563,10 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { let n = "content-type"; match data { Some(eString(_)) => - request_headers.set_raw(n.into_string(), vec![join_raw("text/plain", params)]), + request_headers.set_raw(n.to_owned(), vec![join_raw("text/plain", params)]), Some(eURLSearchParams(_)) => request_headers.set_raw( - n.into_string(), vec![join_raw("application/x-www-form-urlencoded", params)]), + n.to_owned(), vec![join_raw("application/x-www-form-urlencoded", params)]), None => () } } @@ -602,9 +603,9 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { buf.push_str(format!("{}", p).as_slice()); }); referer_url.serialize_path().map(|ref h| buf.push_str(h.as_slice())); - self.request_headers.borrow_mut().set_raw("Referer".into_string(), vec![buf.into_bytes()]); + self.request_headers.borrow_mut().set_raw("Referer".to_owned(), vec![buf.into_bytes()]); }, - Ok(Some(ref req)) => self.insert_trusted_header("origin".into_string(), + Ok(Some(ref req)) => self.insert_trusted_header("origin".to_owned(), format!("{}", req.origin)), _ => {} } @@ -705,7 +706,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { }, _ if self.ready_state.get() != XMLHttpRequestState::XHRDone => NullValue(), Json => { - let decoded = UTF_8.decode(self.response.borrow().as_slice(), DecoderTrap::Replace).unwrap().into_string(); + let decoded = UTF_8.decode(self.response.borrow().as_slice(), DecoderTrap::Replace).unwrap().to_owned(); let decoded: Vec<u16> = decoded.as_slice().utf16_units().collect(); let mut vp = UndefinedValue(); unsafe { @@ -727,7 +728,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { _empty | Text => { match self.ready_state.get() { XMLHttpRequestState::Loading | XMLHttpRequestState::XHRDone => Ok(self.text_response()), - _ => Ok("".into_string()) + _ => Ok("".to_owned()) } }, _ => Err(InvalidState) @@ -770,7 +771,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { self.ready_state.set(rs); let global = self.global.root(); let event = Event::new(global.r(), - "readystatechange".into_string(), + "readystatechange".to_owned(), EventBubbles::DoesNotBubble, EventCancelable::Cancelable).root(); let target: JSRef<EventTarget> = EventTargetCast::from_ref(self); @@ -804,11 +805,11 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { self.upload_complete.set(true); // Substeps 2-4 if !self.sync.get() { - self.dispatch_upload_progress_event("progress".into_string(), None); + self.dispatch_upload_progress_event("progress".to_owned(), None); return_if_fetch_was_terminated!(); - self.dispatch_upload_progress_event("load".into_string(), None); + self.dispatch_upload_progress_event("load".to_owned(), None); return_if_fetch_was_terminated!(); - self.dispatch_upload_progress_event("loadend".into_string(), None); + self.dispatch_upload_progress_event("loadend".to_owned(), None); return_if_fetch_was_terminated!(); } // Part of step 13, send() (processing response) @@ -836,7 +837,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { self.change_ready_state(XMLHttpRequestState::Loading); return_if_fetch_was_terminated!(); } - self.dispatch_response_progress_event("progress".into_string()); + self.dispatch_response_progress_event("progress".to_owned()); } }, XHRProgress::Done(_) => { @@ -852,11 +853,11 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { self.change_ready_state(XMLHttpRequestState::XHRDone); return_if_fetch_was_terminated!(); // Subsubsteps 10-12 - self.dispatch_response_progress_event("progress".into_string()); + self.dispatch_response_progress_event("progress".to_owned()); return_if_fetch_was_terminated!(); - self.dispatch_response_progress_event("load".into_string()); + self.dispatch_response_progress_event("load".to_owned()); return_if_fetch_was_terminated!(); - self.dispatch_response_progress_event("loadend".into_string()); + self.dispatch_response_progress_event("loadend".to_owned()); }, XHRProgress::Errored(_, e) => { self.send_flag.set(false); @@ -873,18 +874,18 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { let upload_complete: &Cell<bool> = &self.upload_complete; if !upload_complete.get() { upload_complete.set(true); - self.dispatch_upload_progress_event("progress".into_string(), None); + self.dispatch_upload_progress_event("progress".to_owned(), None); return_if_fetch_was_terminated!(); - self.dispatch_upload_progress_event(errormsg.into_string(), None); + self.dispatch_upload_progress_event(errormsg.to_owned(), None); return_if_fetch_was_terminated!(); - self.dispatch_upload_progress_event("loadend".into_string(), None); + self.dispatch_upload_progress_event("loadend".to_owned(), None); return_if_fetch_was_terminated!(); } - self.dispatch_response_progress_event("progress".into_string()); + self.dispatch_response_progress_event("progress".to_owned()); return_if_fetch_was_terminated!(); - self.dispatch_response_progress_event(errormsg.into_string()); + self.dispatch_response_progress_event(errormsg.to_owned()); return_if_fetch_was_terminated!(); - self.dispatch_response_progress_event("loadend".into_string()); + self.dispatch_response_progress_event("loadend".to_owned()); } } } @@ -970,7 +971,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { // According to Simon, decode() should never return an error, so unwrap()ing // the result should be fine. XXXManishearth have a closer look at this later - encoding.decode(self.response.borrow().as_slice(), DecoderTrap::Replace).unwrap().into_string() + encoding.decode(self.response.borrow().as_slice(), DecoderTrap::Replace).unwrap().to_owned() } fn filter_response_headers(self) -> Headers { // http://fetch.spec.whatwg.org/#concept-response-header-list |