diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 49abbdfd6fb..793a4b1ef24 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2307,7 +2307,7 @@ class CGPerSignatureCall(CGThing): def process(arg, i): argVal = "arg" + str(i) if arg.type.isGeckoInterface() and not arg.type.unroll().inner.isCallback(): - argVal += ".root_ref()" + argVal += ".r()" return argVal return [(a, process(a, i)) for (i, a) in enumerate(self.arguments)] @@ -3540,7 +3540,7 @@ class CGProxySpecialOperation(CGPerSignatureCall): def process(arg): argVal = arg.identifier.name if arg.type.isGeckoInterface() and not arg.type.unroll().inner.isCallback(): - argVal += ".root_ref()" + argVal += ".r()" return argVal args = [(a, process(a)) for a in self.arguments] if self.idlNode.isGetter(): diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 3640aabb88d..7fa9ba6c05c 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -103,8 +103,8 @@ impl GlobalRoot { /// lifetime of this root. pub fn root_ref<'c>(&'c self) -> GlobalRef<'c> { match *self { - GlobalRoot::Window(ref window) => GlobalRef::Window(window.root_ref()), - GlobalRoot::Worker(ref worker) => GlobalRef::Worker(worker.root_ref()), + GlobalRoot::Window(ref window) => GlobalRef::Window(window.r()), + GlobalRoot::Worker(ref worker) => GlobalRef::Worker(worker.r()), } } } diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 42ba52b6d34..3eb911e7be3 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -31,11 +31,11 @@ //! Both `Temporary` and `JS` do not allow access to their inner value without explicitly //! creating a stack-based root via the `root` method. This returns a `Root`, which causes //! the JS-owned value to be uncollectable for the duration of the `Root` object's lifetime. -//! A `JSRef` can be obtained from a `Root` either by dereferencing the `Root` (`*rooted`) -//! or explicitly calling the `root_ref` method. These `JSRef` values are not allowed to -//! outlive their originating `Root`, to ensure that all interactions with the enclosed value -//! only occur when said value is uncollectable, and will cause static lifetime errors if -//! misused. +//! A `JSRef` can be obtained from a `Root` by calling the `r` method. (Dereferencing the +//! object is still supported, but as it is unsafe, this is deprecated.) These `JSRef` values +//! are not allowed to outlive their originating `Root`, to ensure that all interactions with +//! the enclosed value only occur when said value is uncollectable, and will cause static lifetime +//! errors if misused. //! //! Other miscellaneous helper traits: //! @@ -307,23 +307,23 @@ impl JS { /// Get an `Option>` out of an `Option>` pub trait RootedReference { - fn root_ref<'a>(&'a self) -> Option>; + fn r<'a>(&'a self) -> Option>; } impl RootedReference for Option> { - fn root_ref<'a>(&'a self) -> Option> { - self.as_ref().map(|root| root.root_ref()) + fn r<'a>(&'a self) -> Option> { + self.as_ref().map(|root| root.r()) } } /// Get an `Option>>` out of an `Option>>` pub trait OptionalRootedReference { - fn root_ref<'a>(&'a self) -> Option>>; + fn r<'a>(&'a self) -> Option>>; } impl OptionalRootedReference for Option>> { - fn root_ref<'a>(&'a self) -> Option>> { - self.as_ref().map(|inner| inner.root_ref()) + fn r<'a>(&'a self) -> Option>> { + self.as_ref().map(|inner| inner.r()) } } @@ -513,7 +513,7 @@ impl Root { /// Obtain a safe reference to the wrapped JS owned-value that cannot outlive /// the lifetime of this root. - pub fn root_ref<'b>(&'b self) -> JSRef<'b,T> { + pub fn r<'b>(&'b self) -> JSRef<'b, T> { self.jsref.clone() } } diff --git a/components/script/dom/domstringmap.rs b/components/script/dom/domstringmap.rs index 39c08e32b87..268087a3533 100644 --- a/components/script/dom/domstringmap.rs +++ b/components/script/dom/domstringmap.rs @@ -29,7 +29,7 @@ impl DOMStringMap { pub fn new(element: JSRef) -> Temporary { let window = window_from_node(element).root(); reflect_dom_object(box DOMStringMap::new_inherited(element), - GlobalRef::Window(window.root_ref()), DOMStringMapBinding::Wrap) + GlobalRef::Window(window.r()), DOMStringMapBinding::Wrap) } } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 382e6925b09..ecf1ecf9d23 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -313,7 +313,7 @@ fn broadcast_radio_checked(broadcaster: JSRef, group: Option<& let mut iter = unsafe { doc_node.query_selector_iter("input[type=radio]".into_string()).unwrap() .filter_map(|t| HTMLInputElementCast::to_ref(t)) - .filter(|&r| in_same_group(r, owner.root_ref(), group) && broadcaster != r) + .filter(|&r| in_same_group(r, owner.r(), group) && broadcaster != r) }; for r in iter { if r.Checked() { @@ -326,7 +326,7 @@ fn in_same_group<'a,'b>(other: JSRef<'a, HTMLInputElement>, owner: Option>, group: Option<&str>) -> bool { let other_owner = other.form_owner().root(); - let other_owner = other_owner.root_ref(); + let other_owner = other_owner.r(); other.input_type.get() == InputType::InputRadio && // TODO Both a and b are in the same home subtree. other_owner.equals(owner) && @@ -638,7 +638,7 @@ impl<'a> Activatable for JSRef<'a, HTMLInputElement> { let checked_member = unsafe { doc_node.query_selector_iter("input[type=radio]".into_string()).unwrap() .filter_map(|t| HTMLInputElementCast::to_ref(t)) - .filter(|&r| in_same_group(r, owner.root_ref(), + .filter(|&r| in_same_group(r, owner.r(), group.as_ref().map(|gr| gr.as_slice()))) .find(|r| r.Checked()) }; diff --git a/components/script/dom/keyboardevent.rs b/components/script/dom/keyboardevent.rs index 282341d2630..e409a20b5e0 100644 --- a/components/script/dom/keyboardevent.rs +++ b/components/script/dom/keyboardevent.rs @@ -101,7 +101,7 @@ impl KeyboardEvent { let event = KeyboardEvent::new(global.as_window(), type_, init.parent.parent.parent.bubbles, init.parent.parent.parent.cancelable, - init.parent.parent.view.root_ref(), + init.parent.parent.view.r(), init.parent.parent.detail, init.key.clone(), init.code.clone(), init.location, init.repeat, init.isComposing, init.parent.ctrlKey, diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs index ec3c18263b4..38fe5119ea9 100644 --- a/components/script/dom/mouseevent.rs +++ b/components/script/dom/mouseevent.rs @@ -92,12 +92,12 @@ impl MouseEvent { let event = MouseEvent::new(global.as_window(), type_, init.parent.parent.parent.bubbles, init.parent.parent.parent.cancelable, - init.parent.parent.view.root_ref(), + init.parent.parent.view.r(), init.parent.parent.detail, init.screenX, init.screenY, init.clientX, init.clientY, init.parent.ctrlKey, init.parent.altKey, init.parent.shiftKey, init.parent.metaKey, - init.button, init.relatedTarget.root_ref()); + init.button, init.relatedTarget.r()); Ok(event) } } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index befbe131553..595410a4818 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -307,10 +307,10 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { assert!(new_child.next_sibling().is_none()); match before { Some(ref before) => { - assert!(before.parent_node().root().root_ref() == Some(self)); + assert!(before.parent_node().root().r() == Some(self)); match before.prev_sibling().root() { None => { - assert!(Some(*before) == self.first_child().root().root_ref()); + assert!(Some(*before) == self.first_child().root().r()); self.first_child.assign(Some(new_child)); }, Some(prev_sibling) => { @@ -342,7 +342,7 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> { /// /// Fails unless `child` is a child of this node. fn remove_child(self, child: JSRef) { - assert!(child.parent_node().root().root_ref() == Some(self)); + assert!(child.parent_node().root().r() == Some(self)); match child.prev_sibling.get().root() { None => { @@ -1811,7 +1811,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { }.root(); // Step 3. - Node::replace_all(node.root_ref(), self); + Node::replace_all(node.r(), self); } NodeTypeId::Comment | NodeTypeId::Text | diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs index 04d8f22e88f..a5a867fd222 100644 --- a/components/script/dom/uievent.rs +++ b/components/script/dom/uievent.rs @@ -62,7 +62,7 @@ impl UIEvent { init: &UIEventBinding::UIEventInit) -> Fallible> { let event = UIEvent::new(global.as_window(), type_, init.parent.bubbles, init.parent.cancelable, - init.view.root_ref(), init.detail); + init.view.r(), init.detail); Ok(event) } }