diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/bindings/js.rs | 18 | ||||
-rw-r--r-- | components/script/lib.rs | 2 | ||||
-rw-r--r-- | components/script/tests.rs | 14 |
3 files changed, 19 insertions, 15 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 1eef7548bb7..3c9eba38911 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -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; @@ -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> {} @@ -149,8 +151,9 @@ 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) } } } @@ -158,8 +161,9 @@ impl JS<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) } } @@ -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> @@ -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>, } @@ -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 } } } diff --git a/components/script/lib.rs b/components/script/lib.rs index faa80504a55..5ffaa96b657 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -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; diff --git a/components/script/tests.rs b/components/script/tests.rs index 6b60f0ee534..a0f82628cd6 100644 --- a/components/script/tests.rs +++ b/components/script/tests.rs @@ -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); |