diff options
Diffstat (limited to 'src/components/script')
38 files changed, 300 insertions, 267 deletions
diff --git a/src/components/script/dom/attr.rs b/src/components/script/dom/attr.rs index a7137a4c8a2..a44e9e3f111 100644 --- a/src/components/script/dom/attr.rs +++ b/src/components/script/dom/attr.rs @@ -120,7 +120,7 @@ impl<'a> AttrMethods for JSRef<'a, Attr> { fn GetNamespaceURI(&self) -> Option<DOMString> { match self.namespace.to_str() { "" => None, - url => Some(url.to_owned()), + url => Some(url.to_string()), } } diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 62cb66d5f1f..171301ac7d4 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -641,7 +641,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, default = "None" else: assert defaultValue.type.tag() == IDLType.Tags.domstring - value = "str::from_utf8(data).unwrap().to_owned()" + value = "str::from_utf8(data).unwrap().to_string()" if type.nullable(): value = "Some(%s)" % value @@ -691,7 +691,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, " Ok(None) => { %(handleInvalidEnumValueCode)s },\n" " Ok(Some(index)) => {\n" " //XXXjdm need some range checks up in here.\n" - " unsafe { cast::transmute(index) }\n" + " unsafe { mem::transmute(index) }\n" " },\n" "}" % { "values" : enum + "Values::strings", "exceptionCode" : exceptionCode, @@ -2130,7 +2130,7 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod): trace: Some(%s) }; js_info.dom_static.proxy_handlers.insert(PrototypeList::id::%s as uint, - CreateProxyHandler(&traps, cast::transmute(&Class))); + CreateProxyHandler(&traps, mem::transmute(&Class))); """ % (FINALIZE_HOOK_NAME, TRACE_HOOK_NAME, @@ -2673,7 +2673,7 @@ pub static strings: &'static [&'static str] = &[ impl ToJSValConvertible for valuelist { fn to_jsval(&self, cx: *mut JSContext) -> JSVal { - strings[*self as uint].to_owned().to_jsval(cx) + strings[*self as uint].to_string().to_jsval(cx) } } """ % (",\n ".join(map(getEnumValueName, enum.values())), @@ -3821,7 +3821,7 @@ class CGAbstractClassHook(CGAbstractExternMethod): def finalizeHook(descriptor, hookName, context): release = """let val = JS_GetReservedSlot(obj, dom_object_slot(obj)); -let _: Box<%s> = cast::transmute(val.to_private()); +let _: Box<%s> = mem::transmute(val.to_private()); debug!("%s finalize: {:p}", this); """ % (descriptor.concreteType, descriptor.concreteType) return release @@ -4343,7 +4343,7 @@ class CGBindingRoot(CGThing): 'script_task::JSPageInfo', 'libc', 'servo_util::str::DOMString', - 'std::cast', + 'std::mem', 'std::cmp', 'std::ptr', 'std::str', diff --git a/src/components/script/dom/bindings/codegen/GlobalGen.py b/src/components/script/dom/bindings/codegen/GlobalGen.py index aa820d497b8..cdca464e029 100644 --- a/src/components/script/dom/bindings/codegen/GlobalGen.py +++ b/src/components/script/dom/bindings/codegen/GlobalGen.py @@ -17,9 +17,7 @@ from CodegenRust import GlobalGenRoots, replaceFileIfChanged # import Codegen in general, so we can set a variable on it import Codegen -def generate_file(config, name): - filename = name + '.rs' - +def generate_file(config, name, filename): root = getattr(GlobalGenRoots, name)(config) code = root.define() @@ -65,21 +63,21 @@ def main(): config = Configuration(configFile, parserResults) # Generate the prototype list. - generate_file(config, 'PrototypeList') + generate_file(config, 'PrototypeList', 'PrototypeList.rs') # Generate the common code. - generate_file(config, 'RegisterBindings') + generate_file(config, 'RegisterBindings', 'RegisterBindings.rs') # Generate the type list. - generate_file(config, 'InterfaceTypes') + generate_file(config, 'InterfaceTypes', 'InterfaceTypes.rs') # Generate the type list. - generate_file(config, 'InheritTypes') + generate_file(config, 'InheritTypes', 'InheritTypes.rs') # Generate the module declarations. - generate_file(config, 'Bindings') + generate_file(config, 'Bindings', 'Bindings/mod.rs') - generate_file(config, 'UnionTypes') + generate_file(config, 'UnionTypes', 'UnionTypes.rs') if __name__ == '__main__': main() diff --git a/src/components/script/dom/bindings/conversions.rs b/src/components/script/dom/bindings/conversions.rs index 867e07ade30..96dc946a3d2 100644 --- a/src/components/script/dom/bindings/conversions.rs +++ b/src/components/script/dom/bindings/conversions.rs @@ -60,7 +60,7 @@ impl ToJSValConvertible for JSVal { unsafe fn convert_from_jsval<T: Default>( cx: *mut JSContext, value: JSVal, - convert_fn: extern "C" unsafe fn(*mut JSContext, JSVal, *mut T) -> JSBool) -> Result<T, ()> { + convert_fn: unsafe extern "C" fn(*mut JSContext, JSVal, *mut T) -> JSBool) -> Result<T, ()> { let mut ret = Default::default(); if convert_fn(cx, value, &mut ret) == 0 { Err(()) @@ -243,7 +243,7 @@ impl Default for StringificationBehavior { impl FromJSValConvertible<StringificationBehavior> for DOMString { fn from_jsval(cx: *mut JSContext, value: JSVal, nullBehavior: StringificationBehavior) -> Result<DOMString, ()> { if nullBehavior == Empty && value.is_null() { - Ok("".to_owned()) + Ok("".to_string()) } else { let jsstr = unsafe { JS_ValueToString(cx, value) }; if jsstr.is_null() { diff --git a/src/components/script/dom/bindings/js.rs b/src/components/script/dom/bindings/js.rs index 89898a35ba0..0f96f3e33e6 100644 --- a/src/components/script/dom/bindings/js.rs +++ b/src/components/script/dom/bindings/js.rs @@ -46,9 +46,9 @@ use js::jsapi::{JSObject, JS_AddObjectRoot, JS_RemoveObjectRoot}; use layout_interface::TrustedNodeAddress; use script_task::StackRoots; -use std::cast; use std::cell::{Cell, RefCell}; use std::kinds::marker::ContravariantLifetime; +use std::mem; /// A type that represents a JS-owned value that is rooted for the lifetime of this value. /// Importantly, it requires explicit rooting in order to interact with the inner value. @@ -105,7 +105,7 @@ impl<T: Reflectable> Temporary<T> { //XXXjdm It would be lovely if this could be private. pub unsafe fn transmute<To>(self) -> Temporary<To> { - cast::transmute(self) + mem::transmute(self) } } @@ -195,7 +195,7 @@ impl<T: Reflectable> JS<T> { /// flags. This is the only method that be safely accessed from layout. (The fact that this /// is unsafe is what necessitates the layout wrappers.) pub unsafe fn unsafe_get(&self) -> *mut T { - cast::transmute_copy(&self.ptr) + mem::transmute_copy(&self.ptr) } /// Store an unrooted value in this field. This is safe under the assumption that JS<T> @@ -209,11 +209,11 @@ impl<T: Reflectable> JS<T> { impl<From, To> JS<From> { //XXXjdm It would be lovely if this could be private. pub unsafe fn transmute(self) -> JS<To> { - cast::transmute(self) + mem::transmute(self) } pub unsafe fn transmute_copy(&self) -> JS<To> { - cast::transmute_copy(self) + mem::transmute_copy(self) } } @@ -492,12 +492,12 @@ impl<'a, T> Eq for JSRef<'a, T> { impl<'a,T> JSRef<'a,T> { //XXXjdm It would be lovely if this could be private. pub unsafe fn transmute<'b, To>(&'b self) -> &'b JSRef<'a, To> { - cast::transmute(self) + mem::transmute(self) } //XXXjdm It would be lovely if this could be private. pub unsafe fn transmute_mut<'b, To>(&'b mut self) -> &'b mut JSRef<'a, To> { - cast::transmute(self) + mem::transmute(self) } pub fn unrooted(&self) -> JS<T> { diff --git a/src/components/script/dom/bindings/proxyhandler.rs b/src/components/script/dom/bindings/proxyhandler.rs index 07b881cf287..0f573df6edc 100644 --- a/src/components/script/dom/bindings/proxyhandler.rs +++ b/src/components/script/dom/bindings/proxyhandler.rs @@ -14,7 +14,7 @@ use js::glue::InvokeGetOwnPropertyDescriptor; use js::{JSPROP_GETTER, JSPROP_ENUMERATE, JSPROP_READONLY, JSRESOLVE_QUALIFIED}; use libc; -use std::cast; +use std::mem; use std::ptr; use std::str; use std::mem::size_of; @@ -39,7 +39,7 @@ pub extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject, id return 1; } - JS_GetPropertyDescriptorById(cx, proto, id, JSRESOLVE_QUALIFIED, cast::transmute(desc)) + JS_GetPropertyDescriptorById(cx, proto, id, JSRESOLVE_QUALIFIED, mem::transmute(desc)) } } @@ -47,8 +47,8 @@ pub fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, desc: *JSPropertyDescriptor) -> JSBool { unsafe { //FIXME: Workaround for https://github.com/mozilla/rust/issues/13385 - let setter: *libc::c_void = cast::transmute((*desc).setter); - let setter_stub: *libc::c_void = cast::transmute(JS_StrictPropertyStub); + let setter: *libc::c_void = mem::transmute((*desc).setter); + let setter_stub: *libc::c_void = mem::transmute(JS_StrictPropertyStub); if ((*desc).attrs & JSPROP_GETTER) != 0 && setter == setter_stub { /*return JS_ReportErrorFlagsAndNumber(cx, JSREPORT_WARNING | JSREPORT_STRICT | @@ -82,7 +82,8 @@ pub fn _obj_toString(cx: *mut JSContext, className: *libc::c_char) -> *mut JSStr return ptr::mut_null(); } - let result = "[object ".to_owned() + name + "]"; + let result = format!("[object {}]", name); + let result = result.as_slice(); for (i, c) in result.chars().enumerate() { *chars.offset(i as int) = c as jschar; } diff --git a/src/components/script/dom/bindings/trace.rs b/src/components/script/dom/bindings/trace.rs index 9c7f295795e..0c2388ae44c 100644 --- a/src/components/script/dom/bindings/trace.rs +++ b/src/components/script/dom/bindings/trace.rs @@ -9,7 +9,7 @@ use js::jsapi::{JSObject, JSTracer, JS_CallTracer, JSTRACE_OBJECT}; use js::jsval::JSVal; use libc; -use std::cast; +use std::mem; use std::cell::{Cell, RefCell}; use serialize::{Encodable, Encoder}; @@ -20,7 +20,7 @@ use serialize::{Encodable, Encoder}; fn get_jstracer<'a, S: Encoder<E>, E>(s: &'a mut S) -> &'a mut JSTracer { unsafe { - cast::transmute(s) + mem::transmute(s) } } diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 7dc751bfbdb..ff3300ad6e3 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -14,7 +14,7 @@ use servo_util::str::DOMString; use collections::hashmap::HashMap; use libc; use libc::c_uint; -use std::cast; +use std::mem; use std::cmp::Eq; use std::ptr; use std::ptr::null; @@ -141,7 +141,7 @@ pub fn unwrap_jsmanaged<T: Reflectable>(mut obj: *mut JSObject, } pub unsafe fn squirrel_away_unique<T>(x: Box<T>) -> *T { - cast::transmute(x) + mem::transmute(x) } pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString { diff --git a/src/components/script/dom/characterdata.rs b/src/components/script/dom/characterdata.rs index 88c13f668a3..c4fe6700a3a 100644 --- a/src/components/script/dom/characterdata.rs +++ b/src/components/script/dom/characterdata.rs @@ -66,11 +66,11 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { } fn SubstringData(&self, offset: u32, count: u32) -> Fallible<DOMString> { - Ok(self.data.slice(offset as uint, count as uint).to_str()) + Ok(self.data.as_slice().slice(offset as uint, count as uint).to_str()) } fn AppendData(&mut self, arg: DOMString) -> ErrorResult { - self.data = self.data + arg; + self.data.push_str(arg.as_slice()); Ok(()) } @@ -79,7 +79,7 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { } fn DeleteData(&mut self, offset: u32, count: u32) -> ErrorResult { - self.ReplaceData(offset, count, "".to_owned()) + self.ReplaceData(offset, count, "".to_string()) } fn ReplaceData(&mut self, offset: u32, count: u32, arg: DOMString) -> ErrorResult { @@ -92,9 +92,9 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { } else { count }; - let mut data = self.data.slice(0, offset as uint).to_strbuf(); - data.push_str(arg); - data.push_str(self.data.slice((offset + count) as uint, length as uint)); + let mut data = self.data.as_slice().slice(0, offset as uint).to_string(); + data.push_str(arg.as_slice()); + data.push_str(self.data.as_slice().slice((offset + count) as uint, length as uint)); self.data = data.into_owned(); // FIXME: Once we have `Range`, we should implement step7 to step11 Ok(()) diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 8672da19b55..a00a12c26de 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -219,16 +219,16 @@ impl Document { Some(string) => string.clone(), None => match is_html_document { // http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument - HTMLDocument => "text/html".to_owned(), + HTMLDocument => "text/html".to_string(), // http://dom.spec.whatwg.org/#concept-document-content-type - NonHTMLDocument => "application/xml".to_owned() + NonHTMLDocument => "application/xml".to_string() } }, url: Untraceable::new(url), // http://dom.spec.whatwg.org/#concept-document-quirks quirks_mode: Untraceable::new(NoQuirks), // http://dom.spec.whatwg.org/#concept-document-encoding - encoding_name: "utf-8".to_owned(), + encoding_name: "utf-8".to_string(), is_html_document: is_html_document == HTMLDocument, } } @@ -355,14 +355,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-compatmode fn CompatMode(&self) -> DOMString { match *self.quirks_mode { - NoQuirks => "CSS1Compat".to_owned(), - LimitedQuirks | FullQuirks => "BackCompat".to_owned() + NoQuirks => "CSS1Compat".to_string(), + LimitedQuirks | FullQuirks => "BackCompat".to_string() } } // http://dom.spec.whatwg.org/#dom-document-characterset fn CharacterSet(&self) -> DOMString { - self.encoding_name.to_ascii_lower() + self.encoding_name.as_slice().to_ascii_lower() } // http://dom.spec.whatwg.org/#dom-document-content_type @@ -398,7 +398,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { let window = self.window.root(); let namespace = match maybe_ns { - Some(namespace) => Namespace::from_str(namespace), + Some(namespace) => Namespace::from_str(namespace.as_slice()), None => Null }; HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), tag_name, namespace) @@ -421,11 +421,11 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-createelement fn CreateElement(&self, local_name: DOMString) -> Fallible<Temporary<Element>> { - if xml_name_type(local_name) == InvalidXMLName { + if xml_name_type(local_name.as_slice()) == InvalidXMLName { debug!("Not a valid element name"); return Err(InvalidCharacter); } - let local_name = local_name.to_ascii_lower(); + let local_name = local_name.as_slice().to_ascii_lower(); Ok(build_element_from_tag(local_name, self)) } @@ -434,7 +434,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { namespace: Option<DOMString>, qualified_name: DOMString) -> Fallible<Temporary<Element>> { let ns = Namespace::from_str(null_str_as_empty_ref(&namespace)); - match xml_name_type(qualified_name) { + match xml_name_type(qualified_name.as_slice()) { InvalidXMLName => { debug!("Not a valid element name"); return Err(InvalidCharacter); @@ -454,12 +454,12 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { return Err(NamespaceError); }, // throw if prefix is "xml" and namespace is not the XML namespace - (_, Some(ref prefix), _) if "xml" == *prefix && ns != namespace::XML => { + (_, Some(ref prefix), _) if "xml" == prefix.as_slice() && ns != namespace::XML => { debug!("Namespace must be the xml namespace if the prefix is 'xml'"); return Err(NamespaceError); }, // throw if namespace is the XMLNS namespace and neither qualifiedName nor prefix is "xmlns" - (&namespace::XMLNS, Some(ref prefix), _) if "xmlns" == *prefix => {}, + (&namespace::XMLNS, Some(ref prefix), _) if "xmlns" == prefix.as_slice() => {}, (&namespace::XMLNS, _, "xmlns") => {}, (&namespace::XMLNS, _, _) => { debug!("The prefix or the qualified name must be 'xmlns' if namespace is the XMLNS namespace "); @@ -495,12 +495,12 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn CreateProcessingInstruction(&self, target: DOMString, data: DOMString) -> Fallible<Temporary<ProcessingInstruction>> { // Step 1. - if xml_name_type(target) == InvalidXMLName { + if xml_name_type(target.as_slice()) == InvalidXMLName { return Err(InvalidCharacter); } // Step 2. - if data.contains("?>") { + if data.as_slice().contains("?>") { return Err(InvalidCharacter); } @@ -542,7 +542,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn CreateEvent(&self, interface: DOMString) -> Fallible<Temporary<Event>> { let window = self.window.root(); - match interface.to_ascii_lower().as_slice() { + match interface.as_slice().to_ascii_lower().as_slice() { // FIXME: Implement CustomEvent (http://dom.spec.whatwg.org/#customevent) "uievents" | "uievent" => Ok(EventCast::from_temporary(UIEvent::new_uninitialized(&*window))), "mouseevents" | "mouseevent" => Ok(EventCast::from_temporary(MouseEvent::new_uninitialized(&*window))), @@ -554,7 +554,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://www.whatwg.org/specs/web-apps/current-work/#document.title fn Title(&self) -> DOMString { - let mut title = StrBuf::new(); + let mut title = String::new(); self.GetDocumentElement().root().map(|root| { let root: &JSRef<Node> = NodeCast::from_ref(&*root); root.traverse_preorder() @@ -570,7 +570,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { }); let v: Vec<&str> = title.as_slice().words().collect(); let title = v.connect(" "); - title.trim().to_owned() + title.as_slice().trim().to_string() } // http://www.whatwg.org/specs/web-apps/current-work/#document.title @@ -595,7 +595,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { assert!(title_node.AppendChild(NodeCast::from_ref(&*new_text)).is_ok()); }, None => { - let new_title = HTMLTitleElement::new("title".to_owned(), self).root(); + let new_title = HTMLTitleElement::new("title".to_string(), self).root(); let new_title: &JSRef<Node> = NodeCast::from_ref(&*new_title); let new_text = self.CreateTextNode(title.clone()).root(); @@ -691,7 +691,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap(); element.get_attribute(Null, "name").root().map_or(false, |mut attr| { - attr.value_ref() == name + attr.value_ref() == name.as_slice() }) }) } @@ -703,7 +703,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { struct ImagesFilter; impl CollectionFilter for ImagesFilter { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { - "img" == elem.deref().local_name + "img" == elem.deref().local_name.as_slice() } } let filter = box ImagesFilter; @@ -717,7 +717,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { struct EmbedsFilter; impl CollectionFilter for EmbedsFilter { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { - "embed" == elem.deref().local_name + "embed" == elem.deref().local_name.as_slice() } } let filter = box EmbedsFilter; @@ -736,7 +736,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { struct LinksFilter; impl CollectionFilter for LinksFilter { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { - ("a" == elem.deref().local_name || "area" == elem.deref().local_name) && + ("a" == elem.deref().local_name.as_slice() || "area" == elem.deref().local_name.as_slice()) && elem.get_attribute(Null, "href").is_some() } } @@ -751,7 +751,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { struct FormsFilter; impl CollectionFilter for FormsFilter { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { - "form" == elem.deref().local_name + "form" == elem.deref().local_name.as_slice() } } let filter = box FormsFilter; @@ -765,7 +765,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { struct ScriptsFilter; impl CollectionFilter for ScriptsFilter { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { - "script" == elem.deref().local_name + "script" == elem.deref().local_name.as_slice() } } let filter = box ScriptsFilter; @@ -779,7 +779,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { struct AnchorsFilter; impl CollectionFilter for AnchorsFilter { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { - "a" == elem.deref().local_name && elem.get_attribute(Null, "name").is_some() + "a" == elem.deref().local_name.as_slice() && elem.get_attribute(Null, "name").is_some() } } let filter = box AnchorsFilter; @@ -793,7 +793,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { struct AppletsFilter; impl CollectionFilter for AppletsFilter { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { - "applet" == elem.deref().local_name + "applet" == elem.deref().local_name.as_slice() } } let filter = box AppletsFilter; diff --git a/src/components/script/dom/documenttype.rs b/src/components/script/dom/documenttype.rs index c10d2730d1f..110e650f288 100644 --- a/src/components/script/dom/documenttype.rs +++ b/src/components/script/dom/documenttype.rs @@ -34,8 +34,8 @@ impl DocumentType { DocumentType { node: Node::new_inherited(DoctypeNodeTypeId, document), name: name, - public_id: public_id.unwrap_or("".to_owned()), - system_id: system_id.unwrap_or("".to_owned()) + public_id: public_id.unwrap_or("".to_string()), + system_id: system_id.unwrap_or("".to_string()) } } diff --git a/src/components/script/dom/domexception.rs b/src/components/script/dom/domexception.rs index 291dd4276a1..bd59020dbbd 100644 --- a/src/components/script/dom/domexception.rs +++ b/src/components/script/dom/domexception.rs @@ -112,27 +112,27 @@ impl<'a> DOMExceptionMethods for JSRef<'a, DOMException> { // http://dom.spec.whatwg.org/#error-names-0 fn Message(&self) -> DOMString { match self.code { - IndexSizeError => "The index is not in the allowed range.".to_owned(), - HierarchyRequestError => "The operation would yield an incorrect node tree.".to_owned(), - WrongDocumentError => "The object is in the wrong document.".to_owned(), - InvalidCharacterError => "The string contains invalid characters.".to_owned(), - NoModificationAllowedError => "The object can not be modified.".to_owned(), - NotFoundError => "The object can not be found here.".to_owned(), - NotSupportedError => "The operation is not supported.".to_owned(), - InvalidStateError => "The object is in an invalid state.".to_owned(), - SyntaxError => "The string did not match the expected pattern.".to_owned(), - InvalidModificationError => "The object can not be modified in this way.".to_owned(), - NamespaceError => "The operation is not allowed by Namespaces in XML.".to_owned(), - InvalidAccessError => "The object does not support the operation or argument.".to_owned(), - SecurityError => "The operation is insecure.".to_owned(), - NetworkError => "A network error occurred.".to_owned(), - AbortError => "The operation was aborted.".to_owned(), - URLMismatchError => "The given URL does not match another URL.".to_owned(), - QuotaExceededError => "The quota has been exceeded.".to_owned(), - TimeoutError => "The operation timed out.".to_owned(), - InvalidNodeTypeError => "The supplied node is incorrect or has an incorrect ancestor for this operation.".to_owned(), - DataCloneError => "The object can not be cloned.".to_owned(), - EncodingError => "The encoding operation (either encoded or decoding) failed.".to_owned() + IndexSizeError => "The index is not in the allowed range.".to_string(), + HierarchyRequestError => "The operation would yield an incorrect node tree.".to_string(), + WrongDocumentError => "The object is in the wrong document.".to_string(), + InvalidCharacterError => "The string contains invalid characters.".to_string(), + NoModificationAllowedError => "The object can not be modified.".to_string(), + NotFoundError => "The object can not be found here.".to_string(), + NotSupportedError => "The operation is not supported.".to_string(), + InvalidStateError => "The object is in an invalid state.".to_string(), + SyntaxError => "The string did not match the expected pattern.".to_string(), + InvalidModificationError => "The object can not be modified in this way.".to_string(), + NamespaceError => "The operation is not allowed by Namespaces in XML.".to_string(), + InvalidAccessError => "The object does not support the operation or argument.".to_string(), + SecurityError => "The operation is insecure.".to_string(), + NetworkError => "A network error occurred.".to_string(), + AbortError => "The operation was aborted.".to_string(), + URLMismatchError => "The given URL does not match another URL.".to_string(), + QuotaExceededError => "The quota has been exceeded.".to_string(), + TimeoutError => "The operation timed out.".to_string(), + InvalidNodeTypeError => "The supplied node is incorrect or has an incorrect ancestor for this operation.".to_string(), + DataCloneError => "The object can not be cloned.".to_string(), + EncodingError => "The encoding operation (either encoded or decoding) failed.".to_string() } } } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index 4d568ba52fe..370a233f67d 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -60,7 +60,7 @@ pub trait DOMImplementationMethods { impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { // http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible<Temporary<DocumentType>> { - match xml_name_type(qname) { + match xml_name_type(qname.as_slice()) { // Step 1. InvalidXMLName => Err(InvalidCharacter), // Step 2. @@ -129,19 +129,19 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { { // Step 3. - let doc_type = DocumentType::new("html".to_owned(), None, None, &*doc).root(); + let doc_type = DocumentType::new("html".to_string(), None, None, &*doc).root(); assert!(doc_node.AppendChild(NodeCast::from_ref(&*doc_type)).is_ok()); } { // Step 4. - let doc_html: Root<Node> = NodeCast::from_temporary(HTMLHtmlElement::new("html".to_owned(), &*doc)).root(); + let doc_html: Root<Node> = NodeCast::from_temporary(HTMLHtmlElement::new("html".to_string(), &*doc)).root(); let doc_html = doc_html.deref(); assert!(doc_node.AppendChild(doc_html).is_ok()); { // Step 5. - let doc_head: Root<Node> = NodeCast::from_temporary(HTMLHeadElement::new("head".to_owned(), &*doc)).root(); + let doc_head: Root<Node> = NodeCast::from_temporary(HTMLHeadElement::new("head".to_string(), &*doc)).root(); let doc_head = doc_head.deref(); assert!(doc_html.AppendChild(doc_head).is_ok()); @@ -150,7 +150,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".to_owned(), &*doc)).root(); + let doc_title: Root<Node> = NodeCast::from_temporary(HTMLTitleElement::new("title".to_string(), &*doc)).root(); let doc_title = doc_title.deref(); assert!(doc_head.AppendChild(doc_title).is_ok()); @@ -163,7 +163,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { } // Step 7. - let doc_body: Root<HTMLBodyElement> = HTMLBodyElement::new("body".to_owned(), &*doc).root(); + let doc_body: Root<HTMLBodyElement> = HTMLBodyElement::new("body".to_string(), &*doc).root(); let doc_body = doc_body.deref(); assert!(doc_html.AppendChild(NodeCast::from_ref(doc_body)).is_ok()); } diff --git a/src/components/script/dom/domparser.rs b/src/components/script/dom/domparser.rs index a49e97cd61d..540de38727a 100644 --- a/src/components/script/dom/domparser.rs +++ b/src/components/script/dom/domparser.rs @@ -48,10 +48,10 @@ impl<'a> DOMParserMethods for JSRef<'a, DOMParser> { let owner = self.owner.root(); match ty { Text_html => { - Ok(Document::new(&owner.root_ref(), None, HTMLDocument, Some("text/html".to_owned()))) + Ok(Document::new(&owner.root_ref(), None, HTMLDocument, Some("text/html".to_string()))) } Text_xml => { - Ok(Document::new(&owner.root_ref(), None, NonHTMLDocument, Some("text/xml".to_owned()))) + Ok(Document::new(&owner.root_ref(), None, NonHTMLDocument, Some("text/xml".to_string()))) } _ => { Err(FailureUnknown) diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index db8658ab9b5..66027956a65 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -30,8 +30,8 @@ use servo_util::namespace::{Namespace, Null}; use servo_util::str::{DOMString, null_str_as_empty_ref, split_html_space_chars}; use std::ascii::StrAsciiExt; -use std::cast; use std::cell::{Cell, RefCell}; +use std::mem; #[deriving(Encodable)] pub struct Element { @@ -168,13 +168,13 @@ impl RawLayoutElementHelpers for Element { unsafe fn get_attr_val_for_layout(&self, namespace: &Namespace, name: &str) -> Option<&'static str> { // cast to point to T in RefCell<T> directly - let attrs: *Vec<JS<Attr>> = cast::transmute(&self.attrs); + let attrs: *Vec<JS<Attr>> = mem::transmute(&self.attrs); (*attrs).iter().find(|attr: & &JS<Attr>| { let attr = attr.unsafe_get(); - name == (*attr).local_name && (*attr).namespace == *namespace + name == (*attr).local_name.as_slice() && (*attr).namespace == *namespace }).map(|attr| { let attr = attr.unsafe_get(); - cast::transmute((*attr).value.as_slice()) + mem::transmute((*attr).value.as_slice()) }) } } @@ -238,7 +238,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { let same_name = if is_html_element { name.to_ascii_lower() == attr.local_name } else { - name == attr.local_name + name == attr.local_name.as_slice() }; same_name && attr.namespace == namespace @@ -274,7 +274,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { let position: |&JSRef<Attr>| -> bool = if self.html_element_in_html_document() { - |attr| attr.deref().local_name.eq_ignore_ascii_case(local_name) + |attr| attr.deref().local_name.as_slice().eq_ignore_ascii_case(local_name.as_slice()) } else { |attr| attr.deref().local_name == local_name }; @@ -345,7 +345,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { fn has_class(&self, name: &str) -> bool { let class_names = self.get_string_attribute("class"); - let mut classes = split_html_space_chars(class_names); + let mut classes = split_html_space_chars(class_names.as_slice()); classes.any(|class| name == class) } @@ -363,17 +363,17 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { let x = x.root(); x.deref().Value() } - None => "".to_owned() + None => "".to_string() } } fn set_string_attribute(&self, name: &str, value: DOMString) { - assert!(name == name.to_ascii_lower()); - assert!(self.set_attribute(Null, name.to_owned(), value).is_ok()); + assert!(name == name.to_ascii_lower().as_slice()); + assert!(self.set_attribute(Null, name.to_string(), value).is_ok()); } fn set_uint_attribute(&self, name: &str, value: u32) { - assert!(name == name.to_ascii_lower()); - assert!(self.set_attribute(Null, name.to_owned(), value.to_str()).is_ok()); + assert!(name == name.to_ascii_lower().as_slice()); + assert!(self.set_attribute(Null, name.to_string(), value.to_str()).is_ok()); } } @@ -425,7 +425,7 @@ pub trait ElementMethods { impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-namespaceuri fn NamespaceURI(&self) -> DOMString { - self.namespace.to_str().to_owned() + self.namespace.to_str().to_string() } fn LocalName(&self) -> DOMString { @@ -441,10 +441,11 @@ impl<'a> ElementMethods for JSRef<'a, Element> { fn TagName(&self) -> DOMString { match self.prefix { None => { - self.local_name.to_ascii_upper() + self.local_name.as_slice().to_ascii_upper() } Some(ref prefix_str) => { - (*prefix_str + ":" + self.local_name).to_ascii_upper() + let s = format!("{}:{}", prefix_str, self.local_name); + s.as_slice().to_ascii_upper() } } } @@ -489,11 +490,11 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // http://dom.spec.whatwg.org/#dom-element-getattribute fn GetAttribute(&self, name: DOMString) -> Option<DOMString> { let name = if self.html_element_in_html_document() { - name.to_ascii_lower() + name.as_slice().to_ascii_lower() } else { name }; - self.get_attribute(Null, name).root() + self.get_attribute(Null, name.as_slice()).root() .map(|s| s.deref().Value()) } @@ -502,7 +503,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { namespace: Option<DOMString>, local_name: DOMString) -> Option<DOMString> { let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - self.get_attribute(namespace, local_name).root() + self.get_attribute(namespace, local_name.as_slice()).root() .map(|attr| attr.deref().Value()) } @@ -516,14 +517,14 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // Step 1. - match xml_name_type(name) { + match xml_name_type(name.as_slice()) { InvalidXMLName => return Err(InvalidCharacter), _ => {} } // Step 2. let name = if self.html_element_in_html_document() { - name.to_ascii_lower() + name.as_slice().to_ascii_lower() } else { name }; @@ -548,7 +549,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { // Step 1. let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url)); - let name_type = xml_name_type(name); + let name_type = xml_name_type(name.as_slice()); match name_type { // Step 2. InvalidXMLName => return Err(InvalidCharacter), @@ -580,12 +581,12 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // Step 7a. - if "xmlns" == name && namespace != namespace::XMLNS { + if "xmlns" == name.as_slice() && namespace != namespace::XMLNS { return Err(NamespaceError); } // Step 8. - if namespace == namespace::XMLNS && "xmlns" != name && Some("xmlns".to_owned()) != prefix { + if namespace == namespace::XMLNS && "xmlns" != name.as_slice() && Some("xmlns".to_string()) != prefix { return Err(NamespaceError); } @@ -601,7 +602,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { fn RemoveAttribute(&self, name: DOMString) -> ErrorResult { let name = if self.html_element_in_html_document() { - name.to_ascii_lower() + name.as_slice().to_ascii_lower() } else { name }; @@ -637,7 +638,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> { fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, localname: DOMString) -> Temporary<HTMLCollection> { let namespace = match maybe_ns { - Some(namespace) => Namespace::from_str(namespace), + Some(namespace) => Namespace::from_str(namespace.as_slice()), None => Null }; let window = window_from_node(self).root(); @@ -700,12 +701,12 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } } -pub fn get_attribute_parts(name: DOMString) -> (Option<~str>, ~str) { +pub fn get_attribute_parts(name: DOMString) -> (Option<String>, String) { //FIXME: Throw for XML-invalid names //FIXME: Throw for XMLNS-invalid names - let (prefix, local_name) = if name.contains(":") { - let mut parts = name.splitn(':', 1); - (Some(parts.next().unwrap().to_owned()), parts.next().unwrap().to_owned()) + let (prefix, local_name) = if name.as_slice().contains(":") { + let mut parts = name.as_slice().splitn(':', 1); + (Some(parts.next().unwrap().to_string()), parts.next().unwrap().to_string()) } else { (None, name) }; @@ -729,7 +730,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { "style" => { let doc = document_from_node(self).root(); let base_url = doc.deref().url().clone(); - self.deref_mut().style_attribute = Some(style::parse_style_attribute(value, &base_url)) + self.deref_mut().style_attribute = Some(style::parse_style_attribute(value.as_slice(), &base_url)) } "id" => { let node: &JSRef<Node> = NodeCast::from_ref(self); diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index 2d238396a0d..b30a4d6dc4b 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -70,7 +70,7 @@ impl Event { current_target: Cell::new(None), target: Cell::new(None), phase: PhaseNone, - type_: "".to_owned(), + type_: "".to_string(), canceled: false, cancelable: true, bubbles: false, diff --git a/src/components/script/dom/eventdispatcher.rs b/src/components/script/dom/eventdispatcher.rs index 2dc2b3a8c1d..6c199886b75 100644 --- a/src/components/script/dom/eventdispatcher.rs +++ b/src/components/script/dom/eventdispatcher.rs @@ -44,7 +44,7 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>, /* capturing */ for cur_target in chain.as_slice().iter().rev() { - let stopped = match cur_target.get_listeners_for(type_, Capturing) { + let stopped = match cur_target.get_listeners_for(type_.as_slice(), Capturing) { Some(listeners) => { event.current_target.assign(Some(cur_target.deref().clone())); for listener in listeners.iter() { @@ -74,7 +74,7 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>, event.current_target.assign(Some(target.clone())); } - let opt_listeners = target.deref().get_listeners(type_); + let opt_listeners = target.deref().get_listeners(type_.as_slice()); for listeners in opt_listeners.iter() { for listener in listeners.iter() { // Explicitly drop any exception on the floor. @@ -92,7 +92,7 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>, event.deref_mut().phase = PhaseBubbling; for cur_target in chain.iter() { - let stopped = match cur_target.deref().get_listeners_for(type_, Bubbling) { + let stopped = match cur_target.deref().get_listeners_for(type_.as_slice(), Bubbling) { Some(listeners) => { event.deref_mut().current_target.assign(Some(cur_target.deref().clone())); for listener in listeners.iter() { diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs index 1ebfc77875a..165454f6243 100644 --- a/src/components/script/dom/eventtarget.rs +++ b/src/components/script/dom/eventtarget.rs @@ -192,11 +192,11 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { { let event_listener = listener.map(|listener| EventListener::new(listener.callback())); - self.set_inline_event_listener(ty.to_owned(), event_listener); + self.set_inline_event_listener(ty.to_string(), event_listener); } fn get_event_handler_common<T: CallbackContainer>(&self, ty: &str) -> Option<T> { - let listener = self.get_inline_event_listener(ty.to_owned()); + let listener = self.get_inline_event_listener(ty.to_string()); listener.map(|listener| CallbackContainer::new(listener.parent.callback())) } } diff --git a/src/components/script/dom/formdata.rs b/src/components/script/dom/formdata.rs index a843b62db30..142b08fc262 100644 --- a/src/components/script/dom/formdata.rs +++ b/src/components/script/dom/formdata.rs @@ -54,7 +54,7 @@ impl<'a> FormDataMethods for JSRef<'a, FormData> { fn Append(&mut self, name: DOMString, value: &JSRef<Blob>, filename: Option<DOMString>) { let blob = BlobData { blob: value.unrooted(), - name: filename.unwrap_or("default".to_owned()) + name: filename.unwrap_or("default".to_string()) }; self.data.insert(name.clone(), blob); } diff --git a/src/components/script/dom/htmlanchorelement.rs b/src/components/script/dom/htmlanchorelement.rs index 855588ed196..3ed06945f80 100644 --- a/src/components/script/dom/htmlanchorelement.rs +++ b/src/components/script/dom/htmlanchorelement.rs @@ -50,7 +50,7 @@ trait PrivateHTMLAnchorElementHelpers { impl<'a> PrivateHTMLAnchorElementHelpers for JSRef<'a, HTMLAnchorElement> { fn handle_event_impl(&self, event: &JSRef<Event>) { - if "click" == event.Type() && !event.DefaultPrevented() { + if "click" == event.Type().as_slice() && !event.DefaultPrevented() { let element: &JSRef<Element> = ElementCast::from_ref(self); let attr = element.get_attribute(Null, "href").root(); match attr { diff --git a/src/components/script/dom/htmlbodyelement.rs b/src/components/script/dom/htmlbodyelement.rs index fc3196062b7..bf02ba963cd 100644 --- a/src/components/script/dom/htmlbodyelement.rs +++ b/src/components/script/dom/htmlbodyelement.rs @@ -70,7 +70,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> { _ => (), } - if name.starts_with("on") { + if name.as_slice().starts_with("on") { static forwarded_events: &'static [&'static str] = &["onfocus", "onload", "onscroll", "onafterprint", "onbeforeprint", "onbeforeunload", "onhashchange", "onlanguagechange", "onmessage", @@ -87,7 +87,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> { EventTargetCast::from_mut_ref(self) }; evtarget.set_event_handler_uncompiled(cx, url, reflector, - name.slice_from(2).to_owned(), + name.as_slice().slice_from(2), value); } } diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 3de86456c1c..aeb506938f8 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -99,11 +99,11 @@ impl HTMLCollection { } impl CollectionFilter for ClassNameFilter { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { - self.classes.iter().all(|class| elem.has_class(*class)) + self.classes.iter().all(|class| elem.has_class(class.as_slice())) } } let filter = ClassNameFilter { - classes: split_html_space_chars(classes).map(|class| class.into_owned()).collect() + classes: split_html_space_chars(classes.as_slice()).map(|class| class.into_owned()).collect() }; HTMLCollection::create(window, root, box filter) } diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index fd310d619f9..8b95feb3a84 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -46,7 +46,7 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> { struct HTMLDataListOptionsFilter; impl CollectionFilter for HTMLDataListOptionsFilter { fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool { - "option" == elem.deref().local_name + "option" == elem.deref().local_name.as_slice() } } let node: &JSRef<Node> = NodeCast::from_ref(self); diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index aa622b55216..45394af413e 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -52,7 +52,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { static tag_names: StaticStringVec = &["button", "fieldset", "input", "keygen", "object", "output", "select", "textarea"]; let root: &JSRef<Element> = ElementCast::to_ref(root).unwrap(); - elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.deref().local_name) + elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.deref().local_name.as_slice()) } } let node: &JSRef<Node> = NodeCast::from_ref(self); diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index b48d91e8793..9c4467208be 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -133,9 +133,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> { _ => (), } - if "sandbox" == name { + if "sandbox" == name.as_slice() { let mut modes = AllowNothing as u8; - for word in value.split(' ') { + for word in value.as_slice().split(' ') { modes |= match word.to_ascii_lower().as_slice() { "allow-same-origin" => AllowSameOrigin, "allow-forms" => AllowForms, @@ -156,7 +156,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> { _ => (), } - if "sandbox" == name { + if "sandbox" == name.as_slice() { self.deref_mut().sandbox = None; } } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index 5b6d9f9e54b..33946b588a4 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -49,7 +49,7 @@ impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, HTMLImageElement> { *self.image = None; } Some(src) => { - let img_url = parse_url(src, url); + let img_url = parse_url(src.as_slice(), url); *self.image = Some(img_url.clone()); // inform the image cache to load this, but don't store a @@ -147,7 +147,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { fn IsMap(&self) -> bool { let element: &JSRef<Element> = ElementCast::from_ref(self); - from_str::<bool>(element.get_string_attribute("hspace")).unwrap() + from_str::<bool>(element.get_string_attribute("hspace").as_slice()).unwrap() } fn SetIsMap(&self, is_map: bool) { @@ -199,7 +199,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { fn Hspace(&self) -> u32 { let element: &JSRef<Element> = ElementCast::from_ref(self); - from_str::<u32>(element.get_string_attribute("hspace")).unwrap() + from_str::<u32>(element.get_string_attribute("hspace").as_slice()).unwrap() } fn SetHspace(&self, hspace: u32) { @@ -209,7 +209,7 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { fn Vspace(&self) -> u32 { let element: &JSRef<Element> = ElementCast::from_ref(self); - from_str::<u32>(element.get_string_attribute("vspace")).unwrap() + from_str::<u32>(element.get_string_attribute("vspace").as_slice()).unwrap() } fn SetVspace(&self, vspace: u32) { @@ -250,7 +250,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { _ => (), } - if "src" == name { + if "src" == name.as_slice() { let window = window_from_node(self).root(); let url = Some(window.deref().get_url()); self.update_image(Some(value), url); @@ -263,7 +263,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { _ => (), } - if "src" == name { + if "src" == name.as_slice() { self.update_image(None, None); } } diff --git a/src/components/script/dom/htmlmainelement.rs b/src/components/script/dom/htmlmainelement.rs new file mode 100644 index 00000000000..61c4506de7f --- /dev/null +++ b/src/components/script/dom/htmlmainelement.rs @@ -0,0 +1,40 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use dom::bindings::codegen::Bindings::HTMLMainElementBinding; +use dom::bindings::codegen::InheritTypes::HTMLMainElementDerived; +use dom::bindings::js::{JSRef, Temporary}; +use dom::document::Document; +use dom::element::HTMLMainElementTypeId; +use dom::eventtarget::{EventTarget, NodeTargetTypeId}; +use dom::htmlelement::HTMLElement; +use dom::node::{Node, ElementNodeTypeId}; +use servo_util::str::DOMString; + +#[deriving(Encodable)] +pub struct HTMLMainElement { + pub htmlelement: HTMLElement +} + +impl HTMLMainElementDerived for EventTarget { + fn is_htmlmainelement(&self) -> bool { + self.type_id == NodeTargetTypeId(ElementNodeTypeId(HTMLMainElementTypeId)) + } +} + +impl HTMLMainElement { + pub fn new_inherited(localName: DOMString, document: &JSRef<Document>) -> HTMLMainElement { + HTMLMainElement { + htmlelement: HTMLElement::new_inherited(HTMLMainElementTypeId, localName, document) + } + } + + pub fn new(localName: DOMString, document: &JSRef<Document>) -> Temporary<HTMLMainElement> { + let element = HTMLMainElement::new_inherited(localName, document); + Node::reflect_node(box element, document, HTMLMainElementBinding::Wrap) + } +} + +pub trait HTMLMainElementMethods { +} diff --git a/src/components/script/dom/htmlobjectelement.rs b/src/components/script/dom/htmlobjectelement.rs index 3a339dd933d..a2bf1b317d3 100644 --- a/src/components/script/dom/htmlobjectelement.rs +++ b/src/components/script/dom/htmlobjectelement.rs @@ -62,8 +62,8 @@ impl<'a> ProcessDataURL for JSRef<'a, HTMLObjectElement> { match (elem.get_attribute(Null, "type").map(|x| x.root().Value()), elem.get_attribute(Null, "data").map(|x| x.root().Value())) { (None, Some(uri)) => { - if is_image_data(uri) { - let data_url = parse_url(uri, url); + if is_image_data(uri.as_slice()) { + let data_url = parse_url(uri.as_slice(), url); // Issue #84 image_cache.send(image_cache_task::Prefetch(data_url)); } @@ -96,7 +96,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> { _ => (), } - if "data" == name { + if "data" == name.as_slice() { let window = window_from_node(self).root(); let url = Some(window.deref().get_url()); self.process_data_url(window.deref().image_cache_task.clone(), url); diff --git a/src/components/script/dom/htmlserializer.rs b/src/components/script/dom/htmlserializer.rs index ea33f79fee0..a1c6d709a47 100644 --- a/src/components/script/dom/htmlserializer.rs +++ b/src/components/script/dom/htmlserializer.rs @@ -19,9 +19,9 @@ use dom::node::{TextNodeTypeId, NodeHelpers}; use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; -pub fn serialize(iterator: &mut NodeIterator) -> ~str { - let mut html = StrBuf::new(); - let mut open_elements: Vec<~str> = vec!(); +pub fn serialize(iterator: &mut NodeIterator) -> String { + let mut html = String::new(); + let mut open_elements: Vec<String> = vec!(); for node in *iterator { while open_elements.len() > iterator.depth { @@ -65,13 +65,13 @@ pub fn serialize(iterator: &mut NodeIterator) -> ~str { html.into_owned() } -fn serialize_comment(comment: &JSRef<Comment>, html: &mut StrBuf) { +fn serialize_comment(comment: &JSRef<Comment>, html: &mut String) { html.push_str("<!--"); - html.push_str(comment.deref().characterdata.data); + html.push_str(comment.deref().characterdata.data.as_slice()); html.push_str("-->"); } -fn serialize_text(text: &JSRef<Text>, html: &mut StrBuf) { +fn serialize_text(text: &JSRef<Text>, html: &mut String) { let text_node: &JSRef<Node> = NodeCast::from_ref(text); match text_node.parent_node().map(|node| node.root()) { Some(ref parent) if parent.is_element() => { @@ -80,32 +80,32 @@ fn serialize_text(text: &JSRef<Text>, html: &mut StrBuf) { "style" | "script" | "xmp" | "iframe" | "noembed" | "noframes" | "plaintext" | "noscript" if elem.deref().namespace == namespace::HTML - => html.push_str(text.deref().characterdata.data), - _ => escape(text.deref().characterdata.data, false, html) + => html.push_str(text.deref().characterdata.data.as_slice()), + _ => escape(text.deref().characterdata.data.as_slice(), false, html) } } - _ => escape(text.deref().characterdata.data, false, html) + _ => escape(text.deref().characterdata.data.as_slice(), false, html) } } fn serialize_processing_instruction(processing_instruction: &JSRef<ProcessingInstruction>, - html: &mut StrBuf) { + html: &mut String) { html.push_str("<?"); - html.push_str(processing_instruction.deref().target); + html.push_str(processing_instruction.deref().target.as_slice()); html.push_char(' '); - html.push_str(processing_instruction.deref().characterdata.data); + html.push_str(processing_instruction.deref().characterdata.data.as_slice()); html.push_str("?>"); } -fn serialize_doctype(doctype: &JSRef<DocumentType>, html: &mut StrBuf) { +fn serialize_doctype(doctype: &JSRef<DocumentType>, html: &mut String) { html.push_str("<!DOCTYPE"); - html.push_str(doctype.deref().name); + html.push_str(doctype.deref().name.as_slice()); html.push_char('>'); } -fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>, html: &mut StrBuf) { +fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<String>, html: &mut String) { html.push_char('<'); - html.push_str(elem.deref().local_name); + html.push_str(elem.deref().local_name.as_slice()); for attr in elem.deref().attrs.borrow().iter() { let attr = attr.root(); serialize_attr(&*attr, html); @@ -118,7 +118,7 @@ fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>, html: &m match node.first_child().map(|child| child.root()) { Some(ref child) if child.is_text() => { let text: &JSRef<CharacterData> = CharacterDataCast::to_ref(&**child).unwrap(); - if text.deref().data.len() > 0 && text.deref().data[0] == 0x0A as u8 { + if text.deref().data.len() > 0 && text.deref().data.as_slice().char_at(0) == '\n' { html.push_char('\x0A'); } }, @@ -133,29 +133,29 @@ fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>, html: &m } } -fn serialize_attr(attr: &JSRef<Attr>, html: &mut StrBuf) { +fn serialize_attr(attr: &JSRef<Attr>, html: &mut String) { html.push_char(' '); if attr.deref().namespace == namespace::XML { html.push_str("xml:"); - html.push_str(attr.deref().local_name); + html.push_str(attr.deref().local_name.as_slice()); } else if attr.deref().namespace == namespace::XMLNS && attr.deref().local_name.as_slice() == "xmlns" { html.push_str("xmlns"); } else if attr.deref().namespace == namespace::XMLNS { html.push_str("xmlns:"); - html.push_str(attr.deref().local_name); + html.push_str(attr.deref().local_name.as_slice()); } else if attr.deref().namespace == namespace::XLink { html.push_str("xlink:"); - html.push_str(attr.deref().local_name); + html.push_str(attr.deref().local_name.as_slice()); } else { - html.push_str(attr.deref().name); + html.push_str(attr.deref().name.as_slice()); }; html.push_str("=\""); - escape(attr.deref().value, true, html); + escape(attr.deref().value.as_slice(), true, html); html.push_char('"'); } -fn escape(string: &str, attr_mode: bool, html: &mut StrBuf) { +fn escape(string: &str, attr_mode: bool, html: &mut String) { for c in string.chars() { match c { '&' => html.push_str("&"), diff --git a/src/components/script/dom/navigator.rs b/src/components/script/dom/navigator.rs index 9c53c8a220b..3603709971f 100644 --- a/src/components/script/dom/navigator.rs +++ b/src/components/script/dom/navigator.rs @@ -37,7 +37,7 @@ pub trait NavigatorMethods { impl<'a> NavigatorMethods for JSRef<'a, Navigator> { fn Product(&self) -> DOMString { - "Gecko".to_owned() + "Gecko".to_string() } fn TaintEnabled(&self) -> bool { @@ -45,15 +45,15 @@ impl<'a> NavigatorMethods for JSRef<'a, Navigator> { } fn AppName(&self) -> DOMString { - "Netscape".to_owned() // Like Gecko/Webkit + "Netscape".to_string() // Like Gecko/Webkit } fn AppCodeName(&self) -> DOMString { - "Mozilla".to_owned() + "Mozilla".to_string() } fn Platform(&self) -> DOMString { - "".to_owned() + "".to_string() } } diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index d722d1abe3e..c7cde126e42 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -39,8 +39,6 @@ use js::jsapi::{JSContext, JSObject, JSRuntime}; use js::jsfriendapi; use libc; use libc::uintptr_t; -use std::cast::transmute; -use std::cast; use std::cell::{Cell, RefCell, Ref, RefMut}; use std::iter::{Map, Filter}; use std::mem; @@ -171,7 +169,7 @@ impl LayoutDataRef { pub unsafe fn from_data<T>(data: Box<T>) -> LayoutDataRef { LayoutDataRef { - data_cell: RefCell::new(Some(cast::transmute(data))), + data_cell: RefCell::new(Some(mem::transmute(data))), } } @@ -195,7 +193,7 @@ impl LayoutDataRef { /// safe layout data accessor. #[inline] pub unsafe fn borrow_unchecked(&self) -> *Option<LayoutData> { - cast::transmute(&self.data_cell) + mem::transmute(&self.data_cell) } /// Borrows the layout data immutably. This function is *not* thread-safe. @@ -384,7 +382,7 @@ pub trait NodeHelpers { fn dump(&self); fn dump_indent(&self, indent: uint); - fn debug_str(&self) -> ~str; + fn debug_str(&self) -> String; fn traverse_preorder<'a>(&'a self) -> TreeIterator<'a>; fn sequential_traverse_postorder<'a>(&'a self) -> TreeIterator<'a>; @@ -406,12 +404,12 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { /// Dumps the node tree, for debugging, with indentation. fn dump_indent(&self, indent: uint) { - let mut s = StrBuf::new(); + let mut s = String::new(); for _ in range(0, indent) { s.push_str(" "); } - s.push_str(self.debug_str()); + s.push_str(self.debug_str().as_slice()); debug!("{:s}", s); // FIXME: this should have a pure version? @@ -421,7 +419,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { } /// Returns a string that describes this node. - fn debug_str(&self) -> ~str { + fn debug_str(&self) -> String { format!("{:?}", self.type_id()) } @@ -600,7 +598,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> { pub fn from_untrusted_node_address(runtime: *mut JSRuntime, candidate: UntrustedNodeAddress) -> Temporary<Node> { unsafe { - let candidate: uintptr_t = cast::transmute(candidate); + let candidate: uintptr_t = mem::transmute(candidate); let object: *mut JSObject = jsfriendapi::bindgen::JS_GetAddressableObject(runtime, candidate); if object.is_null() { @@ -1353,19 +1351,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> { let elem: &JSRef<Element> = ElementCast::to_ref(self).unwrap(); elem.TagName() } - TextNodeTypeId => "#text".to_owned(), + TextNodeTypeId => "#text".to_string(), ProcessingInstructionNodeTypeId => { let processing_instruction: &JSRef<ProcessingInstruction> = ProcessingInstructionCast::to_ref(self).unwrap(); processing_instruction.Target() } - CommentNodeTypeId => "#comment".to_owned(), + CommentNodeTypeId => "#comment".to_string(), DoctypeNodeTypeId => { let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(self).unwrap(); doctype.deref().name.clone() }, - DocumentFragmentNodeTypeId => "#document-fragment".to_owned(), - DocumentNodeTypeId => "#document".to_owned() + DocumentFragmentNodeTypeId => "#document-fragment".to_string(), + DocumentNodeTypeId => "#document".to_string() } } @@ -1476,7 +1474,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { match self.type_id { DocumentFragmentNodeTypeId | ElementNodeTypeId(..) => { - let mut content = StrBuf::new(); + let mut content = String::new(); for node in self.traverse_preorder() { if node.is_text() { let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap(); diff --git a/src/components/script/dom/testbinding.rs b/src/components/script/dom/testbinding.rs index 4f6020e8c20..852b7443418 100644 --- a/src/components/script/dom/testbinding.rs +++ b/src/components/script/dom/testbinding.rs @@ -48,7 +48,7 @@ pub trait TestBindingMethods { fn SetFloatAttribute(&self, _: f32) {} fn DoubleAttribute(&self) -> f64 { 0. } fn SetDoubleAttribute(&self, _: f64) {} - fn StringAttribute(&self) -> DOMString { "".to_owned() } + fn StringAttribute(&self) -> DOMString { "".to_string() } fn SetStringAttribute(&self, _: DOMString) {} fn ByteStringAttribute(&self) -> ByteString { ByteString::new(vec!()) } fn SetByteStringAttribute(&self, _: ByteString) {} @@ -83,7 +83,7 @@ pub trait TestBindingMethods { 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("".to_owned()) } + fn GetStringAttributeNullable(&self) -> Option<DOMString> { Some("".to_string()) } fn SetStringAttributeNullable(&self, _: Option<DOMString>) {} fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(_empty) } fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>>; @@ -101,7 +101,7 @@ pub trait TestBindingMethods { fn ReceiveUnsignedLongLong(&self) -> u64 { 0 } fn ReceiveFloat(&self) -> f32 { 0. } fn ReceiveDouble(&self) -> f64 { 0. } - fn ReceiveString(&self) -> DOMString { "".to_owned() } + fn ReceiveString(&self) -> DOMString { "".to_string() } fn ReceiveByteString(&self) -> ByteString { ByteString::new(vec!()) } fn ReceiveEnum(&self) -> TestEnum { _empty } fn ReceiveInterface(&self) -> Temporary<Blob>; @@ -118,7 +118,7 @@ pub trait TestBindingMethods { 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("".to_owned()) } + fn ReceiveNullableString(&self) -> Option<DOMString> { Some("".to_string()) } fn ReceiveNullableByteString(&self) -> Option<ByteString> { Some(ByteString::new(vec!())) } fn ReceiveNullableEnum(&self) -> Option<TestEnum> { Some(_empty) } fn ReceiveNullableInterface(&self) -> Option<Temporary<Blob>>; diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index edb969cd90f..170c2bfa657 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -302,9 +302,9 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { fn load_url(&self, href: DOMString) { let base_url = Some(self.page().get_url()); debug!("current page url is {:?}", base_url); - let url = parse_url(href, base_url); + let url = parse_url(href.as_slice(), base_url); let ScriptChan(ref script_chan) = self.script_chan; - if href.starts_with("#") { + if href.as_slice().starts_with("#") { script_chan.send(TriggerFragmentMsg(self.page.id, url)); } else { script_chan.send(TriggerLoadMsg(self.page.id, url)); diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs index 3d5dd42cdf0..b5240e0536f 100644 --- a/src/components/script/dom/xmlhttprequest.rs +++ b/src/components/script/dom/xmlhttprequest.rs @@ -129,13 +129,13 @@ pub struct XMLHttpRequest { impl XMLHttpRequest { pub fn new_inherited(owner: &JSRef<Window>) -> XMLHttpRequest { - let mut xhr = XMLHttpRequest { + let xhr = XMLHttpRequest { eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestTypeId), ready_state: Unsent, timeout: 0u32, with_credentials: false, upload: Cell::new(None), - response_url: "".to_owned(), + response_url: "".to_string(), status: 0, status_text: ByteString::new(vec!()), response: ByteString::new(vec!()), @@ -146,7 +146,7 @@ impl XMLHttpRequest { request_method: Untraceable::new(Get), request_url: Untraceable::new(parse_url("", None)), request_headers: Untraceable::new(RequestHeaderCollection::new()), - request_body: "".to_owned(), + request_body: "".to_string(), sync: false, send_flag: false, @@ -266,7 +266,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> { fn Open(&mut self, method: ByteString, url: DOMString) -> ErrorResult { let maybe_method: Option<Method> = method.as_str().and_then(|s| { - FromStr::from_str(s.to_ascii_upper()) // rust-http tests against the uppercase versions + FromStr::from_str(s.to_ascii_upper().as_slice()) // rust-http tests against the uppercase versions }); // Step 2 let base: Option<Url> = Some(self.global.root().get_url()); @@ -276,7 +276,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> { *self.request_method = maybe_method.unwrap(); // Step 6 - let parsed_url = match try_parse_url(url, base) { + let parsed_url = match try_parse_url(url.as_slice(), base) { Ok(parsed) => parsed, Err(_) => return Err(Syntax) // Step 7 }; @@ -337,7 +337,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> { "upgrade" | "user-agent" | "via" => { return Ok(()); // Step 5 }, - _ => StrBuf::from_str(s) + _ => String::from_str(s) } }, None => return Err(Syntax) @@ -423,9 +423,9 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> { // Step 9 self.send_flag = true; - self.dispatch_response_progress_event("loadstart".to_owned()); + self.dispatch_response_progress_event("loadstart".to_string()); if !self.upload_complete { - self.dispatch_upload_progress_event("loadstart".to_owned(), Some(0)); + self.dispatch_upload_progress_event("loadstart".to_string(), Some(0)); } } @@ -436,7 +436,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> { // XXXManishearth deal with the Origin/Referer/Accept headers // XXXManishearth the below is only valid when content type is not already set by the user. - self.insert_trusted_header("content-type".to_owned(), "text/plain;charset=UTF-8".to_owned()); + self.insert_trusted_header("content-type".to_string(), "text/plain;charset=UTF-8".to_string()); load_data.headers = (*self.request_headers).clone(); load_data.method = (*self.request_method).clone(); if self.sync { @@ -488,7 +488,7 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> { if self.ready_state == XHRDone || self.ready_state == Loading { self.response.to_jsval(cx) } else { - "".to_owned().to_jsval(cx) + "".to_string().to_jsval(cx) } }, _ => { @@ -509,8 +509,8 @@ impl<'a> XMLHttpRequestMethods<'a> for JSRef<'a, XMLHttpRequest> { // XXXManishearth handle charset, etc (http://xhr.spec.whatwg.org/#text-response) // 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 - Loading | XHRDone => Ok(UTF_8.decode(self.response.as_slice(), DecodeReplace).unwrap().to_owned()), - _ => Ok("".to_owned()) + Loading | XHRDone => Ok(UTF_8.decode(self.response.as_slice(), DecodeReplace).unwrap().to_string()), + _ => Ok("".to_string()) } }, _ => Err(InvalidState) @@ -556,7 +556,7 @@ trait PrivateXMLHttpRequestHelpers { fn release(&mut self); fn change_ready_state(&mut self, XMLHttpRequestState); fn process_partial_response(&mut self, progress: XHRProgress); - fn insert_trusted_header(&mut self, name: ~str, value: ~str); + fn insert_trusted_header(&mut self, name: String, value: String); fn dispatch_progress_event(&self, upload: bool, type_: DOMString, loaded: u64, total: Option<u64>); fn dispatch_upload_progress_event(&self, type_: DOMString, partial_load: Option<u64>); fn dispatch_response_progress_event(&self, type_: DOMString); @@ -584,7 +584,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { self.ready_state = rs; let win = &*self.global.root(); let mut event = - Event::new(win, "readystatechange".to_owned(), false, true).root(); + Event::new(win, "readystatechange".to_string(), false, true).root(); let target: &JSRef<EventTarget> = EventTargetCast::from_ref(self); target.dispatch_event_with_target(None, &mut *event).ok(); } @@ -598,9 +598,9 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { // Substep 1 self.upload_complete = true; // Substeps 2-4 - self.dispatch_upload_progress_event("progress".to_owned(), None); - self.dispatch_upload_progress_event("load".to_owned(), None); - self.dispatch_upload_progress_event("loadend".to_owned(), None); + self.dispatch_upload_progress_event("progress".to_string(), None); + self.dispatch_upload_progress_event("load".to_string(), None); + self.dispatch_upload_progress_event("loadend".to_string(), None); // Part of step 13, send() (processing response) // XXXManishearth handle errors, if any (substep 1) @@ -627,7 +627,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { // Substep 3 self.response = partial_response; // Substep 4 - self.dispatch_response_progress_event("progress".to_owned()); + self.dispatch_response_progress_event("progress".to_string()); }, DoneMsg => { // Part of step 13, send() (processing response end of file) @@ -640,10 +640,9 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { self.change_ready_state(XHRDone); // Subsubsteps 5-7 - let len = self.response.len() as u64; - self.dispatch_response_progress_event("progress".to_owned()); - self.dispatch_response_progress_event("load".to_owned()); - self.dispatch_response_progress_event("loadend".to_owned()); + self.dispatch_response_progress_event("progress".to_string()); + self.dispatch_response_progress_event("load".to_string()); + self.dispatch_response_progress_event("loadend".to_string()); } }, ErroredMsg => { @@ -654,13 +653,13 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { if !self.sync { if !self.upload_complete { self.upload_complete = true; - self.dispatch_upload_progress_event("progress".to_owned(), None); - self.dispatch_upload_progress_event("load".to_owned(), None); - self.dispatch_upload_progress_event("loadend".to_owned(), None); + self.dispatch_upload_progress_event("progress".to_string(), None); + self.dispatch_upload_progress_event("load".to_string(), None); + self.dispatch_upload_progress_event("loadend".to_string(), None); } - self.dispatch_response_progress_event("progress".to_owned()); - self.dispatch_response_progress_event("load".to_owned()); - self.dispatch_response_progress_event("loadend".to_owned()); + self.dispatch_response_progress_event("progress".to_string()); + self.dispatch_response_progress_event("load".to_string()); + self.dispatch_response_progress_event("loadend".to_string()); } }, @@ -670,14 +669,14 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { } } - fn insert_trusted_header(&mut self, name: ~str, value: ~str) { + fn insert_trusted_header(&mut self, name: String, value: String) { // Insert a header without checking spec-compliance // Use for hardcoded headers let collection = self.request_headers.deref_mut(); let value_bytes = value.into_bytes(); - let mut reader = BufReader::new(value_bytes); + let mut reader = BufReader::new(value_bytes.as_slice()); let maybe_header: Option<Header> = HeaderEnum::value_from_stream( - StrBuf::from_str(name), + String::from_str(name.as_slice()), &mut HeaderValueByteIterator::new(&mut reader)); collection.insert(maybe_header.unwrap()); } @@ -705,7 +704,6 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { } fn dispatch_response_progress_event(&self, type_: DOMString) { - let win = &*self.global.root(); let len = self.response.len() as u64; let total = self.response_headers.deref().content_length.map(|x| {x as u64}); self.dispatch_progress_event(false, type_, len, total); diff --git a/src/components/script/html/cssparse.rs b/src/components/script/html/cssparse.rs index b8addc5d31b..cb54e9dd198 100644 --- a/src/components/script/html/cssparse.rs +++ b/src/components/script/html/cssparse.rs @@ -15,11 +15,11 @@ use url::Url; /// Where a style sheet comes from. pub enum StylesheetProvenance { UrlProvenance(Url, ResourceTask), - InlineProvenance(Url, ~str), + InlineProvenance(Url, String), } // Parses the style data and returns the stylesheet -pub fn parse_inline_css(url: Url, data: ~str) -> Stylesheet { +pub fn parse_inline_css(url: Url, data: String) -> Stylesheet { parse_css(InlineProvenance(url, data)) } @@ -43,7 +43,7 @@ fn parse_css(provenance: StylesheetProvenance) -> Stylesheet { } InlineProvenance(base_url, data) => { debug!("cssparse: loading inline stylesheet {:s}", data); - Stylesheet::from_str(data, base_url, environment_encoding) + Stylesheet::from_str(data.as_slice(), base_url, environment_encoding) } } } diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 7978c34fec6..fac27f299b1 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -25,10 +25,9 @@ use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS}; use servo_util::task::spawn_named; use servo_util::url::parse_url; use std::ascii::StrAsciiExt; -use std::cast; +use std::mem; use std::cell::RefCell; use std::comm::{channel, Sender, Receiver}; -use std::str; use style::Stylesheet; use url::Url; @@ -38,7 +37,7 @@ macro_rules! handle_element( $string: expr, $ctor: ident $(, $arg:expr )*) => ( - if $string == $localName { + if $string == $localName.as_slice() { return ElementCast::from_temporary($ctor::new($localName, $document $(, $arg)*)); } ) @@ -46,7 +45,7 @@ macro_rules! handle_element( pub struct JSFile { - pub data: ~str, + pub data: String, pub url: Url } @@ -59,7 +58,7 @@ enum CSSMessage { enum JSMessage { JSTaskNewFile(Url), - JSTaskNewInlineScript(~str, Url), + JSTaskNewInlineScript(String, Url), JSTaskExit } @@ -79,12 +78,12 @@ trait NodeWrapping<T> { impl<'a, T: NodeBase+Reflectable> NodeWrapping<T> for JSRef<'a, T> { unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr { - cast::transmute(self.deref()) + mem::transmute(self.deref()) } } unsafe fn from_hubbub_node<T: Reflectable>(n: hubbub::NodeDataPtr) -> Temporary<T> { - Temporary::new(JS::from_raw(cast::transmute(n))) + Temporary::new(JS::from_raw(mem::transmute(n))) } /** @@ -120,7 +119,7 @@ fn css_link_listener(to_parent: Sender<HtmlDiscoveryMessage>, // Send the sheets back in order // FIXME: Shouldn't wait until after we've recieved CSSTaskExit to start sending these for port in result_vec.iter() { - to_parent.send_opt(HtmlDiscoveredStyle(port.recv())); + assert!(to_parent.send_opt(HtmlDiscoveredStyle(port.recv())).is_ok()); } } @@ -138,7 +137,7 @@ fn js_script_listener(to_parent: Sender<HtmlDiscoveryMessage>, } Ok((metadata, bytes)) => { result_vec.push(JSFile { - data: str::from_utf8(bytes.as_slice()).unwrap().to_owned(), + data: String::from_utf8(bytes).unwrap().to_string(), url: metadata.final_url, }); } @@ -153,7 +152,7 @@ fn js_script_listener(to_parent: Sender<HtmlDiscoveryMessage>, } } - to_parent.send_opt(HtmlDiscoveredScript(result_vec)); + assert!(to_parent.send_opt(HtmlDiscoveredScript(result_vec)).is_ok()); } // Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized @@ -340,7 +339,7 @@ pub fn parse_html(page: &Page, let doc_cell = RefCell::new(document); let mut tree_handler = hubbub::TreeHandler { - create_comment: |data: ~str| { + create_comment: |data: String| { debug!("create comment"); // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); @@ -370,7 +369,7 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; - let element: Root<Element> = build_element_from_tag(tag.name.clone(), *tmp).root(); + let mut element: Root<Element> = build_element_from_tag(tag.name.clone(), *tmp).root(); debug!("-- attach attrs"); for attr in tag.attributes.iter() { @@ -381,10 +380,10 @@ pub fn parse_html(page: &Page, XmlNsNs => (namespace::XMLNS, Some("xmlns")), ns => fail!("Not expecting namespace {:?}", ns), }; - element.deref().set_attribute_from_parser(attr.name.clone(), - attr.value.clone(), - namespace, - prefix.map(|p| p.to_owned())); + element.set_attribute_from_parser(attr.name.clone(), + attr.value.clone(), + namespace, + prefix.map(|p| p.to_string())); } //FIXME: workaround for https://github.com/mozilla/rust/issues/13246; @@ -407,9 +406,9 @@ pub fn parse_html(page: &Page, // Handle CSS style sheets from <link> elements ElementNodeTypeId(HTMLLinkElementTypeId) => { match (rel, href) { - (Some(ref rel), Some(ref href)) if rel.split(HTML_SPACE_CHARACTERS.as_slice()) + (Some(ref rel), Some(ref href)) if rel.as_slice().split(HTML_SPACE_CHARACTERS.as_slice()) .any(|s| { - s.eq_ignore_ascii_case("stylesheet") + s.as_slice().eq_ignore_ascii_case("stylesheet") }) => { debug!("found CSS stylesheet: {:s}", *href); let url = parse_url(href.as_slice(), Some(url2.clone())); @@ -423,7 +422,7 @@ pub fn parse_html(page: &Page, unsafe { element.deref().to_hubbub_node() } }, - create_text: |data: ~str| { + create_text: |data: String| { debug!("create text"); // NOTE: tmp vars are workaround for lifetime issues. Both required. let tmp_borrow = doc_cell.borrow(); diff --git a/src/components/script/script.rs b/src/components/script/script.rs index 4a2974d8cd2..f6dd0ba7025 100644 --- a/src/components/script/script.rs +++ b/src/components/script/script.rs @@ -16,6 +16,7 @@ #[phase(syntax, link)] extern crate log; +extern crate debug; extern crate collections; extern crate geom; extern crate hubbub; @@ -48,11 +49,11 @@ pub mod dom { pub mod str; pub mod trace; pub mod codegen { + pub mod Bindings; pub mod InterfaceTypes; pub mod InheritTypes; pub mod PrototypeList; pub mod RegisterBindings; - pub mod Bindings; pub mod UnionTypes; } } diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 918e80c4c47..1929449f9a7 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -53,7 +53,6 @@ use servo_util::geometry::to_frac_px; use servo_util::task::send_on_failure; use servo_util::namespace::Null; use servo_util::str::DOMString; -use std::cast; use std::cell::{Cell, RefCell, Ref, RefMut}; use std::comm::{channel, Sender, Receiver, Empty, Disconnected}; use std::mem::replace; @@ -239,10 +238,8 @@ impl Page { .enumerate() .find(|&(_idx, ref page_tree)| { // FIXME: page_tree has a lifetime such that it's unusable for anything. - let page_tree = unsafe { - cast::transmute_lifetime(page_tree) - }; - page_tree.id == id + let page_tree_id = page_tree.id; + page_tree_id == id }) .map(|(idx, _)| idx) }; @@ -442,7 +439,7 @@ impl Page { /// Attempt to find a named element in this page's document. fn find_fragment_node(&self, fragid: DOMString) -> Option<Temporary<Element>> { let document = self.frame().get_ref().document.root(); - match document.deref().GetElementById(fragid.to_owned()) { + match document.deref().GetElementById(fragid.to_string()) { Some(node) => Some(node), None => { let doc_node: &JSRef<Node> = NodeCast::from_ref(&*document); @@ -451,7 +448,7 @@ impl Page { anchors.find(|node| { let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap(); elem.get_attribute(Null, "name").root().map_or(false, |attr| { - attr.deref().value_ref() == fragid + attr.deref().value_ref() == fragid.as_slice() }) }).map(|node| Temporary::from_rooted(ElementCast::to_ref(&node).unwrap())) } @@ -1007,7 +1004,7 @@ impl ScriptTask { // Kick off the initial reflow of the page. document.content_changed(); - let fragment = url.fragment.as_ref().map(|ref fragment| fragment.to_owned()); + let fragment = url.fragment.as_ref().map(|ref fragment| fragment.to_string()); { // No more reflow required @@ -1037,7 +1034,7 @@ impl ScriptTask { // "load" event as soon as we've finished executing all scripts parsed during // the initial load. let mut event = - Event::new(&*window, "load".to_owned(), false, false).root(); + Event::new(&*window, "load".to_string(), false, false).root(); let doctarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*document); let wintarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*window); let _ = wintarget.dispatch_event_with_target(Some((*doctarget).clone()), @@ -1092,7 +1089,7 @@ impl ScriptTask { Some(mut window) => { // http://dev.w3.org/csswg/cssom-view/#resizing-viewports // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize - let mut uievent = UIEvent::new(&window.clone(), "resize".to_owned(), false, false, + let mut uievent = UIEvent::new(&window.clone(), "resize".to_string(), false, false, Some((*window).clone()), 0i32).root(); let event: &mut JSRef<Event> = EventCast::from_mut_ref(&mut *uievent); @@ -1134,7 +1131,7 @@ impl ScriptTask { let window = frame.window.root(); let mut event = Event::new(&*window, - "click".to_owned(), + "click".to_string(), true, true).root(); let eventtarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&node); let _ = eventtarget.dispatch_event_with_target(None, &mut *event); |