Skip to content

Commit

Permalink
auto merge of #4787 : Ms2ger/servo/NonZero, r=jdm
Browse files Browse the repository at this point in the history
  • Loading branch information
bors-servo committed Jan 30, 2015
2 parents 06cedc8 + 5225442 commit 49dc60c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
18 changes: 11 additions & 7 deletions components/script/dom/bindings/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ use layout_interface::TrustedNodeAddress;
use script_task::STACK_ROOTS;

use util::smallvec::{SmallVec, SmallVec16};

use core::nonzero::NonZero;
use std::cell::{Cell, UnsafeCell};
use std::default::Default;
use std::marker::ContravariantLifetime;
Expand Down Expand Up @@ -124,7 +126,7 @@ impl<T: Reflectable> Temporary<T> {
/// A rooted, JS-owned value. Must only be used as a field in other JS-owned types.
#[must_root]
pub struct JS<T> {
ptr: *const T
ptr: NonZero<*const T>
}

impl<T> Copy for JS<T> {}
Expand All @@ -149,17 +151,19 @@ impl JS<Node> {
/// Create a new JS-owned value wrapped from an address known to be a `Node` pointer.
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<Node> {
let TrustedNodeAddress(addr) = inner;
assert!(!addr.is_null());
JS {
ptr: addr as *const Node
ptr: NonZero::new(addr as *const Node)
}
}
}

impl<T: Reflectable> JS<T> {
/// Create a new JS-owned value wrapped from a raw Rust pointer.
pub unsafe fn from_raw(raw: *const T) -> JS<T> {
assert!(!raw.is_null());
JS {
ptr: raw
ptr: NonZero::new(raw)
}
}

Expand Down Expand Up @@ -313,7 +317,7 @@ impl<T: Reflectable> JS<T> {
/// only method that be safely accessed from layout. (The fact that this is
/// unsafe is what necessitates the layout wrappers.)
pub unsafe fn unsafe_get(&self) -> *const T {
self.ptr
*self.ptr
}

/// Store an unrooted value in this field. This is safe under the assumption that JS<T>
Expand Down Expand Up @@ -577,14 +581,14 @@ impl<'a, T: Reflectable> Deref for JSRef<'a, T> {
type Target = T;
fn deref<'b>(&'b self) -> &'b T {
unsafe {
&*self.ptr
&**self.ptr
}
}
}

/// Encapsulates a reference to something that is guaranteed to be alive. This is freely copyable.
pub struct JSRef<'a, T> {
ptr: *const T,
ptr: NonZero<*const T>,
chain: ContravariantLifetime<'a>,
}

Expand Down Expand Up @@ -630,7 +634,7 @@ impl<'a, T: Reflectable> JSRef<'a, T> {
/// Returns the inner pointer directly.
pub fn extended_deref(self) -> &'a T {
unsafe {
&*self.ptr
&**self.ptr
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,5 @@ mod timers;
pub mod textinput;
mod devtools;

#[cfg(all(test, target_word_size = "64"))]
#[cfg(all(test, target_pointer_width = "64"))]
mod tests;
14 changes: 7 additions & 7 deletions components/script/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ macro_rules! sizeof_checker (

// Update the sizes here
sizeof_checker!(size_event_target, EventTarget, 48);
sizeof_checker!(size_node, Node, 288);
sizeof_checker!(size_element, Element, 432);
sizeof_checker!(size_htmlelement, HTMLElement, 464);
sizeof_checker!(size_div, HTMLDivElement, 464);
sizeof_checker!(size_span, HTMLSpanElement, 464);
sizeof_checker!(size_text, Text, 320);
sizeof_checker!(size_characterdata, CharacterData, 320);
sizeof_checker!(size_node, Node, 216);
sizeof_checker!(size_element, Element, 328);
sizeof_checker!(size_htmlelement, HTMLElement, 344);
sizeof_checker!(size_div, HTMLDivElement, 344);
sizeof_checker!(size_span, HTMLSpanElement, 344);
sizeof_checker!(size_text, Text, 248);
sizeof_checker!(size_characterdata, CharacterData, 248);

0 comments on commit 49dc60c

Please sign in to comment.