Skip to content
Permalink
Browse files

Remove most RootedReference uses

We can replace all uses of RootedReference for Option<T> by Option::deref calls.
  • Loading branch information...
nox committed Mar 10, 2019
1 parent 7bdfad9 commit 5fe5e5d6debef5adf234b650ee1b758e683a5230
Showing with 186 additions and 185 deletions.
  1. +3 −3 components/script/dom/attr.rs
  2. +3 −1 components/script/dom/bindings/codegen/CodegenRust.py
  3. +0 −15 components/script/dom/bindings/root.rs
  4. +2 −3 components/script/dom/bluetoothadvertisingevent.rs
  5. +2 −2 components/script/dom/compositionevent.rs
  6. +14 −15 components/script/dom/document.rs
  7. +12 −12 components/script/dom/element.rs
  8. +8 −3 components/script/dom/event.rs
  9. +3 −3 components/script/dom/focusevent.rs
  10. +2 −2 components/script/dom/htmlelement.rs
  11. +7 −8 components/script/dom/htmlformelement.rs
  12. +3 −3 components/script/dom/htmlheadelement.rs
  13. +20 −21 components/script/dom/htmlinputelement.rs
  14. +3 −3 components/script/dom/htmllinkelement.rs
  15. +4 −4 components/script/dom/htmlmetaelement.rs
  16. +3 −3 components/script/dom/htmloptionscollection.rs
  17. +5 −5 components/script/dom/htmlscriptelement.rs
  18. +5 −5 components/script/dom/htmltableelement.rs
  19. +2 −2 components/script/dom/htmltablerowelement.rs
  20. +3 −2 components/script/dom/htmltablesectionelement.rs
  21. +2 −2 components/script/dom/inputevent.rs
  22. +2 −2 components/script/dom/keyboardevent.rs
  23. +3 −3 components/script/dom/mouseevent.rs
  24. +42 −33 components/script/dom/node.rs
  25. +3 −3 components/script/dom/nodelist.rs
  26. +2 −2 components/script/dom/offlineaudiocompletionevent.rs
  27. +10 −8 components/script/dom/range.rs
  28. +2 −2 components/script/dom/servoparser/mod.rs
  29. +2 −2 components/script/dom/storageevent.rs
  30. +2 −2 components/script/dom/text.rs
  31. +2 −2 components/script/dom/uievent.rs
  32. +3 −3 components/script/dom/windowproxy.rs
  33. +1 −0 components/script/lib.rs
  34. +6 −6 components/script/script_thread.rs
@@ -6,7 +6,7 @@ use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::AttrBinding::{self, AttrMethods};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom, RootedReference};
use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::customelementregistry::CallbackReaction;
use crate::dom::element::{AttributeMutation, Element};
@@ -194,7 +194,7 @@ impl Attr {
ScriptThread::enqueue_callback_reaction(owner, reaction, None);
}

assert_eq!(Some(owner), self.owner().r());
assert_eq!(Some(owner), self.owner().deref());
owner.will_mutate_attr(self);
self.swap_value(&mut value);
if self.identifier.namespace == ns!() {
@@ -227,7 +227,7 @@ impl Attr {
match (self.owner(), owner) {
(Some(old), None) => {
// Already gone from the list of attributes of old owner.
assert!(old.get_attribute(&ns, &self.identifier.local_name).r() != Some(self))
assert!(old.get_attribute(&ns, &self.identifier.local_name).deref() != Some(self))
},
(Some(old), Some(new)) => assert_eq!(&*old, new),
_ => {},
@@ -7250,8 +7250,10 @@ def camel_to_upper_snake(s):

def process_arg(expr, arg):
if arg.type.isGeckoInterface() and not arg.type.unroll().inner.isCallback():
if arg.type.nullable() or arg.type.isSequence() or arg.optional:
if arg.variadic or arg.type.isSequence() or arg.type.nullable() and arg.optional:
expr += ".r()"
elif arg.type.nullable() or arg.optional:
expr += ".deref()"
else:
expr = "&" + expr
elif isinstance(arg.type, IDLPromiseType):
@@ -42,7 +42,6 @@ use std::marker::PhantomData;
use std::mem;
use std::ops::Deref;
use std::ptr;
use std::rc::Rc;
use style::thread_state;

/// A rooted value.
@@ -272,27 +271,13 @@ impl<'root, T: DomObject + 'root> RootedReference<'root> for DomRoot<T> {
}
}

impl<'root, T: DomObject + 'root> RootedReference<'root> for Dom<T> {
type Ref = &'root T;
fn r(&'root self) -> &'root T {
&self
}
}

impl<'root, T: JSTraceable + DomObject + 'root> RootedReference<'root> for [Dom<T>] {
type Ref = &'root [&'root T];
fn r(&'root self) -> &'root [&'root T] {
unsafe { mem::transmute(self) }
}
}

