diff --git a/components/script/devtools.rs b/components/script/devtools.rs index c92098db2be..c2f0957f9ec 100644 --- a/components/script/devtools.rs +++ b/components/script/devtools.rs @@ -25,8 +25,8 @@ pub fn handle_evaluate_js(page: &Rc, pipeline: PipelineId, eval: String, r let page = get_page(&*page, pipeline); let frame = page.frame(); let window = frame.as_ref().unwrap().window.root(); - let cx = window.get_cx(); - let rval = window.evaluate_js_with_result(eval.as_slice()); + let cx = window.r().get_cx(); + let rval = window.r().evaluate_js_with_result(eval.as_slice()); reply.send(if rval.is_undefined() { devtools_traits::VoidValue @@ -51,7 +51,7 @@ pub fn handle_get_root_node(page: &Rc, pipeline: PipelineId, reply: Sender let frame = page.frame(); let document = frame.as_ref().unwrap().document.root(); - let node: JSRef = NodeCast::from_ref(*document); + let node: JSRef = NodeCast::from_ref(document.r()); reply.send(node.summarize()); } @@ -59,9 +59,9 @@ pub fn handle_get_document_element(page: &Rc, pipeline: PipelineId, reply: let page = get_page(&*page, pipeline); let frame = page.frame(); let document = frame.as_ref().unwrap().document.root(); - let document_element = document.GetDocumentElement().root().unwrap(); + let document_element = document.r().GetDocumentElement().root().unwrap(); - let node: JSRef = NodeCast::from_ref(*document_element); + let node: JSRef = NodeCast::from_ref(document_element.r()); reply.send(node.summarize()); } @@ -69,7 +69,7 @@ fn find_node_by_unique_id(page: &Rc, pipeline: PipelineId, node_id: String let page = get_page(&*page, pipeline); let frame = page.frame(); let document = frame.as_ref().unwrap().document.root(); - let node: JSRef = NodeCast::from_ref(*document); + let node: JSRef = NodeCast::from_ref(document.r()); for candidate in node.traverse_preorder() { if candidate.get_unique_id().as_slice() == node_id.as_slice() { @@ -82,20 +82,20 @@ fn find_node_by_unique_id(page: &Rc, pipeline: PipelineId, node_id: String pub fn handle_get_children(page: &Rc, pipeline: PipelineId, node_id: String, reply: Sender>) { let parent = find_node_by_unique_id(&*page, pipeline, node_id).root(); - let children = parent.children().map(|child| child.summarize()).collect(); + let children = parent.r().children().map(|child| child.summarize()).collect(); reply.send(children); } pub fn handle_get_layout(page: &Rc, pipeline: PipelineId, node_id: String, reply: Sender<(f32, f32)>) { let node = find_node_by_unique_id(&*page, pipeline, node_id).root(); - let elem: JSRef = ElementCast::to_ref(*node).expect("should be getting layout of element"); + let elem: JSRef = ElementCast::to_ref(node.r()).expect("should be getting layout of element"); let rect = elem.GetBoundingClientRect().root(); - reply.send((rect.Width(), rect.Height())); + reply.send((rect.r().Width(), rect.r().Height())); } pub fn handle_modify_attribute(page: &Rc, pipeline: PipelineId, node_id: String, modifications: Vec) { let node = find_node_by_unique_id(&*page, pipeline, node_id).root(); - let elem: JSRef = ElementCast::to_ref(*node).expect("should be getting layout of element"); + let elem: JSRef = ElementCast::to_ref(node.r()).expect("should be getting layout of element"); for modification in modifications.iter(){ match modification.newValue { diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs index 628cbe76016..6299abaa672 100644 --- a/components/script/dom/activation.rs +++ b/components/script/dom/activation.rs @@ -32,22 +32,23 @@ pub trait Activatable : Copy { fn synthetic_click_activation(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { let element = self.as_element().root(); // Step 1 - if element.click_in_progress() { + if element.r().click_in_progress() { return; } // Step 2 - element.set_click_in_progress(true); + element.r().set_click_in_progress(true); // Step 3 self.pre_click_activation(); // Step 4 // https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-mouse-event - let win = window_from_node(*element).root(); - let target: JSRef = EventTargetCast::from_ref(*element); - let mouse = MouseEvent::new(*win, "click".into_string(), false, false, Some(*win), 1, + let win = window_from_node(element.r()).root(); + let target: JSRef = EventTargetCast::from_ref(element.r()); + let mouse = MouseEvent::new(win.r(), "click".into_string(), + false, false, Some(win.r()), 1, 0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey, 0, None).root(); - let event: JSRef = EventCast::from_ref(*mouse); + let event: JSRef = EventCast::from_ref(mouse.r()); event.set_trusted(true); target.dispatch_event(event); @@ -60,6 +61,6 @@ pub trait Activatable : Copy { } // Step 6 - element.set_click_in_progress(false); + element.r().set_click_in_progress(false); } } diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 34f1d48c5a9..9a062679a4f 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -8,6 +8,7 @@ use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, JSRef, Temporary}; +use dom::bindings::js::{OptionalRootedRootable, RootedReference}; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::element::{Element, AttributeHandlers}; use dom::node::Node; @@ -151,8 +152,8 @@ impl<'a> AttrMethods for JSRef<'a, Attr> { } Some(o) => { let owner = o.root(); - let value = owner.parse_attribute(&self.namespace, self.local_name(), value); - self.set_value(AttrSettingType::ReplacedAttr, value, *owner); + let value = owner.r().parse_attribute(&self.namespace, self.local_name(), value); + self.set_value(AttrSettingType::ReplacedAttr, value, owner.r()); } } } @@ -207,7 +208,7 @@ pub trait AttrHelpers<'a> { impl<'a> AttrHelpers<'a> for JSRef<'a, Attr> { fn set_value(self, set_type: AttrSettingType, value: AttrValue, owner: JSRef) { - assert!(Some(owner) == self.owner.map(|o| *o.root())); + assert!(Some(owner) == self.owner.root().r()); let node: JSRef = NodeCast::from_ref(owner); let namespace_is_null = self.namespace == ns!(""); diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index 9d74b0560da..ec6071e0700 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -147,7 +147,7 @@ impl CallSetup { pub fn new(callback: T, handling: ExceptionHandling) -> CallSetup { let global = global_object_for_js_object(callback.callback()); let global = global.root(); - let cx = global.root_ref().get_cx(); + let cx = global.r().get_cx(); CallSetup { cx: cx, _handling: handling diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index f59517a0b23..dc9beb97ed4 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2199,7 +2199,7 @@ class CGCallGenerator(CGThing): if static: call = CGWrapper(call, pre="%s::" % descriptorProvider.interface.identifier.name) else: - call = CGWrapper(call, pre="%s." % object) + call = CGWrapper(call, pre="%s.r()." % object) call = CGList([call, CGWrapper(args, pre="(", post=")")]) self.cgRoot.append(CGList([ @@ -2214,7 +2214,7 @@ class CGCallGenerator(CGThing): if static: glob = "" else: - glob = " let global = global_object_for_js_object(this.reflector().get_jsobject());\n"\ + glob = " let global = global_object_for_js_object(this.r().reflector().get_jsobject());\n"\ " let global = global.root();\n" self.cgRoot.append(CGGeneric( @@ -2222,7 +2222,7 @@ class CGCallGenerator(CGThing): " Ok(result) => result,\n" " Err(e) => {\n" "%s" - " throw_dom_exception(cx, global.root_ref(), e);\n" + " throw_dom_exception(cx, global.r(), e);\n" " return%s;\n" " },\n" "};" % (glob, errorResult))) @@ -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(): @@ -4014,7 +4014,7 @@ let global = global_object_for_js_object(JS_CALLEE(cx, vp).to_object()); let global = global.root(); """) nativeName = MakeNativeName(self._ctor.identifier.name) - callGenerator = CGMethodCall(["&global.root_ref()"], nativeName, True, + callGenerator = CGMethodCall(["&global.r()"], nativeName, True, self.descriptor, self._ctor) return CGList([preamble, callGenerator]) diff --git a/components/script/dom/bindings/codegen/Configuration.py b/components/script/dom/bindings/codegen/Configuration.py index be3ff10ab68..ac103c86378 100644 --- a/components/script/dom/bindings/codegen/Configuration.py +++ b/components/script/dom/bindings/codegen/Configuration.py @@ -156,7 +156,7 @@ class Descriptor(DescriptorProvider): self.needsRooting = True self.returnType = "Temporary<%s>" % ifaceName self.argumentType = "JSRef<%s>" % ifaceName - self.memberType = "Root<'a, 'b, %s>" % ifaceName + self.memberType = "Root<%s>" % ifaceName self.nativeType = "JS<%s>" % ifaceName self.concreteType = ifaceName diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 85a71d15680..446b2b27829 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -471,9 +471,9 @@ impl FromJSValConvertible<()> for JS { } } -impl<'a, 'b, T: Reflectable> ToJSValConvertible for Root<'a, 'b, T> { +impl ToJSValConvertible for Root { fn to_jsval(&self, cx: *mut JSContext) -> JSVal { - self.reflector().to_jsval(cx) + self.r().reflector().to_jsval(cx) } } diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 38e018fe24f..8079c796094 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -32,9 +32,9 @@ pub enum GlobalRef<'a> { } /// A stack-based rooted reference to a global object. -pub enum GlobalRoot<'a, 'b> { - Window(Root<'a, 'b, window::Window>), - Worker(Root<'a, 'b, WorkerGlobalScope>), +pub enum GlobalRoot { + Window(Root), + Worker(Root), } /// A traced reference to a global object, for use in fields of traced Rust @@ -98,13 +98,13 @@ impl<'a> Reflectable for GlobalRef<'a> { } } -impl<'a, 'b> GlobalRoot<'a, 'b> { +impl GlobalRoot { /// Obtain a safe reference to the global object that cannot outlive the /// lifetime of this root. - pub fn root_ref<'c>(&'c self) -> GlobalRef<'c> { + pub fn r<'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 a1957f6797a..f7208237cc1 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: //! @@ -91,7 +91,7 @@ impl Temporary { } /// Create a stack-bounded root for this value. - pub fn root<'a, 'b>(self) -> Root<'a, 'b, T> { + pub fn root(self) -> Root { let collection = StackRoots.get().unwrap(); unsafe { Root::new(&**collection, &self.inner) @@ -150,7 +150,7 @@ impl JS { /// Root this JS-owned value to prevent its collection as garbage. - pub fn root<'a, 'b>(&self) -> Root<'a, 'b, T> { + pub fn root(&self) -> Root { let collection = StackRoots.get().unwrap(); unsafe { Root::new(&**collection, self) @@ -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<'a, 'b, T: Reflectable> RootedReference for Option> { - fn root_ref<'a>(&'a self) -> Option> { - self.as_ref().map(|root| root.root_ref()) +impl RootedReference for Option> { + 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<'a, 'b, T: Reflectable> OptionalRootedReference for Option>> { - fn root_ref<'a>(&'a self) -> Option>> { - self.as_ref().map(|inner| inner.root_ref()) +impl OptionalRootedReference for Option>> { + fn r<'a>(&'a self) -> Option>> { + self.as_ref().map(|inner| inner.r()) } } @@ -367,11 +367,11 @@ impl, U: Reflectable> OptionalSettable for Cell /// Root a rootable `Option` type (used for `Option>`) pub trait OptionalRootable { - fn root<'a, 'b>(self) -> Option>; + fn root(self) -> Option>; } impl OptionalRootable for Option> { - fn root<'a, 'b>(self) -> Option> { + fn root(self) -> Option> { self.map(|inner| inner.root()) } } @@ -389,22 +389,22 @@ impl<'a, T: Reflectable> OptionalUnrootable for Option> { /// Root a rootable `Option` type (used for `Option>`) pub trait OptionalRootedRootable { - fn root<'a, 'b>(&self) -> Option>; + fn root(&self) -> Option>; } impl OptionalRootedRootable for Option> { - fn root<'a, 'b>(&self) -> Option> { + fn root(&self) -> Option> { self.as_ref().map(|inner| inner.root()) } } /// Root a rootable `Option