aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2015-04-27 18:34:15 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2015-04-28 09:22:46 +0200
commit1a30925cad5c55943e21d60e2891003b0ff722c9 (patch)
tree9a68eaef3d1cfdd2883879c13758508ec53c1f47 /components/script
parent2770886196269d264d46b0357669bbd0f9626995 (diff)
downloadservo-1a30925cad5c55943e21d60e2891003b0ff722c9.tar.gz
servo-1a30925cad5c55943e21d60e2891003b0ff722c9.zip
Remove Temporary::new()
Temporary::from_rooted() now takes an Assignable value.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/attr.rs2
-rw-r--r--components/script/dom/bindings/js.rs19
-rw-r--r--components/script/dom/browsercontext.rs4
-rw-r--r--components/script/dom/canvasrenderingcontext2d.rs2
-rw-r--r--components/script/dom/document.rs10
-rw-r--r--components/script/dom/domrectlist.rs2
-rw-r--r--components/script/dom/event.rs4
-rw-r--r--components/script/dom/htmlcollection.rs2
-rw-r--r--components/script/dom/mouseevent.rs2
-rw-r--r--components/script/dom/namednodemap.rs2
-rw-r--r--components/script/dom/node.rs22
-rw-r--r--components/script/dom/nodelist.rs2
-rw-r--r--components/script/dom/performance.rs2
-rw-r--r--components/script/dom/storageevent.rs2
-rw-r--r--components/script/dom/treewalker.rs4
-rw-r--r--components/script/dom/uievent.rs2
-rw-r--r--components/script/dom/xmlhttprequest.rs4
-rw-r--r--components/script/page.rs4
-rw-r--r--components/script/parse/html.rs2
19 files changed, 45 insertions, 48 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index 5df12e5aa63..88384aabe5f 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -274,7 +274,7 @@ impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> {
}
fn owner(self) -> Option<Temporary<Element>> {
- self.owner.get().map(Temporary::new)
+ self.owner.get().map(Temporary::from_rooted)
}
fn summarize(self) -> AttrInfo {
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs
index 4f953d6bb61..115fcdbbe97 100644
--- a/components/script/dom/bindings/js.rs
+++ b/components/script/dom/bindings/js.rs
@@ -153,14 +153,6 @@ impl<T> PartialEq for Temporary<T> {
}
impl<T: Reflectable> Temporary<T> {
- /// Create a new `Temporary` value from a JS-owned value.
- pub fn new(inner: JS<T>) -> Temporary<T> {
- Temporary {
- inner: inner,
- _js_ptr: inner.reflector().get_jsobject(),
- }
- }
-
/// Create a new `Temporary` value from an unrooted value.
#[allow(unrooted_must_root)]
pub fn from_unrooted(unrooted: Unrooted<T>) -> Temporary<T> {
@@ -171,8 +163,13 @@ impl<T: Reflectable> Temporary<T> {
}
/// Create a new `Temporary` value from a rooted value.
- pub fn from_rooted<'a>(root: JSRef<'a, T>) -> Temporary<T> {
- Temporary::new(JS::from_rooted(root))
+ #[allow(unrooted_must_root)]
+ pub fn from_rooted<U: Assignable<T>>(root: U) -> Temporary<T> {
+ let inner = JS::from_rooted(root);
+ Temporary {
+ inner: inner,
+ _js_ptr: inner.reflector().get_jsobject(),
+ }
}
}
@@ -372,7 +369,7 @@ impl<T: Reflectable> MutNullableHeap<JS<T>> {
where F: FnOnce() -> Temporary<T>
{
match self.get() {
- Some(inner) => Temporary::new(inner),
+ Some(inner) => Temporary::from_rooted(inner),
None => {
let inner = cb();
self.set(Some(JS::from_rooted(inner.clone())));
diff --git a/components/script/dom/browsercontext.rs b/components/script/dom/browsercontext.rs
index ac2fb117ca1..8744c169572 100644
--- a/components/script/dom/browsercontext.rs
+++ b/components/script/dom/browsercontext.rs
@@ -50,7 +50,7 @@ impl BrowserContext {
}
pub fn active_document(&self) -> Temporary<Document> {
- Temporary::new(self.history[self.active_index].document.clone())
+ Temporary::from_rooted(self.history[self.active_index].document.clone())
}
pub fn active_window(&self) -> Temporary<Window> {
@@ -59,7 +59,7 @@ impl BrowserContext {
}
pub fn frame_element(&self) -> Option<Temporary<Element>> {
- self.frame_element.map(Temporary::new)
+ self.frame_element.map(Temporary::from_rooted)
}
pub fn window_proxy(&self) -> *mut JSObject {
diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs
index 44e2ea33966..cd02eb18f0e 100644
--- a/components/script/dom/canvasrenderingcontext2d.rs
+++ b/components/script/dom/canvasrenderingcontext2d.rs
@@ -326,7 +326,7 @@ impl LayoutCanvasRenderingContext2DHelpers for LayoutJS<CanvasRenderingContext2D
impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D> {
// https://html.spec.whatwg.org/multipage/#dom-context-2d-canvas
fn Canvas(self) -> Temporary<HTMLCanvasElement> {
- Temporary::new(self.canvas)
+ Temporary::from_rooted(self.canvas)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-save
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 19b5c74af0e..ce1abc1cd89 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -242,7 +242,7 @@ pub trait DocumentHelpers<'a> {
impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
#[inline]
fn window(self) -> Temporary<Window> {
- Temporary::new(self.window)
+ Temporary::from_rooted(self.window)
}
#[inline]
@@ -444,7 +444,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
/// Return the element that currently has focus.
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#events-focusevent-doc-focus
fn get_focused_element(self) -> Option<Temporary<Element>> {
- self.focused.get().map(Temporary::new)
+ self.focused.get().map(Temporary::from_rooted)
}
/// Initiate a new round of checking for elements requesting focus. The last element to call
@@ -1019,7 +1019,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let id = Atom::from_slice(&id);
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let idmap = self.idmap.borrow();
- idmap.get(&id).map(|ref elements| Temporary::new((*elements)[0].clone()))
+ idmap.get(&id).map(|ref elements| Temporary::from_rooted((*elements)[0].clone()))
}
// https://dom.spec.whatwg.org/#dom-document-createelement
@@ -1269,7 +1269,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
// https://html.spec.whatwg.org/#dom-document-currentscript
fn GetCurrentScript(self) -> Option<Temporary<HTMLScriptElement>> {
- self.current_script.get().map(Temporary::new)
+ self.current_script.get().map(Temporary::from_rooted)
}
// https://html.spec.whatwg.org/#dom-document-body
@@ -1481,7 +1481,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
// https://html.spec.whatwg.org/multipage/#dom-document-defaultview
fn DefaultView(self) -> Temporary<Window> {
- Temporary::new(self.window)
+ Temporary::from_rooted(self.window)
}
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
diff --git a/components/script/dom/domrectlist.rs b/components/script/dom/domrectlist.rs
index ec70329e092..a6ad5b50771 100644
--- a/components/script/dom/domrectlist.rs
+++ b/components/script/dom/domrectlist.rs
@@ -43,7 +43,7 @@ impl<'a> DOMRectListMethods for JSRef<'a, DOMRectList> {
fn Item(self, index: u32) -> Option<Temporary<DOMRect>> {
let rects = &self.rects;
if index < rects.len() as u32 {
- Some(Temporary::new(rects[index as usize].clone()))
+ Some(Temporary::from_rooted(rects[index as usize].clone()))
} else {
None
}
diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs
index 25b52b51849..55883659c39 100644
--- a/components/script/dom/event.rs
+++ b/components/script/dom/event.rs
@@ -188,12 +188,12 @@ impl<'a> EventMethods for JSRef<'a, Event> {
// https://dom.spec.whatwg.org/#dom-event-target
fn GetTarget(self) -> Option<Temporary<EventTarget>> {
- self.target.get().map(Temporary::new)
+ self.target.get().map(Temporary::from_rooted)
}
// https://dom.spec.whatwg.org/#dom-event-currenttarget
fn GetCurrentTarget(self) -> Option<Temporary<EventTarget>> {
- self.current_target.get().map(Temporary::new)
+ self.current_target.get().map(Temporary::from_rooted)
}
// https://dom.spec.whatwg.org/#dom-event-defaultprevented
diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs
index bbb96af7e02..e4520f6760c 100644
--- a/components/script/dom/htmlcollection.rs
+++ b/components/script/dom/htmlcollection.rs
@@ -194,7 +194,7 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
match self.collection {
CollectionTypeId::Static(ref elems) => elems
.get(index)
- .map(|elem| Temporary::new(elem.clone())),
+ .map(|elem| Temporary::from_rooted(elem.clone())),
CollectionTypeId::Live(ref root, ref filter) => {
let root = root.root();
HTMLCollection::traverse(root.r())
diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs
index ccac8e331e9..a9c6a6b26f2 100644
--- a/components/script/dom/mouseevent.rs
+++ b/components/script/dom/mouseevent.rs
@@ -143,7 +143,7 @@ impl<'a> MouseEventMethods for JSRef<'a, MouseEvent> {
}
fn GetRelatedTarget(self) -> Option<Temporary<EventTarget>> {
- self.related_target.get().map(Temporary::new)
+ self.related_target.get().map(Temporary::from_rooted)
}
fn InitMouseEvent(self,
diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs
index a134c8de233..75ea2bcfeb3 100644
--- a/components/script/dom/namednodemap.rs
+++ b/components/script/dom/namednodemap.rs
@@ -52,7 +52,7 @@ impl<'a> NamedNodeMapMethods for JSRef<'a, NamedNodeMap> {
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let owner = owner.r();
let attrs = owner.attrs();
- attrs.get(index as usize).map(|x| Temporary::new(x.clone()))
+ attrs.get(index as usize).map(|x| Temporary::from_rooted(x.clone()))
}
// https://dom.spec.whatwg.org/#dom-namednodemap-getnameditem
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 27e1a6edc19..f8dc318b6c6 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -570,25 +570,25 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
}
fn parent_node(self) -> Option<Temporary<Node>> {
- self.parent_node.get().map(Temporary::new)
+ self.parent_node.get().map(Temporary::from_rooted)
}
fn first_child(self) -> Option<Temporary<Node>> {
- self.first_child.get().map(Temporary::new)
+ self.first_child.get().map(Temporary::from_rooted)
}
fn last_child(self) -> Option<Temporary<Node>> {
- self.last_child.get().map(Temporary::new)
+ self.last_child.get().map(Temporary::from_rooted)
}
/// Returns the previous sibling of this node. Fails if this node is borrowed mutably.
fn prev_sibling(self) -> Option<Temporary<Node>> {
- self.prev_sibling.get().map(Temporary::new)
+ self.prev_sibling.get().map(Temporary::from_rooted)
}
/// Returns the next sibling of this node. Fails if this node is borrowed mutably.
fn next_sibling(self) -> Option<Temporary<Node>> {
- self.next_sibling.get().map(Temporary::new)
+ self.next_sibling.get().map(Temporary::from_rooted)
}
#[inline]
@@ -947,7 +947,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
}
fn owner_doc(self) -> Temporary<Document> {
- Temporary::new(self.owner_doc.get().unwrap())
+ Temporary::from_rooted(self.owner_doc.get().unwrap())
}
fn set_owner_doc(self, document: JSRef<Document>) {
@@ -1873,7 +1873,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// https://dom.spec.whatwg.org/#dom-node-parentnode
fn GetParentNode(self) -> Option<Temporary<Node>> {
- self.parent_node.get().map(Temporary::new)
+ self.parent_node.get().map(Temporary::from_rooted)
}
// https://dom.spec.whatwg.org/#dom-node-parentelement
@@ -1903,22 +1903,22 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
// https://dom.spec.whatwg.org/#dom-node-firstchild
fn GetFirstChild(self) -> Option<Temporary<Node>> {
- self.first_child.get().map(Temporary::new)
+ self.first_child.get().map(Temporary::from_rooted)
}
// https://dom.spec.whatwg.org/#dom-node-lastchild
fn GetLastChild(self) -> Option<Temporary<Node>> {
- self.last_child.get().map(Temporary::new)
+ self.last_child.get().map(Temporary::from_rooted)
}
// https://dom.spec.whatwg.org/#dom-node-previoussibling
fn GetPreviousSibling(self) -> Option<Temporary<Node>> {
- self.prev_sibling.get().map(Temporary::new)
+ self.prev_sibling.get().map(Temporary::from_rooted)
}
// https://dom.spec.whatwg.org/#dom-node-nextsibling
fn GetNextSibling(self) -> Option<Temporary<Node>> {
- self.next_sibling.get().map(Temporary::new)
+ self.next_sibling.get().map(Temporary::from_rooted)
}
// https://dom.spec.whatwg.org/#dom-node-nodevalue
diff --git a/components/script/dom/nodelist.rs b/components/script/dom/nodelist.rs
index d7830deb9f4..66b2cb6c5c4 100644
--- a/components/script/dom/nodelist.rs
+++ b/components/script/dom/nodelist.rs
@@ -64,7 +64,7 @@ impl<'a> NodeListMethods for JSRef<'a, NodeList> {
fn Item(self, index: u32) -> Option<Temporary<Node>> {
match self.list_type {
_ if index >= self.Length() => None,
- NodeListType::Simple(ref elems) => Some(Temporary::new(elems[index as usize].clone())),
+ NodeListType::Simple(ref elems) => Some(Temporary::from_rooted(elems[index as usize].clone())),
NodeListType::Children(ref node) => {
let node = node.root();
node.r().children().nth(index as usize)
diff --git a/components/script/dom/performance.rs b/components/script/dom/performance.rs
index e2fb476c111..d9dd8472d74 100644
--- a/components/script/dom/performance.rs
+++ b/components/script/dom/performance.rs
@@ -45,7 +45,7 @@ impl Performance {
impl<'a> PerformanceMethods for JSRef<'a, Performance> {
fn Timing(self) -> Temporary<PerformanceTiming> {
- Temporary::new(self.timing.clone())
+ Temporary::from_rooted(self.timing.clone())
}
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html#dom-performance-now
diff --git a/components/script/dom/storageevent.rs b/components/script/dom/storageevent.rs
index 860da7a4ad3..1fad3001140 100644
--- a/components/script/dom/storageevent.rs
+++ b/components/script/dom/storageevent.rs
@@ -108,7 +108,7 @@ impl<'a> StorageEventMethods for JSRef<'a, StorageEvent> {
}
fn GetStorageArea(self) -> Option<Temporary<Storage>> {
- self.storageArea.get().map(Temporary::new)
+ self.storageArea.get().map(Temporary::from_rooted)
}
}
diff --git a/components/script/dom/treewalker.rs b/components/script/dom/treewalker.rs
index 29104f7dfde..094092ec90e 100644
--- a/components/script/dom/treewalker.rs
+++ b/components/script/dom/treewalker.rs
@@ -64,7 +64,7 @@ impl TreeWalker {
impl<'a> TreeWalkerMethods for JSRef<'a, TreeWalker> {
// https://dom.spec.whatwg.org/#dom-treewalker-root
fn Root(self) -> Temporary<Node> {
- Temporary::new(self.root_node)
+ Temporary::from_rooted(self.root_node)
}
// https://dom.spec.whatwg.org/#dom-treewalker-whattoshow
@@ -83,7 +83,7 @@ impl<'a> TreeWalkerMethods for JSRef<'a, TreeWalker> {
// https://dom.spec.whatwg.org/#dom-treewalker-currentnode
fn CurrentNode(self) -> Temporary<Node> {
- Temporary::new(self.current_node.get())
+ Temporary::from_rooted(self.current_node.get())
}
// https://dom.spec.whatwg.org/#dom-treewalker-currentnode
diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs
index f4271e501d8..d65a30d10aa 100644
--- a/components/script/dom/uievent.rs
+++ b/components/script/dom/uievent.rs
@@ -74,7 +74,7 @@ impl UIEvent {
impl<'a> UIEventMethods for JSRef<'a, UIEvent> {
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#widl-UIEvent-view
fn GetView(self) -> Option<Temporary<Window>> {
- self.view.get().map(Temporary::new)
+ self.view.get().map(Temporary::from_rooted)
}
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#widl-UIEvent-detail
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs
index a64d57b7792..3e84dfc0037 100644
--- a/components/script/dom/xmlhttprequest.rs
+++ b/components/script/dom/xmlhttprequest.rs
@@ -463,7 +463,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> {
// https://xhr.spec.whatwg.org/#the-upload-attribute
fn Upload(self) -> Temporary<XMLHttpRequestUpload> {
- Temporary::new(self.upload)
+ Temporary::from_rooted(self.upload)
}
// https://xhr.spec.whatwg.org/#the-send()-method
@@ -711,7 +711,7 @@ impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> {
// https://xhr.spec.whatwg.org/#the-responsexml-attribute
fn GetResponseXML(self) -> Option<Temporary<Document>> {
- self.response_xml.get().map(Temporary::new)
+ self.response_xml.get().map(Temporary::from_rooted)
}
}
diff --git a/components/script/page.rs b/components/script/page.rs
index 0a226211016..57c22e4e3e7 100644
--- a/components/script/page.rs
+++ b/components/script/page.rs
@@ -73,7 +73,7 @@ impl Page {
}
pub fn window(&self) -> Temporary<Window> {
- Temporary::new(self.frame.borrow().as_ref().unwrap().window.clone())
+ Temporary::from_rooted(self.frame.borrow().as_ref().unwrap().window.clone())
}
pub fn window_for_script_deallocation(&self) -> Unrooted<Window> {
@@ -81,7 +81,7 @@ impl Page {
}
pub fn document(&self) -> Temporary<Document> {
- Temporary::new(self.frame.borrow().as_ref().unwrap().document.clone())
+ Temporary::from_rooted(self.frame.borrow().as_ref().unwrap().document.clone())
}
// must handle root case separately
diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs
index bd262ebe1f2..70880ef34e3 100644
--- a/components/script/parse/html.rs
+++ b/components/script/parse/html.rs
@@ -63,7 +63,7 @@ trait SinkHelpers {
impl SinkHelpers for servohtmlparser::Sink {
fn get_or_create(&self, child: NodeOrText<JS<Node>>) -> Temporary<Node> {
match child {
- AppendNode(n) => Temporary::new(n),
+ AppendNode(n) => Temporary::from_rooted(n),
AppendText(t) => {
let doc = self.document.root();
let text = Text::new(t, doc.r());