impl<'root, T: DomObject + 'root> RootedReference<'root> for Rc<T> {
type Ref = &'root T;
fn r(&'root self) -> &'root T {
self
}
}

impl<'root, T: RootedReference<'root> + 'root> RootedReference<'root> for Option<T> {
type Ref = Option<T::Ref>;
fn r(&'root self) -> Option<T::Ref> {
@@ -10,7 +10,7 @@ use crate::dom::bindings::codegen::Bindings::EventBinding::EventBinding::EventMe
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::{Dom, DomRoot, RootedReference};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::bluetoothdevice::BluetoothDevice;
use crate::dom::event::{Event, EventBubbles, EventCancelable};
@@ -80,7 +80,6 @@ impl BluetoothAdvertisingEvent {
init: &BluetoothAdvertisingEventInit,
) -> Fallible<DomRoot<BluetoothAdvertisingEvent>> {
let global = window.upcast::<GlobalScope>();
let device = init.device.r();
let name = init.name.clone();
let appearance = init.appearance.clone();
let txPower = init.txPower.clone();
@@ -92,7 +91,7 @@ impl BluetoothAdvertisingEvent {
Atom::from(type_),
bubbles,
cancelable,
device,
&init.device,
name,
appearance,
txPower,
@@ -8,7 +8,7 @@ use crate::dom::bindings::codegen::Bindings::CompositionEventBinding::{
use crate::dom::bindings::codegen::Bindings::UIEventBinding::UIEventBinding::UIEventMethods;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::{DomRoot, RootedReference};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::uievent::UIEvent;
use crate::dom::window::Window;
@@ -53,7 +53,7 @@ impl CompositionEvent {
type_,
init.parent.parent.bubbles,
init.parent.parent.cancelable,
init.parent.view.r(),
init.parent.view.deref(),
init.parent.detail,
init.data.clone(),
);
@@ -640,7 +640,7 @@ impl Document {
.upcast::<Element>()
.has_attribute(&local_name!("href"))
});
self.base_element.set(base.r());
self.base_element.set(base.deref());
}

pub fn dom_count(&self) -> u32 {
@@ -766,7 +766,7 @@ impl Document {
{
let mut id_map = self.id_map.borrow_mut();
let elements = id_map.entry(id.clone()).or_insert(Vec::new());
elements.insert_pre_order(element, root.r().upcast::<Node>());
elements.insert_pre_order(element, root.upcast::<Node>());
}
self.reset_form_owner_for_listeners(&id);
}
@@ -817,10 +817,10 @@ impl Document {
let target = self.find_fragment_node(fragment);

// Step 1
self.set_target_element(target.r());
self.set_target_element(target.deref());

let point = target
.r()
.as_ref()
.map(|element| {
// FIXME(#8275, pcwalton): This is pretty bogus when multiple layers are involved.
// Really what needs to happen is that this needs to go through layout to ask which
@@ -858,7 +858,7 @@ impl Document {
y,
global_scope.pipeline_id().root_scroll_id(),
ScrollBehavior::Instant,
target.r(),
target.deref(),
);
}
}
@@ -922,7 +922,7 @@ impl Document {
/// Reassign the focus context to the element that last requested focus during this
/// transaction, or none if no elements requested it.
pub fn commit_focus_transaction(&self, focus_type: FocusType) {
if self.focused == self.possibly_focused.get().r() {
if self.focused == self.possibly_focused.get().deref() {
return;
}
if let Some(ref elem) = self.focused.get() {
@@ -937,7 +937,7 @@ impl Document {
}
}

self.focused.set(self.possibly_focused.get().r());
self.focused.set(self.possibly_focused.get().deref());

if let Some(ref elem) = self.focused.get() {
elem.set_focus_state(true);
@@ -1265,7 +1265,7 @@ impl Document {
}

// Store the current mouse over target for next frame.
prev_mouse_over_target.set(maybe_new_target.r());
prev_mouse_over_target.set(maybe_new_target.deref());

self.window
.reflow(ReflowGoal::Full, ReflowReason::MouseEvent);
@@ -2859,7 +2859,7 @@ impl Document {

fn create_node_list<F: Fn(&Node) -> bool>(&self, callback: F) -> DomRoot<NodeList> {
let doc = self.GetDocumentElement();
let maybe_node = doc.r().map(Castable::upcast::<Node>);
let maybe_node = doc.deref().map(Castable::upcast::<Node>);
let iter = maybe_node
.iter()
.flat_map(|node| node.traverse_preorder())
@@ -3140,7 +3140,7 @@ impl Document {
// https://fullscreen.spec.whatwg.org/#dom-element-requestfullscreen
pub fn enter_fullscreen(&self, pending: &Element) -> Rc<Promise> {
// Step 1
let promise = Promise::new(self.global().r());
let promise = Promise::new(&self.global());
let mut error = false;

// Step 4
@@ -3211,7 +3211,7 @@ impl Document {
pub fn exit_fullscreen(&self) -> Rc<Promise> {
let global = self.global();
// Step 1
let promise = Promise::new(global.r());
let promise = Promise::new(&global);
// Step 2
if self.fullscreen_element.get().is_none() {
promise.reject_error(Error::Type(String::from("fullscreen is null")));
@@ -3228,7 +3228,7 @@ impl Document {
self.send_to_embedder(event);

// Step 9
let trusted_element = Trusted::new(element.r());
let trusted_element = Trusted::new(&*element);
let trusted_promise = TrustedPromise::new(promise.clone());
let handler = ElementPerformFullscreenExit::new(trusted_element, trusted_promise);
let pipeline_id = Some(global.pipeline_id());
@@ -3275,7 +3275,6 @@ impl Document {
if let Some(listeners) = map.get(id) {
for listener in listeners {
listener
.r()
.as_maybe_form_control()
.expect("Element must be a form control")
.reset_form_owner();
@@ -3841,7 +3840,7 @@ impl DocumentMethods for Document {
let parent = root.upcast::<Node>();
let child = elem.upcast::<Node>();
parent
.InsertBefore(child, parent.GetFirstChild().r())
.InsertBefore(child, parent.GetFirstChild().deref())
.unwrap()
},
}
@@ -3926,7 +3925,7 @@ impl DocumentMethods for Document {

// Step 2.
let old_body = self.GetBody();
if old_body.r() == Some(new_body) {
if old_body.deref() == Some(new_body) {
return Ok(());
}

@@ -23,7 +23,7 @@ use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom, RootedReference};
use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom};
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::bindings::xmlname::XMLName::InvalidXMLName;
use crate::dom::bindings::xmlname::{
@@ -1292,7 +1292,7 @@ impl Element {
ScriptThread::enqueue_callback_reaction(self, reaction, None);
}

assert!(attr.GetOwnerElement().r() == Some(self));
assert!(attr.GetOwnerElement().deref() == Some(self));
self.will_mutate_attr(attr);
self.attrs.borrow_mut().push(Dom::from_ref(attr));
if attr.namespace() == &ns!() {
@@ -1607,12 +1607,12 @@ impl Element {
}
},
AdjacentPosition::AfterBegin => {
Node::pre_insert(node, &self_node, self_node.GetFirstChild().r()).map(Some)
Node::pre_insert(node, &self_node, self_node.GetFirstChild().deref()).map(Some)
},
AdjacentPosition::BeforeEnd => Node::pre_insert(node, &self_node, None).map(Some),
AdjacentPosition::AfterEnd => {
if let Some(parent) = self_node.GetParentNode() {
Node::pre_insert(node, &parent, self_node.GetNextSibling().r()).map(Some)
Node::pre_insert(node, &parent, self_node.GetNextSibling().deref()).map(Some)
} else {
Ok(None)
}
@@ -1652,7 +1652,7 @@ impl Element {
}

// Step 9
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
if doc.GetBody().deref() == self.downcast::<HTMLElement>() &&
doc.quirks_mode() == QuirksMode::Quirks &&
!self.potentially_scrollable()
{
@@ -2121,7 +2121,7 @@ impl ElementMethods for Element {
}

// Step 7
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
if doc.GetBody().deref() == self.downcast::<HTMLElement>() &&
doc.quirks_mode() == QuirksMode::Quirks &&
!self.potentially_scrollable()
{
@@ -2171,7 +2171,7 @@ impl ElementMethods for Element {
}

// Step 9
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
if doc.GetBody().deref() == self.downcast::<HTMLElement>() &&
doc.quirks_mode() == QuirksMode::Quirks &&
!self.potentially_scrollable()
{
@@ -2217,7 +2217,7 @@ impl ElementMethods for Element {
}

// Step 7
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
if doc.GetBody().deref() == self.downcast::<HTMLElement>() &&
doc.quirks_mode() == QuirksMode::Quirks &&
!self.potentially_scrollable()
{
@@ -2268,7 +2268,7 @@ impl ElementMethods for Element {
}

// Step 9
if doc.GetBody().r() == self.downcast::<HTMLElement>() &&
if doc.GetBody().deref() == self.downcast::<HTMLElement>() &&
doc.quirks_mode() == QuirksMode::Quirks &&
!self.potentially_scrollable()
{
@@ -2737,7 +2737,7 @@ impl VirtualMethods for Element {

let doc = document_from_node(self);
let fullscreen = doc.GetFullscreenElement();
if fullscreen.r() == Some(self) {
if fullscreen.deref() == Some(self) {
doc.exit_fullscreen();
}
if let Some(ref value) = *self.id_attribute.borrow() {
@@ -3392,7 +3392,7 @@ impl TaskOnce for ElementPerformFullscreenEnter {
fn run_once(self) {
let element = self.element.root();
let promise = self.promise.root();
let document = document_from_node(element.r());
let document = document_from_node(&*element);

// Step 7.1
if self.error || !element.fullscreen_element_ready_check() {
@@ -3442,7 +3442,7 @@ impl TaskOnce for ElementPerformFullscreenExit {
#[allow(unrooted_must_root)]
fn run_once(self) {
let element = self.element.root();
let document = document_from_node(element.r());
let document = document_from_node(&*element);
// TODO Step 9.1-5
// Step 9.6
element.set_fullscreen_state(false);
@@ -477,7 +477,12 @@ fn dispatch_to_listeners(event: &Event, target: &EventTarget, event_path: &[&Eve

// Step 6.
for object in event_path.iter().rev() {
invoke(window.r(), object, event, Some(ListenerPhase::Capturing));
invoke(
window.deref(),
object,
event,
Some(ListenerPhase::Capturing),
);
if event.stop_propagation.get() {
return;
}
@@ -489,7 +494,7 @@ fn dispatch_to_listeners(event: &Event, target: &EventTarget, event_path: &[&Eve
event.phase.set(EventPhase::AtTarget);

// Step 8.
invoke(window.r(), target, event, None);
invoke(window.deref(), target, event, None);
if event.stop_propagation.get() {
return;
}
@@ -505,7 +510,7 @@ fn dispatch_to_listeners(event: &Event, target: &EventTarget, event_path: &[&Eve

// Step 9.2.
for object in event_path {
invoke(window.r(), object, event, Some(ListenerPhase::Bubbling));
invoke(window.deref(), object, event, Some(ListenerPhase::Bubbling));
if event.stop_propagation.get() {
return;
}
Oops, something went wrong.

0 comments on commit 5fe5e5d

Please sign in to comment.
You can’t perform that action at this time.