diff options
44 files changed, 137 insertions, 177 deletions
diff --git a/Cargo.lock b/Cargo.lock index 8918a3cc89e..1598b0b3a7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1455,7 +1455,6 @@ dependencies = [ "metrics 0.0.1", "msg 0.0.1", "net_traits 0.0.1", - "nonzero 0.0.1", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "profile_traits 0.0.1", "range 0.0.1", @@ -1617,7 +1616,7 @@ dependencies = [ "cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "hashglobe 0.1.0", - "mozjs 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "mozjs 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", "servo_arc 0.1.0", "smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1778,7 +1777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mozjs" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2434,10 +2433,9 @@ dependencies = [ "mime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mozjs 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "mozjs 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", - "nonzero 0.0.1", "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "offscreen_gl_context 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)", "open 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2496,7 +2494,6 @@ dependencies = [ "metrics 0.0.1", "msg 0.0.1", "net_traits 0.0.1", - "nonzero 0.0.1", "profile_traits 0.0.1", "range 0.0.1", "script_traits 0.0.1", @@ -3704,7 +3701,7 @@ dependencies = [ "checksum mio 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9e965267d4d58496fc4f740e9861118367f13570cadf66316ed2c3f2f14d87c7" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9de3eca27871df31c33b807f834b94ef7d000956f57aa25c5aed9c5f0aae8f6f" -"checksum mozjs 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2cd8370617e9a151ed9e7b49f38092075d0ae80bdf9f1dcd807a60cc9c3b7151" +"checksum mozjs 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "199f707066bf05b559ef6e46741c20e4f7bca8ae3a9c9d953d728dbb840f4eaa" "checksum mozjs_sys 0.50.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1e24df9f76502cd4459919098ec1ac3af75ce694ec5b8837aa91f69f2ad0eb" "checksum mp3-metadata 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ab5f1d2693586420208d1200ce5a51cd44726f055b635176188137aff42c7de" "checksum mp4parse 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f821e3799bc0fd16d9b861fb02fa7ee1b5fba29f45ad591dade105c48ca9a1a0" diff --git a/components/hashglobe/src/shim.rs b/components/hashglobe/src/shim.rs index 08fbf32b72f..146ff851a0e 100644 --- a/components/hashglobe/src/shim.rs +++ b/components/hashglobe/src/shim.rs @@ -1,5 +1,6 @@ use std::marker::PhantomData; +// FIXME: remove this and use std::ptr::NonNull when Firefox requires Rust 1.25+ pub struct NonZeroPtr<T: 'static>(&'static T); impl<T: 'static> NonZeroPtr<T> { @@ -57,4 +58,4 @@ impl<'a, T> From<&'a mut T> for Shared<T> { fn from(reference: &'a mut T) -> Self { unsafe { Shared::new_unchecked(reference) } } -}
\ No newline at end of file +} diff --git a/components/layout/model.rs b/components/layout/model.rs index d5b85a7424e..5d5238ece77 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -548,7 +548,7 @@ impl SizeConstraint { max_size = max_size.map(|x| max(x, min_size)); if let Some(border) = border { - min_size = max((min_size - border), Au(0)); + min_size = max(min_size - border, Au(0)); max_size = max_size.map(|x| max(x - border, Au(0))); } diff --git a/components/layout/query.rs b/components/layout/query.rs index 36e4a9b04d3..eac23f563ac 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -868,7 +868,7 @@ pub fn process_node_overflow_request<N: LayoutNode>(requested_node: N) -> NodeOv let style = &*layout_node.as_element().unwrap().resolved_style(); let style_box = style.get_box(); - NodeOverflowResponse(Some((Point2D::new(style_box.overflow_x, style_box.overflow_y)))) + NodeOverflowResponse(Some(Point2D::new(style_box.overflow_x, style_box.overflow_y))) } pub fn process_margin_style_query<N: LayoutNode>(requested_node: N) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 4eba8b88a4d..df93edb776d 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -67,7 +67,7 @@ pub trait GetRawData { impl<T: GetLayoutData> GetRawData for T { fn get_raw_data(&self) -> Option<&StyleAndLayoutData> { self.get_style_and_layout_data().map(|opaque| { - let container = opaque.ptr.get() as *mut StyleAndLayoutData; + let container = opaque.ptr.as_ptr() as *mut StyleAndLayoutData; unsafe { &*container } }) } diff --git a/components/layout_thread/Cargo.toml b/components/layout_thread/Cargo.toml index f4a2e5d9acb..661a7f849de 100644 --- a/components/layout_thread/Cargo.toml +++ b/components/layout_thread/Cargo.toml @@ -10,7 +10,7 @@ name = "layout_thread" path = "lib.rs" [features] -unstable = ["parking_lot/nightly", "nonzero/unstable"] +unstable = ["parking_lot/nightly"] [dependencies] app_units = "0.6" @@ -30,7 +30,6 @@ malloc_size_of = { path = "../malloc_size_of" } metrics = {path = "../metrics"} msg = {path = "../msg"} net_traits = {path = "../net_traits"} -nonzero = {path = "../nonzero"} parking_lot = "0.4" profile_traits = {path = "../profile_traits"} range = {path = "../range"} diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 1b58f9f81b5..6eef1106c3d 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -36,7 +36,6 @@ use html5ever::{LocalName, Namespace}; use layout::data::StyleAndLayoutData; use layout::wrapper::GetRawData; use msg::constellation_msg::{BrowsingContextId, PipelineId}; -use nonzero::NonZero; use range::Range; use script::layout_exports::{CharacterDataTypeId, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use script::layout_exports::{Document, Element, Node, Text}; @@ -59,6 +58,7 @@ use std::fmt; use std::fmt::Debug; use std::hash::{Hash, Hasher}; use std::marker::PhantomData; +use std::ptr::NonNull; use std::sync::atomic::Ordering; use style::CaseSensitivityExt; use style::applicable_declarations::ApplicableDeclarationBlock; @@ -76,7 +76,7 @@ use style::shared_lock::{SharedRwLock as StyleSharedRwLock, Locked as StyleLocke use style::str::is_whitespace; pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) { - let ptr = data.ptr.get() as *mut StyleData; + let ptr = data.ptr.as_ptr() as *mut StyleData; let non_opaque: *mut StyleAndLayoutData = ptr as *mut _; let _ = Box::from_raw(non_opaque); } @@ -229,7 +229,7 @@ impl<'ln> LayoutNode for ServoLayoutNode<'ln> { let ptr: *mut StyleAndLayoutData = Box::into_raw(Box::new(StyleAndLayoutData::new())); let opaque = OpaqueStyleAndLayoutData { - ptr: NonZero::new_unchecked(ptr as *mut StyleData), + ptr: NonNull::new_unchecked(ptr as *mut StyleData), }; self.init_style_and_layout_data(opaque); }; @@ -450,7 +450,7 @@ impl<'le> TElement for ServoLayoutElement<'le> { fn get_data(&self) -> Option<&AtomicRefCell<ElementData>> { unsafe { self.get_style_and_layout_data().map(|d| { - &(*(d.ptr.get() as *mut StyleData)).element_data + &(*(d.ptr.as_ptr() as *mut StyleData)).element_data }) } } @@ -575,7 +575,7 @@ impl<'le> ServoLayoutElement<'le> { fn get_style_data(&self) -> Option<&StyleData> { unsafe { - self.get_style_and_layout_data().map(|d| &*(d.ptr.get() as *mut StyleData)) + self.get_style_and_layout_data().map(|d| &*(d.ptr.as_ptr() as *mut StyleData)) } } diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index bca5da278b8..3fb7d0c8c73 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -28,7 +28,6 @@ extern crate malloc_size_of; extern crate metrics; extern crate msg; extern crate net_traits; -extern crate nonzero; extern crate parking_lot; #[macro_use] extern crate profile_traits; diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index a78053f76cd..4aae00f551b 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -65,7 +65,6 @@ mime_guess = "1.8.0" mozjs = { version = "0.1.10", features = ["promises"]} msg = {path = "../msg"} net_traits = {path = "../net_traits"} -nonzero = {path = "../nonzero"} num-traits = "0.1.32" offscreen_gl_context = { version = "0.14", features = ["serde"] } open = "1.1.1" diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 4a377aa351f..92f6b3a71b6 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -1422,7 +1422,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider): if returnType.isAny(): return CGGeneric("JSVal") if returnType.isObject() or returnType.isSpiderMonkeyInterface(): - result = CGGeneric("NonNullJSObjectPtr") + result = CGGeneric("NonNull<JSObject>") if returnType.nullable(): result = CGWrapper(result, pre="Option<", post=">") return result @@ -2268,7 +2268,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config): 'dom::bindings::conversions::StringificationBehavior', 'dom::bindings::conversions::root_from_handlevalue', 'dom::bindings::error::throw_not_in_union', - 'dom::bindings::nonnull::NonNullJSObjectPtr', + 'std::ptr::NonNull', 'dom::bindings::mozmap::MozMap', 'dom::bindings::root::DomRoot', 'dom::bindings::str::ByteString', @@ -5811,7 +5811,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'dom::bindings::proxyhandler::get_expando_object', 'dom::bindings::proxyhandler::get_property_descriptor', 'dom::bindings::mozmap::MozMap', - 'dom::bindings::nonnull::NonNullJSObjectPtr', + 'std::ptr::NonNull', 'dom::bindings::num::Finite', 'dom::bindings::str::ByteString', 'dom::bindings::str::DOMString', diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 68318c53d70..e40a1d7092b 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -34,7 +34,6 @@ use dom::bindings::error::{Error, Fallible}; use dom::bindings::inheritance::Castable; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::num::Finite; use dom::bindings::reflector::{DomObject, Reflector}; use dom::bindings::root::DomRoot; @@ -54,7 +53,7 @@ use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetProperty, JS_GetReserved use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_IsArrayObject, JS_IsExceptionPending}; use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars, MutableHandleValue}; use js::jsval::{ObjectValue, StringValue, UndefinedValue}; -use js::rust::{ToString, get_object_class, is_dom_class, is_dom_object, maybe_wrap_value, maybe_wrap_object_value}; +use js::rust::{ToString, get_object_class, is_dom_class, is_dom_object, maybe_wrap_value}; use libc; use num_traits::Float; use servo_config::opts; @@ -71,15 +70,6 @@ pub trait IDLInterface { rustc_on_unimplemented = "The IDL interface `{Self}` is not derived from `{T}`.")] pub trait DerivedFrom<T: Castable>: Castable {} -// https://heycam.github.io/webidl/#es-object -impl ToJSValConvertible for NonNullJSObjectPtr { - #[inline] - unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { - rval.set(ObjectValue(self.get())); - maybe_wrap_object_value(cx, rval); - } -} - impl<T: Float + ToJSValConvertible> ToJSValConvertible for Finite<T> { #[inline] unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { diff --git a/components/script/dom/bindings/iterable.rs b/components/script/dom/bindings/iterable.rs index 36cef24d4bd..15fbe7175cb 100644 --- a/components/script/dom/bindings/iterable.rs +++ b/components/script/dom/bindings/iterable.rs @@ -9,7 +9,6 @@ use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyAndValueResult; use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyOrValueResult; use dom::bindings::error::Fallible; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::trace::JSTraceable; @@ -20,6 +19,7 @@ use js::jsapi::{HandleValue, Heap, JSContext, MutableHandleObject, JSObject}; use js::jsval::UndefinedValue; use std::cell::Cell; use std::ptr; +use std::ptr::NonNull; /// The values that an iterator will iterate over. #[derive(JSTraceable, MallocSizeOf)] @@ -73,7 +73,7 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> { /// Return the next value from the iterable object. #[allow(non_snake_case)] - pub fn Next(&self, cx: *mut JSContext) -> Fallible<NonNullJSObjectPtr> { + pub fn Next(&self, cx: *mut JSContext) -> Fallible<NonNull<JSObject>> { let index = self.index.get(); rooted!(in(cx) let mut value = UndefinedValue()); rooted!(in(cx) let mut rval = ptr::null_mut::<JSObject>()); @@ -105,8 +105,7 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> { }; self.index.set(index + 1); result.map(|_| { - assert!(!rval.is_null()); - unsafe { NonNullJSObjectPtr::new_unchecked(rval.get()) } + NonNull::new(rval.get()).expect("got a null pointer") }) } } diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs index 6fdf690588f..8ba3ea72332 100644 --- a/components/script/dom/bindings/mod.rs +++ b/components/script/dom/bindings/mod.rs @@ -145,7 +145,6 @@ pub mod interface; pub mod iterable; pub mod mozmap; pub mod namespace; -pub mod nonnull; pub mod num; pub mod proxyhandler; pub mod refcounted; diff --git a/components/script/dom/bindings/nonnull.rs b/components/script/dom/bindings/nonnull.rs deleted file mode 100644 index 36dade7136b..00000000000 --- a/components/script/dom/bindings/nonnull.rs +++ /dev/null @@ -1,24 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -//! A wrapper type for `NonZero<*mut JSObject>`, to enable local trait impls - -use js::jsapi::JSObject; -use nonzero::NonZero; - -/// A wrapper type for `NonZero<*mut JSObject>`, to enable local trait impls -#[derive(Clone, Copy)] -pub struct NonNullJSObjectPtr(NonZero<*mut JSObject>); - -impl NonNullJSObjectPtr { - #[inline] - pub unsafe fn new_unchecked(ptr: *mut JSObject) -> Self { - NonNullJSObjectPtr(NonZero::new_unchecked(ptr)) - } - - #[inline] - pub fn get(self) -> *mut JSObject { - self.0.get() - } -} diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs index 636c14b4d5c..18cb0062023 100644 --- a/components/script/dom/bindings/root.rs +++ b/components/script/dom/bindings/root.rs @@ -34,7 +34,6 @@ use js::jsapi::{JSObject, JSTracer, Heap}; use js::rust::GCMethods; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use mitochondria::OnceCell; -use nonzero::NonZero; use script_layout_interface::TrustedNodeAddress; use std::cell::{Cell, UnsafeCell}; use std::default::Default; @@ -312,7 +311,7 @@ impl<'root, T: RootedReference<'root> + 'root> RootedReference<'root> for Option /// This should only be used as a field in other DOM objects. #[must_root] pub struct Dom<T> { - ptr: NonZero<*const T>, + ptr: ptr::NonNull<T>, } // Dom<T> is similar to Rc<T>, in that it's not always clear how to avoid double-counting. @@ -339,7 +338,7 @@ impl<T: DomObject> Dom<T> { pub fn from_ref(obj: &T) -> Dom<T> { debug_assert!(thread_state::get().is_script()); Dom { - ptr: unsafe { NonZero::new_unchecked(&*obj) }, + ptr: ptr::NonNull::from(obj), } } } @@ -351,7 +350,7 @@ impl<T: DomObject> Deref for Dom<T> { debug_assert!(thread_state::get().is_script()); // We can only have &Dom<T> from a rooted thing, so it's safe to deref // it to &T. - unsafe { &*self.ptr.get() } + unsafe { &*self.ptr.as_ptr() } } } @@ -366,7 +365,7 @@ unsafe impl<T: DomObject> JSTraceable for Dom<T> { trace_reflector(trc, trace_info, - (*self.ptr.get()).reflector()); + (*self.ptr.as_ptr()).reflector()); } } @@ -374,7 +373,7 @@ unsafe impl<T: DomObject> JSTraceable for Dom<T> { /// traits must be implemented on this. #[allow_unrooted_interior] pub struct LayoutDom<T> { - ptr: NonZero<*const T>, + ptr: ptr::NonNull<T>, } impl<T: Castable> LayoutDom<T> { @@ -384,9 +383,9 @@ impl<T: Castable> LayoutDom<T> { T: DerivedFrom<U> { debug_assert!(thread_state::get().is_layout()); - let ptr: *const T = self.ptr.get(); + let ptr: *mut T = self.ptr.as_ptr(); LayoutDom { - ptr: unsafe { NonZero::new_unchecked(ptr as *const U) }, + ptr: unsafe { ptr::NonNull::new_unchecked(ptr as *mut U) }, } } @@ -397,9 +396,9 @@ impl<T: Castable> LayoutDom<T> { debug_assert!(thread_state::get().is_layout()); unsafe { if (*self.unsafe_get()).is::<U>() { - let ptr: *const T = self.ptr.get(); + let ptr: *mut T = self.ptr.as_ptr(); Some(LayoutDom { - ptr: NonZero::new_unchecked(ptr as *const U), + ptr: ptr::NonNull::new_unchecked(ptr as *mut U), }) } else { None @@ -412,7 +411,7 @@ impl<T: DomObject> LayoutDom<T> { /// Get the reflector. pub unsafe fn get_jsobject(&self) -> *mut JSObject { debug_assert!(thread_state::get().is_layout()); - (*self.ptr.get()).reflector().get_jsobject().get() + (*self.ptr.as_ptr()).reflector().get_jsobject().get() } } @@ -420,7 +419,7 @@ impl<T> Copy for LayoutDom<T> {} impl<T> PartialEq for Dom<T> { fn eq(&self, other: &Dom<T>) -> bool { - self.ptr == other.ptr + self.ptr.as_ptr() == other.ptr.as_ptr() } } @@ -428,7 +427,7 @@ impl<T> Eq for Dom<T> {} impl<T> PartialEq for LayoutDom<T> { fn eq(&self, other: &LayoutDom<T>) -> bool { - self.ptr == other.ptr + self.ptr.as_ptr() == other.ptr.as_ptr() } } @@ -436,13 +435,13 @@ impl<T> Eq for LayoutDom<T> {} impl<T> Hash for Dom<T> { fn hash<H: Hasher>(&self, state: &mut H) { - self.ptr.hash(state) + self.ptr.as_ptr().hash(state) } } impl<T> Hash for LayoutDom<T> { fn hash<H: Hasher>(&self, state: &mut H) { - self.ptr.hash(state) + self.ptr.as_ptr().hash(state) } } @@ -474,7 +473,7 @@ impl LayoutDom<Node> { debug_assert!(thread_state::get().is_layout()); let TrustedNodeAddress(addr) = inner; LayoutDom { - ptr: NonZero::new_unchecked(addr as *const Node), + ptr: ptr::NonNull::new_unchecked(addr as *const Node as *mut Node), } } } @@ -700,7 +699,7 @@ impl<T: DomObject> LayoutDom<T> { /// this is unsafe is what necessitates the layout wrappers.) pub unsafe fn unsafe_get(&self) -> *const T { debug_assert!(thread_state::get().is_layout()); - self.ptr.get() + self.ptr.as_ptr() } /// Returns a reference to the interior of this JS object. This method is @@ -708,7 +707,7 @@ impl<T: DomObject> LayoutDom<T> { /// mutate DOM nodes. pub fn get_for_script(&self) -> &T { debug_assert!(thread_state::get().is_script()); - unsafe { &*self.ptr.get() } + unsafe { &*self.ptr.as_ptr() } } } diff --git a/components/script/dom/bindings/weakref.rs b/components/script/dom/bindings/weakref.rs index 2aa12490867..e4e5f00103f 100644 --- a/components/script/dom/bindings/weakref.rs +++ b/components/script/dom/bindings/weakref.rs @@ -18,10 +18,10 @@ use js::jsapi::{JSTracer, JS_GetReservedSlot, JS_SetReservedSlot}; use js::jsval::PrivateValue; use libc::c_void; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; -use nonzero::NonZero; use std::cell::{Cell, UnsafeCell}; use std::mem; use std::ops::{Deref, DerefMut, Drop}; +use std::ptr; /// The index of the slot wherein a pointer to the weak holder cell is /// stored for weak-referenceable bindings. We use slot 1 for holding it, @@ -30,9 +30,10 @@ use std::ops::{Deref, DerefMut, Drop}; pub const DOM_WEAK_SLOT: u32 = 1; /// A weak reference to a JS-managed DOM object. +#[allow(unrooted_must_root)] #[allow_unrooted_interior] pub struct WeakRef<T: WeakReferenceable> { - ptr: NonZero<*mut WeakBox<T>>, + ptr: ptr::NonNull<WeakBox<T>>, } /// The inner box of weak references, public for the finalization in codegen. @@ -42,7 +43,7 @@ pub struct WeakBox<T: WeakReferenceable> { /// have already been set to `None`. The pointee contributes one to the count. pub count: Cell<usize>, /// The pointer to the JS-managed object, set to None when it is collected. - pub value: Cell<Option<NonZero<*const T>>>, + pub value: Cell<Option<ptr::NonNull<T>>>, } /// Trait implemented by weak-referenceable interfaces. @@ -58,7 +59,7 @@ pub trait WeakReferenceable: DomObject + Sized { trace!("Creating new WeakBox holder for {:p}.", self); ptr = Box::into_raw(Box::new(WeakBox { count: Cell::new(1), - value: Cell::new(Some(NonZero::new_unchecked(self))), + value: Cell::new(Some(ptr::NonNull::from(self))), })); JS_SetReservedSlot(object, DOM_WEAK_SLOT, PrivateValue(ptr as *const c_void)); } @@ -70,7 +71,7 @@ pub trait WeakReferenceable: DomObject + Sized { new_count); box_.count.set(new_count); WeakRef { - ptr: NonZero::new_unchecked(ptr), + ptr: ptr::NonNull::new_unchecked(ptr), } } } @@ -86,21 +87,21 @@ impl<T: WeakReferenceable> WeakRef<T> { /// DomRoot a weak reference. Returns `None` if the object was already collected. pub fn root(&self) -> Option<DomRoot<T>> { - unsafe { &*self.ptr.get() }.value.get().map(|ptr| unsafe { - DomRoot::from_ref(&*ptr.get()) + unsafe { &*self.ptr.as_ptr() }.value.get().map(|ptr| unsafe { + DomRoot::from_ref(&*ptr.as_ptr()) }) } /// Return whether the weakly-referenced object is still alive. pub fn is_alive(&self) -> bool { - unsafe { &*self.ptr.get() }.value.get().is_some() + unsafe { &*self.ptr.as_ptr() }.value.get().is_some() } } impl<T: WeakReferenceable> Clone for WeakRef<T> { fn clone(&self) -> WeakRef<T> { unsafe { - let box_ = &*self.ptr.get(); + let box_ = &*self.ptr.as_ptr(); let new_count = box_.count.get() + 1; box_.count.set(new_count); WeakRef { @@ -119,7 +120,8 @@ impl<T: WeakReferenceable> MallocSizeOf for WeakRef<T> { impl<T: WeakReferenceable> PartialEq for WeakRef<T> { fn eq(&self, other: &Self) -> bool { unsafe { - (*self.ptr.get()).value.get() == (*other.ptr.get()).value.get() + (*self.ptr.as_ptr()).value.get().map(ptr::NonNull::as_ptr) == + (*other.ptr.as_ptr()).value.get().map(ptr::NonNull::as_ptr) } } } @@ -127,8 +129,8 @@ impl<T: WeakReferenceable> PartialEq for WeakRef<T> { impl<T: WeakReferenceable> PartialEq<T> for WeakRef<T> { fn eq(&self, other: &T) -> bool { unsafe { - match (*self.ptr.get()).value.get() { - Some(ptr) => ptr.get() == other, + match self.ptr.as_ref().value.get() { + Some(ptr) => ptr::eq(ptr.as_ptr(), other), None => false, } } @@ -145,7 +147,7 @@ impl<T: WeakReferenceable> Drop for WeakRef<T> { fn drop(&mut self) { unsafe { let (count, value) = { - let weak_box = &*self.ptr.get(); + let weak_box = &*self.ptr.as_ptr(); assert!(weak_box.count.get() > 0); let count = weak_box.count.get() - 1; weak_box.count.set(count); @@ -153,7 +155,7 @@ impl<T: WeakReferenceable> Drop for WeakRef<T> { }; if count == 0 { assert!(value.is_none()); - mem::drop(Box::from_raw(self.ptr.get())); + mem::drop(Box::from_raw(self.ptr.as_ptr())); } } } diff --git a/components/script/dom/crypto.rs b/components/script/dom/crypto.rs index 1a13194151c..71e67e46b9a 100644 --- a/components/script/dom/crypto.rs +++ b/components/script/dom/crypto.rs @@ -6,7 +6,6 @@ use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::CryptoBinding; use dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods; use dom::bindings::error::{Error, Fallible}; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::root::DomRoot; use dom::globalscope::GlobalScope; @@ -14,6 +13,7 @@ use dom_struct::dom_struct; use js::jsapi::{JSContext, JSObject}; use js::jsapi::Type; use servo_rand::{ServoRng, Rng}; +use std::ptr::NonNull; unsafe_no_jsmanaged_fields!(ServoRng); @@ -44,7 +44,7 @@ impl CryptoMethods for Crypto { unsafe fn GetRandomValues(&self, _cx: *mut JSContext, input: *mut JSObject) - -> Fallible<NonNullJSObjectPtr> { + -> Fallible<NonNull<JSObject>> { assert!(!input.is_null()); typedarray!(in(_cx) let mut array_buffer_view: ArrayBufferView = input); let (array_type, mut data) = match array_buffer_view.as_mut() { @@ -65,7 +65,7 @@ impl CryptoMethods for Crypto { self.rng.borrow_mut().fill_bytes(&mut data); - Ok(NonNullJSObjectPtr::new_unchecked(input)) + Ok(NonNull::new_unchecked(input)) } } diff --git a/components/script/dom/cssrulelist.rs b/components/script/dom/cssrulelist.rs index 1f800a6a0b4..baa685d5a72 100644 --- a/components/script/dom/cssrulelist.rs +++ b/components/script/dom/cssrulelist.rs @@ -103,7 +103,7 @@ impl CSSRuleList { let parent_stylesheet = &*self.parent_stylesheet; let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule); self.dom_rules.borrow_mut().insert(index, MutNullableDom::new(Some(&*dom_rule))); - Ok((idx)) + Ok(idx) } // In case of a keyframe rule, index must be valid. diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index aecc0b0d0e7..a833ac75f58 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -21,7 +21,6 @@ use dom::bindings::codegen::Bindings::WindowBinding::{FrameRequestCallback, Scro use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId}; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::num::Finite; use dom::bindings::refcounted::{Trusted, TrustedPromise}; use dom::bindings::reflector::{DomObject, reflect_dom_object}; @@ -96,7 +95,7 @@ use html5ever::{LocalName, Namespace, QualName}; use hyper::header::{Header, SetCookie}; use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; -use js::jsapi::{JSContext, JSRuntime}; +use js::jsapi::{JSContext, JSObject, JSRuntime}; use js::jsapi::JS_GetRuntime; use metrics::{InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory, ProgressiveWebMetric}; use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId}; @@ -125,6 +124,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::default::Default; use std::iter::once; use std::mem; +use std::ptr::NonNull; use std::rc::Rc; use std::time::{Duration, Instant}; use style::attr::AttrValue; @@ -3554,7 +3554,7 @@ impl DocumentMethods for Document { #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter - unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonNullJSObjectPtr> { + unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonNull<JSObject>> { #[derive(JSTraceable, MallocSizeOf)] struct NamedElementFilter { name: Atom, @@ -3611,7 +3611,7 @@ impl DocumentMethods for Document { if elements.peek().is_none() { // TODO: Step 2. // Step 3. - return Some(NonNullJSObjectPtr::new_unchecked(first.reflector().get_jsobject().get())); + return Some(NonNull::new_unchecked(first.reflector().get_jsobject().get())); } } else { return None; @@ -3622,7 +3622,7 @@ impl DocumentMethods for Document { name: name, }; let collection = HTMLCollection::create(self.window(), root, Box::new(filter)); - Some(NonNullJSObjectPtr::new_unchecked(collection.reflector().get_jsobject().get())) + Some(NonNull::new_unchecked(collection.reflector().get_jsobject().get())) } // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names diff --git a/components/script/dom/gamepad.rs b/components/script/dom/gamepad.rs index e5381d5587b..769b1ee548f 100644 --- a/components/script/dom/gamepad.rs +++ b/components/script/dom/gamepad.rs @@ -5,7 +5,6 @@ use dom::bindings::codegen::Bindings::GamepadBinding; use dom::bindings::codegen::Bindings::GamepadBinding::GamepadMethods; use dom::bindings::inheritance::Castable; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::num::Finite; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot}; @@ -21,6 +20,7 @@ use js::jsapi::{Heap, JSContext, JSObject}; use js::typedarray::{Float64Array, CreateWith}; use std::cell::Cell; use std::ptr; +use std::ptr::NonNull; use webvr_traits::{WebVRGamepadData, WebVRGamepadHand, WebVRGamepadState}; #[dom_struct] @@ -131,8 +131,8 @@ impl GamepadMethods for Gamepad { #[allow(unsafe_code)] // https://w3c.github.io/gamepad/#dom-gamepad-axes - unsafe fn Axes(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { - NonNullJSObjectPtr::new_unchecked(self.axes.get()) + unsafe fn Axes(&self, _cx: *mut JSContext) -> NonNull<JSObject> { + NonNull::new_unchecked(self.axes.get()) } // https://w3c.github.io/gamepad/#dom-gamepad-buttons diff --git a/components/script/dom/imagedata.rs b/components/script/dom/imagedata.rs index 6be4e5d89c2..9e80d86d089 100644 --- a/components/script/dom/imagedata.rs +++ b/components/script/dom/imagedata.rs @@ -5,7 +5,6 @@ use dom::bindings::codegen::Bindings::ImageDataBinding; use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods; use dom::bindings::error::{Fallible, Error}; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::root::DomRoot; use dom::globalscope::GlobalScope; @@ -16,6 +15,7 @@ use js::rust::Runtime; use js::typedarray::{Uint8ClampedArray, CreateWith}; use std::default::Default; use std::ptr; +use std::ptr::NonNull; use std::vec::Vec; #[dom_struct] @@ -159,8 +159,7 @@ impl ImageDataMethods for ImageData { #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-imagedata-data - unsafe fn Data(&self, _: *mut JSContext) -> NonNullJSObjectPtr { - assert!(!self.data.get().is_null()); - NonNullJSObjectPtr::new_unchecked(self.data.get()) + unsafe fn Data(&self, _: *mut JSContext) -> NonNull<JSObject> { + NonNull::new(self.data.get()).expect("got a null pointer") } } diff --git a/components/script/dom/performanceobserver.rs b/components/script/dom/performanceobserver.rs index 96ad99edf92..af43fe76246 100644 --- a/components/script/dom/performanceobserver.rs +++ b/components/script/dom/performanceobserver.rs @@ -106,7 +106,7 @@ impl PerformanceObserverMethods for PerformanceObserver { // step 2 // There must be at least one valid entry type. if entry_types.is_empty() { - return Err((Error::Type("entryTypes cannot be empty".to_string()))); + return Err(Error::Type("entryTypes cannot be empty".to_string())); } // step 3-4-5 diff --git a/components/script/dom/screen.rs b/components/script/dom/screen.rs index bec082e9729..3cd54034994 100644 --- a/components/script/dom/screen.rs +++ b/components/script/dom/screen.rs @@ -39,14 +39,14 @@ impl Screen { let (send, recv) = ipc::channel::<(Size2D<u32>)>().unwrap(); self.window.upcast::<GlobalScope>() .script_to_constellation_chan().send(ScriptMsg::GetScreenSize(send)).unwrap(); - recv.recv().unwrap_or((Size2D::zero())) + recv.recv().unwrap_or(Size2D::zero()) } fn screen_avail_size(&self) -> Size2D<u32> { let (send, recv) = ipc::channel::<(Size2D<u32>)>().unwrap(); self.window.upcast::<GlobalScope>() .script_to_constellation_chan().send(ScriptMsg::GetScreenAvailSize(send)).unwrap(); - recv.recv().unwrap_or((Size2D::zero())) + recv.recv().unwrap_or(Size2D::zero()) } } diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 6ffe2efefdd..2dd77427590 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -21,7 +21,6 @@ use dom::bindings::codegen::UnionTypes::{StringOrLongSequence, StringOrStringSeq use dom::bindings::codegen::UnionTypes::{StringOrUnsignedLong, StringOrBoolean, UnsignedLongOrBoolean}; use dom::bindings::error::{Error, Fallible}; use dom::bindings::mozmap::MozMap; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::num::Finite; use dom::bindings::refcounted::TrustedPromise; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; @@ -43,6 +42,7 @@ use script_traits::MsDuration; use servo_config::prefs::PREFS; use std::borrow::ToOwned; use std::ptr; +use std::ptr::NonNull; use std::rc::Rc; use timers::OneshotTimerCallback; @@ -152,20 +152,18 @@ impl TestBindingMethods for TestBinding { } fn SetUnion9Attribute(&self, _: ByteStringOrLong) {} #[allow(unsafe_code)] - unsafe fn ArrayAttribute(&self, cx: *mut JSContext) -> NonNullJSObjectPtr { + unsafe fn ArrayAttribute(&self, cx: *mut JSContext) -> NonNull<JSObject> { rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16)); - assert!(!array.is_null()); - NonNullJSObjectPtr::new_unchecked(array.get()) + NonNull::new(array.get()).expect("got a null pointer") } #[allow(unsafe_code)] unsafe fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() } #[allow(unsafe_code)] unsafe fn SetAnyAttribute(&self, _: *mut JSContext, _: HandleValue) {} #[allow(unsafe_code)] - unsafe fn ObjectAttribute(&self, cx: *mut JSContext) -> NonNullJSObjectPtr { + unsafe fn ObjectAttribute(&self, cx: *mut JSContext) -> NonNull<JSObject> { rooted!(in(cx) let obj = JS_NewPlainObject(cx)); - assert!(!obj.is_null()); - NonNullJSObjectPtr::new_unchecked(obj.get()) + NonNull::new(obj.get()).expect("got a null pointer") } #[allow(unsafe_code)] unsafe fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {} @@ -221,7 +219,7 @@ impl TestBindingMethods for TestBinding { self.url.set(url); } #[allow(unsafe_code)] - unsafe fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> Option<NonNullJSObjectPtr> { None } + unsafe fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> Option<NonNull<JSObject>> { None } #[allow(unsafe_code)] unsafe fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {} fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> { @@ -273,7 +271,7 @@ impl TestBindingMethods for TestBinding { #[allow(unsafe_code)] unsafe fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() } #[allow(unsafe_code)] - unsafe fn ReceiveObject(&self, cx: *mut JSContext) -> NonNullJSObjectPtr { + unsafe fn ReceiveObject(&self, cx: *mut JSContext) -> NonNull<JSObject> { self.ObjectAttribute(cx) } fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) } @@ -317,7 +315,7 @@ impl TestBindingMethods for TestBinding { Some(Blob::new(&self.global(), BlobImpl::new_from_bytes(vec![]), "".to_owned())) } #[allow(unsafe_code)] - unsafe fn ReceiveNullableObject(&self, cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { + unsafe fn ReceiveNullableObject(&self, cx: *mut JSContext) -> Option<NonNull<JSObject>> { self.GetObjectAttributeNullable(cx) } fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> { diff --git a/components/script/dom/textencoder.rs b/components/script/dom/textencoder.rs index 8fb97ac9e78..cc0eae4e5a2 100644 --- a/components/script/dom/textencoder.rs +++ b/components/script/dom/textencoder.rs @@ -5,7 +5,6 @@ use dom::bindings::codegen::Bindings::TextEncoderBinding; use dom::bindings::codegen::Bindings::TextEncoderBinding::TextEncoderMethods; use dom::bindings::error::Fallible; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::root::DomRoot; use dom::bindings::str::{DOMString, USVString}; @@ -14,6 +13,7 @@ use dom_struct::dom_struct; use js::jsapi::{JSContext, JSObject}; use js::typedarray::{Uint8Array, CreateWith}; use std::ptr; +use std::ptr::NonNull; #[dom_struct] pub struct TextEncoder { @@ -47,12 +47,12 @@ impl TextEncoderMethods for TextEncoder { #[allow(unsafe_code)] // https://encoding.spec.whatwg.org/#dom-textencoder-encode - unsafe fn Encode(&self, cx: *mut JSContext, input: USVString) -> NonNullJSObjectPtr { + unsafe fn Encode(&self, cx: *mut JSContext, input: USVString) -> NonNull<JSObject> { let encoded = input.0.as_bytes(); rooted!(in(cx) let mut js_object = ptr::null_mut::<JSObject>()); assert!(Uint8Array::create(cx, CreateWith::Slice(&encoded), js_object.handle_mut()).is_ok()); - NonNullJSObjectPtr::new_unchecked(js_object.get()) + NonNull::new_unchecked(js_object.get()) } } diff --git a/components/script/dom/vreyeparameters.rs b/components/script/dom/vreyeparameters.rs index 496277ba65d..333c717f06b 100644 --- a/components/script/dom/vreyeparameters.rs +++ b/components/script/dom/vreyeparameters.rs @@ -5,7 +5,6 @@ use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::VREyeParametersBinding; use dom::bindings::codegen::Bindings::VREyeParametersBinding::VREyeParametersMethods; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot}; use dom::globalscope::GlobalScope; @@ -15,6 +14,7 @@ use js::jsapi::{Heap, JSContext, JSObject}; use js::typedarray::{Float32Array, CreateWith}; use std::default::Default; use std::ptr; +use std::ptr::NonNull; use webvr_traits::WebVREyeParameters; #[dom_struct] @@ -60,8 +60,8 @@ impl VREyeParameters { impl VREyeParametersMethods for VREyeParameters { #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vreyeparameters-offset - unsafe fn Offset(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { - NonNullJSObjectPtr::new_unchecked(self.offset.get()) + unsafe fn Offset(&self, _cx: *mut JSContext) -> NonNull<JSObject> { + NonNull::new_unchecked(self.offset.get()) } // https://w3c.github.io/webvr/#dom-vreyeparameters-fieldofview diff --git a/components/script/dom/vrframedata.rs b/components/script/dom/vrframedata.rs index 530a3727020..621f70a55c9 100644 --- a/components/script/dom/vrframedata.rs +++ b/components/script/dom/vrframedata.rs @@ -5,7 +5,6 @@ use dom::bindings::codegen::Bindings::VRFrameDataBinding; use dom::bindings::codegen::Bindings::VRFrameDataBinding::VRFrameDataMethods; use dom::bindings::error::Fallible; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::num::Finite; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot}; @@ -17,6 +16,7 @@ use js::jsapi::{Heap, JSContext, JSObject}; use js::typedarray::{Float32Array, CreateWith}; use std::cell::Cell; use std::ptr; +use std::ptr::NonNull; use webvr_traits::WebVRFrameData; #[dom_struct] @@ -118,26 +118,26 @@ impl VRFrameDataMethods for VRFrameData { #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrframedata-leftprojectionmatrix - unsafe fn LeftProjectionMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { - NonNullJSObjectPtr::new_unchecked(self.left_proj.get()) + unsafe fn LeftProjectionMatrix(&self, _cx: *mut JSContext) -> NonNull<JSObject> { + NonNull::new_unchecked(self.left_proj.get()) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrframedata-leftviewmatrix - unsafe fn LeftViewMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { - NonNullJSObjectPtr::new_unchecked(self.left_view.get()) + unsafe fn LeftViewMatrix(&self, _cx: *mut JSContext) -> NonNull<JSObject> { + NonNull::new_unchecked(self.left_view.get()) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrframedata-rightprojectionmatrix - unsafe fn RightProjectionMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { - NonNullJSObjectPtr::new_unchecked(self.right_proj.get()) + unsafe fn RightProjectionMatrix(&self, _cx: *mut JSContext) -> NonNull<JSObject> { + NonNull::new_unchecked(self.right_proj.get()) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrframedata-rightviewmatrix - unsafe fn RightViewMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { - NonNullJSObjectPtr::new_unchecked(self.right_view.get()) + unsafe fn RightViewMatrix(&self, _cx: *mut JSContext) -> NonNull<JSObject> { + NonNull::new_unchecked(self.right_view.get()) } // https://w3c.github.io/webvr/#dom-vrframedata-pose diff --git a/components/script/dom/vrpose.rs b/components/script/dom/vrpose.rs index a0b3ec7c92a..01778471ccb 100644 --- a/components/script/dom/vrpose.rs +++ b/components/script/dom/vrpose.rs @@ -4,7 +4,6 @@ use dom::bindings::codegen::Bindings::VRPoseBinding; use dom::bindings::codegen::Bindings::VRPoseBinding::VRPoseMethods; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::root::DomRoot; use dom::globalscope::GlobalScope; @@ -12,6 +11,7 @@ use dom_struct::dom_struct; use js::jsapi::{Heap, JSContext, JSObject}; use js::typedarray::{Float32Array, CreateWith}; use std::ptr; +use std::ptr::NonNull; use webvr_traits::webvr; #[dom_struct] @@ -52,13 +52,13 @@ unsafe fn update_or_create_typed_array(cx: *mut JSContext, #[inline] #[allow(unsafe_code)] -fn heap_to_option(heap: &Heap<*mut JSObject>) -> Option<NonNullJSObjectPtr> { +fn heap_to_option(heap: &Heap<*mut JSObject>) -> Option<NonNull<JSObject>> { let js_object = heap.get(); if js_object.is_null() { None } else { unsafe { - Some(NonNullJSObjectPtr::new_unchecked(js_object)) + Some(NonNull::new_unchecked(js_object)) } } } @@ -101,37 +101,37 @@ impl VRPose { impl VRPoseMethods for VRPose { #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrpose-position - unsafe fn GetPosition(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { + unsafe fn GetPosition(&self, _cx: *mut JSContext) -> Option<NonNull<JSObject>> { heap_to_option(&self.position) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrpose-linearvelocity - unsafe fn GetLinearVelocity(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { + unsafe fn GetLinearVelocity(&self, _cx: *mut JSContext) -> Option<NonNull<JSObject>> { heap_to_option(&self.linear_vel) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrpose-linearacceleration - unsafe fn GetLinearAcceleration(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { + unsafe fn GetLinearAcceleration(&self, _cx: *mut JSContext) -> Option<NonNull<JSObject>> { heap_to_option(&self.linear_acc) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrpose-orientation - unsafe fn GetOrientation(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { + unsafe fn GetOrientation(&self, _cx: *mut JSContext) -> Option<NonNull<JSObject>> { heap_to_option(&self.orientation) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrpose-angularvelocity - unsafe fn GetAngularVelocity(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { + unsafe fn GetAngularVelocity(&self, _cx: *mut JSContext) -> Option<NonNull<JSObject>> { heap_to_option(&self.angular_vel) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrpose-angularacceleration - unsafe fn GetAngularAcceleration(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { + unsafe fn GetAngularAcceleration(&self, _cx: *mut JSContext) -> Option<NonNull<JSObject>> { heap_to_option(&self.angular_acc) } } diff --git a/components/script/dom/vrstageparameters.rs b/components/script/dom/vrstageparameters.rs index 9a34af4c03e..bd4dfa5a3a6 100644 --- a/components/script/dom/vrstageparameters.rs +++ b/components/script/dom/vrstageparameters.rs @@ -5,7 +5,6 @@ use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::VRStageParametersBinding; use dom::bindings::codegen::Bindings::VRStageParametersBinding::VRStageParametersMethods; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::num::Finite; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::root::DomRoot; @@ -14,6 +13,7 @@ use dom_struct::dom_struct; use js::jsapi::{Heap, JSContext, JSObject}; use js::typedarray::{Float32Array, CreateWith}; use std::ptr; +use std::ptr::NonNull; use webvr_traits::WebVRStageParameters; #[dom_struct] @@ -69,8 +69,8 @@ impl VRStageParameters { impl VRStageParametersMethods for VRStageParameters { #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrstageparameters-sittingtostandingtransform - unsafe fn SittingToStandingTransform(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { - NonNullJSObjectPtr::new_unchecked(self.transform.get()) + unsafe fn SittingToStandingTransform(&self, _cx: *mut JSContext) -> NonNull<JSObject> { + NonNull::new_unchecked(self.transform.get()) } // https://w3c.github.io/webvr/#dom-vrstageparameters-sizex diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index 168f1146370..9bf016f9631 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -10,7 +10,6 @@ use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContext use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods; use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement; use dom::bindings::error::Fallible; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::{reflect_dom_object, Reflector}; use dom::bindings::root::{Dom, DomRoot, LayoutDom}; use dom::bindings::str::DOMString; @@ -33,6 +32,7 @@ use js::jsapi::{JSContext, JSObject}; use js::jsval::JSVal; use offscreen_gl_context::GLContextAttributes; use script_layout_interface::HTMLCanvasDataSource; +use std::ptr::NonNull; #[dom_struct] pub struct WebGL2RenderingContext { @@ -132,7 +132,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext { #[allow(unsafe_code)] /// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14 - unsafe fn GetExtension(&self, cx: *mut JSContext, name: DOMString) -> Option<NonNullJSObjectPtr> { + unsafe fn GetExtension(&self, cx: *mut JSContext, name: DOMString) -> Option<NonNull<JSObject>> { self.base.GetExtension(cx, name) } diff --git a/components/script/dom/webgl_extensions/extensions.rs b/components/script/dom/webgl_extensions/extensions.rs index e599df7a25c..3c22817d555 100644 --- a/components/script/dom/webgl_extensions/extensions.rs +++ b/components/script/dom/webgl_extensions/extensions.rs @@ -7,19 +7,20 @@ use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants; use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::root::DomRoot; use dom::bindings::trace::JSTraceable; use dom::webglrenderingcontext::WebGLRenderingContext; use fnv::{FnvHashMap, FnvHashSet}; use gleam::gl::GLenum; use js::jsapi::JSContext; +use js::jsapi::JSObject; use js::jsval::JSVal; use malloc_size_of::MallocSizeOf; use ref_filter_map::ref_filter_map; use std::cell::Ref; use std::collections::HashMap; use std::iter::FromIterator; +use std::ptr::NonNull; use super::{ext, WebGLExtension, WebGLExtensionSpec}; use super::wrapper::{WebGLExtensionWrapper, TypedWebGLExtensionWrapper}; @@ -127,7 +128,7 @@ impl WebGLExtensions { .collect() } - pub fn get_or_init_extension(&self, name: &str, ctx: &WebGLRenderingContext) -> Option<NonNullJSObjectPtr> { + pub fn get_or_init_extension(&self, name: &str, ctx: &WebGLRenderingContext) -> Option<NonNull<JSObject>> { let name = name.to_uppercase(); self.extensions.borrow().get(&name).and_then(|extension| { if extension.is_supported(self) { diff --git a/components/script/dom/webgl_extensions/wrapper.rs b/components/script/dom/webgl_extensions/wrapper.rs index 8af48a6d93e..05fb375ffbd 100644 --- a/components/script/dom/webgl_extensions/wrapper.rs +++ b/components/script/dom/webgl_extensions/wrapper.rs @@ -2,13 +2,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::DomObject; use dom::bindings::root::{DomRoot, MutNullableDom}; use dom::bindings::trace::JSTraceable; use dom::webglrenderingcontext::WebGLRenderingContext; +use js::jsapi::JSObject; use malloc_size_of::MallocSizeOf; use std::any::Any; +use std::ptr::NonNull; use super::{WebGLExtension, WebGLExtensions, WebGLExtensionSpec}; /// Trait used internally by WebGLExtensions to store and @@ -17,7 +18,7 @@ pub trait WebGLExtensionWrapper: JSTraceable + MallocSizeOf { fn instance_or_init(&self, ctx: &WebGLRenderingContext, ext: &WebGLExtensions) - -> NonNullJSObjectPtr; + -> NonNull<JSObject>; fn spec(&self) -> WebGLExtensionSpec; fn is_supported(&self, &WebGLExtensions) -> bool; fn is_enabled(&self) -> bool; @@ -48,7 +49,7 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T> fn instance_or_init(&self, ctx: &WebGLRenderingContext, ext: &WebGLExtensions) - -> NonNullJSObjectPtr { + -> NonNull<JSObject> { let mut enabled = true; let extension = self.extension.or_init(|| { enabled = false; @@ -58,7 +59,7 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T> self.enable(ext); } unsafe { - NonNullJSObjectPtr::new_unchecked(extension.reflector().get_jsobject().get()) + NonNull::new_unchecked(extension.reflector().get_jsobject().get()) } } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 21712563e40..61f05a923e8 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -17,7 +17,6 @@ use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasE use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible}; use dom::bindings::error::{Error, Fallible}; use dom::bindings::inheritance::Castable; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom}; use dom::bindings::str::DOMString; @@ -57,6 +56,7 @@ use script_layout_interface::HTMLCanvasDataSource; use servo_config::prefs::PREFS; use std::cell::{Cell, Ref}; use std::iter::FromIterator; +use std::ptr::NonNull; use webrender_api; type ImagePixelResult = Result<(Vec<u8>, Size2D<i32>, bool), ()>; @@ -1389,7 +1389,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { #[allow(unsafe_code)] // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14 unsafe fn GetExtension(&self, _cx: *mut JSContext, name: DOMString) - -> Option<NonNullJSObjectPtr> { + -> Option<NonNull<JSObject>> { self.extension_manager.init_once(|| { self.get_gl_extensions() }); diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index ed67be90900..68764eb1080 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -6,7 +6,6 @@ use document_loader::DocumentLoader; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::XMLDocumentBinding::{self, XMLDocumentMethods}; use dom::bindings::inheritance::Castable; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::reflector::reflect_dom_object; use dom::bindings::root::DomRoot; use dom::bindings::str::DOMString; @@ -16,8 +15,10 @@ use dom::node::Node; use dom::window::Window; use dom_struct::dom_struct; use js::jsapi::JSContext; +use js::jsapi::JSObject; use script_traits::DocumentActivity; use servo_url::{MutableOrigin, ServoUrl}; +use std::ptr::NonNull; // https://dom.spec.whatwg.org/#xmldocument #[dom_struct] @@ -101,7 +102,7 @@ impl XMLDocumentMethods for XMLDocument { #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter - unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonNullJSObjectPtr> { + unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonNull<JSObject>> { self.upcast::<Document>().NamedGetter(_cx, name) } } diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 716115307d2..cb42db58ad4 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -14,7 +14,6 @@ use dom::bindings::codegen::UnionTypes::DocumentOrBodyInit; use dom::bindings::conversions::ToJSValConvertible; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::inheritance::Castable; -use dom::bindings::nonnull::NonNullJSObjectPtr; use dom::bindings::refcounted::Trusted; use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::root::{Dom, DomRoot, MutNullableDom}; @@ -67,6 +66,7 @@ use std::borrow::ToOwned; use std::cell::Cell; use std::default::Default; use std::ptr; +use std::ptr::NonNull; use std::slice; use std::str; use std::sync::{Arc, Mutex}; @@ -1120,11 +1120,11 @@ impl XMLHttpRequest { // https://xhr.spec.whatwg.org/#arraybuffer-response #[allow(unsafe_code)] - unsafe fn arraybuffer_response(&self, cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { + unsafe fn arraybuffer_response(&self, cx: *mut JSContext) -> Option<NonNull<JSObject>> { // Step 1 let created = self.response_arraybuffer.get(); - if !created.is_null() { - return Some(NonNullJSObjectPtr::new_unchecked(created)); + if let Some(nonnull) = NonNull::new(created) { + return Some(nonnull) } // Step 2 @@ -1132,7 +1132,7 @@ impl XMLHttpRequest { rooted!(in(cx) let mut array_buffer = ptr::null_mut::<JSObject>()); ArrayBuffer::create(cx, CreateWith::Slice(&bytes), array_buffer.handle_mut()).ok().and_then(|()| { self.response_arraybuffer.set(array_buffer.get()); - Some(NonNullJSObjectPtr::new_unchecked(array_buffer.get())) + Some(NonNull::new_unchecked(array_buffer.get())) }) } diff --git a/components/script/lib.rs b/components/script/lib.rs index c3517691e8b..a871b320758 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -68,7 +68,6 @@ extern crate mitochondria; extern crate mozjs as js; extern crate msg; extern crate net_traits; -extern crate nonzero; extern crate num_traits; extern crate offscreen_gl_context; extern crate open; diff --git a/components/script_layout_interface/Cargo.toml b/components/script_layout_interface/Cargo.toml index 6a64c2b205e..db3c63dddbe 100644 --- a/components/script_layout_interface/Cargo.toml +++ b/components/script_layout_interface/Cargo.toml @@ -25,7 +25,6 @@ malloc_size_of_derive = { path = "../malloc_size_of_derive" } metrics = {path = "../metrics"} msg = {path = "../msg"} net_traits = {path = "../net_traits"} -nonzero = {path = "../nonzero"} profile_traits = {path = "../profile_traits"} range = {path = "../range"} script_traits = {path = "../script_traits"} diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index 4e17570f92d..0538aabafd0 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -24,7 +24,6 @@ extern crate malloc_size_of; extern crate metrics; extern crate msg; extern crate net_traits; -extern crate nonzero; extern crate profile_traits; extern crate range; extern crate script_traits; @@ -45,9 +44,9 @@ use canvas_traits::canvas::CanvasMsg; use ipc_channel::ipc::IpcSender; use libc::c_void; use net_traits::image_cache::PendingImageId; -use nonzero::NonZero; use script_traits::UntrustedNodeAddress; use servo_url::ServoUrl; +use std::ptr::NonNull; use std::sync::atomic::AtomicIsize; use style::data::ElementData; @@ -77,7 +76,7 @@ pub struct OpaqueStyleAndLayoutData { // NB: We really store a `StyleAndLayoutData` here, so be careful! #[ignore_malloc_size_of = "TODO(#6910) Box value that should be counted but \ the type lives in layout"] - pub ptr: NonZero<*mut StyleData>, + pub ptr: NonNull<StyleData>, } #[allow(unsafe_code)] diff --git a/components/servo_arc/lib.rs b/components/servo_arc/lib.rs index d7694901130..1301a8e6611 100644 --- a/components/servo_arc/lib.rs +++ b/components/servo_arc/lib.rs @@ -83,6 +83,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize; /// that this is all a temporary hack, this restriction is fine for now. /// /// [1]: https://github.com/rust-lang/rust/issues/27730 +// FIXME: remove this and use std::ptr::NonNull when Firefox requires Rust 1.25+ pub struct NonZeroPtrMut<T: ?Sized + 'static>(&'static mut T); impl<T: ?Sized> NonZeroPtrMut<T> { pub fn new(ptr: *mut T) -> Self { diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs index e5b7e273885..2a137d7eb79 100644 --- a/components/style/rule_tree/mod.rs +++ b/components/style/rule_tree/mod.rs @@ -828,6 +828,8 @@ impl MallocSizeOf for RuleNode { } } +// FIXME: use std::ptr::NonNull when Firefox requires Rust 1.25+ + #[derive(Clone)] struct WeakRuleNode { p: NonZeroPtrMut<RuleNode>, diff --git a/ports/cef/eutil.rs b/ports/cef/eutil.rs index 03d98d31e1c..06591618332 100644 --- a/ports/cef/eutil.rs +++ b/ports/cef/eutil.rs @@ -30,7 +30,7 @@ pub fn slice_to_str<F>(s: *const u8, l: usize, f: F) -> c_int where F: FnOnce(&s /// All fields are initialized to zero. It is the caller's responsibility to ensure that the given /// type is a CEF type with `cef_base_t` as its first member. pub unsafe fn create_cef_object<Base,Extra>(size: size_t) -> *mut Base { - let object = libc::calloc(1, (mem::size_of::<Base>() + mem::size_of::<Extra>())) as + let object = libc::calloc(1, mem::size_of::<Base>() + mem::size_of::<Extra>()) as *mut cef_base_t; (*object).size = size; (*object).add_ref = Some(servo_add_ref as extern "C" fn(*mut cef_base_t) -> c_int); diff --git a/ports/cef/wrappers.rs b/ports/cef/wrappers.rs index 16beca788f9..707ad0e2355 100644 --- a/ports/cef/wrappers.rs +++ b/ports/cef/wrappers.rs @@ -199,7 +199,7 @@ cef_unimplemented_wrapper!(cef_string_t, String); impl<'a> CefWrap<*const cef_string_t> for &'a [u16] { fn to_c(buffer: &'a [u16]) -> *const cef_string_t { unsafe { - let ptr = libc::malloc(((buffer.len() + 1) * 2)) as *mut c_ushort; + let ptr = libc::malloc((buffer.len() + 1) * 2) as *mut c_ushort; ptr::copy(buffer.as_ptr(), ptr, buffer.len()); *ptr.offset(buffer.len() as isize) = 0; diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 2ee79abc56c..f155903ac5e 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -4396,7 +4396,7 @@ pub extern "C" fn Servo_GetCustomPropertyValue( None => return false, }; - let name = unsafe { Atom::from((&*name)) }; + let name = unsafe { Atom::from(&*name) }; let computed_value = match custom_properties.get(&name) { Some(v) => v, None => return false, diff --git a/rust-toolchain b/rust-toolchain index 4e28cf4072d..a80d36c679b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2018-01-14 +nightly-2018-01-21 |