diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-03-18 11:25:00 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-03-18 11:25:00 -0600 |
commit | 99cf9dbfc107bacb84dfe5afa9539a0ede3beac2 (patch) | |
tree | cc36210329cb1a31709a03685c05c4aaa99407e3 /components/script/dom | |
parent | 65d4b12bf20783ea784f1c61f4b33ec0fc975f4f (diff) | |
parent | 5f15eb5fbfb7a8649132cc8b3a07314389836714 (diff) | |
download | servo-99cf9dbfc107bacb84dfe5afa9539a0ede3beac2.tar.gz servo-99cf9dbfc107bacb84dfe5afa9539a0ede3beac2.zip |
auto merge of #5256 : servo/servo/rustup_20150311, r=jdm
...v.
Relies on:
* https://github.com/servo/rust-geom/pull/72
* https://github.com/servo/rust-glx/pull/10
* https://github.com/servo/gleam/pull/15
* https://github.com/servo/rust-mozjs/pull/137
* https://github.com/servo/rust-core-text/pull/35
* https://github.com/servo/rust-io-surface/pull/28
Diffstat (limited to 'components/script/dom')
30 files changed, 265 insertions, 111 deletions
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 9aa6331f2ed..56f647ce841 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -54,11 +54,12 @@ use js::jsval::{StringValue, ObjectValue, ObjectOrNullValue}; use libc; use std::borrow::ToOwned; use std::default; +use std::marker::MarkerTrait; use std::slice; /// A trait to retrieve the constants necessary to check if a `JSObject` /// implements a given interface. -pub trait IDLInterface { +pub trait IDLInterface: MarkerTrait { /// Returns the prototype ID. fn get_prototype_id() -> PrototypeList::ID; /// Returns the prototype depth, i.e., the number of interfaces this @@ -74,6 +75,7 @@ pub trait ToJSValConvertible { /// A trait to convert `JSVal`s to Rust types. pub trait FromJSValConvertible { + /// Optional configurable behaviour switch; use () for no configuration. type Config; /// Convert `val` to type `Self`. /// Optional configuration of type `T` can be passed as the `option` diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 7ada9f45d14..72f4c16e832 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -62,7 +62,7 @@ use util::smallvec::{SmallVec, SmallVec16}; use core::nonzero::NonZero; use std::cell::{Cell, UnsafeCell}; use std::default::Default; -use std::marker::ContravariantLifetime; +use std::marker::PhantomData; use std::mem; use std::ops::Deref; @@ -677,7 +677,7 @@ impl<T: Reflectable> Root<T> { pub fn r<'b>(&'b self) -> JSRef<'b, T> { JSRef { ptr: self.ptr, - chain: ContravariantLifetime, + chain: PhantomData, } } @@ -688,7 +688,7 @@ impl<T: Reflectable> Root<T> { pub fn get_unsound_ref_forever<'b>(&self) -> JSRef<'b, T> { JSRef { ptr: self.ptr, - chain: ContravariantLifetime, + chain: PhantomData, } } } @@ -713,7 +713,7 @@ impl<'a, T: Reflectable> Deref for JSRef<'a, T> { /// copyable. pub struct JSRef<'a, T> { ptr: NonZero<*const T>, - chain: ContravariantLifetime<'a>, + chain: PhantomData<&'a ()>, } impl<'a, T> Copy for JSRef<'a, T> {} diff --git a/components/script/dom/bindings/refcounted.rs b/components/script/dom/bindings/refcounted.rs index b7f039cb527..c009687e40a 100644 --- a/components/script/dom/bindings/refcounted.rs +++ b/components/script/dom/bindings/refcounted.rs @@ -32,6 +32,7 @@ use libc; use std::cell::RefCell; use std::collections::hash_map::HashMap; use std::collections::hash_map::Entry::{Vacant, Occupied}; +use std::marker::PhantomData; use std::rc::Rc; use std::sync::{Arc, Mutex}; @@ -53,6 +54,7 @@ pub struct Trusted<T> { refcount: Arc<Mutex<usize>>, script_chan: Box<ScriptChan + Send>, owner_thread: *const libc::c_void, + phantom: PhantomData<T>, } unsafe impl<T: Reflectable> Send for Trusted<T> {} @@ -71,6 +73,7 @@ impl<T: Reflectable> Trusted<T> { refcount: refcount, script_chan: script_chan.clone(), owner_thread: (&*live_references) as *const _ as *const libc::c_void, + phantom: PhantomData, } }) } @@ -102,6 +105,7 @@ impl<T: Reflectable> Clone for Trusted<T> { refcount: self.refcount.clone(), script_chan: self.script_chan.clone(), owner_thread: self.owner_thread, + phantom: PhantomData, } } } diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 38e7d898e97..88561210617 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -5,7 +5,7 @@ //! The `ByteString` struct. use std::borrow::ToOwned; -use std::hash::{Hash, SipHasher}; +use std::hash::{Hash, Hasher}; use std::str; use std::str::FromStr; @@ -144,8 +144,8 @@ impl ByteString { } } -impl Hash<SipHasher> for ByteString { - fn hash(&self, state: &mut SipHasher) { +impl Hash for ByteString { + fn hash<H: Hasher>(&self, state: &mut H) { let ByteString(ref vec) = *self; vec.hash(state); } diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index e0738e3b07a..505307dd7bf 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -184,10 +184,10 @@ impl<T: JSTraceable> JSTraceable for Option<T> { } impl<K,V,S> JSTraceable for HashMap<K, V, S> - where K: Hash<<S as HashState>::Hasher> + Eq + JSTraceable, + where K: Hash + Eq + JSTraceable, V: JSTraceable, S: HashState, - <S as HashState>::Hasher: Hasher<Output=u64>, + <S as HashState>::Hasher: Hasher, { #[inline] fn trace(&self, trc: *mut JSTracer) { diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index 67a06b21a48..c24c6110821 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -577,7 +577,10 @@ pub extern fn outerize_global(_cx: *mut JSContext, obj: JSHandleObject) -> *mut debug!("outerizing"); let obj = *obj.unnamed_field1; let win: Root<window::Window> = native_from_reflector_jsmanaged(obj).unwrap().root(); - win.r().browser_context().as_ref().unwrap().window_proxy() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let win = win.r(); + let context = win.browser_context(); + context.as_ref().unwrap().window_proxy() } } diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs index b7703e7e72a..9320322f841 100644 --- a/components/script/dom/characterdata.rs +++ b/components/script/dom/characterdata.rs @@ -68,7 +68,9 @@ impl CharacterData { impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { fn Data(self) -> DOMString { - self.data.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let data = self.data.borrow(); + data.clone() } fn SetData(self, arg: DOMString) -> ErrorResult { @@ -77,11 +79,15 @@ impl<'a> CharacterDataMethods for JSRef<'a, CharacterData> { } fn Length(self) -> u32 { - self.data.borrow().chars().count() as u32 + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let data = self.data.borrow(); + data.chars().count() as u32 } fn SubstringData(self, offset: u32, count: u32) -> Fallible<DOMString> { - Ok(self.data.borrow().slice_chars(offset as usize, (offset + count) as usize).to_owned()) + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let data = self.data.borrow(); + Ok(data.slice_chars(offset as usize, (offset + count) as usize).to_owned()) } fn AppendData(self, arg: DOMString) -> ErrorResult { diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 3ae4cbc147e..fa72ae297ff 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -188,9 +188,11 @@ pub trait DedicatedWorkerGlobalScopeHelpers { impl<'a> DedicatedWorkerGlobalScopeHelpers for JSRef<'a, DedicatedWorkerGlobalScope> { fn script_chan(self) -> Box<ScriptChan+Send> { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let worker = self.worker.borrow(); box SendableWorkerScriptChan { sender: self.own_sender.clone(), - worker: self.worker.borrow().as_ref().unwrap().clone(), + worker: worker.as_ref().unwrap().clone(), } } } diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 6da0dd57316..8a7d87ba6b6 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -365,10 +365,13 @@ 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() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + value.as_slice() == fragid.as_slice() }) }; let doc_node: JSRef<Node> = NodeCast::from_ref(self); @@ -461,7 +464,10 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { /// Sends this document's title to the compositor. fn send_title_to_compositor(self) { let window = self.window().root(); - window.r().compositor().set_title(window.r().pipeline(), Some(self.Title())); + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let window = window.r(); + let mut compositor = window.compositor(); + compositor.set_title(window.pipeline(), Some(self.Title())); } fn dirty_all_nodes(self) { @@ -843,12 +849,16 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-document-characterset fn CharacterSet(self) -> DOMString { - self.encoding_name.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let encoding_name = self.encoding_name.borrow(); + encoding_name.clone() } // http://dom.spec.whatwg.org/#dom-document-inputencoding fn InputEncoding(self) -> DOMString { - self.encoding_name.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let encoding_name = self.encoding_name.borrow(); + encoding_name.clone() } // http://dom.spec.whatwg.org/#dom-document-content_type @@ -893,7 +903,9 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid fn GetElementById(self, id: DOMString) -> Option<Temporary<Element>> { let id = Atom::from_slice(id.as_slice()); - match self.idmap.borrow().get(&id) { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let idmap = self.idmap.borrow(); + match idmap.get(&id) { None => None, Some(ref elements) => Some(Temporary::new((*elements)[0].clone())), } @@ -1218,7 +1230,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { None => return false, }; element.get_attribute(ns!(""), &atom!("name")).root().map_or(false, |attr| { - attr.r().value().as_slice() == name.as_slice() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + value.as_slice() == name.as_slice() }) }) } diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs index c0ba2e1ebd1..2d0a4338be5 100644 --- a/components/script/dom/domtokenlist.rs +++ b/components/script/dom/domtokenlist.rs @@ -67,15 +67,23 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> { // http://dom.spec.whatwg.org/#dom-domtokenlist-length fn Length(self) -> u32 { self.attribute().root().map(|attr| { - attr.r().value().tokens().map(|tokens| tokens.len()).unwrap_or(0) + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + value.tokens().map(|tokens| tokens.len()).unwrap_or(0) }).unwrap_or(0) as u32 } // http://dom.spec.whatwg.org/#dom-domtokenlist-item fn Item(self, index: u32) -> Option<DOMString> { - self.attribute().root().and_then(|attr| attr.r().value().tokens().and_then(|tokens| { - tokens.get(index as usize).map(|token| token.as_slice().to_owned()) - })) + self.attribute().root().and_then(|attr| { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + value.tokens().and_then(|tokens| { + tokens.get(index as usize).map(|token| token.as_slice().to_owned()) + }) + }) } fn IndexedGetter(self, index: u32, found: &mut bool) -> Option<DOMString> { @@ -88,12 +96,13 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> { fn Contains(self, token: DOMString) -> Fallible<bool> { self.check_token_exceptions(token.as_slice()).map(|token| { self.attribute().root().map(|attr| { - attr.r() - .value() - .tokens() - .expect("Should have parsed this attribute") - .iter() - .any(|atom| *atom == token) + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + value.tokens() + .expect("Should have parsed this attribute") + .iter() + .any(|atom| *atom == token) }).unwrap_or(false) }) } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 3576f20f78c..d8ebb804c87 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -618,9 +618,14 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn get_attributes(self, local_name: &Atom) -> Vec<Temporary<Attr>> { - self.attrs.borrow().iter().map(|attr| attr.root()).filter_map(|attr| { - if *attr.r().local_name() == *local_name { - Some(Temporary::from_rooted(attr.r())) + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attrs = self.attrs.borrow(); + attrs.iter().map(|attr| attr.root()).filter_map(|attr| { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let attr_local_name = attr.local_name(); + if *attr_local_name == *local_name { + Some(Temporary::from_rooted(attr)) } else { None } @@ -746,12 +751,15 @@ 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()) }; self.get_attribute(ns!(""), &atom!("class")).root().map(|attr| { - attr.r().value().tokens().map(|tokens| { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + value.tokens().map(|tokens| { tokens.iter().any(|atom| is_equal(name, atom)) }).unwrap_or(false) }).unwrap_or(false) @@ -764,9 +772,15 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { } fn has_attribute(self, name: &Atom) -> bool { - 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!("") + assert!(name.as_slice().bytes().all(|b| b.to_ascii_lowercase() == b)); + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attrs = self.attrs.borrow(); + attrs.iter().map(|attr| attr.root()).any(|attr| { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let local_name = attr.local_name(); + let namespace = attr.namespace(); + *local_name == *name && *namespace == ns!("") }) } @@ -811,11 +825,12 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { fn get_tokenlist_attribute(self, name: &Atom) -> Vec<Atom> { self.get_attribute(ns!(""), name).root().map(|attr| { - attr.r() - .value() - .tokens() - .expect("Expected a TokenListAttrValue") - .to_vec() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + value.tokens() + .expect("Expected a TokenListAttrValue") + .to_vec() }).unwrap_or(vec!()) } @@ -1328,14 +1343,20 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { fn get_attr(self, namespace: &Namespace, attr: &Atom) -> Option<&'a str> { self.get_attribute(namespace.clone(), attr).root().map(|attr| { // This transmute is used to cheat the lifetime restriction. - unsafe { mem::transmute(attr.r().value().as_slice()) } + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + unsafe { mem::transmute(value.as_slice()) } }) } #[allow(unsafe_blocks)] fn get_attrs(self, attr: &Atom) -> Vec<&'a str> { self.get_attributes(attr).into_iter().map(|attr| attr.root()).map(|attr| { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); // This transmute is used to cheat the lifetime restriction. - unsafe { mem::transmute(attr.r().value().as_slice()) } + unsafe { mem::transmute(value.as_slice()) } }).collect() } fn get_link(self) -> Option<&'a str> { @@ -1375,7 +1396,10 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { fn get_id(self) -> Option<Atom> { self.get_attribute(ns!(""), &atom!("id")).map(|attr| { let attr = attr.root(); - match *attr.r().value() { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + match *value { AttrValue::Atom(ref val) => val.clone(), _ => panic!("`id` attribute should be AttrValue::Atom"), } diff --git a/components/script/dom/errorevent.rs b/components/script/dom/errorevent.rs index d16df30c7d5..5aed667e3b6 100644 --- a/components/script/dom/errorevent.rs +++ b/components/script/dom/errorevent.rs @@ -68,12 +68,14 @@ impl ErrorEvent { let event: JSRef<Event> = EventCast::from_ref(ev.r()); event.InitEvent(type_, bubbles == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable); - *ev.r().message.borrow_mut() = message; - *ev.r().filename.borrow_mut() = filename; - ev.r().lineno.set(lineno); - ev.r().colno.set(colno); - ev.r().error.set(error); - Temporary::from_rooted(ev.r()) + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let ev = ev.r(); + *ev.message.borrow_mut() = message; + *ev.filename.borrow_mut() = filename; + ev.lineno.set(lineno); + ev.colno.set(colno); + ev.error.set(error); + Temporary::from_rooted(ev) } pub fn Constructor(global: GlobalRef, @@ -116,11 +118,15 @@ impl<'a> ErrorEventMethods for JSRef<'a, ErrorEvent> { } fn Message(self) -> DOMString { - self.message.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let message = self.message.borrow(); + message.clone() } fn Filename(self) -> DOMString { - self.filename.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let filename = self.filename.borrow(); + filename.clone() } fn Error(self, _cx: *mut JSContext) -> JSVal { diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs index 2a284fcb45e..a225c7b3439 100644 --- a/components/script/dom/event.rs +++ b/components/script/dom/event.rs @@ -178,7 +178,9 @@ impl<'a> EventMethods for JSRef<'a, Event> { } fn Type(self) -> DOMString { - self.type_.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let type_ = self.type_.borrow(); + type_.clone() } fn GetTarget(self) -> Option<Temporary<EventTarget>> { diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs index ee4fd3b2745..018579e6127 100644 --- a/components/script/dom/eventtarget.rs +++ b/components/script/dom/eventtarget.rs @@ -245,7 +245,9 @@ impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { } fn has_handlers(self) -> bool { - !self.handlers.borrow().is_empty() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let handlers = self.handlers.borrow(); + !handlers.is_empty() } } diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs index 5d8e5a8f809..a40e269aaaa 100644 --- a/components/script/dom/formdata.rs +++ b/components/script/dom/formdata.rs @@ -84,8 +84,10 @@ impl<'a> FormDataMethods for JSRef<'a, FormData> { #[allow(unsafe_blocks)] fn Get(self, name: DOMString) -> Option<FileOrString> { - if self.data.borrow().contains_key(&name) { - match (*self.data.borrow())[name][0].clone() { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let data = self.data.borrow(); + if data.contains_key(&name) { + match data[name][0].clone() { FormDatum::StringData(ref s) => Some(eString(s.clone())), FormDatum::FileData(ref f) => { Some(eFile(Unrooted::from_js(*f))) @@ -97,7 +99,9 @@ impl<'a> FormDataMethods for JSRef<'a, FormData> { } fn Has(self, name: DOMString) -> bool { - self.data.borrow().contains_key(&name) + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let data = self.data.borrow(); + data.contains_key(&name) } #[allow(unrooted_must_root)] fn Set(self, name: DOMString, value: JSRef<Blob>, filename: Option<DOMString>) { diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 718727b5487..8f09c5d8745 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -229,7 +229,7 @@ impl<'a> Activatable for JSRef<'a, HTMLButtonElement> { 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/htmlelement.rs b/components/script/dom/htmlelement.rs index 98bcbd6d92e..973de33d34d 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -32,6 +32,7 @@ use util::str::DOMString; use string_cache::Atom; +use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::default::Default; @@ -161,7 +162,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> { fn set_custom_attr(self, name: DOMString, value: DOMString) -> ErrorResult { if name.as_slice().chars() .skip_while(|&ch| ch != '\u{2d}') - .nth(1).map_or(false, |ch| ch as u8 - b'a' < 26) { + .nth(1).map_or(false, |ch| ch >= 'a' && ch <= 'z') { return Err(Syntax); } let element: JSRef<Element> = ElementCast::from_ref(self); @@ -172,7 +173,10 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> { let element: JSRef<Element> = ElementCast::from_ref(self); element.get_attribute(ns!(""), &Atom::from_slice(to_snake_case(name).as_slice())).map(|attr| { let attr = attr.root(); - attr.r().value().as_slice().to_owned() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + value.as_slice().to_owned() }) } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 15d5ee0182d..670d02c9a37 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -238,7 +238,9 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> { // https://html.spec.whatwg.org/multipage/forms.html#dom-input-value fn Value(self) -> DOMString { - self.textinput.borrow().get_content() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let textinput = self.textinput.borrow(); + textinput.get_content() } // https://html.spec.whatwg.org/multipage/forms.html#dom-input-value @@ -781,7 +783,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { 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 0cf9bf40ae0..8014a7af4af 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -59,7 +59,12 @@ impl HTMLLinkElement { fn get_attr(element: JSRef<Element>, name: &Atom) -> Option<String> { let elem = element.get_attribute(ns!(""), name).root(); - elem.map(|e| e.r().value().as_slice().to_owned()) + elem.map(|e| { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let e = e.r(); + let value = e.value(); + value.as_slice().to_owned() + }) } fn is_stylesheet(value: &Option<String>) -> bool { diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index acacf3cb01a..dcf79d70091 100644 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -177,7 +177,9 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> { // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-value fn Value(self) -> DOMString { - self.textinput.borrow().get_content() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let textinput = self.textinput.borrow(); + textinput.get_content() } // https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-value diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs index 8ff5fe27e63..025c64ac59c 100644 --- a/components/script/dom/keyboardevent.rs +++ b/components/script/dom/keyboardevent.rs @@ -85,15 +85,17 @@ impl KeyboardEvent { let ev = KeyboardEvent::new_uninitialized(window).root(); ev.r().InitKeyboardEvent(type_, canBubble, cancelable, view, key, location, "".to_owned(), repeat, "".to_owned()); - *ev.r().code.borrow_mut() = code; - ev.r().ctrl.set(ctrlKey); - ev.r().alt.set(altKey); - ev.r().shift.set(shiftKey); - ev.r().meta.set(metaKey); - ev.r().char_code.set(char_code); - ev.r().key_code.set(key_code); - ev.r().is_composing.set(isComposing); - Temporary::from_rooted(ev.r()) + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let ev = ev.r(); + *ev.code.borrow_mut() = code; + ev.ctrl.set(ctrlKey); + ev.alt.set(altKey); + ev.shift.set(shiftKey); + ev.meta.set(metaKey); + ev.char_code.set(char_code); + ev.key_code.set(key_code); + ev.is_composing.set(isComposing); + Temporary::from_rooted(ev) } pub fn Constructor(global: GlobalRef, @@ -571,11 +573,15 @@ impl<'a> KeyboardEventMethods for JSRef<'a, KeyboardEvent> { } fn Key(self) -> DOMString { - self.key.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let key = self.key.borrow(); + key.clone() } fn Code(self) -> DOMString { - self.code.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let code = self.code.borrow(); + code.clone() } fn Location(self) -> u32 { diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs index 74989ec3ddc..6b6bf0e64cd 100644 --- a/components/script/dom/namednodemap.rs +++ b/components/script/dom/namednodemap.rs @@ -33,11 +33,19 @@ impl NamedNodeMap { impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> { fn Length(self) -> u32 { - self.owner.root().r().attrs().len() as u32 + let owner = self.owner.root(); + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let owner = owner.r(); + let attrs = owner.attrs(); + attrs.len() as u32 } fn Item(self, index: u32) -> Option<Temporary<Attr>> { - self.owner.root().r().attrs().as_slice().get(index as uint).map(|x| Temporary::new(x.clone())) + let owner = self.owner.root(); + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let owner = owner.r(); + let attrs = owner.attrs(); + attrs.as_slice().get(index as uint).map(|x| Temporary::new(x.clone())) } fn IndexedGetter(self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 699477a5a2e..0981c5e802d 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -856,7 +856,9 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { } fn get_unique_id(self) -> String { - self.unique_id.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let id = self.unique_id.borrow(); + id.clone() } fn summarize(self) -> NodeInfo { @@ -865,8 +867,10 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { *unique_id = uuid::Uuid::new_v4().to_simple_string(); } + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let unique_id = self.unique_id.borrow(); NodeInfo { - uniqueId: self.unique_id.borrow().clone(), + uniqueId: unique_id.clone(), baseURI: self.GetBaseURI().unwrap_or("".to_owned()), parent: self.GetParentNode().root().map(|node| node.r().get_unique_id()).unwrap_or("".to_owned()), nodeType: self.NodeType() as uint, @@ -1122,7 +1126,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() }; @@ -1163,10 +1167,10 @@ impl<'a> Iterator for NodeIterator { .expect("Got to root without reaching start node") .root() .get_unsound_ref_forever(); - self.depth -= 1; if JS::from_rooted(candidate) == self.start_node { break; } + self.depth -= 1; } if JS::from_rooted(candidate) != self.start_node { candidate.next_sibling().map(|node| JS::from_rooted(node.root().r())) @@ -2058,13 +2062,18 @@ impl<'a> NodeMethods for JSRef<'a, Node> { fn is_equal_characterdata(node: JSRef<Node>, other: JSRef<Node>) -> bool { let characterdata: JSRef<CharacterData> = CharacterDataCast::to_ref(node).unwrap(); let other_characterdata: JSRef<CharacterData> = CharacterDataCast::to_ref(other).unwrap(); - *characterdata.data() == *other_characterdata.data() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let own_data = characterdata.data(); + let other_data = other_characterdata.data(); + *own_data == *other_data } fn is_equal_element_attrs(node: JSRef<Node>, other: JSRef<Node>) -> bool { let element: JSRef<Element> = ElementCast::to_ref(node).unwrap(); let other_element: JSRef<Element> = ElementCast::to_ref(other).unwrap(); assert!(element.attrs().len() == other_element.attrs().len()); - element.attrs().iter().map(|attr| attr.root()).all(|attr| { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attrs = element.attrs(); + attrs.iter().map(|attr| attr.root()).all(|attr| { other_element.attrs().iter().map(|attr| attr.root()).any(|other_attr| { (*attr.r().namespace() == *other_attr.r().namespace()) && (attr.r().local_name() == other_attr.r().local_name()) && @@ -2217,7 +2226,9 @@ impl<'a> VirtualMethods for JSRef<'a, Node> { } } -impl<'a> style::node::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> { +impl<'a> style::node::TNode<'a> for JSRef<'a, Node> { + type Element = JSRef<'a, Element>; + fn parent_node(self) -> Option<JSRef<'a, Node>> { // FIXME(zwarich): Remove this when UFCS lands and there is a better way // of disambiguating methods. @@ -2305,12 +2316,22 @@ impl<'a> style::node::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> { match attr.namespace { NamespaceConstraint::Specific(ref ns) => { self.as_element().get_attribute(ns.clone(), name).root() - .map_or(false, |attr| test(attr.r().value().as_slice())) + .map_or(false, |attr| { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + test(value.as_slice()) + }) }, NamespaceConstraint::Any => { self.as_element().get_attributes(name).into_iter() .map(|attr| attr.root()) - .any(|attr| test(attr.r().value().as_slice())) + .any(|attr| { + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let attr = attr.r(); + let value = attr.value(); + test(value.as_slice()) + }) } } } diff --git a/components/script/dom/treewalker.rs b/components/script/dom/treewalker.rs index c05798532da..f74e5f975b0 100644 --- a/components/script/dom/treewalker.rs +++ b/components/script/dom/treewalker.rs @@ -344,7 +344,7 @@ impl<'a> PrivateTreeWalkerHelpers for JSRef<'a, TreeWalker> { } } -pub trait TreeWalkerHelpers<'a> { +pub trait TreeWalkerHelpers { fn parent_node(self) -> Fallible<Option<Temporary<Node>>>; fn first_child(self) -> Fallible<Option<Temporary<Node>>>; fn last_child(self) -> Fallible<Option<Temporary<Node>>>; @@ -354,7 +354,7 @@ pub trait TreeWalkerHelpers<'a> { fn prev_node(self) -> Fallible<Option<Temporary<Node>>>; } -impl<'a> TreeWalkerHelpers<'a> for JSRef<'a, TreeWalker> { +impl<'a> TreeWalkerHelpers for JSRef<'a, TreeWalker> { // http://dom.spec.whatwg.org/#dom-treewalker-parentnode fn parent_node(self) -> Fallible<Option<Temporary<Node>>> { // "1. Let node be the value of the currentNode attribute." diff --git a/components/script/dom/urlsearchparams.rs b/components/script/dom/urlsearchparams.rs index b76504f4137..a8cfa3caf7d 100644 --- a/components/script/dom/urlsearchparams.rs +++ b/components/script/dom/urlsearchparams.rs @@ -53,7 +53,10 @@ impl URLSearchParams { let u = u.root(); let usp = usp.r(); let mut map = usp.data.borrow_mut(); - *map = u.r().data.borrow().clone(); + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let r = u.r(); + let data = r.data.borrow(); + *map = data.clone(); }, None => {} } @@ -81,11 +84,15 @@ impl<'a> URLSearchParamsMethods for JSRef<'a, URLSearchParams> { } fn Get(self, name: DOMString) -> Option<DOMString> { - self.data.borrow().get(&name).map(|v| v[0].clone()) + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let data = self.data.borrow(); + data.get(&name).map(|v| v[0].clone()) } fn Has(self, name: DOMString) -> bool { - self.data.borrow().contains_key(&name) + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let data = self.data.borrow(); + data.contains_key(&name) } fn Set(self, name: DOMString, value: DOMString) { diff --git a/components/script/dom/webidls/Window.webidl b/components/script/dom/webidls/Window.webidl index c24057eeeba..ff0d9f31388 100644 --- a/components/script/dom/webidls/Window.webidl +++ b/components/script/dom/webidls/Window.webidl @@ -10,7 +10,7 @@ //[Unforgeable] readonly attribute WindowProxy window; //[Replaceable] readonly attribute WindowProxy self; readonly attribute Window window; - readonly attribute Window self; + [BinaryName="Self_"] readonly attribute Window self; /*[Unforgeable]*/ readonly attribute Document document; // attribute DOMString name; /*[PutForwards=href, Unforgeable]*/ readonly attribute Location location; diff --git a/components/script/dom/webidls/WorkerGlobalScope.webidl b/components/script/dom/webidls/WorkerGlobalScope.webidl index abb15523d98..1a53893b53e 100644 --- a/components/script/dom/webidls/WorkerGlobalScope.webidl +++ b/components/script/dom/webidls/WorkerGlobalScope.webidl @@ -5,7 +5,7 @@ // http://www.whatwg.org/html/#workerglobalscope //[Exposed=Worker] interface WorkerGlobalScope : EventTarget { - readonly attribute WorkerGlobalScope self; + [BinaryName="Self_"] readonly attribute WorkerGlobalScope self; readonly attribute WorkerLocation location; //void close(); diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 70c12abc9f3..5705a5235e1 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -179,11 +179,11 @@ impl Window { &self.image_cache_task } - pub fn compositor(&self) -> RefMut<Box<ScriptListener+'static>> { + pub fn compositor<'a>(&'a self) -> RefMut<'a, Box<ScriptListener+'static>> { self.compositor.borrow_mut() } - pub fn browser_context(&self) -> Ref<Option<BrowserContext>> { + pub fn browser_context<'a>(&'a self) -> Ref<'a, Option<BrowserContext>> { self.browser_context.borrow() } @@ -281,7 +281,9 @@ impl<'a> WindowMethods for JSRef<'a, Window> { } fn Document(self) -> Temporary<Document> { - self.browser_context().as_ref().unwrap().active_document() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let context = self.browser_context(); + context.as_ref().unwrap().active_document() } fn Location(self) -> Temporary<Location> { @@ -301,7 +303,9 @@ impl<'a> WindowMethods for JSRef<'a, Window> { } fn GetFrameElement(self) -> Option<Temporary<Element>> { - self.browser_context().as_ref().unwrap().frame_element() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let context = self.browser_context(); + context.as_ref().unwrap().frame_element() } fn Navigator(self) -> Temporary<Navigator> { @@ -356,7 +360,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> { Temporary::from_rooted(self) } - fn Self(self) -> Temporary<Window> { + fn Self_(self) -> Temporary<Window> { self.Window() } @@ -373,7 +377,10 @@ impl<'a> WindowMethods for JSRef<'a, Window> { browser_context.frame_element().map_or(self.Window(), |fe| { let frame_element = fe.root(); let window = window_from_node(frame_element.r()).root(); - window.r().browser_context().as_ref().unwrap().active_window() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let r = window.r(); + let context = r.browser_context(); + context.as_ref().unwrap().active_window() }) } @@ -644,7 +651,9 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { } fn steal_fragment_name(self) -> Option<String> { - self.fragment_name.borrow_mut().take() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let mut name = self.fragment_name.borrow_mut(); + name.take() } fn set_window_size(self, size: WindowSizeData) { @@ -688,7 +697,9 @@ impl<'a> WindowHelpers for JSRef<'a, Window> { } fn layout_is_idle(self) -> bool { - self.layout_join_port.borrow().is_none() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let port = self.layout_join_port.borrow(); + port.is_none() } fn set_resize_event(self, event: WindowSizeData) { diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 86d93db6ce0..1a8e8b89e1e 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -84,7 +84,7 @@ impl WorkerGlobalScope { } impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> { - fn Self(self) -> Temporary<WorkerGlobalScope> { + fn Self_(self) -> Temporary<WorkerGlobalScope> { Temporary::from_rooted(self) } diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index cb257f1ed25..36f9a0b06f7 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -369,9 +369,13 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { // Step 4 Some(Method::Connect) | Some(Method::Trace) => Err(Security), Some(Method::Extension(ref t)) if t.as_slice() == "TRACK" => Err(Security), - Some(_) if method.is_token() => { + Some(parsed_method) => { + // Step 3 + if !method.is_token() { + return Err(Syntax) + } - *self.request_method.borrow_mut() = maybe_method.unwrap(); + *self.request_method.borrow_mut() = parsed_method; // Step 6 let base = self.global.root().r().get_url(); @@ -675,7 +679,9 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> { self.status.get() } fn StatusText(self) -> ByteString { - self.status_text.borrow().clone() + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let status_text = self.status_text.borrow(); + status_text.clone() } fn GetResponseHeader(self, name: ByteString) -> Option<ByteString> { self.filter_response_headers().iter().find(|h| { @@ -981,9 +987,12 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { None => {} } + + // FIXME(https://github.com/rust-lang/rust/issues/23338) + let response = self.response.borrow(); // According to Simon, decode() should never return an error, so unwrap()ing // the result should be fine. XXXManishearth have a closer look at this later - encoding.decode(self.response.borrow().as_slice(), DecoderTrap::Replace).unwrap().to_owned() + encoding.decode(response.as_slice(), DecoderTrap::Replace).unwrap().to_owned() } fn filter_response_headers(self) -> Headers { // http://fetch.spec.whatwg.org/#concept-response-header-list @@ -992,7 +1001,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> { use hyper::header::SetCookie; // a dummy header so we can use headers.remove::<SetCookie2>() - #[derive(Clone)] + #[derive(Clone, Debug)] struct SetCookie2; impl Header for SetCookie2 { fn header_name() -> &'static str { |