Skip to content

Commit

Permalink
Remove intrinsic Root::r()
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Oct 11, 2016
1 parent 51bcf51 commit 0b3ab87
Show file tree
Hide file tree
Showing 55 changed files with 275 additions and 310 deletions.
2 changes: 1 addition & 1 deletion components/script/devtools.rs
Expand Up @@ -146,7 +146,7 @@ pub fn handle_get_layout(context: &BrowsingContext,

let window = context.active_window();
let elem = node.downcast::<Element>().expect("should be getting layout of element");
let computed_style = window.r().GetComputedStyle(elem, None);
let computed_style = window.GetComputedStyle(elem, None);

reply.send(Some(ComputedNodeLayout {
display: String::from(computed_style.Display()),
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/activation.rs
Expand Up @@ -83,11 +83,11 @@ pub fn synthetic_click_activation(element: &Element,
// https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event
let win = window_from_node(element);
let target = element.upcast::<EventTarget>();
let mouse = MouseEvent::new(win.r(),
let mouse = MouseEvent::new(&win,
DOMString::from("click"),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
Some(win.r()),
Some(&win),
1,
0,
0,
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/attr.rs
Expand Up @@ -104,7 +104,7 @@ impl AttrMethods for Attr {
let value = owner.parse_attribute(&self.identifier.namespace,
self.local_name(),
value);
self.set_value(value, owner.r());
self.set_value(value, &owner);
} else {
*self.value.borrow_mut() = AttrValue::String(value.into());
}
Expand Down Expand Up @@ -200,12 +200,12 @@ impl Attr {
/// or removed from its older parent.
pub fn set_owner(&self, owner: Option<&Element>) {
let ns = &self.identifier.namespace;
match (self.owner().r(), owner) {
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))
}
(Some(old), Some(new)) => assert!(old == new),
(Some(old), Some(new)) => assert!(&*old == new),
_ => {},
}
self.owner.set(owner);
Expand Down
23 changes: 11 additions & 12 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -3256,12 +3256,7 @@ def getArgc(self):
return "argc"

def getArguments(self):
def process(arg, i):
argVal = "arg" + str(i)
if arg.type.isGeckoInterface() and not arg.type.unroll().inner.isCallback():
argVal += ".r()"
return argVal
return [(a, process(a, i)) for (i, a) in enumerate(self.arguments)]
return [(a, process_arg("arg" + str(i), a)) for (i, a) in enumerate(self.arguments)]

def isFallible(self):
return 'infallible' not in self.extendedAttributes
Expand Down Expand Up @@ -4651,12 +4646,7 @@ def __init__(self, descriptor, operation):
self.cgRoot.prepend(CGGeneric("rooted!(in(cx) let value = desc.value);"))

def getArguments(self):
def process(arg):
argVal = arg.identifier.name
if arg.type.isGeckoInterface() and not arg.type.unroll().inner.isCallback():
argVal += ".r()"
return argVal
args = [(a, process(a)) for a in self.arguments]
args = [(a, process_arg(a.identifier.name, a)) for a in self.arguments]
return args

def wrap_return_value(self):
Expand Down Expand Up @@ -6775,6 +6765,15 @@ def camel_to_upper_snake(s):
return "_".join(m.group(0).upper() for m in re.finditer("[A-Z][a-z]*", 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:
expr += ".r()"
else:
expr = "&" + expr
return expr


class GlobalGenRoots():
"""
Roots for global codegen.
Expand Down
8 changes: 1 addition & 7 deletions components/script/dom/bindings/js.rs
Expand Up @@ -473,7 +473,7 @@ impl<T: Reflectable> RootedReference<T> for Option<Rc<T>> {

impl<T: Reflectable> RootedReference<T> for Option<Root<T>> {
fn r(&self) -> Option<&T> {
self.as_ref().map(|root| root.r())
self.as_ref().map(|root| &**root)
}
}

Expand Down Expand Up @@ -615,12 +615,6 @@ impl<T: Reflectable> Root<T> {
pub fn from_ref(unrooted: &T) -> Root<T> {
Root::new(unsafe { NonZero::new(&*unrooted) })
}

/// Obtain a safe reference to the wrapped JS owned-value that cannot
/// outlive the lifetime of this root.
pub fn r(&self) -> &T {
&**self
}
}

impl<T: Reflectable> Deref for Root<T> {
Expand Down
19 changes: 8 additions & 11 deletions components/script/dom/canvasrenderingcontext2d.rs
Expand Up @@ -232,7 +232,7 @@ impl CanvasRenderingContext2D {
canvas.origin_is_clean()
}
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::CanvasRenderingContext2D(image) =>
image.r().origin_is_clean(),
image.origin_is_clean(),
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::HTMLImageElement(image) =>
match image.get_url() {
None => true,
Expand Down Expand Up @@ -280,23 +280,20 @@ impl CanvasRenderingContext2D {
-> ErrorResult {
let result = match image {
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::HTMLCanvasElement(ref canvas) => {
self.draw_html_canvas_element(canvas.r(),
self.draw_html_canvas_element(&canvas,
sx, sy, sw, sh,
dx, dy, dw, dh)
}
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::CanvasRenderingContext2D(ref image) => {
let context = image.r();
let canvas = context.Canvas();
self.draw_html_canvas_element(canvas.r(),
self.draw_html_canvas_element(&image.Canvas(),
sx, sy, sw, sh,
dx, dy, dw, dh)
}
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::HTMLImageElement(ref image) => {
let image_element = image.r();
// https://html.spec.whatwg.org/multipage/#img-error
// If the image argument is an HTMLImageElement object that is in the broken state,
// then throw an InvalidStateError exception
let (image_data, image_size) = match self.fetch_image_data(&image_element) {
let (image_data, image_size) = match self.fetch_image_data(image) {
Some((mut data, size)) => {
// Pixels come from cache in BGRA order and drawImage expects RGBA so we
// have to swap the color values
Expand Down Expand Up @@ -464,7 +461,7 @@ impl CanvasRenderingContext2D {
#[inline]
fn request_image_from_cache(&self, url: Url) -> ImageResponse {
let window = window_from_node(&*self.canvas);
canvas_utils::request_image_from_cache(window.r(), url)
canvas_utils::request_image_from_cache(&window, url)
}

fn create_drawable_rect(&self, x: f64, y: f64, w: f64, h: f64) -> Option<Rect<f32>> {
Expand Down Expand Up @@ -941,14 +938,14 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
},
StringOrCanvasGradientOrCanvasPattern::CanvasGradient(gradient) => {
self.state.borrow_mut().stroke_style =
CanvasFillOrStrokeStyle::Gradient(JS::from_ref(gradient.r()));
CanvasFillOrStrokeStyle::Gradient(JS::from_ref(&*gradient));
let msg = CanvasMsg::Canvas2d(
Canvas2dMsg::SetStrokeStyle(gradient.to_fill_or_stroke_style()));
self.ipc_renderer.send(msg).unwrap();
},
StringOrCanvasGradientOrCanvasPattern::CanvasPattern(pattern) => {
self.state.borrow_mut().stroke_style =
CanvasFillOrStrokeStyle::Pattern(JS::from_ref(pattern.r()));
CanvasFillOrStrokeStyle::Pattern(JS::from_ref(&*pattern));
let msg = CanvasMsg::Canvas2d(
Canvas2dMsg::SetStrokeStyle(pattern.to_fill_or_stroke_style()));
self.ipc_renderer.send(msg).unwrap();
Expand Down Expand Up @@ -1162,7 +1159,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
// https://html.spec.whatwg.org/multipage/#img-error
// If the image argument is an HTMLImageElement object that is in the broken state,
// then throw an InvalidStateError exception
try!(self.fetch_image_data(&image.r()).ok_or(Error::InvalidState))
try!(self.fetch_image_data(image).ok_or(Error::InvalidState))
},
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::HTMLCanvasElement(ref canvas) => {
let _ = canvas.get_or_init_2d_context();
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/comment.rs
Expand Up @@ -33,6 +33,6 @@ impl Comment {

pub fn Constructor(global: &GlobalScope, data: DOMString) -> Fallible<Root<Comment>> {
let document = global.as_window().Document();
Ok(Comment::new(data, document.r()))
Ok(Comment::new(data, &document))
}
}
2 changes: 1 addition & 1 deletion components/script/dom/dedicatedworkerglobalscope.rs
Expand Up @@ -207,7 +207,7 @@ impl DedicatedWorkerGlobalScope {
}

{
let _ar = AutoWorkerReset::new(global.r(), worker);
let _ar = AutoWorkerReset::new(&global, worker);
scope.execute_script(DOMString::from(source));
}

Expand Down
29 changes: 13 additions & 16 deletions components/script/dom/document.rs
Expand Up @@ -539,7 +539,7 @@ impl Document {
if &*(*elements)[head] == elem {
head += 1;
}
if new_node == node.r() || head == elements.len() {
if new_node == &*node || head == elements.len() {
break;
}
}
Expand Down Expand Up @@ -1043,7 +1043,7 @@ impl Document {
}

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

self.window.reflow(ReflowGoal::ForDisplay,
ReflowQueryType::NoQuery,
Expand Down Expand Up @@ -1104,7 +1104,7 @@ impl Document {

let touch = Touch::new(window,
identifier,
target.r(),
&target,
client_x,
client_y, // TODO: Get real screen coordinates?
client_x,
Expand Down Expand Up @@ -1163,7 +1163,7 @@ impl Document {
false,
false);
let event = event.upcast::<Event>();
let result = event.fire(target.r());
let result = event.fire(&target);

window.reflow(ReflowGoal::ForDisplay,
ReflowQueryType::NoQuery,
Expand Down Expand Up @@ -1308,13 +1308,13 @@ impl Document {
for node in nodes {
match node {
NodeOrString::Node(node) => {
try!(fragment.AppendChild(node.r()));
try!(fragment.AppendChild(&node));
},
NodeOrString::String(string) => {
let node = Root::upcast::<Node>(self.CreateTextNode(string));
// No try!() here because appending a text node
// should not fail.
fragment.AppendChild(node.r()).unwrap();
fragment.AppendChild(&node).unwrap();
}
}
}
Expand Down Expand Up @@ -1444,9 +1444,7 @@ impl Document {
let mut animation_frame_list =
mem::replace(&mut *self.animation_frame_list.borrow_mut(), vec![]);
self.running_animation_callbacks.set(true);
let performance = self.window.Performance();
let performance = performance.r();
let timing = performance.Now();
let timing = self.window.Performance().Now();

for (_, callback) in animation_frame_list.drain(..) {
if let Some(callback) = callback {
Expand Down Expand Up @@ -1506,8 +1504,8 @@ impl Document {
// A finished resource load can potentially unblock parsing. In that case, resume the
// parser so its loop can find out.
if let Some(parser) = self.get_current_parser() {
if parser.r().is_suspended() {
parser.r().resume();
if parser.is_suspended() {
parser.resume();
}
} else if self.reflow_timeout.get().is_none() {
// If we don't have a parser, and the reflow timer has been reset, explicitly
Expand Down Expand Up @@ -1859,7 +1857,6 @@ impl Document {
pub fn Constructor(global: &GlobalScope) -> Fallible<Root<Document>> {
let win = global.as_window();
let doc = win.Document();
let doc = doc.r();
let docloader = DocumentLoader::new(&*doc.loader());
Ok(Document::new(win,
None,
Expand Down Expand Up @@ -1898,7 +1895,7 @@ impl Document {
DocumentBinding::Wrap);
{
let node = document.upcast::<Node>();
node.set_owner_doc(document.r());
node.set_owner_doc(&document);
}
document
}
Expand All @@ -1908,7 +1905,7 @@ impl Document {
let maybe_node = doc.r().map(Castable::upcast::<Node>);
let iter = maybe_node.iter()
.flat_map(|node| node.traverse_preorder())
.filter(|node| callback(node.r()));
.filter(|node| callback(&node));
NodeList::new_simple_list(&self.window, iter)
}

Expand Down Expand Up @@ -2592,7 +2589,7 @@ impl DocumentMethods for Document {

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

Expand Down Expand Up @@ -2875,7 +2872,7 @@ impl DocumentMethods for Document {
{
// Step 1.
let mut elements = root.traverse_preorder()
.filter(|node| filter_by_name(&name, node.r()))
.filter(|node| filter_by_name(&name, &node))
.peekable();
if let Some(first) = elements.next() {
if elements.peek().is_none() {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/documentfragment.rs
Expand Up @@ -41,7 +41,7 @@ impl DocumentFragment {
pub fn Constructor(global: &GlobalScope) -> Fallible<Root<DocumentFragment>> {
let document = global.as_window().Document();

Ok(DocumentFragment::new(document.r()))
Ok(DocumentFragment::new(&document))
}
}

Expand Down
12 changes: 6 additions & 6 deletions components/script/dom/domimplementation.rs
Expand Up @@ -135,7 +135,7 @@ impl DOMImplementationMethods for DOMImplementation {
{
// Step 3.
let doc_node = doc.upcast::<Node>();
let doc_type = DocumentType::new(DOMString::from("html"), None, None, doc.r());
let doc_type = DocumentType::new(DOMString::from("html"), None, None, &doc);
doc_node.AppendChild(doc_type.upcast()).unwrap();
}

Expand All @@ -144,14 +144,14 @@ impl DOMImplementationMethods for DOMImplementation {
let doc_node = doc.upcast::<Node>();
let doc_html = Root::upcast::<Node>(HTMLHtmlElement::new(atom!("html"),
None,
doc.r()));
&doc));
doc_node.AppendChild(&doc_html).expect("Appending failed");

{
// Step 5.
let doc_head = Root::upcast::<Node>(HTMLHeadElement::new(atom!("head"),
None,
doc.r()));
&doc));
doc_html.AppendChild(&doc_head).unwrap();

// Step 6.
Expand All @@ -162,18 +162,18 @@ impl DOMImplementationMethods for DOMImplementation {
let doc_title =
Root::upcast::<Node>(HTMLTitleElement::new(atom!("title"),
None,
doc.r()));
&doc));
doc_head.AppendChild(&doc_title).unwrap();

// Step 6.2.
let title_text = Text::new(title_str, doc.r());
let title_text = Text::new(title_str, &doc);
doc_title.AppendChild(title_text.upcast()).unwrap();
}
}
}

// Step 7.
let doc_body = HTMLBodyElement::new(atom!("body"), None, doc.r());
let doc_body = HTMLBodyElement::new(atom!("body"), None, &doc);
doc_html.AppendChild(doc_body.upcast()).unwrap();
}

Expand Down

0 comments on commit 0b3ab87

Please sign in to comment.