mirror of
https://github.com/servo/servo.git
synced 2025-10-12 06:20:26 +01:00
Upgrade Rust.
This commit is contained in:
parent
2ae671b5aa
commit
629c4c6afe
148 changed files with 992 additions and 967 deletions
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
40
src/components/script/dom/htmlmainelement.rs
Normal file
40
src/components/script/dom/htmlmainelement.rs
Normal file
|
@ -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 {
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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("&"),
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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>>;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue