diff options
Diffstat (limited to 'components/script/dom')
56 files changed, 634 insertions, 501 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 789e5f925d6..e8a66199db7 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -29,7 +29,7 @@ pub enum AttrSettingType { ReplacedAttr, } -#[deriving(PartialEq, Clone)] +#[derive(PartialEq, Clone)] #[jstraceable] pub enum AttrValue { String(DOMString), @@ -58,7 +58,8 @@ impl AttrValue { } pub fn from_u32(string: DOMString, default: u32) -> AttrValue { - let result: u32 = from_str(string.as_slice()).unwrap_or(default); + // XXX Is parse() correct? + let result: u32 = string.parse().unwrap_or(default); AttrValue::UInt(string, result) } diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index 6b8fcc09e34..3bfc0c107a4 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -14,10 +14,11 @@ use js::jsapi::{JS_GetProperty, JS_IsExceptionPending, JS_ReportPendingException use js::jsval::{JSVal, UndefinedValue}; use js::rust::with_compartment; +use std::ffi::CString; use std::ptr; /// The exception handling used for a call. -#[deriving(Copy, PartialEq)] +#[derive(Copy, PartialEq)] pub enum ExceptionHandling { /// Report any exception and don't throw it to the caller code. Report, @@ -26,7 +27,7 @@ pub enum ExceptionHandling { } /// A common base class for representing IDL callback function types. -#[deriving(Copy, Clone,PartialEq)] +#[derive(Copy, Clone,PartialEq)] #[jstraceable] pub struct CallbackFunction { object: CallbackObject @@ -44,7 +45,7 @@ impl CallbackFunction { } /// A common base class for representing IDL callback interface types. -#[deriving(Copy, Clone,PartialEq)] +#[derive(Copy, Clone,PartialEq)] #[jstraceable] pub struct CallbackInterface { object: CallbackObject @@ -53,7 +54,7 @@ pub struct CallbackInterface { /// A common base class for representing IDL callback function and /// callback interface types. #[allow(raw_pointer_deriving)] -#[deriving(Copy, Clone,PartialEq)] +#[derive(Copy, Clone,PartialEq)] #[jstraceable] struct CallbackObject { /// The underlying `JSObject`. @@ -99,7 +100,7 @@ impl CallbackInterface { pub fn GetCallableProperty(&self, cx: *mut JSContext, name: &str) -> Result<JSVal, ()> { let mut callable = UndefinedValue(); unsafe { - let name = name.to_c_str(); + let name = CString::from_slice(name.as_bytes()); if JS_GetProperty(cx, self.callback(), name.as_ptr(), &mut callable) == 0 { return Err(()); } diff --git a/components/script/dom/bindings/codegen/Bindings.conf b/components/script/dom/bindings/codegen/Bindings.conf index 48b6067d00c..439ddfbd59e 100644 --- a/components/script/dom/bindings/codegen/Bindings.conf +++ b/components/script/dom/bindings/codegen/Bindings.conf @@ -15,7 +15,7 @@ DOMInterfaces = { 'Window': { - 'outerObjectHook': 'Some(bindings::utils::outerize_global)', + 'outerObjectHook': 'Some(bindings::utils::outerize_global as extern fn(*mut JSContext, JSHandleObject) -> *mut JSObject)', }, #FIXME(jdm): This should be 'register': False, but then we don't generate enum types diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index e1e5bee2036..47dd912d700 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -679,7 +679,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None, value = "Some(%s)" % value default = ( - "const data: [u8, ..%s] = [ %s ];\n" + "const data: [u8; %s] = [ %s ];\n" "%s" % (len(defaultValue.value) + 1, ", ".join(["'" + char + "' as u8" for char in defaultValue.value] + ["0"]), @@ -1189,14 +1189,16 @@ class MethodDefiner(PropertyDefiner): def specData(m): if m.get("methodInfo", True): jitinfo = ("&%s_methodinfo" % m["name"]) - accessor = "genericMethod" + accessor = "genericMethod as NonNullJSNative" else: jitinfo = "0 as *const JSJitInfo" accessor = m.get("nativeName", m["name"]) + if accessor[0:3] != 'JS_': + accessor = "%s as NonNullJSNative" % accessor return (m["name"], accessor, jitinfo, m["length"], m["flags"]) def stringDecl(m): - return "const %s_name: [u8, ..%i] = %s;\n" % (m["name"], len(m["name"]) + 1, + return "const %s_name: [u8; %i] = %s;\n" % (m["name"], len(m["name"]) + 1, str_to_const_array(m["name"])) decls = ''.join([stringDecl(m) for m in array]) @@ -1236,7 +1238,7 @@ class AttrDefiner(PropertyDefiner): accessor = "genericGetter" jitinfo = "&%s_getterinfo" % attr.identifier.name - return ("JSPropertyOpWrapper {op: Some(%(native)s), info: %(info)s as *const JSJitInfo}" + return ("JSPropertyOpWrapper {op: Some(%(native)s as NonNullJSNative), info: %(info)s as *const JSJitInfo}" % {"info" : jitinfo, "native" : accessor}) @@ -1254,7 +1256,7 @@ class AttrDefiner(PropertyDefiner): accessor = "genericSetter" jitinfo = "&%s_setterinfo" % attr.identifier.name - return ("JSStrictPropertyOpWrapper {op: Some(%(native)s), info: %(info)s as *const JSJitInfo}" + return ("JSStrictPropertyOpWrapper {op: Some(%(native)s as NonNullJSNative), info: %(info)s as *const JSJitInfo}" % {"info" : jitinfo, "native" : accessor}) @@ -1264,7 +1266,7 @@ class AttrDefiner(PropertyDefiner): def stringDecl(attr): name = attr.identifier.name - return "const %s_name: [u8, ..%i] = %s;\n" % (name, len(name) + 1, + return "const %s_name: [u8; %i] = %s;\n" % (name, len(name) + 1, str_to_const_array(name)) decls = ''.join([stringDecl(m) for m in array]) @@ -1434,7 +1436,7 @@ class CGDOMJSClass(CGThing): self.descriptor = descriptor def define(self): - traceHook = "Some(%s)" % TRACE_HOOK_NAME + traceHook = 'Some(%s as unsafe extern "C" fn(*mut JSTracer, *mut JSObject))' % TRACE_HOOK_NAME if self.descriptor.isGlobal(): flags = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL" slots = "JSCLASS_GLOBAL_SLOT_COUNT + 1" @@ -1442,7 +1444,7 @@ class CGDOMJSClass(CGThing): flags = "0" slots = "1" return """\ -const Class_name: [u8, ..%i] = %s; +const Class_name: [u8; %i] = %s; static Class: DOMJSClass = DOMJSClass { base: js::Class { name: &Class_name as *const u8 as *const libc::c_char, @@ -1454,7 +1456,7 @@ static Class: DOMJSClass = DOMJSClass { enumerate: Some(JS_EnumerateStub), resolve: Some(JS_ResolveStub), convert: Some(JS_ConvertStub), - finalize: Some(%s), + finalize: Some(%s as unsafe extern "C" fn(*mut JSFreeOp, *mut JSObject)), checkAccess: None, call: None, hasInstance: None, @@ -1526,7 +1528,7 @@ class CGPrototypeJSClass(CGThing): def define(self): return """\ -const PrototypeClassName__: [u8, ..%s] = %s; +const PrototypeClassName__: [u8; %s] = %s; static PrototypeClass: JSClass = JSClass { name: &PrototypeClassName__ as *const u8 as *const libc::c_char, flags: (1 & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT as uint, //JSCLASS_HAS_RESERVED_SLOTS(1) @@ -1543,7 +1545,7 @@ static PrototypeClass: JSClass = JSClass { hasInstance: None, construct: None, trace: None, - reserved: [0 as *mut libc::c_void, ..40] + reserved: [0 as *mut libc::c_void; 40] }; """ % (len(self.descriptor.interface.identifier.name + "Prototype") + 1, str_to_const_array(self.descriptor.interface.identifier.name + "Prototype")) @@ -1992,7 +1994,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): constructHook = "ThrowingConstructor" constructArgs = 0 - constructor = 'Some((%s, "%s", %d))' % ( + constructor = 'Some((%s as NonNullJSNative, "%s", %d))' % ( constructHook, self.descriptor.interface.identifier.name, constructArgs) else: @@ -2096,16 +2098,16 @@ class CGDefineProxyHandler(CGAbstractMethod): body = """\ let traps = ProxyTraps { - getPropertyDescriptor: Some(getPropertyDescriptor), - getOwnPropertyDescriptor: Some(getOwnPropertyDescriptor), - defineProperty: Some(%s), - getOwnPropertyNames: Some(getOwnPropertyNames_), - delete_: Some(%s), - enumerate: Some(enumerate_), + getPropertyDescriptor: Some(getPropertyDescriptor as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, bool, *mut JSPropertyDescriptor) -> bool), + getOwnPropertyDescriptor: Some(getOwnPropertyDescriptor as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, bool, *mut JSPropertyDescriptor) -> bool), + defineProperty: Some(%s as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, *mut JSPropertyDescriptor) -> bool), + getOwnPropertyNames: Some(getOwnPropertyNames_ as unsafe extern "C" fn(*mut JSContext, *mut JSObject, *mut AutoIdVector) -> bool), + delete_: Some(%s as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, *mut bool) -> bool), + enumerate: Some(enumerate_ as unsafe extern "C" fn(*mut JSContext, *mut JSObject, *mut AutoIdVector) -> bool), has: None, - hasOwn: Some(hasOwn), - get: Some(get), + hasOwn: Some(hasOwn as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, *mut bool) -> bool), + get: Some(get as unsafe extern "C" fn(*mut JSContext, *mut JSObject, *mut JSObject, jsid, *mut JSVal) -> bool), set: None, keys: None, iterate: None, @@ -2116,15 +2118,15 @@ let traps = ProxyTraps { hasInstance: None, typeOf: None, objectClassIs: None, - obj_toString: Some(obj_toString), + obj_toString: Some(obj_toString as unsafe extern "C" fn(*mut JSContext, *mut JSObject) -> *mut js::jsapi::JSString), fun_toString: None, //regexp_toShared: ptr::null(), defaultValue: None, iteratorNext: None, - finalize: Some(%s), + finalize: Some(%s as unsafe extern "C" fn(*mut JSFreeOp, *mut JSObject)), getElementIfPresent: None, getPrototypeOf: None, - trace: Some(%s) + trace: Some(%s as unsafe extern "C" fn(*mut JSTracer, *mut JSObject)) }; CreateProxyHandler(&traps, &Class as *const _ as *const _)\ @@ -2763,7 +2765,7 @@ class CGEnum(CGThing): decl = """\ #[repr(uint)] -#[deriving(PartialEq, Copy)] +#[derive(PartialEq, Copy)] #[jstraceable] pub enum %s { %s @@ -4256,7 +4258,7 @@ class CGNonNamespacedEnum(CGThing): # Build the enum body. enumstr = comment + 'pub enum %s {\n%s\n}\n' % (enumName, ',\n'.join(entries)) if deriving: - enumstr = ('#[deriving(%s)]\n' % deriving) + enumstr + enumstr = ('#[derive(%s)]\n' % deriving) + enumstr curr = CGGeneric(enumstr) # Add some whitespace padding. @@ -4458,7 +4460,7 @@ class CGRegisterProxyHandlers(CGThing): descriptors = config.getDescriptors(proxy=True) length = len(descriptors) self.root = CGList([ - CGGeneric("pub static mut proxy_handlers: [*const libc::c_void, ..%d] = [0 as *const libc::c_void, ..%d];" % (length, length)), + CGGeneric("pub static mut proxy_handlers: [*const libc::c_void; %d] = [0 as *const libc::c_void; %d];" % (length, length)), CGRegisterProxyHandlersMethod(descriptors), ], "\n") @@ -4530,11 +4532,12 @@ class CGBindingRoot(CGThing): 'js::jsapi::{JSPropertyOpWrapper, JSPropertySpec, JS_PropertyStub}', 'js::jsapi::{JSStrictPropertyOpWrapper, JSString, JSTracer, JS_ConvertStub}', 'js::jsapi::{JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub}', + 'js::jsapi::{JSMutableHandleValue, JSHandleId, JSType}', 'js::jsval::JSVal', 'js::jsval::{ObjectValue, ObjectOrNullValue, PrivateValue}', 'js::jsval::{NullValue, UndefinedValue}', 'js::glue::{CallJitMethodOp, CallJitPropertyOp, CreateProxyHandler}', - 'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps}', + 'js::glue::{GetProxyPrivate, NewProxyObject, ProxyTraps, AutoIdVector}', 'js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO}', 'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}', 'js::rust::with_compartment', @@ -4559,6 +4562,7 @@ class CGBindingRoot(CGThing): 'dom::bindings::utils::get_dictionary_property', 'dom::bindings::utils::{NativeProperties, NativePropertyHooks}', 'dom::bindings::utils::ConstantVal::{IntVal, UintVal}', + 'dom::bindings::utils::NonNullJSNative', 'dom::bindings::trace::JSTraceable', 'dom::bindings::callback::{CallbackContainer,CallbackInterface,CallbackFunction}', 'dom::bindings::callback::{CallSetup,ExceptionHandling}', @@ -4696,7 +4700,7 @@ class CGCallback(CGClass): bases=[ClassBase(baseName)], constructors=self.getConstructors(), methods=realMethods+getters+setters, - decorators="#[deriving(PartialEq,Copy,Clone)]#[jstraceable]") + decorators="#[derive(PartialEq,Copy,Clone)]#[jstraceable]") def getConstructors(self): return [ClassConstructor( @@ -5225,11 +5229,11 @@ class GlobalGenRoots(): CGGeneric("use std::mem;\n\n")] for descriptor in descriptors: name = descriptor.name - protos = [CGGeneric('pub trait %s {}\n' % (name + 'Base'))] + protos = [CGGeneric('pub trait %s : Sized {}\n' % (name + 'Base'))] for proto in descriptor.prototypeChain: protos += [CGGeneric('impl %s for %s {}\n' % (proto + 'Base', descriptor.concreteType))] - derived = [CGGeneric('pub trait %s { fn %s(&self) -> bool; }\n' % + derived = [CGGeneric('pub trait %s : Sized { fn %s(&self) -> bool; }\n' % (name + 'Derived', 'is_' + name.lower()))] for protoName in descriptor.prototypeChain[1:-1]: protoDescriptor = config.getDescriptor(protoName) @@ -5237,7 +5241,8 @@ class GlobalGenRoots(): impl ${selfName} for ${baseName} { #[inline] fn ${fname}(&self) -> bool { - ${parentName}Cast::from_actual(self).${fname}() +let base: &${parentName} = ${parentName}Cast::from_actual(self); + base.${fname}() } }\ """).substitute({'fname': 'is_' + name.lower(), @@ -5248,7 +5253,7 @@ impl ${selfName} for ${baseName} { derived += [CGGeneric('\n')] cast = [CGGeneric(string.Template("""\ -pub trait ${castTraitName} { +pub trait ${castTraitName} : Sized { #[inline(always)] fn to_ref<'a, T: ${toBound}+Reflectable>(base: JSRef<'a, T>) -> Option<JSRef<'a, Self>> { match base.${checkFn}() { diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 8447b9e9554..27e9c1682d1 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -45,7 +45,7 @@ pub trait IDLInterface { } /// A trait to convert Rust types to `JSVal`s. -pub trait ToJSValConvertible for Sized? { +pub trait ToJSValConvertible { /// Convert `self` to a `JSVal`. JSAPI failure causes a task failure. fn to_jsval(&self, cx: *mut JSContext) -> JSVal; } @@ -253,7 +253,7 @@ impl ToJSValConvertible for DOMString { } /// Behavior for stringification of `JSVal`s. -#[deriving(PartialEq)] +#[derive(PartialEq)] pub enum StringificationBehavior { /// Convert `null` to the string `"null"`. Default, @@ -498,6 +498,7 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> { } } +#[old_impl_check] impl<X: default::Default, T: FromJSValConvertible<X>> FromJSValConvertible<()> for Option<T> { fn from_jsval(cx: *mut JSContext, value: JSVal, _: ()) -> Result<Option<T>, ()> { if value.is_null_or_undefined() { diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs index 2d02dc08ee9..e6e62473a76 100644 --- a/components/script/dom/bindings/error.rs +++ b/components/script/dom/bindings/error.rs @@ -18,10 +18,11 @@ use js::glue::{ReportError}; use js::rust::with_compartment; use libc; +use std::ffi::CString; use std::ptr; /// DOM exceptions that can be thrown by a native DOM method. -#[deriving(Show, Clone)] +#[derive(Show, Clone)] pub enum Error { /// IndexSizeError IndexSize, @@ -95,14 +96,13 @@ pub fn report_pending_exception(cx: *mut JSContext, obj: *mut JSObject) { pub fn throw_not_in_union(cx: *mut JSContext, names: &'static str) -> JSBool { assert!(unsafe { JS_IsExceptionPending(cx) } == 0); let message = format!("argument could not be converted to any of: {}", names); - message.with_c_str(|string| { - unsafe { ReportError(cx, string) }; - }); + let string = CString::from_slice(message.as_bytes()); + unsafe { ReportError(cx, string.as_ptr()) }; return 0; } /// Format string used to throw `TypeError`s. -static ERROR_FORMAT_STRING_STRING: [libc::c_char, ..4] = [ +static ERROR_FORMAT_STRING_STRING: [libc::c_char; 4] = [ '{' as libc::c_char, '0' as libc::c_char, '}' as libc::c_char, @@ -110,7 +110,7 @@ static ERROR_FORMAT_STRING_STRING: [libc::c_char, ..4] = [ ]; /// Format string struct used to throw `TypeError`s. -static ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString { +static mut ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString { format: &ERROR_FORMAT_STRING_STRING as *const libc::c_char, argCount: 1, exnType: JSEXN_TYPEERR as i16, @@ -127,8 +127,12 @@ unsafe extern fn get_error_message(_user_ref: *mut libc::c_void, /// Throw a `TypeError` with the given message. pub fn throw_type_error(cx: *mut JSContext, error: &str) { - let error = error.to_c_str(); + let error = CString::from_slice(error.as_bytes()); unsafe { - JS_ReportErrorNumber(cx, Some(get_error_message), ptr::null_mut(), 0, error.as_ptr()); + JS_ReportErrorNumber(cx, + Some(get_error_message as + unsafe extern "C" fn(*mut libc::c_void, *const libc::c_char, + libc::c_uint) -> *const JSErrorFormatString), + ptr::null_mut(), 0, error.as_ptr()); } } diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 94a9fdf0cd4..0343771c77e 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -28,7 +28,7 @@ use url::Url; use std::ptr; /// A freely-copyable reference to a rooted global object. -#[deriving(Copy)] +#[derive(Copy)] pub enum GlobalRef<'a> { /// A reference to a `Window` object. Window(JSRef<'a, window::Window>), diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index bc2d52a24bd..637ee079a4d 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -57,8 +57,9 @@ use script_task::STACK_ROOTS; use servo_util::smallvec::{SmallVec, SmallVec16}; use std::cell::{Cell, UnsafeCell}; use std::default::Default; -use std::kinds::marker::ContravariantLifetime; +use std::marker::ContravariantLifetime; use std::mem; +use std::ops::Deref; /// 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. @@ -176,6 +177,7 @@ impl<T: Reflectable> JS<T> { } } +#[old_impl_check] impl<T: Assignable<U>, U: Reflectable> JS<U> { /// Create a `JS<T>` from any JS-managed pointer. pub fn from_rooted(root: T) -> JS<U> { @@ -246,6 +248,7 @@ pub struct MutNullableJS<T: Reflectable> { ptr: Cell<Option<JS<T>>> } +#[old_impl_check] impl<T: Assignable<U>, U: Reflectable> MutNullableJS<U> { /// Create a new `MutNullableJS` pub fn new(initial: Option<T>) -> MutNullableJS<U> { @@ -295,7 +298,9 @@ impl<T: Reflectable> MutNullableJS<T> { /// Retrieve a copy of the current inner value. If it is `None`, it is /// initialized with the result of `cb` first. - pub fn or_init(&self, cb: || -> Temporary<T>) -> Temporary<T> { + pub fn or_init<F>(&self, cb: F) -> Temporary<T> + where F: FnOnce() -> Temporary<T> + { match self.get() { Some(inner) => inner, None => { @@ -323,6 +328,7 @@ impl<T: Reflectable> JS<T> { } } +#[old_impl_check] impl<From, To> JS<From> { /// Return `self` as a `JS` of another type. //XXXjdm It would be lovely if this could be private. @@ -500,7 +506,7 @@ impl RootCollection { unsafe { let roots = self.roots.get(); (*roots).push(untracked.js_ptr); - debug!(" rooting {}", untracked.js_ptr); + debug!(" rooting {:?}", untracked.js_ptr); } } @@ -508,7 +514,7 @@ impl RootCollection { fn unroot<'b, T: Reflectable>(&self, rooted: &Root<T>) { unsafe { let roots = self.roots.get(); - debug!("unrooting {} (expecting {}", + debug!("unrooting {:?} (expecting {:?}", (*roots).as_slice().last().unwrap(), rooted.js_ptr); assert!(*(*roots).as_slice().last().unwrap() == rooted.js_ptr); @@ -565,13 +571,15 @@ impl<T: Reflectable> Drop for Root<T> { } } -impl<'b, T: Reflectable> Deref<JSRef<'b, T>> for Root<T> { +impl<'b, T: Reflectable> Deref for Root<T> { + type Target = JSRef<'b, T>; fn deref<'c>(&'c self) -> &'c JSRef<'b, T> { &self.jsref } } -impl<'a, T: Reflectable> Deref<T> for JSRef<'a, T> { +impl<'a, T: Reflectable> Deref for JSRef<'a, T> { + type Target = T; fn deref<'b>(&'b self) -> &'b T { unsafe { &*self.ptr diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index 05dd4fb43ad..5a23e7f2027 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -32,15 +32,17 @@ use js::jsapi::{JS_AddObjectRoot, JS_RemoveObjectRoot, JSContext}; use libc; use std::cell::RefCell; -use std::collections::hash_map::{HashMap, Vacant, Occupied}; +use std::collections::hash_map::HashMap; +use std::collections::hash_map::Entry::{Vacant, Occupied}; use std::rc::Rc; use std::sync::{Arc, Mutex}; -thread_local!(pub static LIVE_REFERENCES: Rc<RefCell<Option<LiveDOMReferences>>> = Rc::new(RefCell::new(None))) +thread_local!(pub static LIVE_REFERENCES: Rc<RefCell<Option<LiveDOMReferences>>> = Rc::new(RefCell::new(None))); /// A pointer to a Rust DOM object that needs to be destroyed. pub struct TrustedReference(*const libc::c_void); +unsafe impl Send for TrustedReference {} /// A safe wrapper around a raw pointer to a DOM object that can be /// shared among tasks for use in asynchronous operations. The underlying @@ -55,6 +57,8 @@ pub struct Trusted<T> { owner_thread: *const libc::c_void, } +unsafe impl<T: Reflectable> Send for Trusted<T> {} + impl<T: Reflectable> Trusted<T> { /// Create a new `Trusted<T>` instance from an existing DOM pointer. The DOM object will /// be prevented from being GCed for the duration of the resulting `Trusted<T>` object's @@ -91,7 +95,7 @@ impl<T: Reflectable> Trusted<T> { impl<T: Reflectable> Clone for Trusted<T> { fn clone(&self) -> Trusted<T> { { - let mut refcount = self.refcount.lock(); + let mut refcount = self.refcount.lock().unwrap(); *refcount += 1; } @@ -107,7 +111,7 @@ impl<T: Reflectable> Clone for Trusted<T> { #[unsafe_destructor] impl<T: Reflectable> Drop for Trusted<T> { fn drop(&mut self) { - let mut refcount = self.refcount.lock(); + let mut refcount = self.refcount.lock().unwrap(); assert!(*refcount > 0); *refcount -= 1; if *refcount == 0 { @@ -139,7 +143,7 @@ impl LiveDOMReferences { match table.entry(ptr as *const libc::c_void) { Occupied(mut entry) => { let refcount = entry.get_mut(); - *refcount.lock() += 1; + *refcount.lock().unwrap() += 1; refcount.clone() } Vacant(entry) => { @@ -148,7 +152,7 @@ impl LiveDOMReferences { JS_AddObjectRoot(cx, rootable); } let refcount = Arc::new(Mutex::new(1)); - entry.set(refcount.clone()); + entry.insert(refcount.clone()); refcount } } @@ -164,7 +168,7 @@ impl LiveDOMReferences { let mut table = live_references.table.borrow_mut(); match table.entry(raw_reflectable) { Occupied(entry) => { - if *entry.get().lock() != 0 { + if *entry.get().lock().unwrap() != 0 { // there could have been a new reference taken since // this message was dispatched. return; @@ -173,7 +177,7 @@ impl LiveDOMReferences { unsafe { JS_RemoveObjectRoot(cx, (*reflectable).rootable()); } - let _ = entry.take(); + let _ = entry.remove(); } Vacant(_) => { // there could be a cleanup message dispatched, then a new diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index e67c8ac7d6a..77653513717 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -7,12 +7,12 @@ //! The `ByteString` struct. use std::borrow::ToOwned; -use std::hash::{Hash, sip}; +use std::hash::{Hash, SipHasher}; use std::str; use std::str::FromStr; /// Encapsulates the IDL `ByteString` type. -#[deriving(Clone,Eq,PartialEq)] +#[derive(Clone,Eq,PartialEq)] #[jstraceable] pub struct ByteString(Vec<u8>); @@ -26,7 +26,7 @@ impl ByteString { /// otherwise. pub fn as_str<'a>(&'a self) -> Option<&'a str> { let ByteString(ref vec) = *self; - str::from_utf8(vec.as_slice()) + str::from_utf8(vec.as_slice()).ok() } /// Returns the underlying vector as a slice. @@ -84,7 +84,7 @@ impl ByteString { /// [RFC 2616](http://tools.ietf.org/html/rfc2616#page-32). pub fn is_field_value(&self) -> bool { // Classifications of characters necessary for the [CRLF] (SP|HT) rule - #[deriving(PartialEq)] + #[derive(PartialEq)] enum PreviousCharacter { Other, CR, @@ -146,8 +146,8 @@ impl ByteString { } } -impl Hash for ByteString { - fn hash(&self, state: &mut sip::SipState) { +impl Hash<SipHasher> for ByteString { + fn hash(&self, state: &mut SipHasher) { let ByteString(ref vec) = *self; vec.hash(state); } diff --git a/components/script/dom/bindings/structuredclone.rs b/components/script/dom/bindings/structuredclone.rs index 85f813cda8b..e7baa868187 100644 --- a/components/script/dom/bindings/structuredclone.rs +++ b/components/script/dom/bindings/structuredclone.rs @@ -60,3 +60,5 @@ impl StructuredCloneData { message } } + +unsafe impl Send for StructuredCloneData {} diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index ff730ea1e12..ff329ce6165 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -33,7 +33,6 @@ use dom::bindings::utils::{Reflectable, Reflector, WindowProxyHandler}; use dom::node::{Node, TrustedNodeAddress}; use script_task::ScriptChan; -use collections::hash::{Hash, Hasher}; use cssparser::RGBA; use geom::rect::Rect; use html5ever::tree_builder::QuirksMode; @@ -54,9 +53,12 @@ use servo_util::smallvec::{SmallVec1, SmallVec}; use servo_util::str::{LengthOrPercentageOrAuto}; use std::cell::{Cell, RefCell}; use std::collections::HashMap; -use std::comm::{Receiver, Sender}; +use std::collections::hash_state::HashState; +use std::ffi::CString; +use std::hash::{Hash, Hasher}; use std::io::timer::Timer; use std::rc::Rc; +use std::sync::mpsc::{Receiver, Sender}; use string_cache::{Atom, Namespace}; use style::PropertyDeclarationBlock; use url::Url; @@ -74,7 +76,7 @@ impl<T: Reflectable> JSTraceable for JS<T> { } } -no_jsmanaged_fields!(Reflector) +no_jsmanaged_fields!(Reflector); /// Trace a `JSVal`. pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) { @@ -83,7 +85,7 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: JSVal) { } unsafe { - let name = description.to_c_str(); + let name = CString::from_slice(description.as_bytes()); (*tracer).debugPrinter = None; (*tracer).debugPrintIndex = -1; (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void; @@ -101,7 +103,7 @@ pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Ref /// Trace a `JSObject`. pub fn trace_object(tracer: *mut JSTracer, description: &str, obj: *mut JSObject) { unsafe { - let name = description.to_c_str(); + let name = CString::from_slice(description.as_bytes()); (*tracer).debugPrinter = None; (*tracer).debugPrintIndex = -1; (*tracer).debugPrintArg = name.as_ptr() as *const libc::c_void; @@ -175,14 +177,17 @@ impl<T: JSTraceable> JSTraceable for Option<T> { } } -impl<K,V,S,H> JSTraceable for HashMap<K, V, H> where K: Eq + Hash<S> + JSTraceable, - V: JSTraceable, - H: Hasher<S> { +impl<K,V,S> JSTraceable for HashMap<K, V, S> + where K: Hash<<S as HashState>::Hasher> + Eq + JSTraceable, + V: JSTraceable, + S: HashState, + <S as HashState>::Hasher: Hasher<Output=u64>, +{ #[inline] fn trace(&self, trc: *mut JSTracer) { - for e in self.iter() { - e.val0().trace(trc); - e.val1().trace(trc); + for (k, v) in self.iter() { + k.trace(trc); + v.trace(trc); } } } @@ -197,28 +202,28 @@ impl<A: JSTraceable, B: JSTraceable> JSTraceable for (A, B) { } -no_jsmanaged_fields!(bool, f32, f64, String, Url) -no_jsmanaged_fields!(uint, u8, u16, u32, u64) -no_jsmanaged_fields!(int, i8, i16, i32, i64) -no_jsmanaged_fields!(Sender<T>) -no_jsmanaged_fields!(Receiver<T>) -no_jsmanaged_fields!(Rect<T>) -no_jsmanaged_fields!(ImageCacheTask, ScriptControlChan) -no_jsmanaged_fields!(Atom, Namespace, Timer) -no_jsmanaged_fields!(Trusted<T>) -no_jsmanaged_fields!(PropertyDeclarationBlock) +no_jsmanaged_fields!(bool, f32, f64, String, Url); +no_jsmanaged_fields!(uint, u8, u16, u32, u64); +no_jsmanaged_fields!(int, i8, i16, i32, i64); +no_jsmanaged_fields!(Sender<T>); +no_jsmanaged_fields!(Receiver<T>); +no_jsmanaged_fields!(Rect<T>); +no_jsmanaged_fields!(ImageCacheTask, ScriptControlChan); +no_jsmanaged_fields!(Atom, Namespace, Timer); +no_jsmanaged_fields!(Trusted<T>); +no_jsmanaged_fields!(PropertyDeclarationBlock); // These three are interdependent, if you plan to put jsmanaged data // in one of these make sure it is propagated properly to containing structs -no_jsmanaged_fields!(SubpageId, WindowSizeData, PipelineId) -no_jsmanaged_fields!(QuirksMode) -no_jsmanaged_fields!(Cx) -no_jsmanaged_fields!(Headers, Method) -no_jsmanaged_fields!(ConstellationChan) -no_jsmanaged_fields!(LayoutChan) -no_jsmanaged_fields!(WindowProxyHandler) -no_jsmanaged_fields!(UntrustedNodeAddress) -no_jsmanaged_fields!(LengthOrPercentageOrAuto) -no_jsmanaged_fields!(RGBA) +no_jsmanaged_fields!(SubpageId, WindowSizeData, PipelineId); +no_jsmanaged_fields!(QuirksMode); +no_jsmanaged_fields!(Cx); +no_jsmanaged_fields!(Headers, Method); +no_jsmanaged_fields!(ConstellationChan); +no_jsmanaged_fields!(LayoutChan); +no_jsmanaged_fields!(WindowProxyHandler); +no_jsmanaged_fields!(UntrustedNodeAddress); +no_jsmanaged_fields!(LengthOrPercentageOrAuto); +no_jsmanaged_fields!(RGBA); impl JSTraceable for Box<ScriptChan+Send> { #[inline] diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 13d662ae5f7..eef06a16a3b 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -18,6 +18,7 @@ use dom::window; use libc; use libc::c_uint; use std::cell::Cell; +use std::ffi::CString; use std::mem; use std::ptr; use js::glue::UnwrapObject; @@ -84,7 +85,7 @@ pub const DOM_PROTOTYPE_SLOT: u32 = js::JSCLASS_GLOBAL_SLOT_COUNT; pub const JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1; /// Representation of an IDL constant value. -#[deriving(Clone)] +#[derive(Clone)] pub enum ConstantVal { /// `long` constant. IntVal(i32), @@ -99,7 +100,7 @@ pub enum ConstantVal { } /// Representation of an IDL constant. -#[deriving(Clone)] +#[derive(Clone)] pub struct ConstantSpec { /// name of the constant. pub name: &'static [u8], @@ -130,24 +131,26 @@ pub struct NativePropertyHooks { } /// The struct that holds inheritance information for DOM object reflectors. -#[deriving(Copy)] +#[derive(Copy)] pub struct DOMClass { /// A list of interfaces that this object implements, in order of decreasing /// derivedness. - pub interface_chain: [PrototypeList::ID, ..MAX_PROTO_CHAIN_LENGTH], + pub interface_chain: [PrototypeList::ID; MAX_PROTO_CHAIN_LENGTH], /// The NativePropertyHooks for the interface associated with this class. pub native_hooks: &'static NativePropertyHooks, } +unsafe impl Sync for DOMClass {} /// The JSClass used for DOM object reflectors. -#[deriving(Copy)] +#[derive(Copy)] pub struct DOMJSClass { /// The actual JSClass. pub base: js::Class, /// Associated data for DOM object reflectors. pub dom_class: DOMClass } +unsafe impl Sync for DOMJSClass {} /// Returns the ProtoOrIfaceArray for the given global object. /// Fails if `global` is not a DOM global object. @@ -172,6 +175,7 @@ pub struct NativeProperties { /// Static attributes for the interface. pub staticAttrs: Option<&'static [JSPropertySpec]>, } +unsafe impl Sync for NativeProperties {} /// A JSNative that cannot be null. pub type NonNullJSNative = @@ -196,7 +200,7 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv match constructor { Some((native, name, nargs)) => { - let s = name.to_c_str(); + let s = CString::from_slice(name.as_bytes()); CreateInterfaceObject(cx, global, receiver, native, nargs, proto, members, s.as_ptr()) @@ -322,7 +326,7 @@ pub unsafe extern fn ThrowingConstructor(cx: *mut JSContext, _argc: c_uint, _vp: /// Construct and cache the ProtoOrIfaceArray for the given global. /// Fails if the argument is not a DOM global. pub fn initialize_global(global: *mut JSObject) { - let protoArray = box () ([0 as *mut JSObject, ..PrototypeList::ID::Count as uint]); + let protoArray = box () ([0 as *mut JSObject; PrototypeList::ID::Count as uint]); unsafe { assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0); let box_ = squirrel_away_unique(protoArray); @@ -351,7 +355,7 @@ pub fn reflect_dom_object<T: Reflectable> /// A struct to store a reference to the reflector of a DOM object. // Allowing unused_attribute because the lint sometimes doesn't run in order #[allow(raw_pointer_deriving, unrooted_must_root, unused_attributes)] -#[deriving(PartialEq)] +#[derive(PartialEq)] #[must_root] #[servo_lang = "reflector"] // If you're renaming or moving this field, update the path in plugins::reflector as well @@ -495,7 +499,7 @@ pub fn IsPlatformObject(obj: *mut JSObject) -> bool { pub fn get_dictionary_property(cx: *mut JSContext, object: *mut JSObject, property: &str) -> Result<Option<JSVal>, ()> { - use std::c_str::CString; + use std::ffi::CString; fn has_property(cx: *mut JSContext, object: *mut JSObject, property: &CString, found: &mut JSBool) -> bool { unsafe { @@ -509,7 +513,7 @@ pub fn get_dictionary_property(cx: *mut JSContext, } } - let property = property.to_c_str(); + let property = CString::from_slice(property.as_bytes()); if object.is_null() { return Ok(None); } @@ -594,7 +598,7 @@ pub unsafe fn delete_property_by_id(cx: *mut JSContext, object: *mut JSObject, } /// Results of `xml_name_type`. -#[deriving(PartialEq)] +#[derive(PartialEq)] #[allow(missing_docs)] pub enum XMLName { QName, diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs index 782fff57c9d..69d75231fe8 100644 --- a/components/script/dom/blob.rs +++ b/components/script/dom/blob.rs @@ -11,9 +11,11 @@ use dom::bindings::codegen::Bindings::BlobBinding; use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods; use servo_util::str::DOMString; + +use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cmp::{min, max}; -use std::ascii::AsciiExt; +use std::num::ToPrimitive; #[jstraceable] pub enum BlobTypeId { @@ -69,7 +71,7 @@ impl Blob { } else { "" }; - let typeStrLower = typeString.as_slice().to_ascii_lower(); + let typeStrLower = typeString.as_slice().to_ascii_lowercase(); Ok(Blob::new(global, bytes, typeStrLower.as_slice())) } } @@ -113,7 +115,7 @@ impl<'a> BlobMethods for JSRef<'a, Blob> { None => "".to_owned(), Some(str) => { if is_ascii_printable(&str) { - str.as_slice().to_ascii_lower().to_owned() + str.as_slice().to_ascii_lowercase().to_owned() } else { "".to_owned() } diff --git a/components/script/dom/browsercontext.rs b/components/script/dom/browsercontext.rs index 959c021b4bc..2e7be2d05f0 100644 --- a/components/script/dom/browsercontext.rs +++ b/components/script/dom/browsercontext.rs @@ -194,17 +194,20 @@ unsafe extern fn set(cx: *mut JSContext, proxy: *mut JSObject, _receiver: *mut J } static PROXY_HANDLER: ProxyTraps = ProxyTraps { - getPropertyDescriptor: Some(getPropertyDescriptor), - getOwnPropertyDescriptor: Some(getOwnPropertyDescriptor), - defineProperty: Some(defineProperty), + getPropertyDescriptor: Some(getPropertyDescriptor as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, bool, *mut JSPropertyDescriptor) -> bool), + getOwnPropertyDescriptor: Some(getOwnPropertyDescriptor + as unsafe extern "C" fn(*mut JSContext, *mut JSObject, + jsid, bool, *mut JSPropertyDescriptor) + -> bool), + defineProperty: Some(defineProperty as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, *mut JSPropertyDescriptor) -> bool), getOwnPropertyNames: None, delete_: None, enumerate: None, has: None, - hasOwn: Some(hasOwn), - get: Some(get), - set: Some(set), + hasOwn: Some(hasOwn as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, *mut bool) -> bool), + get: Some(get as unsafe extern "C" fn(*mut JSContext, *mut JSObject, *mut JSObject, jsid, *mut JSVal) -> bool), + set: Some(set as unsafe extern "C" fn(*mut JSContext, *mut JSObject, *mut JSObject, jsid, bool, *mut JSVal) -> bool), keys: None, iterate: None, diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index 9ed36217fec..a1eb1af9997 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -16,6 +16,8 @@ use geom::size::Size2D; use canvas::canvas_paint_task::{CanvasMsg, CanvasPaintTask}; use canvas::canvas_paint_task::CanvasMsg::{ClearRect, Close, FillRect, Recreate, StrokeRect}; +use std::sync::mpsc::Sender; + #[dom_struct] pub struct CanvasRenderingContext2D { reflector_: Reflector, diff --git a/components/script/dom/create.rs b/components/script/dom/create.rs index 73e39768f6e..8bbbdc9c832 100644 --- a/components/script/dom/create.rs +++ b/components/script/dom/create.rs @@ -89,11 +89,15 @@ pub fn create_element(name: QualName, prefix: Option<DOMString>, } macro_rules! make( - ($ctor:ident $(, $arg:expr)*) => ({ - let obj = $ctor::new(name.local.as_slice().to_owned(), prefix, document $(, $arg)*); + ($ctor:ident) => ({ + let obj = $ctor::new(name.local.as_slice().to_owned(), prefix, document); + ElementCast::from_temporary(obj) + }); + ($ctor:ident, $($arg:expr),+) => ({ + let obj = $ctor::new(name.local.as_slice().to_owned(), prefix, document, $($arg),+); ElementCast::from_temporary(obj) }) - ) + ); // This is a big match, and the IDs for inline-interned atoms are not very structured. // Perhaps we should build a perfect hash from those IDs instead. diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 32f7f174433..2e438721b6c 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -30,7 +30,7 @@ pub struct CSSStyleDeclaration { readonly: bool, } -#[deriving(PartialEq)] +#[derive(PartialEq)] pub enum CSSModificationAccess { ReadWrite, Readonly @@ -47,7 +47,7 @@ macro_rules! css_properties( } )* ); -) +); fn serialize_list(list: &Vec<PropertyDeclaration>) -> DOMString { let mut result = String::new(); @@ -116,11 +116,11 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { if index as uint > declarations.normal.len() { declarations.important .get(index as uint - declarations.normal.len()) - .map(|decl| format!("{} !important", decl)) + .map(|decl| format!("{:?} !important", decl)) } else { declarations.normal .get(index as uint) - .map(|decl| format!("{}", decl)) + .map(|decl| format!("{:?}", decl)) } }); @@ -130,7 +130,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue fn GetPropertyValue(self, property: DOMString) -> DOMString { // Step 1 - let property = Atom::from_slice(property.as_slice().to_ascii_lower().as_slice()); + let property = Atom::from_slice(property.as_slice().to_ascii_lowercase().as_slice()); // Step 2 let longhand_properties = longhands_from_shorthand(property.as_slice()); @@ -165,7 +165,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority fn GetPropertyPriority(self, property: DOMString) -> DOMString { // Step 1 - let property = Atom::from_slice(property.as_slice().to_ascii_lower().as_slice()); + let property = Atom::from_slice(property.as_slice().to_ascii_lowercase().as_slice()); // Step 2 let longhand_properties = longhands_from_shorthand(property.as_slice()); @@ -195,7 +195,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { } // Step 2 - let property = property.as_slice().to_ascii_lower(); + let property = property.as_slice().to_ascii_lowercase(); // Step 3 if !is_supported_property(property.as_slice()) { @@ -208,7 +208,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { } // Step 5 - let priority = priority.as_slice().to_ascii_lower(); + let priority = priority.as_slice().to_ascii_lowercase(); if priority.as_slice() != "!important" && !priority.is_empty() { return Ok(()); } @@ -254,7 +254,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { } // Step 2 - let property = property.as_slice().to_ascii_lower(); + let property = property.as_slice().to_ascii_lowercase(); // Step 3 if !is_supported_property(property.as_slice()) { @@ -262,7 +262,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { } // Step 4 - let priority = priority.as_slice().to_ascii_lower(); + let priority = priority.as_slice().to_ascii_lowercase(); if priority.as_slice() != "important" && !priority.is_empty() { return Ok(()); } @@ -301,7 +301,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { } // Step 2 - let property = property.as_slice().to_ascii_lower(); + let property = property.as_slice().to_ascii_lowercase(); // Step 3 let value = self.GetPropertyValue(property.clone()); @@ -343,5 +343,5 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { rval } - css_properties_accessors!(css_properties) + css_properties_accessors!(css_properties); } diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 1403344dad2..22b7befd87c 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -32,12 +32,13 @@ use js::jsval::JSVal; use js::rust::Cx; use std::rc::Rc; +use std::sync::mpsc::{Sender, Receiver}; use url::Url; /// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with /// every message. While this SendableWorkerScriptChan is alive, the associated Worker object /// will remain alive. -#[deriving(Clone)] +#[derive(Clone)] #[jstraceable] pub struct SendableWorkerScriptChan { sender: Sender<(TrustedWorkerAddress, ScriptMsg)>, @@ -133,7 +134,7 @@ impl DedicatedWorkerGlobalScope { parent_sender: Box<ScriptChan+Send>, own_sender: Sender<(TrustedWorkerAddress, ScriptMsg)>, receiver: Receiver<(TrustedWorkerAddress, ScriptMsg)>) { - spawn_named(format!("WebWorker for {}", worker_url.serialize()), proc() { + spawn_named(format!("WebWorker for {}", worker_url.serialize()), move || { task_state::initialize(SCRIPT | IN_WORKER); let roots = RootCollection::new(); @@ -165,7 +166,7 @@ impl DedicatedWorkerGlobalScope { } loop { - match global.r().receiver.recv_opt() { + match global.r().receiver.recv() { Ok((linked_worker, msg)) => { let _ar = AutoWorkerReset::new(global.r(), linked_worker); global.r().handle_event(msg); @@ -228,7 +229,7 @@ impl<'a> DedicatedWorkerGlobalScopeMethods for JSRef<'a, DedicatedWorkerGlobalSc Ok(()) } - event_handler!(message, GetOnmessage, SetOnmessage) + event_handler!(message, GetOnmessage, SetOnmessage); } impl DedicatedWorkerGlobalScopeDerived for EventTarget { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index d20dcda10e7..d7e9ce0daa2 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -65,13 +65,13 @@ use url::Url; use std::borrow::ToOwned; use std::collections::HashMap; -use std::collections::hash_map::{Vacant, Occupied}; +use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::ascii::AsciiExt; use std::cell::{Cell, Ref}; use std::default::Default; use time; -#[deriving(PartialEq)] +#[derive(PartialEq)] #[jstraceable] pub enum IsHTMLDocument { HTMLDocument, @@ -284,7 +284,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { match idmap.entry(id) { Vacant(entry) => { - entry.set(vec!(element.unrooted())); + entry.insert(vec!(element.unrooted())); } Occupied(entry) => { let elements = entry.into_mut(); @@ -321,7 +321,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { /// https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document fn find_fragment_node(self, fragid: DOMString) -> Option<Temporary<Element>> { self.GetElementById(fragid.clone()).or_else(|| { - let check_anchor = |&node: &JSRef<HTMLAnchorElement>| { + let check_anchor = |&:&node: &JSRef<HTMLAnchorElement>| { let elem: JSRef<Element> = ElementCast::from_ref(node); elem.get_attribute(ns!(""), &atom!("name")).root().map_or(false, |attr| { attr.r().value().as_slice() == fragid.as_slice() @@ -385,7 +385,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { } } -#[deriving(PartialEq)] +#[derive(PartialEq)] pub enum DocumentSource { FromParser, NotFromParser, @@ -475,12 +475,12 @@ impl Document { } trait PrivateDocumentHelpers { - fn createNodeList(self, callback: |node: JSRef<Node>| -> bool) -> Temporary<NodeList>; + fn createNodeList<F: Fn(JSRef<Node>) -> bool>(self, callback: F) -> Temporary<NodeList>; fn get_html_element(self) -> Option<Temporary<HTMLHtmlElement>>; } impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> { - fn createNodeList(self, callback: |node: JSRef<Node>| -> bool) -> Temporary<NodeList> { + fn createNodeList<F: Fn(JSRef<Node>) -> bool>(self, callback: F) -> Temporary<NodeList> { let window = self.window.root(); let document_element = self.GetDocumentElement().root(); let nodes = match document_element { @@ -591,7 +591,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { return Err(InvalidCharacter); } let local_name = if self.is_html_document { - local_name.as_slice().to_ascii_lower() + local_name.as_slice().to_ascii_lowercase() } else { local_name }; @@ -727,7 +727,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn CreateEvent(self, interface: DOMString) -> Fallible<Temporary<Event>> { let window = self.window.root(); - match interface.as_slice().to_ascii_lower().as_slice() { + match interface.as_slice().to_ascii_lowercase().as_slice() { "uievents" | "uievent" => Ok(EventCast::from_temporary( UIEvent::new_uninitialized(window.r()))), "mouseevents" | "mouseevent" => Ok(EventCast::from_temporary( @@ -771,7 +771,11 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { root.traverse_preorder() .find(|node| node.type_id() == NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTitleElement))) .map(|title_elem| { - for text in title_elem.children().filter_map::<JSRef<Text>>(TextCast::to_ref) { + let mut children = title_elem.children().filter_map(|n| { + let t: Option<JSRef<Text>> = TextCast::to_ref(n); + t + }); + for text in children { title.push_str(text.characterdata().data().as_slice()); } }); @@ -1000,7 +1004,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { Temporary::new(self.window) } - global_event_handlers!() - event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange) + global_event_handlers!(); + event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange); } diff --git a/components/script/dom/domexception.rs b/components/script/dom/domexception.rs index 112dcedf4b2..48f8e4b52f6 100644 --- a/components/script/dom/domexception.rs +++ b/components/script/dom/domexception.rs @@ -14,7 +14,7 @@ use servo_util::str::DOMString; use std::borrow::ToOwned; #[repr(uint)] -#[deriving(Copy, Show)] +#[derive(Copy, Show)] #[jstraceable] pub enum DOMErrorName { IndexSizeError = DOMExceptionConstants::INDEX_SIZE_ERR as uint, @@ -98,7 +98,7 @@ impl<'a> DOMExceptionMethods for JSRef<'a, DOMException> { // http://dom.spec.whatwg.org/#error-names-0 fn Name(self) -> DOMString { - self.code.to_string() + format!("{:?}", self.code) } // http://dom.spec.whatwg.org/#error-names-0 diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index 3ae0a4f09de..ed61123d9a2 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -118,7 +118,7 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> { let mut atoms = element.r().get_tokenlist_attribute(&self.local_name); for token in tokens.iter() { let token = try!(self.check_token_exceptions(token.as_slice())); - atoms.iter().position(|atom| *atom == token).and_then(|index| { + atoms.iter().position(|atom| *atom == token).map(|index| { atoms.remove(index) }); } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 98dcb3b0be1..d7ebd75f579 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -59,7 +59,7 @@ use html5ever::tree_builder::{NoQuirks, LimitedQuirks, Quirks}; use cssparser::RGBA; use std::ascii::AsciiExt; -use std::borrow::ToOwned; +use std::borrow::{IntoCow, ToOwned}; use std::cell::{Ref, RefMut}; use std::default::Default; use std::mem; @@ -89,14 +89,14 @@ impl ElementDerived for EventTarget { } } -#[deriving(Copy, PartialEq, Show)] +#[derive(Copy, PartialEq, Show)] #[jstraceable] pub enum ElementTypeId { HTMLElement(HTMLElementTypeId), Element, } -#[deriving(PartialEq)] +#[derive(PartialEq)] pub enum ElementCreator { ParserCreated, ScriptCreated, @@ -388,7 +388,7 @@ impl LayoutElementHelpers for JS<Element> { } } -#[deriving(PartialEq)] +#[derive(PartialEq)] pub enum StylePriority { Important, Normal, @@ -424,7 +424,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { // https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name fn parsed_name(self, name: DOMString) -> DOMString { if self.html_element_in_html_document() { - name.as_slice().to_ascii_lower() + name.as_slice().to_ascii_lowercase() } else { name } @@ -505,7 +505,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { fn update_inline_style(self, property_decl: style::PropertyDeclaration, style_priority: StylePriority) { let mut inline_declarations = self.style_attribute().borrow_mut(); - if let &Some(ref mut declarations) = &mut *inline_declarations { + if let &mut Some(ref mut declarations) = &mut *inline_declarations { let existing_declarations = if style_priority == StylePriority::Important { declarations.important.make_unique() } else { @@ -569,9 +569,10 @@ pub trait AttributeHandlers { prefix: Option<DOMString>); fn set_attribute(self, name: &Atom, value: AttrValue); fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult; - fn do_set_attribute(self, local_name: Atom, value: AttrValue, - name: Atom, namespace: Namespace, - prefix: Option<DOMString>, cb: |JSRef<Attr>| -> bool); + fn do_set_attribute<F>(self, local_name: Atom, value: AttrValue, + name: Atom, namespace: Namespace, + prefix: Option<DOMString>, cb: F) + where F: Fn(JSRef<Attr>) -> bool; fn parse_attribute(self, namespace: &Namespace, local_name: &Atom, value: DOMString) -> AttrValue; @@ -633,7 +634,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn set_attribute(self, name: &Atom, value: AttrValue) { - assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice()); + assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); assert!(!name.as_slice().contains(":")); self.do_set_attribute(name.clone(), value, name.clone(), @@ -657,9 +658,15 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { Ok(()) } - fn do_set_attribute(self, local_name: Atom, value: AttrValue, - name: Atom, namespace: Namespace, - prefix: Option<DOMString>, cb: |JSRef<Attr>| -> bool) { + fn do_set_attribute<F>(self, + local_name: Atom, + value: AttrValue, + name: Atom, + namespace: Namespace, + prefix: Option<DOMString>, + cb: F) + where F: Fn(JSRef<Attr>) -> bool + { let idx = self.attrs.borrow().iter() .map(|attr| attr.root()) .position(|attr| cb(attr.r())); @@ -724,7 +731,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { let owner_doc = node.owner_doc().root(); owner_doc.r().quirks_mode() }; - let is_equal = |lhs: &Atom, rhs: &Atom| match quirks_mode { + let is_equal = |&:lhs: &Atom, rhs: &Atom| match quirks_mode { NoQuirks | LimitedQuirks => lhs == rhs, Quirks => lhs.as_slice().eq_ignore_ascii_case(rhs.as_slice()) }; @@ -742,9 +749,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn has_attribute(self, name: &Atom) -> bool { - assert!(name.as_slice().chars().all(|ch| { - !ch.is_ascii() || ch.to_ascii().to_lowercase() == ch.to_ascii() - })); + assert!(name.as_slice().bytes().all(|&:b| b.to_ascii_lowercase() == b)); self.attrs.borrow().iter().map(|attr| attr.root()).any(|attr| { *attr.r().local_name() == *name && *attr.r().namespace() == ns!("") }) @@ -760,7 +765,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn get_url_attribute(self, name: &Atom) -> DOMString { - assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice()); + assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); if !self.has_attribute(name) { return "".to_owned(); } @@ -785,7 +790,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } } fn set_string_attribute(self, name: &Atom, value: DOMString) { - assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice()); + assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); self.set_attribute(name, AttrValue::String(value)); } @@ -800,18 +805,18 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn set_tokenlist_attribute(self, name: &Atom, value: DOMString) { - assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice()); + assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); self.set_attribute(name, AttrValue::from_serialized_tokenlist(value)); } fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>) { - assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice()); + assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); self.set_attribute(name, AttrValue::from_atomic_tokens(tokens)); } fn get_uint_attribute(self, name: &Atom) -> u32 { assert!(name.as_slice().chars().all(|ch| { - !ch.is_ascii() || ch.to_ascii().to_lowercase() == ch.to_ascii() + !ch.is_ascii() || ch.to_ascii_lowercase() == ch })); let attribute = self.get_attribute(ns!(""), name).root(); match attribute { @@ -826,7 +831,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } } fn set_uint_attribute(self, name: &Atom, value: u32) { - assert!(name.as_slice() == name.as_slice().to_ascii_lower().as_slice()); + assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); self.set_attribute(name, AttrValue::UInt(value.to_string(), value)); } } @@ -860,9 +865,9 @@ impl<'a> ElementMethods for JSRef<'a, Element> { None => self.local_name.as_slice().into_cow() }; if self.html_element_in_html_document() { - qualified_name.as_slice().to_ascii_upper() + qualified_name.as_slice().to_ascii_uppercase() } else { - qualified_name.into_string() + qualified_name.into_owned() } } @@ -1374,13 +1379,15 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { node.get_enabled_state() } fn get_checked_state(self) -> bool { - match HTMLInputElementCast::to_ref(self) { + let input_element: Option<JSRef<HTMLInputElement>> = HTMLInputElementCast::to_ref(self); + match input_element { Some(input) => input.Checked(), None => false, } } fn get_indeterminate_state(self) -> bool { - match HTMLInputElementCast::to_ref(self) { + let input_element: Option<JSRef<HTMLInputElement>> = HTMLInputElementCast::to_ref(self); + match input_element { Some(input) => input.get_indeterminate_state(), None => false, } @@ -1394,7 +1401,9 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { has_class(self, name) } - fn each_class(self, callback: |&Atom|) { + fn each_class<F>(self, callback: F) + where F: Fn(&Atom) + { match self.get_attribute(ns!(""), &atom!("class")).root() { None => {} Some(ref attr) => { @@ -1410,7 +1419,8 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> { } } fn has_nonzero_border(self) -> bool { - match HTMLTableElementCast::to_ref(self) { + let table_element: Option<JSRef<HTMLTableElement>> = HTMLTableElementCast::to_ref(self); + match table_element { None => false, Some(this) => { match this.get_border() { @@ -1461,7 +1471,10 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { None => { let node: JSRef<Node> = NodeCast::from_ref(self); node.ancestors() - .filter_map(|node| ElementCast::to_ref(node)) + .filter_map(|node| { + let e: Option<JSRef<Element>> = ElementCast::to_ref(node); + e + }) .filter(|e| e.as_maybe_activatable().is_some()).next() .map(|r| Temporary::from_rooted(r)) } diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index eda8690e48d..e2fe8c25609 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -19,7 +19,7 @@ use std::default::Default; use time; #[jstraceable] -#[deriving(Copy)] +#[derive(Copy)] pub enum EventPhase { None = EventConstants::NONE as int, Capturing = EventConstants::CAPTURING_PHASE as int, @@ -27,7 +27,7 @@ pub enum EventPhase { Bubbling = EventConstants::BUBBLING_PHASE as int, } -#[deriving(PartialEq)] +#[derive(PartialEq)] #[jstraceable] pub enum EventTypeId { CustomEvent, @@ -40,13 +40,13 @@ pub enum EventTypeId { ErrorEvent } -#[deriving(PartialEq)] +#[derive(PartialEq)] pub enum EventBubbles { Bubbles, DoesNotBubble } -#[deriving(PartialEq)] +#[derive(PartialEq)] pub enum EventCancelable { Cancelable, NotCancelable diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index fd7de4c64d6..ce80c744615 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -21,22 +21,26 @@ use js::jsapi::{JS_CompileUCFunction, JS_GetFunctionObject, JS_CloneFunctionObje use js::jsapi::{JSContext, JSObject}; use servo_util::fnv::FnvHasher; use servo_util::str::DOMString; + use libc::{c_char, size_t}; use std::borrow::ToOwned; -use std::collections::hash_map::{Occupied, Vacant}; +use std::collections::hash_map::Entry::{Occupied, Vacant}; +use std::collections::hash_state::DefaultState; +use std::default::Default; +use std::ffi::CString; use std::ptr; use url::Url; use std::collections::HashMap; -#[deriving(Copy, PartialEq)] +#[derive(Copy, PartialEq)] #[jstraceable] pub enum ListenerPhase { Capturing, Bubbling, } -#[deriving(Copy, PartialEq)] +#[derive(Copy, PartialEq)] #[jstraceable] pub enum EventTargetTypeId { Node(NodeTypeId), @@ -47,7 +51,7 @@ pub enum EventTargetTypeId { XMLHttpRequestEventTarget(XMLHttpRequestEventTargetTypeId) } -#[deriving(Copy, PartialEq)] +#[derive(Copy, PartialEq)] #[jstraceable] pub enum EventListenerType { Additive(EventListener), @@ -63,7 +67,7 @@ impl EventListenerType { } } -#[deriving(Copy, PartialEq)] +#[derive(Copy, PartialEq)] #[jstraceable] #[privatize] pub struct EventListenerEntry { @@ -75,7 +79,7 @@ pub struct EventListenerEntry { pub struct EventTarget { reflector_: Reflector, type_id: EventTargetTypeId, - handlers: DOMRefCell<HashMap<DOMString, Vec<EventListenerEntry>, FnvHasher>>, + handlers: DOMRefCell<HashMap<DOMString, Vec<EventListenerEntry>, DefaultState<FnvHasher>>>, } impl EventTarget { @@ -83,7 +87,7 @@ impl EventTarget { EventTarget { reflector_: Reflector::new(), type_id: type_id, - handlers: DOMRefCell::new(HashMap::with_hasher(FnvHasher)), + handlers: DOMRefCell::new(Default::default()), } } @@ -146,7 +150,7 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { let mut handlers = self.handlers.borrow_mut(); let entries = match handlers.entry(ty) { Occupied(entry) => entry.into_mut(), - Vacant(entry) => entry.set(vec!()), + Vacant(entry) => entry.insert(vec!()), }; let idx = entries.iter().position(|&entry| { @@ -194,14 +198,14 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { scope: *mut JSObject, ty: &str, source: DOMString) { - let url = url.serialize().to_c_str(); - let name = ty.to_c_str(); + let url = CString::from_slice(url.serialize().as_bytes()); + let name = CString::from_slice(ty.as_bytes()); let lineno = 0; //XXXjdm need to get a real number here let nargs = 1; //XXXjdm not true for onerror - static ARG_NAME: [c_char, ..6] = + const ARG_NAME: [c_char; 6] = ['e' as c_char, 'v' as c_char, 'e' as c_char, 'n' as c_char, 't' as c_char, 0]; - static ARG_NAMES: [*const c_char, ..1] = [&ARG_NAME as *const c_char]; + static mut ARG_NAMES: [*const c_char; 1] = [&ARG_NAME as *const c_char]; let source: Vec<u16> = source.as_slice().utf16_units().collect(); let handler = unsafe { @@ -209,7 +213,7 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { ptr::null_mut(), name.as_ptr(), nargs, - &ARG_NAMES as *const *const i8 as *mut *const i8, + &ARG_NAMES as *const *const c_char as *mut *const c_char, source.as_ptr(), source.len() as size_t, url.as_ptr(), @@ -255,7 +259,7 @@ impl<'a> EventTargetMethods for JSRef<'a, EventTarget> { let mut handlers = self.handlers.borrow_mut(); let entry = match handlers.entry(ty) { Occupied(entry) => entry.into_mut(), - Vacant(entry) => entry.set(vec!()), + Vacant(entry) => entry.insert(vec!()), }; let phase = if capture { ListenerPhase::Capturing } else { ListenerPhase::Bubbling }; diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index 9687bf6d9e5..452832560f9 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -19,9 +19,9 @@ use servo_util::str::DOMString; use std::borrow::ToOwned; use std::collections::HashMap; -use std::collections::hash_map::{Occupied, Vacant}; +use std::collections::hash_map::Entry::{Occupied, Vacant}; -#[deriving(Clone)] +#[derive(Clone)] #[jstraceable] #[must_root] pub enum FormDatum { @@ -65,7 +65,7 @@ impl<'a> FormDataMethods for JSRef<'a, FormData> { match data.entry(name) { Occupied(entry) => entry.into_mut().push(file), Vacant(entry) => { - entry.set(vec!(file)); + entry.insert(vec!(file)); } } } @@ -74,7 +74,7 @@ impl<'a> FormDataMethods for JSRef<'a, FormData> { let mut data = self.data.borrow_mut(); match data.entry(name) { Occupied(entry) => entry.into_mut().push(FormDatum::StringData(value)), - Vacant (entry) => { entry.set(vec!(FormDatum::StringData(value))); }, + Vacant (entry) => { entry.insert(vec!(FormDatum::StringData(value))); }, } } diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 3dd5026a5a0..52206f2652b 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -55,15 +55,15 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { } // http://www.whatwg.org/html/#dom-fe-disabled - make_bool_getter!(Disabled) + make_bool_getter!(Disabled); // http://www.whatwg.org/html/#dom-fe-disabled - make_bool_setter!(SetDisabled, "disabled") + make_bool_setter!(SetDisabled, "disabled"); // https://html.spec.whatwg.org/multipage/forms.html#dom-button-type fn Type(self) -> DOMString { let elem: JSRef<Element> = ElementCast::from_ref(self); - let ty = elem.get_string_attribute(&atom!("type")).into_ascii_lower(); + let ty = elem.get_string_attribute(&atom!("type")).into_ascii_lowercase(); // https://html.spec.whatwg.org/multipage/forms.html#attr-button-type match ty.as_slice() { "reset" | "button" | "menu" => ty, @@ -72,7 +72,7 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { } // https://html.spec.whatwg.org/multipage/forms.html#dom-button-type - make_setter!(SetType, "type") + make_setter!(SetType, "type"); } impl<'a> VirtualMethods for JSRef<'a, HTMLButtonElement> { diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 15f25a495a5..314088a74be 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -26,6 +26,7 @@ use geom::size::Size2D; use std::cell::Cell; use std::default::Default; +use std::sync::mpsc::Sender; const DEFAULT_WIDTH: u32 = 300; const DEFAULT_HEIGHT: u32 = 150; diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 9cbff941c03..a1aa197046e 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -96,7 +96,7 @@ impl HTMLCollection { } let filter = TagNameFilter { tag: Atom::from_slice(tag.as_slice()), - ascii_lower_tag: Atom::from_slice(tag.as_slice().to_ascii_lower().as_slice()), + ascii_lower_tag: Atom::from_slice(tag.as_slice().to_ascii_lowercase().as_slice()), }; HTMLCollection::create(window, root, box filter) } @@ -165,12 +165,13 @@ impl HTMLCollection { } fn traverse<'a>(root: JSRef<'a, Node>) - -> FilterMap<'a, JSRef<'a, Node>, + -> FilterMap<JSRef<'a, Node>, JSRef<'a, Element>, - Skip<TreeIterator<'a>>> { + Skip<TreeIterator<'a>>, + fn(JSRef<Node>) -> Option<JSRef<Element>>> { root.traverse_preorder() .skip(1) - .filter_map(ElementCast::to_ref) + .filter_map(ElementCast::to_ref as fn(JSRef<Node>) -> Option<JSRef<Element>>) } } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index d5fae8353be..633b8f5f297 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -21,6 +21,7 @@ use dom::document::Document; use dom::domstringmap::DOMStringMap; use dom::element::{Element, ElementTypeId, ActivationElementHelpers, AttributeHandlers}; use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::htmlinputelement::HTMLInputElement; use dom::htmlmediaelement::HTMLMediaElementTypeId; use dom::htmltablecellelement::HTMLTableCellElementTypeId; use dom::node::{Node, NodeTypeId, window_from_node}; @@ -84,17 +85,17 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> { }) } - make_getter!(Title) - make_setter!(SetTitle, "title") + make_getter!(Title); + make_setter!(SetTitle, "title"); - make_getter!(Lang) - make_setter!(SetLang, "lang") + make_getter!(Lang); + make_setter!(SetLang, "lang"); // http://html.spec.whatwg.org/multipage/#dom-hidden - make_bool_getter!(Hidden) - make_bool_setter!(SetHidden, "hidden") + make_bool_getter!(Hidden); + make_bool_setter!(SetHidden, "hidden"); - global_event_handlers!(NoOnload) + global_event_handlers!(NoOnload); // https://html.spec.whatwg.org/multipage/dom.html#dom-dataset fn Dataset(self) -> Temporary<DOMStringMap> { @@ -123,7 +124,7 @@ impl<'a> HTMLElementMethods for JSRef<'a, HTMLElement> { // https://html.spec.whatwg.org/multipage/interaction.html#dom-click fn Click(self) { - let maybe_input = HTMLInputElementCast::to_ref(self); + let maybe_input: Option<JSRef<HTMLInputElement>> = HTMLInputElementCast::to_ref(self); match maybe_input { Some(i) if i.Disabled() => return, _ => () @@ -205,7 +206,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLElement> { } } -#[deriving(Copy, PartialEq, Show)] +#[derive(Copy, PartialEq, Show)] #[jstraceable] pub enum HTMLElementTypeId { HTMLElement, diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs index 6f0241ff8cd..f6d1825bc37 100644 --- a/components/script/dom/htmlfieldsetelement.rs +++ b/components/script/dom/htmlfieldsetelement.rs @@ -71,10 +71,10 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { } // http://www.whatwg.org/html/#dom-fieldset-disabled - make_bool_getter!(Disabled) + make_bool_getter!(Disabled); // http://www.whatwg.org/html/#dom-fieldset-disabled - make_bool_setter!(SetDisabled, "disabled") + make_bool_setter!(SetDisabled, "disabled"); } impl<'a> VirtualMethods for JSRef<'a, HTMLFieldSetElement> { diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 7890dc1eb99..48edae7059f 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -62,28 +62,28 @@ impl HTMLFormElement { impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { // https://html.spec.whatwg.org/multipage/forms.html#dom-form-acceptcharset - make_getter!(AcceptCharset, "accept-charset") + make_getter!(AcceptCharset, "accept-charset"); // https://html.spec.whatwg.org/multipage/forms.html#dom-form-acceptcharset - make_setter!(SetAcceptCharset, "accept-charset") + make_setter!(SetAcceptCharset, "accept-charset"); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-action - make_url_or_base_getter!(Action) + make_url_or_base_getter!(Action); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-action - make_setter!(SetAction, "action") + make_setter!(SetAction, "action"); // https://html.spec.whatwg.org/multipage/forms.html#dom-form-autocomplete - make_enumerated_getter!(Autocomplete, "on", "off") + make_enumerated_getter!(Autocomplete, "on", ("off")); // https://html.spec.whatwg.org/multipage/forms.html#dom-form-autocomplete - make_setter!(SetAutocomplete, "autocomplete") + make_setter!(SetAutocomplete, "autocomplete"); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-enctype - make_enumerated_getter!(Enctype, "application/x-www-form-urlencoded", "text/plain" | "multipart/form-data") + make_enumerated_getter!(Enctype, "application/x-www-form-urlencoded", ("text/plain") | ("multipart/form-data")); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-enctype - make_setter!(SetEnctype, "enctype") + make_setter!(SetEnctype, "enctype"); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-encoding fn Encoding(self) -> DOMString { @@ -96,28 +96,28 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { } // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-method - make_enumerated_getter!(Method, "get", "post" | "dialog") + make_enumerated_getter!(Method, "get", ("post") | ("dialog")); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-method - make_setter!(SetMethod, "method") + make_setter!(SetMethod, "method"); // https://html.spec.whatwg.org/multipage/forms.html#dom-form-name - make_getter!(Name) + make_getter!(Name); // https://html.spec.whatwg.org/multipage/forms.html#dom-form-name - make_setter!(SetName, "name") + make_setter!(SetName, "name"); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-novalidate - make_bool_getter!(NoValidate) + make_bool_getter!(NoValidate); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-novalidate - make_bool_setter!(SetNoValidate, "novalidate") + make_bool_setter!(SetNoValidate, "novalidate"); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-target - make_getter!(Target) + make_getter!(Target); // https://html.spec.whatwg.org/multipage/forms.html#dom-fs-target - make_setter!(SetTarget, "target") + make_setter!(SetTarget, "target"); // https://html.spec.whatwg.org/multipage/forms.html#the-form-element:concept-form-submit fn Submit(self) { @@ -130,13 +130,13 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { } } -#[deriving(Copy)] +#[derive(Copy)] pub enum SubmittedFrom { FromFormSubmitMethod, NotFromFormSubmitMethod } -#[deriving(Copy)] +#[derive(Copy)] pub enum ResetFrom { FromFormResetMethod, NotFromFormResetMethod @@ -399,21 +399,21 @@ pub struct FormDatum { pub value: DOMString } -#[deriving(Copy)] +#[derive(Copy)] pub enum FormEncType { TextPlainEncoded, UrlEncoded, FormDataEncoded } -#[deriving(Copy)] +#[derive(Copy)] pub enum FormMethod { FormGet, FormPost, FormDialog } -#[deriving(Copy)] +#[derive(Copy)] pub enum FormSubmitter<'a> { FormElement(JSRef<'a, HTMLFormElement>), InputElement(JSRef<'a, HTMLInputElement>) @@ -482,7 +482,7 @@ impl<'a> FormSubmitter<'a> { } } -pub trait FormControl<'a> : Copy { +pub trait FormControl<'a> : Copy + Sized { // FIXME: This is wrong (https://github.com/servo/servo/issues/3553) // but we need html5ever to do it correctly fn form_owner(self) -> Option<Temporary<HTMLFormElement>> { @@ -507,16 +507,21 @@ pub trait FormControl<'a> : Copy { .map(Temporary::from_rooted) } - fn get_form_attribute(self, - attr: &Atom, - input: |Self| -> DOMString, - owner: |JSRef<HTMLFormElement>| -> DOMString) -> DOMString { + fn get_form_attribute<InputFn, OwnerFn>(self, + attr: &Atom, + input: InputFn, + owner: OwnerFn) + -> DOMString + where InputFn: Fn(Self) -> DOMString, + OwnerFn: Fn(JSRef<HTMLFormElement>) -> DOMString + { if self.to_element().has_attribute(attr) { input(self) } else { self.form_owner().map_or("".to_owned(), |t| owner(t.root().r())) } } + fn to_element(self) -> JSRef<'a, Element>; // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable fn mutable(self) -> bool; diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 66d0f824fa2..3f5220cea72 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -214,7 +214,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> { let mut modes = SandboxAllowance::AllowNothing as u8; if let Some(ref tokens) = attr.value().tokens() { for token in tokens.iter() { - modes |= match token.as_slice().to_ascii_lower().as_slice() { + modes |= match token.as_slice().to_ascii_lowercase().as_slice() { "allow-same-origin" => SandboxAllowance::AllowSameOrigin, "allow-forms" => SandboxAllowance::AllowForms, "allow-pointer-lock" => SandboxAllowance::AllowPointerLock, diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 3d6b8d28c7c..0e0c7da4ea8 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -95,19 +95,19 @@ impl LayoutHTMLImageElementHelpers for JS<HTMLImageElement> { } impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { - make_getter!(Alt) + make_getter!(Alt); - make_setter!(SetAlt, "alt") + make_setter!(SetAlt, "alt"); - make_url_getter!(Src) + make_url_getter!(Src); - make_setter!(SetSrc, "src") + make_setter!(SetSrc, "src"); - make_getter!(UseMap) + make_getter!(UseMap); - make_setter!(SetUseMap, "usemap") + make_setter!(SetUseMap, "usemap"); - make_bool_getter!(IsMap) + make_bool_getter!(IsMap); fn SetIsMap(self, is_map: bool) { let element: JSRef<Element> = ElementCast::from_ref(self); @@ -150,29 +150,29 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { elem.set_uint_attribute(&atom!("height"), height) } - make_getter!(Name) + make_getter!(Name); - make_setter!(SetName, "name") + make_setter!(SetName, "name"); - make_getter!(Align) + make_getter!(Align); - make_setter!(SetAlign, "align") + make_setter!(SetAlign, "align"); - make_uint_getter!(Hspace) + make_uint_getter!(Hspace); - make_uint_setter!(SetHspace, "hspace") + make_uint_setter!(SetHspace, "hspace"); - make_uint_getter!(Vspace) + make_uint_getter!(Vspace); - make_uint_setter!(SetVspace, "vspace") + make_uint_setter!(SetVspace, "vspace"); - make_getter!(LongDesc) + make_getter!(LongDesc); - make_setter!(SetLongDesc, "longdesc") + make_setter!(SetLongDesc, "longdesc"); - make_getter!(Border) + make_getter!(Border); - make_setter!(SetBorder, "border") + make_setter!(SetBorder, "border"); } impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 507f6d05818..0e53879add4 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -46,7 +46,7 @@ const DEFAULT_SUBMIT_VALUE: &'static str = "Submit"; const DEFAULT_RESET_VALUE: &'static str = "Reset"; #[jstraceable] -#[deriving(PartialEq, Copy)] +#[derive(PartialEq, Copy)] #[allow(dead_code)] enum InputType { InputSubmit, @@ -192,16 +192,16 @@ impl RawLayoutHTMLInputElementHelpers for HTMLInputElement { impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { // http://www.whatwg.org/html/#dom-fe-disabled - make_bool_getter!(Disabled) + make_bool_getter!(Disabled); // http://www.whatwg.org/html/#dom-fe-disabled - make_bool_setter!(SetDisabled, "disabled") + make_bool_setter!(SetDisabled, "disabled"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-defaultchecked - make_bool_getter!(DefaultChecked, "checked") + make_bool_getter!(DefaultChecked, "checked"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-defaultchecked - make_bool_setter!(SetDefaultChecked, "checked") + make_bool_setter!(SetDefaultChecked, "checked"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-checked fn Checked(self) -> bool { @@ -214,28 +214,28 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { } // https://html.spec.whatwg.org/multipage/forms.html#dom-input-readonly - make_bool_getter!(ReadOnly) + make_bool_getter!(ReadOnly); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-readonly - make_bool_setter!(SetReadOnly, "readonly") + make_bool_setter!(SetReadOnly, "readonly"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-size - make_uint_getter!(Size) + make_uint_getter!(Size); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-size - make_uint_setter!(SetSize, "size") + make_uint_setter!(SetSize, "size"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-type - make_enumerated_getter!(Type, "text", "hidden" | "search" | "tel" | - "url" | "email" | "password" | - "datetime" | "date" | "month" | - "week" | "time" | "datetime-local" | - "number" | "range" | "color" | - "checkbox" | "radio" | "file" | - "submit" | "image" | "reset" | "button") + make_enumerated_getter!(Type, "text", ("hidden") | ("search") | ("tel") | + ("url") | ("email") | ("password") | + ("datetime") | ("date") | ("month") | + ("week") | ("time") | ("datetime-local") | + ("number") | ("range") | ("color") | + ("checkbox") | ("radio") | ("file") | + ("submit") | ("image") | ("reset") | ("button")); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-type - make_setter!(SetType, "type") + make_setter!(SetType, "type"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-value fn Value(self) -> DOMString { @@ -250,40 +250,40 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { } // https://html.spec.whatwg.org/multipage/forms.html#dom-input-defaultvalue - make_getter!(DefaultValue, "value") + make_getter!(DefaultValue, "value"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-defaultvalue - make_setter!(SetDefaultValue, "value") + make_setter!(SetDefaultValue, "value"); // https://html.spec.whatwg.org/multipage/forms.html#attr-fe-name - make_getter!(Name) + make_getter!(Name); // https://html.spec.whatwg.org/multipage/forms.html#attr-fe-name - make_setter!(SetName, "name") + make_setter!(SetName, "name"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formaction - make_url_or_base_getter!(FormAction) + make_url_or_base_getter!(FormAction); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formaction - make_setter!(SetFormAction, "formaction") + make_setter!(SetFormAction, "formaction"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formenctype - make_enumerated_getter!(FormEnctype, "application/x-www-form-urlencoded", "text/plain" | "multipart/form-data") + make_enumerated_getter!(FormEnctype, "application/x-www-form-urlencoded", ("text/plain") | ("multipart/form-data")); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formenctype - make_setter!(SetFormEnctype, "formenctype") + make_setter!(SetFormEnctype, "formenctype"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formmethod - make_enumerated_getter!(FormMethod, "get", "post" | "dialog") + make_enumerated_getter!(FormMethod, "get", ("post") | ("dialog")); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formmethod - make_setter!(SetFormMethod, "formmethod") + make_setter!(SetFormMethod, "formmethod"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formtarget - make_getter!(FormTarget) + make_getter!(FormTarget); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-formtarget - make_setter!(SetFormTarget, "formtarget") + make_setter!(SetFormTarget, "formtarget"); // https://html.spec.whatwg.org/multipage/forms.html#dom-input-indeterminate fn Indeterminate(self) -> bool { @@ -312,17 +312,23 @@ fn broadcast_radio_checked(broadcaster: JSRef<HTMLInputElement>, group: Option<& let doc = document_from_node(broadcaster).root(); let doc_node: JSRef<Node> = NodeCast::from_ref(doc.r()); - // There is no DOM tree manipulation here, so this is safe - let mut iter = unsafe { - doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap() + // This function is a workaround for lifetime constraint difficulties. + fn do_broadcast<'a>(doc_node: JSRef<'a, Node>, broadcaster: JSRef<'a, HTMLInputElement>, + owner: Option<JSRef<'a, HTMLFormElement>>, group: Option<&str>) { + // There is no DOM tree manipulation here, so this is safe + let mut iter = unsafe { + doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap() .filter_map(|t| HTMLInputElementCast::to_ref(t)) - .filter(|&r| in_same_group(r, owner.r(), group) && broadcaster != r) - }; - for r in iter { - if r.Checked() { - r.SetChecked(false); + .filter(|&r| in_same_group(r, owner, group) && broadcaster != r) + }; + for r in iter { + if r.Checked() { + r.SetChecked(false); + } } } + + do_broadcast(doc_node, broadcaster, owner.r(), group) } fn in_same_group<'a,'b>(other: JSRef<'a, HTMLInputElement>, @@ -766,16 +772,20 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { let doc = document_from_node(*self).root(); let node: JSRef<Node> = NodeCast::from_ref(doc.r()); let owner = self.form_owner(); - if owner.is_none() || ElementCast::from_ref(*self).click_in_progress() { + let elem: JSRef<Element> = ElementCast::from_ref(*self); + if owner.is_none() || elem.click_in_progress() { return; } // This is safe because we are stopping after finding the first element // and only then performing actions which may modify the DOM tree unsafe { node.query_selector_iter("input[type=submit]".to_owned()).unwrap() - .filter_map(|t| HTMLInputElementCast::to_ref(t)) + .filter_map(|t| { + let h: Option<JSRef<HTMLInputElement>> = HTMLInputElementCast::to_ref(t); + h + }) .find(|r| r.form_owner() == owner) - .map(|s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey)); + .map(|&:s| s.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey)); } } } diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 49018903a5a..8170a4e28d9 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -141,20 +141,20 @@ impl<'a> PrivateHTMLLinkElementHelpers for JSRef<'a, HTMLLinkElement> { } impl<'a> HTMLLinkElementMethods for JSRef<'a, HTMLLinkElement> { - make_url_getter!(Href) - make_setter!(SetHref, "href") + make_url_getter!(Href); + make_setter!(SetHref, "href"); - make_getter!(Rel) - make_setter!(SetRel, "rel") + make_getter!(Rel); + make_setter!(SetRel, "rel"); - make_getter!(Media) - make_setter!(SetMedia, "media") + make_getter!(Media); + make_setter!(SetMedia, "media"); - make_getter!(Hreflang) - make_setter!(SetHreflang, "hreflang") + make_getter!(Hreflang); + make_setter!(SetHreflang, "hreflang"); - make_getter!(Type) - make_setter!(SetType, "type") + make_getter!(Type); + make_setter!(SetType, "type"); fn RelList(self) -> Temporary<DOMTokenList> { self.rel_list.or_init(|| { diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index ea8dcfa4041..ef75b1f43ee 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -38,7 +38,7 @@ impl HTMLMediaElement { } } -#[deriving(Copy, PartialEq, Show)] +#[derive(Copy, PartialEq, Show)] #[jstraceable] pub enum HTMLMediaElementTypeId { HTMLAudioElement, diff --git a/components/script/dom/htmlobjectelement.rs b/components/script/dom/htmlobjectelement.rs index 43478c532d5..7ebecd3e945 100644 --- a/components/script/dom/htmlobjectelement.rs +++ b/components/script/dom/htmlobjectelement.rs @@ -89,10 +89,10 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> { } // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-object-type - make_getter!(Type) + make_getter!(Type); // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-object-type - make_setter!(SetType, "type") + make_setter!(SetType, "type"); } impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> { diff --git a/components/script/dom/htmloptgroupelement.rs b/components/script/dom/htmloptgroupelement.rs index 846a53bc41e..ca3cefeead2 100644 --- a/components/script/dom/htmloptgroupelement.rs +++ b/components/script/dom/htmloptgroupelement.rs @@ -47,10 +47,10 @@ impl HTMLOptGroupElement { impl<'a> HTMLOptGroupElementMethods for JSRef<'a, HTMLOptGroupElement> { // http://www.whatwg.org/html#dom-optgroup-disabled - make_bool_getter!(Disabled) + make_bool_getter!(Disabled); // http://www.whatwg.org/html#dom-optgroup-disabled - make_bool_setter!(SetDisabled, "disabled") + make_bool_setter!(SetDisabled, "disabled"); } impl<'a> VirtualMethods for JSRef<'a, HTMLOptGroupElement> { diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs index bfe11883cfc..3df9bae29b1 100644 --- a/components/script/dom/htmloptionelement.rs +++ b/components/script/dom/htmloptionelement.rs @@ -69,7 +69,7 @@ fn collect_text(node: &JSRef<Node>, value: &mut DOMString) { impl<'a> HTMLOptionElementMethods for JSRef<'a, HTMLOptionElement> { // http://www.whatwg.org/html/#dom-option-disabled - make_bool_getter!(Disabled) + make_bool_getter!(Disabled); // http://www.whatwg.org/html/#dom-option-disabled fn SetDisabled(self, disabled: bool) { @@ -104,7 +104,7 @@ impl<'a> HTMLOptionElementMethods for JSRef<'a, HTMLOptionElement> { } // https://html.spec.whatwg.org/multipage/forms.html#attr-option-value - make_setter!(SetValue, "value") + make_setter!(SetValue, "value"); // https://html.spec.whatwg.org/multipage/forms.html#attr-option-label fn Label(self) -> DOMString { @@ -118,7 +118,7 @@ impl<'a> HTMLOptionElementMethods for JSRef<'a, HTMLOptionElement> { } // https://html.spec.whatwg.org/multipage/forms.html#attr-option-label - make_setter!(SetLabel, "label") + make_setter!(SetLabel, "label"); } diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 317769d23db..56d9beb65e6 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -258,7 +258,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { }, Some(ref s) => { debug!("script type={}", *s); - SCRIPT_JS_MIMES.contains(&s.to_ascii_lower().as_slice().trim_chars(HTML_SPACE_CHARACTERS)) + SCRIPT_JS_MIMES.contains(&s.to_ascii_lowercase().as_slice().trim_matches(HTML_SPACE_CHARACTERS)) }, None => { debug!("no script type"); @@ -271,7 +271,7 @@ impl<'a> HTMLScriptElementHelpers for JSRef<'a, HTMLScriptElement> { }, Some(ref s) => { debug!("script language={}", *s); - SCRIPT_JS_MIMES.contains(&format!("text/{}", s).to_ascii_lower().as_slice()) + SCRIPT_JS_MIMES.contains(&format!("text/{}", s).to_ascii_lowercase().as_slice()) }, None => { debug!("no script type or language, inferring js"); @@ -342,9 +342,9 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLScriptElement> { } impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> { - make_url_getter!(Src) + make_url_getter!(Src); - make_setter!(SetSrc, "src") + make_setter!(SetSrc, "src"); // http://www.whatwg.org/html/#dom-script-text fn Text(self) -> DOMString { diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs index fce7277d6a9..611bb687e53 100644 --- a/components/script/dom/htmlselectelement.rs +++ b/components/script/dom/htmlselectelement.rs @@ -61,10 +61,10 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> { } // http://www.whatwg.org/html/#dom-fe-disabled - make_bool_getter!(Disabled) + make_bool_getter!(Disabled); // http://www.whatwg.org/html/#dom-fe-disabled - make_bool_setter!(SetDisabled, "disabled") + make_bool_setter!(SetDisabled, "disabled"); // https://html.spec.whatwg.org/multipage/forms.html#dom-select-type fn Type(self) -> DOMString { diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs index 24450399f77..9bb04740c58 100644 --- a/components/script/dom/htmltablecellelement.rs +++ b/components/script/dom/htmltablecellelement.rs @@ -16,7 +16,7 @@ use cssparser::RGBA; use servo_util::str::{mod, DOMString, LengthOrPercentageOrAuto}; use std::cell::Cell; -#[deriving(Copy, PartialEq, Show)] +#[derive(Copy, PartialEq, Show)] #[jstraceable] pub enum HTMLTableCellElementTypeId { HTMLTableDataCellElement, diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index e5494e71afa..46e23a9665a 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -62,7 +62,10 @@ impl<'a> HTMLTableElementMethods for JSRef<'a, HTMLTableElement> { fn GetCaption(self) -> Option<Temporary<HTMLTableCaptionElement>> { let node: JSRef<Node> = NodeCast::from_ref(self); node.children() - .filter_map::<JSRef<HTMLTableCaptionElement>>(HTMLTableCaptionElementCast::to_ref) + .filter_map(|n| { + let t: Option<JSRef<HTMLTableCaptionElement>> = HTMLTableCaptionElementCast::to_ref(n); + t + }) .next() .map(Temporary::from_rooted) } diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 8ede6e716ae..79316c02d52 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -103,52 +103,52 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> { // constraints // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-cols - make_uint_getter!(Cols) + make_uint_getter!(Cols); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-cols - make_uint_setter!(SetCols, "cols") + make_uint_setter!(SetCols, "cols"); // http://www.whatwg.org/html/#dom-fe-disabled - make_bool_getter!(Disabled) + make_bool_getter!(Disabled); // http://www.whatwg.org/html/#dom-fe-disabled - make_bool_setter!(SetDisabled, "disabled") + make_bool_setter!(SetDisabled, "disabled"); // https://html.spec.whatwg.org/multipage/forms.html#attr-fe-name - make_getter!(Name) + make_getter!(Name); // https://html.spec.whatwg.org/multipage/forms.html#attr-fe-name - make_setter!(SetName, "name") + make_setter!(SetName, "name"); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-placeholder - make_getter!(Placeholder) + make_getter!(Placeholder); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-placeholder - make_setter!(SetPlaceholder, "placeholder") + make_setter!(SetPlaceholder, "placeholder"); // https://html.spec.whatwg.org/multipage/forms.html#attr-textarea-readonly - make_bool_getter!(ReadOnly) + make_bool_getter!(ReadOnly); // https://html.spec.whatwg.org/multipage/forms.html#attr-textarea-readonly - make_bool_setter!(SetReadOnly, "readonly") + make_bool_setter!(SetReadOnly, "readonly"); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-required - make_bool_getter!(Required) + make_bool_getter!(Required); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-required - make_bool_setter!(SetRequired, "required") + make_bool_setter!(SetRequired, "required"); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-rows - make_uint_getter!(Rows) + make_uint_getter!(Rows); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-rows - make_uint_setter!(SetRows, "rows") + make_uint_setter!(SetRows, "rows"); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-wrap - make_getter!(Wrap) + make_getter!(Wrap); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-wrap - make_setter!(SetWrap, "wrap") + make_setter!(SetWrap, "wrap"); // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-type fn Type(self) -> DOMString { diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs index cf4cadca3a1..518543c27ed 100644 --- a/components/script/dom/keyboardevent.rs +++ b/components/script/dom/keyboardevent.rs @@ -350,7 +350,7 @@ fn code_value(key: constellation_msg::Key) -> &'static str { constellation_msg::Key::GraveAccent | constellation_msg::Key::World1 | - constellation_msg::Key::World2 => panic!("unknown char code for {}", key), + constellation_msg::Key::World2 => panic!("unknown char code for {:?}", key), constellation_msg::Key::Escape => "Escape", constellation_msg::Key::Enter => "Enter", diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 646baabf785..30759c3bed0 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -11,13 +11,13 @@ macro_rules! make_getter( #[allow(unused_imports)] use std::ascii::AsciiExt; let element: JSRef<Element> = ElementCast::from_ref(self); - element.get_string_attribute(&Atom::from_slice($htmlname.to_ascii_lower().as_slice())) + element.get_string_attribute(&Atom::from_slice($htmlname.to_ascii_lowercase().as_slice())) } ); ($attr:ident) => { - make_getter!($attr, stringify!($attr).to_ascii_lower().as_slice()) + make_getter!($attr, stringify!($attr).to_ascii_lowercase().as_slice()); } -) +); #[macro_export] macro_rules! make_bool_getter( @@ -33,9 +33,9 @@ macro_rules! make_bool_getter( } ); ($attr:ident) => { - make_bool_getter!($attr, stringify!($attr).to_ascii_lower().as_slice()) + make_bool_getter!($attr, stringify!($attr).to_ascii_lowercase().as_slice()); } -) +); #[macro_export] macro_rules! make_uint_getter( @@ -51,9 +51,9 @@ macro_rules! make_uint_getter( } ); ($attr:ident) => { - make_uint_getter!($attr, stringify!($attr).to_ascii_lower().as_slice()) + make_uint_getter!($attr, stringify!($attr).to_ascii_lowercase().as_slice()); } -) +); #[macro_export] macro_rules! make_url_getter( @@ -70,9 +70,9 @@ macro_rules! make_url_getter( ); ($attr:ident) => { // FIXME(pcwalton): Do this at compile time, not runtime. - make_url_getter!($attr, stringify!($attr).to_ascii_lower().as_slice()) + make_url_getter!($attr, stringify!($attr).to_ascii_lowercase().as_slice()); } -) +); #[macro_export] macro_rules! make_url_or_base_getter( @@ -94,13 +94,13 @@ macro_rules! make_url_or_base_getter( } ); ($attr:ident) => { - make_url_or_base_getter!($attr, stringify!($attr).to_ascii_lower().as_slice()) + make_url_or_base_getter!($attr, stringify!($attr).to_ascii_lowercase().as_slice()); } -) +); #[macro_export] macro_rules! make_enumerated_getter( - ( $attr:ident, $htmlname:expr, $default:expr, $($choices: pat)|+) => ( + ( $attr:ident, $htmlname:expr, $default:expr, $(($choices: pat))|+) => ( fn $attr(self) -> DOMString { use dom::element::{Element, AttributeHandlers}; use dom::bindings::codegen::InheritTypes::ElementCast; @@ -109,7 +109,7 @@ macro_rules! make_enumerated_getter( use std::borrow::ToOwned; let element: JSRef<Element> = ElementCast::from_ref(self); let val = element.get_string_attribute(&Atom::from_slice($htmlname)) - .into_ascii_lower(); + .into_ascii_lowercase(); // https://html.spec.whatwg.org/multipage/forms.html#attr-fs-method match val.as_slice() { $($choices)|+ => val, @@ -117,10 +117,10 @@ macro_rules! make_enumerated_getter( } } ); - ($attr:ident, $default:expr, $($choices: pat)|+) => { - make_enumerated_getter!($attr, stringify!($attr).to_ascii_lower().as_slice(), $default, $($choices)|+) + ($attr:ident, $default:expr, $(($choices: pat))|+) => { + make_enumerated_getter!($attr, stringify!($attr).to_ascii_lowercase().as_slice(), $default, $(($choices))|+); } -) +); // concat_idents! doesn't work for function name positions, so // we have to specify both the content name and the HTML name here @@ -135,7 +135,7 @@ macro_rules! make_setter( element.set_string_attribute(&Atom::from_slice($htmlname), value) } ); -) +); #[macro_export] macro_rules! make_bool_setter( @@ -148,7 +148,7 @@ macro_rules! make_bool_setter( element.set_bool_attribute(&Atom::from_slice($htmlname), value) } ); -) +); #[macro_export] macro_rules! make_uint_setter( @@ -161,7 +161,7 @@ macro_rules! make_uint_setter( element.set_uint_attribute(&Atom::from_slice($htmlname), value) } ); -) +); /// For use on non-jsmanaged types /// Use #[jstraceable] on JS managed types @@ -184,7 +184,7 @@ macro_rules! no_jsmanaged_fields( } } ); -) +); /// These are used to generate a event handler which has no special case. macro_rules! define_event_handler( @@ -199,32 +199,32 @@ macro_rules! define_event_handler( eventtarget.set_event_handler_common(stringify!($event_type), listener) } ) -) +); macro_rules! event_handler( ($event_type: ident, $getter: ident, $setter: ident) => ( - define_event_handler!(EventHandlerNonNull, $event_type, $getter, $setter) + define_event_handler!(EventHandlerNonNull, $event_type, $getter, $setter); ) -) +); macro_rules! error_event_handler( ($event_type: ident, $getter: ident, $setter: ident) => ( - define_event_handler!(OnErrorEventHandlerNonNull, $event_type, $getter, $setter) + define_event_handler!(OnErrorEventHandlerNonNull, $event_type, $getter, $setter); ) -) +); // https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers // see webidls/EventHandler.webidl // As more methods get added, just update them here. macro_rules! global_event_handlers( () => ( - event_handler!(load, GetOnload, SetOnload) - global_event_handlers!(NoOnload) + event_handler!(load, GetOnload, SetOnload); + global_event_handlers!(NoOnload); ); (NoOnload) => ( - event_handler!(click, GetOnclick, SetOnclick) - event_handler!(input, GetOninput, SetOninput) - event_handler!(change, GetOnchange, SetOnchange) + event_handler!(click, GetOnclick, SetOnclick); + event_handler!(input, GetOninput, SetOninput); + event_handler!(change, GetOnchange, SetOnchange); ) -) +); diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 5433e666180..2128b0f93f4 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -52,6 +52,7 @@ use style::{matches, SelectorList}; use js::jsapi::{JSContext, JSObject, JSTracer, JSRuntime}; use js::jsfriendapi; +use core::nonzero::NonZero; use libc; use libc::{uintptr_t, c_void}; use std::borrow::ToOwned; @@ -122,7 +123,6 @@ impl NodeDerived for EventTarget { bitflags! { #[doc = "Flags for node items."] #[jstraceable] - #[deriving(Copy)] flags NodeFlags: u16 { #[doc = "Specifies whether this node is in a document."] const IS_IN_DOC = 0x01, @@ -183,7 +183,7 @@ impl Drop for Node { /// suppress observers flag /// http://dom.spec.whatwg.org/#concept-node-insert /// http://dom.spec.whatwg.org/#concept-node-remove -#[deriving(Copy)] +#[derive(Copy)] enum SuppressObserver { Suppressed, Unsuppressed @@ -199,14 +199,14 @@ pub struct SharedLayoutData { pub struct LayoutData { chan: Option<LayoutChan>, _shared_data: SharedLayoutData, - _data: *const (), + _data: NonZero<*const ()>, } pub struct LayoutDataRef { pub data_cell: RefCell<Option<LayoutData>>, } -no_jsmanaged_fields!(LayoutDataRef) +no_jsmanaged_fields!(LayoutDataRef); impl LayoutDataRef { pub fn new() -> LayoutDataRef { @@ -225,8 +225,8 @@ impl LayoutDataRef { pub fn take_chan(&self) -> Option<LayoutChan> { let mut layout_data = self.data_cell.borrow_mut(); match &mut *layout_data { - &None => None, - &Some(ref mut layout_data) => Some(layout_data.chan.take().unwrap()), + &mut None => None, + &mut Some(ref mut layout_data) => Some(layout_data.chan.take().unwrap()), } } @@ -255,8 +255,10 @@ impl LayoutDataRef { } } +unsafe impl Send for LayoutDataRef {} + /// The different types of nodes. -#[deriving(Copy, PartialEq, Show)] +#[derive(Copy, PartialEq, Show)] #[jstraceable] pub enum NodeTypeId { DocumentType, @@ -387,7 +389,9 @@ impl<'a> QuerySelectorIterator<'a> { } } -impl<'a> Iterator<JSRef<'a, Node>> for QuerySelectorIterator<'a> { +impl<'a> Iterator for QuerySelectorIterator<'a> { + type Item = JSRef<'a, Node>; + fn next(&mut self) -> Option<JSRef<'a, Node>> { let selectors = &self.selectors; // TODO(cgaebel): Is it worth it to build a bloom filter here @@ -501,7 +505,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { } s.push_str(self.debug_str().as_slice()); - debug!("{}", s); + debug!("{:?}", s); // FIXME: this should have a pure version? for kid in self.children() { @@ -511,7 +515,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { /// Returns a string that describes this node. fn debug_str(self) -> String { - format!("{}", self.type_id) + format!("{:?}", self.type_id) } fn is_in_doc(self) -> bool { @@ -825,8 +829,12 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { } fn child_elements(self) -> ChildElementIterator<'a> { + fn cast(n: JSRef<Node>) -> Option<JSRef<Element>> { + ElementCast::to_ref(n) + } + self.children() - .filter_map::<JSRef<Element>>(ElementCast::to_ref) + .filter_map(cast as fn(JSRef<Node>) -> Option<JSRef<Element>>) .peekable() } @@ -861,9 +869,12 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { publicId: "".to_owned(), systemId: "".to_owned(), - attrs: match ElementCast::to_ref(self) { - Some(element) => element.summarize(), - None => vec!(), + attrs: { + let e: Option<JSRef<Element>> = ElementCast::to_ref(self); + match e { + Some(element) => element.summarize(), + None => vec!(), + } }, isDocumentElement: @@ -1007,16 +1018,18 @@ impl RawLayoutNodeHelpers for Node { pub type ChildElementIterator<'a> = Peekable<JSRef<'a, Element>, - FilterMap<'a, - JSRef<'a, Node>, + FilterMap<JSRef<'a, Node>, JSRef<'a, Element>, - NodeChildrenIterator<'a>>>; + NodeChildrenIterator<'a>, + fn(JSRef<Node>) -> Option<JSRef<Element>>>>; pub struct NodeChildrenIterator<'a> { current: Option<JSRef<'a, Node>>, } -impl<'a> Iterator<JSRef<'a, Node>> for NodeChildrenIterator<'a> { +impl<'a> Iterator for NodeChildrenIterator<'a> { + type Item = JSRef<'a, Node>; + fn next(&mut self) -> Option<JSRef<'a, Node>> { let node = self.current; self.current = node.and_then(|node| node.next_sibling().map(|node| *node.root())); @@ -1028,7 +1041,9 @@ pub struct ReverseChildrenIterator { current: Option<Root<Node>>, } -impl Iterator<Temporary<Node>> for ReverseChildrenIterator { +impl Iterator for ReverseChildrenIterator { + type Item = Temporary<Node>; + fn next(&mut self) -> Option<Temporary<Node>> { let node = self.current.r().map(Temporary::from_rooted); self.current = self.current.take().and_then(|node| node.r().prev_sibling()).root(); @@ -1040,7 +1055,9 @@ pub struct AncestorIterator<'a> { current: Option<JSRef<'a, Node>>, } -impl<'a> Iterator<JSRef<'a, Node>> for AncestorIterator<'a> { +impl<'a> Iterator for AncestorIterator<'a> { + type Item = JSRef<'a, Node>; + fn next(&mut self) -> Option<JSRef<'a, Node>> { let node = self.current; self.current = node.and_then(|node| node.parent_node().map(|node| *node.root())); @@ -1063,7 +1080,9 @@ impl<'a> TreeIterator<'a> { } } -impl<'a> Iterator<JSRef<'a, Node>> for TreeIterator<'a> { +impl<'a> Iterator for TreeIterator<'a> { + type Item = JSRef<'a, Node>; + fn next(&mut self) -> Option<JSRef<'a, Node>> { let ret = self.stack.pop(); ret.map(|node| { @@ -1096,7 +1115,7 @@ impl NodeIterator { } fn next_child<'b>(&self, node: JSRef<'b, Node>) -> Option<JSRef<'b, Node>> { - let skip = |element: JSRef<Element>| { + let skip = |&:element: JSRef<Element>| { !self.include_descendants_of_void && element.is_void() }; @@ -1107,7 +1126,9 @@ impl NodeIterator { } } -impl<'a> Iterator<JSRef<'a, Node>> for NodeIterator { +impl<'a> Iterator for NodeIterator { + type Item = JSRef<'a, Node>; + fn next(&mut self) -> Option<JSRef<'a, Node>> { self.current_node = match self.current_node.as_ref().map(|node| node.root()) { None => { @@ -1155,7 +1176,7 @@ impl<'a> Iterator<JSRef<'a, Node>> for NodeIterator { } /// Specifies whether children must be recursively cloned or not. -#[deriving(Copy, PartialEq)] +#[derive(Copy, PartialEq)] pub enum CloneChildrenFlag { CloneChildren, DoNotCloneChildren @@ -1635,13 +1656,13 @@ impl Node { None => {} Some(chan) => { let LayoutChan(chan) = chan; - chan.send(Msg::ReapLayoutData(layout_data)) + chan.send(Msg::ReapLayoutData(layout_data)).unwrap() }, } } } - pub fn collect_text_contents<'a, T: Iterator<JSRef<'a, Node>>>(mut iterator: T) -> String { + pub fn collect_text_contents<'a, T: Iterator<Item=JSRef<'a, Node>>>(mut iterator: T) -> String { let mut content = String::new(); for node in iterator { let text: Option<JSRef<Text>> = TextCast::to_ref(node); @@ -1989,7 +2010,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> { fn Normalize(self) { let mut prev_text = None; for child in self.children() { - match TextCast::to_ref(child) { + let t: Option<JSRef<Text>> = TextCast::to_ref(child); + match t { Some(text) => { let characterdata: JSRef<CharacterData> = CharacterDataCast::from_ref(text); if characterdata.Length() == 0 { @@ -2185,9 +2207,11 @@ impl<'a> NodeMethods for JSRef<'a, Node> { /// and are also used in the HTML parser interface. #[allow(raw_pointer_deriving)] -#[deriving(Clone, PartialEq, Eq, Copy)] +#[derive(Clone, PartialEq, Eq, Copy)] pub struct TrustedNodeAddress(pub *const c_void); +unsafe impl Send for TrustedNodeAddress {} + pub fn document_from_node<T: NodeBase+Reflectable>(derived: JSRef<T>) -> Temporary<Document> { let node: JSRef<Node> = NodeCast::from_ref(derived); node.owner_doc() @@ -2280,7 +2304,9 @@ impl<'a> style::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> { ElementCast::to_ref(self).unwrap() } - fn match_attr(self, attr: &style::AttrSelector, test: |&str| -> bool) -> bool { + fn match_attr<F>(self, attr: &style::AttrSelector, test: F) -> bool + where F: Fn(&str) -> bool + { let name = { if self.is_html_element_in_html_document() { &attr.lower_name @@ -2367,7 +2393,7 @@ impl<'a> DisabledStateHelpers for JSRef<'a, Node> { } /// A summary of the changes that happened to a node. -#[deriving(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq)] pub enum NodeDamage { /// The node's `style` attribute changed. NodeStyleDamaged, diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs index cbbabb912a7..01fce8d2d82 100644 --- a/components/script/dom/storage.rs +++ b/components/script/dom/storage.rs @@ -11,7 +11,7 @@ use dom::bindings::error::Fallible; use servo_util::str::DOMString; use servo_net::storage_task::StorageTask; use servo_net::storage_task::StorageTaskMsg; -use std::comm::channel; +use std::sync::mpsc::channel; use url::Url; #[dom_struct] @@ -55,21 +55,21 @@ impl<'a> StorageMethods for JSRef<'a, Storage> { let (sender, receiver) = channel(); self.get_storage_task().send(StorageTaskMsg::Length(sender, self.get_url())); - receiver.recv() + receiver.recv().unwrap() } fn Key(self, index: u32) -> Option<DOMString> { let (sender, receiver) = channel(); self.get_storage_task().send(StorageTaskMsg::Key(sender, self.get_url(), index)); - receiver.recv() + receiver.recv().unwrap() } fn GetItem(self, name: DOMString) -> Option<DOMString> { let (sender, receiver) = channel(); self.get_storage_task().send(StorageTaskMsg::GetItem(sender, self.get_url(), name)); - receiver.recv() + receiver.recv().unwrap() } fn NamedGetter(self, name: DOMString, found: &mut bool) -> Option<DOMString> { @@ -82,7 +82,7 @@ impl<'a> StorageMethods for JSRef<'a, Storage> { let (sender, receiver) = channel(); self.get_storage_task().send(StorageTaskMsg::SetItem(sender, self.get_url(), name, value)); - if receiver.recv() { + if receiver.recv().unwrap() { //TODO send notification } } @@ -99,7 +99,7 @@ impl<'a> StorageMethods for JSRef<'a, Storage> { let (sender, receiver) = channel(); self.get_storage_task().send(StorageTaskMsg::RemoveItem(sender, self.get_url(), name)); - if receiver.recv() { + if receiver.recv().unwrap() { //TODO send notification } } @@ -112,7 +112,7 @@ impl<'a> StorageMethods for JSRef<'a, Storage> { let (sender, receiver) = channel(); self.get_storage_task().send(StorageTaskMsg::Clear(sender, self.get_url())); - if receiver.recv() { + if receiver.recv().unwrap() { //TODO send notification } } diff --git a/components/script/dom/treewalker.rs b/components/script/dom/treewalker.rs index b578823acd6..d7dab56949d 100644 --- a/components/script/dom/treewalker.rs +++ b/components/script/dom/treewalker.rs @@ -119,30 +119,37 @@ impl<'a> TreeWalkerMethods for JSRef<'a, TreeWalker> { } } -type NodeAdvancer<'a> = |node: JSRef<'a, Node>|: 'a -> Option<Temporary<Node>>; - -trait PrivateTreeWalkerHelpers<'a> { - fn traverse_children(self, - next_child: NodeAdvancer<'a>, - next_sibling: NodeAdvancer<'a>) - -> Fallible<Option<Temporary<Node>>>; - fn traverse_siblings(self, - next_child: NodeAdvancer<'a>, - next_sibling: NodeAdvancer<'a>) - -> Fallible<Option<Temporary<Node>>>; - fn is_root_node(self, node: JSRef<'a, Node>) -> bool; - fn is_current_node(self, node: JSRef<'a, Node>) -> bool; - fn first_following_node_not_following_root(self, node: JSRef<'a, Node>) +type NodeAdvancer<'a> = Fn(JSRef<'a, Node>) -> Option<Temporary<Node>> + 'a; + +trait PrivateTreeWalkerHelpers { + fn traverse_children<F, G>(self, + next_child: F, + next_sibling: G) + -> Fallible<Option<Temporary<Node>>> + where F: Fn(JSRef<Node>) -> Option<Temporary<Node>>, + G: Fn(JSRef<Node>) -> Option<Temporary<Node>>; + fn traverse_siblings<F, G>(self, + next_child: F, + next_sibling: G) + -> Fallible<Option<Temporary<Node>>> + where F: Fn(JSRef<Node>) -> Option<Temporary<Node>>, + G: Fn(JSRef<Node>) -> Option<Temporary<Node>>; + fn is_root_node(self, node: JSRef<Node>) -> bool; + fn is_current_node(self, node: JSRef<Node>) -> bool; + fn first_following_node_not_following_root(self, node: JSRef<Node>) -> Option<Temporary<Node>>; - fn accept_node(self, node: JSRef<'a, Node>) -> Fallible<u16>; + fn accept_node(self, node: JSRef<Node>) -> Fallible<u16>; } -impl<'a> PrivateTreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> { +impl<'a> PrivateTreeWalkerHelpers for JSRef<'a, TreeWalker> { // http://dom.spec.whatwg.org/#concept-traverse-children - fn traverse_children(self, - next_child: NodeAdvancer<'a>, - next_sibling: NodeAdvancer<'a>) - -> Fallible<Option<Temporary<Node>>> { + fn traverse_children<F, G>(self, + next_child: F, + next_sibling: G) + -> Fallible<Option<Temporary<Node>>> + where F: Fn(JSRef<Node>) -> Option<Temporary<Node>>, + G: Fn(JSRef<Node>) -> Option<Temporary<Node>> + { // "To **traverse children** of type *type*, run these steps:" // "1. Let node be the value of the currentNode attribute." // "2. Set node to node's first child if type is first, and node's last child if type is last." @@ -218,10 +225,13 @@ impl<'a> PrivateTreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> { } // http://dom.spec.whatwg.org/#concept-traverse-siblings - fn traverse_siblings(self, - next_child: NodeAdvancer<'a>, - next_sibling: NodeAdvancer<'a>) - -> Fallible<Option<Temporary<Node>>> { + fn traverse_siblings<F, G>(self, + next_child: F, + next_sibling: G) + -> Fallible<Option<Temporary<Node>>> + where F: Fn(JSRef<Node>) -> Option<Temporary<Node>>, + G: Fn(JSRef<Node>) -> Option<Temporary<Node>> + { // "To **traverse siblings** of type *type* run these steps:" // "1. Let node be the value of the currentNode attribute." let mut node = self.current_node.get().root().clone(); @@ -282,7 +292,7 @@ impl<'a> PrivateTreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> { } // http://dom.spec.whatwg.org/#concept-tree-following - fn first_following_node_not_following_root(self, node: JSRef<'a, Node>) + fn first_following_node_not_following_root(self, node: JSRef<Node>) -> Option<Temporary<Node>> { // "An object A is following an object B if A and B are in the same tree // and A comes after B in tree order." @@ -309,7 +319,7 @@ impl<'a> PrivateTreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> { } // http://dom.spec.whatwg.org/#concept-node-filter - fn accept_node(self, node: JSRef<'a, Node>) -> Fallible<u16> { + fn accept_node(self, node: JSRef<Node>) -> Fallible<u16> { // "To filter node run these steps:" // "1. Let n be node's nodeType attribute value minus 1." let n: uint = node.NodeType() as uint - 1; @@ -329,11 +339,11 @@ impl<'a> PrivateTreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> { } } - fn is_root_node(self, node: JSRef<'a, Node>) -> bool { + fn is_root_node(self, node: JSRef<Node>) -> bool { JS::from_rooted(node) == self.root_node } - fn is_current_node(self, node: JSRef<'a, Node>) -> bool { + fn is_current_node(self, node: JSRef<Node>) -> bool { JS::from_rooted(node) == self.current_node.get() } } @@ -526,7 +536,9 @@ impl<'a> TreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> { } } -impl<'a> Iterator<JSRef<'a, Node>> for JSRef<'a, TreeWalker> { +impl<'a> Iterator for JSRef<'a, TreeWalker> { + type Item = JSRef<'a, Node>; + fn next(&mut self) -> Option<JSRef<'a, Node>> { match self.next_node() { Ok(node) => node.map(|n| n.root().clone()), diff --git a/components/script/dom/urlsearchparams.rs b/components/script/dom/urlsearchparams.rs index 035e558d878..b8ab6c9329c 100644 --- a/components/script/dom/urlsearchparams.rs +++ b/components/script/dom/urlsearchparams.rs @@ -18,7 +18,7 @@ use encoding::all::UTF_8; use encoding::types::{EncodingRef, EncoderTrap}; use std::collections::HashMap; -use std::collections::hash_map::{Occupied, Vacant}; +use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::fmt::radix; use std::ascii::OwnedAsciiExt; @@ -67,7 +67,7 @@ impl<'a> URLSearchParamsMethods for JSRef<'a, URLSearchParams> { match data.entry(name) { Occupied(entry) => entry.into_mut().push(value), Vacant(entry) => { - entry.set(vec!(value)); + entry.insert(vec!(value)); } } @@ -117,7 +117,7 @@ impl URLSearchParamsHelpers for URLSearchParams { a => { // http://url.spec.whatwg.org/#percent-encode let mut encoded = vec!(0x25); // % - let s = format!("{}", radix(a, 16)).into_ascii_upper(); + let s = format!("{}", radix(a, 16)).into_ascii_uppercase(); let bytes = s.as_bytes(); encoded.push_all(bytes); encoded diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 91402fe6c1f..fe7ea336122 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -47,6 +47,7 @@ use libc; use serialize::base64::{FromBase64, ToBase64, STANDARD}; use std::cell::{Ref, RefMut}; use std::default::Default; +use std::ffi::CString; use std::rc::Rc; use time; @@ -283,9 +284,9 @@ impl<'a> WindowMethods for JSRef<'a, Window> { }) } - global_event_handlers!() - event_handler!(unload, GetOnunload, SetOnunload) - error_event_handler!(error, GetOnerror, SetOnerror) + global_event_handlers!(); + event_handler!(unload, GetOnunload, SetOnunload); + error_event_handler!(error, GetOnerror, SetOnerror); fn Screen(self) -> Temporary<Screen> { self.screen.or_init(|| Screen::new(self)) @@ -336,7 +337,7 @@ impl<'a, T: Reflectable> ScriptHelpers for JSRef<'a, T> { let global = global_object_for_js_object(this).root().r().reflector().get_jsobject(); let code: Vec<u16> = code.as_slice().utf16_units().collect(); let mut rval = UndefinedValue(); - let filename = filename.to_c_str(); + let filename = CString::from_slice(filename.as_bytes()); with_compartment(cx, global, || { unsafe { diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs index 8fa36436c19..df793ede178 100644 --- a/components/script/dom/worker.rs +++ b/components/script/dom/worker.rs @@ -26,6 +26,7 @@ use js::jsval::JSVal; use url::UrlParser; use std::cell::Cell; +use std::sync::mpsc::{channel, Sender}; pub type TrustedWorkerAddress = Trusted<Worker>; @@ -97,7 +98,7 @@ impl<'a> WorkerMethods for JSRef<'a, Worker> { Ok(()) } - event_handler!(message, GetOnmessage, SetOnmessage) + event_handler!(message, GetOnmessage, SetOnmessage); } pub struct WorkerMessageHandler { diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index da3b50b1f32..e78a4a71ed0 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -30,7 +30,7 @@ use std::default::Default; use std::rc::Rc; use url::{Url, UrlParser}; -#[deriving(Copy, PartialEq)] +#[derive(Copy, PartialEq)] #[jstraceable] pub enum WorkerGlobalScopeTypeId { DedicatedGlobalScope, diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 191d3cf6dde..f1d061bcdb7 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -34,6 +34,7 @@ use encoding::types::{DecoderTrap, Encoding, EncodingRef, EncoderTrap}; use hyper::header::Headers; use hyper::header::common::{Accept, ContentLength, ContentType}; +use hyper::header::quality_item::QualityItem; use hyper::http::RawStatus; use hyper::mime::{mod, Mime}; use hyper::method::Method; @@ -52,7 +53,7 @@ use servo_util::task::spawn_named; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; -use std::comm::{Sender, Receiver, channel}; +use std::sync::mpsc::{Sender, Receiver, channel}; use std::default::Default; use std::io::Timer; use std::str::FromStr; @@ -64,7 +65,7 @@ use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams; use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams::{eString, eURLSearchParams}; pub type SendParam = StringOrURLSearchParams; -#[deriving(PartialEq, Copy)] +#[derive(PartialEq, Copy)] #[jstraceable] enum XMLHttpRequestState { Unsent = 0, @@ -92,11 +93,11 @@ impl Runnable for XHRProgressHandler { } } -#[deriving(PartialEq, Clone, Copy)] +#[derive(PartialEq, Clone, Copy)] #[jstraceable] pub struct GenerationId(uint); -#[deriving(Clone)] +#[derive(Clone)] pub enum XHRProgress { /// Notify that headers have been received HeadersReceived(GenerationId, Option<Headers>, Option<RawStatus>), @@ -230,7 +231,7 @@ impl XMLHttpRequest { notify_partial_progress(fetch_type, XHRProgress::Errored(gen_id, $err)); return Err($err) }); - ) + ); macro_rules! terminate( ($reason:expr) => ( @@ -243,7 +244,7 @@ impl XMLHttpRequest { } } ); - ) + ); match cors_request { @@ -257,13 +258,14 @@ impl XMLHttpRequest { let req2 = req.clone(); // TODO: this exists only to make preflight check non-blocking // perhaps should be handled by the resource_loader? - spawn_named("XHR:Cors".to_owned(), proc() { + spawn_named("XHR:Cors".to_owned(), move || { let response = req2.http_fetch(); chan.send(response); }); select! ( response = cors_port.recv() => { + let response = response.unwrap(); if response.network_error { notify_error_and_return!(Network); } else { @@ -273,8 +275,8 @@ impl XMLHttpRequest { }); } }, - reason = terminate_receiver.recv() => terminate!(reason) - ) + reason = terminate_receiver.recv() => terminate!(reason.unwrap()) + ); } _ => {} } @@ -286,6 +288,7 @@ impl XMLHttpRequest { let progress_port; select! ( response = start_port.recv() => { + let response = response.unwrap(); match cors_request { Ok(Some(ref req)) => { match response.metadata.headers { @@ -302,8 +305,8 @@ impl XMLHttpRequest { progress_port = response.progress_port; }, - reason = terminate_receiver.recv() => terminate!(reason) - ) + reason = terminate_receiver.recv() => terminate!(reason.unwrap()) + ); let mut buf = vec!(); loop { @@ -319,7 +322,7 @@ impl XMLHttpRequest { }; select! ( - progress = progress_port.recv() => match progress { + progress = progress_port.recv() => match progress.unwrap() { Payload(data) => { buf.push_all(data.as_slice()); notify_partial_progress(fetch_type, @@ -333,14 +336,14 @@ impl XMLHttpRequest { notify_error_and_return!(Network); } }, - reason = terminate_receiver.recv() => terminate!(reason) - ) + reason = terminate_receiver.recv() => terminate!(reason.unwrap()) + ); } } } impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { - event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange) + event_handler!(readystatechange, GetOnreadystatechange, SetOnreadystatechange); fn ReadyState(self) -> u16 { self.ready_state.get() as u16 @@ -354,12 +357,12 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { // without changing capitalization, this will actually sidestep rust-http's type system // since methods like "patch" or "PaTcH" will be considered extension methods // despite the there being a rust-http method variant for them - let upper = s.to_ascii_upper(); + let upper = s.to_ascii_uppercase(); match upper.as_slice() { "DELETE" | "GET" | "HEAD" | "OPTIONS" | "POST" | "PUT" | "CONNECT" | "TRACE" | - "TRACK" => from_str(upper.as_slice()), - _ => from_str(s) + "TRACK" => upper.parse(), + _ => s.parse() } }); // Step 2 @@ -438,18 +441,18 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { None => return Err(Syntax) }; - debug!("SetRequestHeader: name={}, value={}", name.as_str(), value.as_str()); + debug!("SetRequestHeader: name={:?}, value={:?}", name.as_str(), value.as_str()); let mut headers = self.request_headers.borrow_mut(); // Steps 6,7 match headers.get_raw(name_str) { Some(raw) => { - debug!("SetRequestHeader: old value = {}", raw[0]); + debug!("SetRequestHeader: old value = {:?}", raw[0]); let mut buf = raw[0].clone(); buf.push_all(b", "); buf.push_all(value.as_slice()); - debug!("SetRequestHeader: new value = {}", buf); + debug!("SetRequestHeader: new value = {:?}", buf); value = ByteString::new(buf); }, None => {} @@ -573,8 +576,9 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { if !request_headers.has::<Accept>() { + let mime = Mime(mime::TopLevel::Star, mime::SubLevel::Star, vec![]); request_headers.set( - Accept(vec![Mime(mime::TopLevel::Star, mime::SubLevel::Star, vec![])])); + Accept(vec![QualityItem::new(mime, 1.0)])); } } // drops the borrow_mut @@ -610,7 +614,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { _ => {} } - debug!("request_headers = {}", *self.request_headers.borrow()); + debug!("request_headers = {:?}", *self.request_headers.borrow()); let gen_id = self.generation_id.get(); if self.sync.get() { @@ -624,7 +628,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { // inflight events queued up in the script task's port. let addr = Trusted::new(self.global.root().r().get_cx(), self, script_chan.clone()); - spawn_named("XHRTask".to_owned(), proc() { + spawn_named("XHRTask".to_owned(), move || { let _ = XMLHttpRequest::fetch(&mut SyncOrAsync::Async(addr, script_chan), resource_task, load_data, @@ -767,7 +771,7 @@ trait PrivateXMLHttpRequestHelpers { impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { fn change_ready_state(self, rs: XMLHttpRequestState) { - assert!(self.ready_state.get() != rs) + assert!(self.ready_state.get() != rs); self.ready_state.set(rs); let global = self.global.root(); let event = Event::new(global.r(), @@ -789,7 +793,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { return } ); - ) + ); // Ignore message if it belongs to a terminated fetch return_if_fetch_was_terminated!(); @@ -893,7 +897,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { fn terminate_ongoing_fetch(self) { let GenerationId(prev_id) = self.generation_id.get(); self.generation_id.set(GenerationId(prev_id + 1)); - self.terminate_sender.borrow().as_ref().map(|s| s.send_opt(TerminateReason::AbortedOrReopened)); + self.terminate_sender.borrow().as_ref().map(|s| s.send(TerminateReason::AbortedOrReopened)); } fn insert_trusted_header(self, name: String, value: String) { @@ -936,10 +940,10 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { let oneshot = self.timer.borrow_mut() .oneshot(Duration::milliseconds(timeout as i64)); let terminate_sender = (*self.terminate_sender.borrow()).clone(); - spawn_named("XHR:Timer".to_owned(), proc () { - match oneshot.recv_opt() { + spawn_named("XHR:Timer".to_owned(), move || { + match oneshot.recv() { Ok(_) => { - terminate_sender.map(|s| s.send_opt(TerminateReason::TimedOut)); + terminate_sender.map(|s| s.send(TerminateReason::TimedOut)); }, Err(_) => { // This occurs if xhr.timeout (the sender) goes out of scope (i.e, xhr went out of scope) @@ -980,7 +984,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { use hyper::header::common::SetCookie; // a dummy header so we can use headers.remove::<SetCookie2>() - #[deriving(Clone)] + #[derive(Clone)] struct SetCookie2; impl Header for SetCookie2 { fn header_name(_: Option<SetCookie2>) -> &'static str { diff --git a/components/script/dom/xmlhttprequesteventtarget.rs b/components/script/dom/xmlhttprequesteventtarget.rs index f596fe8419b..e27496ec2d9 100644 --- a/components/script/dom/xmlhttprequesteventtarget.rs +++ b/components/script/dom/xmlhttprequesteventtarget.rs @@ -9,7 +9,7 @@ use dom::bindings::codegen::InheritTypes::XMLHttpRequestEventTargetDerived; use dom::bindings::js::JSRef; use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; -#[deriving(Copy, PartialEq)] +#[derive(Copy, PartialEq)] #[jstraceable] pub enum XMLHttpRequestEventTargetTypeId { XMLHttpRequest, @@ -44,11 +44,11 @@ impl XMLHttpRequestEventTargetDerived for EventTarget { } impl<'a> XMLHttpRequestEventTargetMethods for JSRef<'a, XMLHttpRequestEventTarget> { - event_handler!(loadstart,GetOnloadstart, SetOnloadstart) - event_handler!(progress, GetOnprogress, SetOnprogress) - event_handler!(abort, GetOnabort, SetOnabort) - event_handler!(error, GetOnerror, SetOnerror) - event_handler!(load, GetOnload, SetOnload) - event_handler!(timeout, GetOntimeout, SetOntimeout) - event_handler!(loadend, GetOnloadend, SetOnloadend) + event_handler!(loadstart,GetOnloadstart, SetOnloadstart); + event_handler!(progress, GetOnprogress, SetOnprogress); + event_handler!(abort, GetOnabort, SetOnabort); + event_handler!(error, GetOnerror, SetOnerror); + event_handler!(load, GetOnload, SetOnload); + event_handler!(timeout, GetOntimeout, SetOntimeout); + event_handler!(loadend, GetOnloadend, SetOnloadend); } |