diff options
22 files changed, 108 insertions, 69 deletions
diff --git a/Cargo.lock b/Cargo.lock index 19ac18f08fd..d58133418bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2618,6 +2618,7 @@ dependencies = [ "mitochondria 1.1.2 (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.11.2 (registry+https://github.com/rust-lang/crates.io-index)", "open 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 6ae95d2fda0..703f9881b46 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -61,6 +61,7 @@ mime = "0.2.1" mime_guess = "1.8.0" msg = {path = "../msg"} net_traits = {path = "../net_traits"} +nonzero = {path = "../nonzero"} num-traits = "0.1.32" offscreen_gl_context = { version = "0.11", 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 a82ad040041..084945fad6b 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -1407,7 +1407,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider): if returnType.isAny(): return CGGeneric("JSVal") if returnType.isObject() or returnType.isSpiderMonkeyInterface(): - result = CGGeneric("NonZero<*mut JSObject>") + result = CGGeneric("NonNullJSObjectPtr") if returnType.nullable(): result = CGWrapper(result, pre="Option<", post=">") return result @@ -2253,6 +2253,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', 'dom::bindings::mozmap::MozMap', 'dom::bindings::root::DomRoot', 'dom::bindings::str::ByteString', @@ -5785,6 +5786,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', '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 075f681308e..665a29efb3c 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -34,6 +34,7 @@ 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; @@ -53,7 +54,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}; +use js::rust::{ToString, get_object_class, is_dom_class, is_dom_object, maybe_wrap_value, maybe_wrap_object_value}; use libc; use num_traits::Float; use servo_config::opts; @@ -69,6 +70,15 @@ 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 33d4e3339cb..779695918c9 100644 --- a/components/script/dom/bindings/iterable.rs +++ b/components/script/dom/bindings/iterable.rs @@ -6,17 +6,17 @@ //! Implementation of `iterable<...>` and `iterable<..., ...>` WebIDL declarations. -use core::nonzero::NonZero; 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; use dom::globalscope::GlobalScope; use dom_struct::dom_struct; use js::conversions::ToJSValConvertible; -use js::jsapi::{HandleValue, Heap, JSContext, JSObject, MutableHandleObject}; +use js::jsapi::{HandleValue, Heap, JSContext, MutableHandleObject}; use js::jsval::UndefinedValue; use std::cell::Cell; use std::ptr; @@ -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<NonZero<*mut JSObject>> { + pub fn Next(&self, cx: *mut JSContext) -> Fallible<NonNullJSObjectPtr> { let index = self.index.get(); rooted!(in(cx) let mut value = UndefinedValue()); rooted!(in(cx) let mut rval = ptr::null_mut()); @@ -106,7 +106,7 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> { self.index.set(index + 1); result.map(|_| { assert!(!rval.is_null()); - unsafe { NonZero::new_unchecked(rval.get()) } + unsafe { NonNullJSObjectPtr::new_unchecked(rval.get()) } }) } } diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs index f251f0bd364..7cd90547105 100644 --- a/components/script/dom/bindings/mod.rs +++ b/components/script/dom/bindings/mod.rs @@ -144,6 +144,7 @@ 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 new file mode 100644 index 00000000000..36dade7136b --- /dev/null +++ b/components/script/dom/bindings/nonnull.rs @@ -0,0 +1,24 @@ +/* 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/crypto.rs b/components/script/dom/crypto.rs index 2093c1cff50..ac56e9f3ff6 100644 --- a/components/script/dom/crypto.rs +++ b/components/script/dom/crypto.rs @@ -2,11 +2,11 @@ * 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 core::nonzero::NonZero; 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; @@ -44,7 +44,7 @@ impl CryptoMethods for Crypto { unsafe fn GetRandomValues(&self, _cx: *mut JSContext, input: *mut JSObject) - -> Fallible<NonZero<*mut JSObject>> { + -> Fallible<NonNullJSObjectPtr> { 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(NonZero::new_unchecked(input)) + Ok(NonNullJSObjectPtr::new_unchecked(input)) } } diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 1d8900ebb84..f4e734ceec5 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use cookie_rs; -use core::nonzero::NonZero; use devtools_traits::ScriptToDevtoolsControlMsg; use document_loader::{DocumentLoader, LoadType}; use dom::activation::{ActivationSource, synthetic_click_activation}; @@ -24,6 +23,7 @@ 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}; @@ -99,7 +99,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, JSObject, JSRuntime}; +use js::jsapi::{JSContext, JSRuntime}; use js::jsapi::JS_GetRuntime; use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId}; @@ -3536,7 +3536,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<NonZero<*mut JSObject>> { + unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonNullJSObjectPtr> { #[derive(HeapSizeOf, JSTraceable)] struct NamedElementFilter { name: Atom, @@ -3604,7 +3604,7 @@ impl DocumentMethods for Document { if elements.peek().is_none() { // TODO: Step 2. // Step 3. - return Some(NonZero::new_unchecked(first.reflector().get_jsobject().get())); + return Some(NonNullJSObjectPtr::new_unchecked(first.reflector().get_jsobject().get())); } } else { return None; @@ -3615,7 +3615,7 @@ impl DocumentMethods for Document { name: name, }; let collection = HTMLCollection::create(self.window(), root, Box::new(filter)); - Some(NonZero::new_unchecked(collection.reflector().get_jsobject().get())) + Some(NonNullJSObjectPtr::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 e5858309191..47605b7794e 100644 --- a/components/script/dom/gamepad.rs +++ b/components/script/dom/gamepad.rs @@ -2,10 +2,10 @@ * 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 core::nonzero::NonZero; 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}; @@ -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) -> NonZero<*mut JSObject> { - NonZero::new_unchecked(self.axes.get()) + unsafe fn Axes(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { + NonNullJSObjectPtr::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 e8ec2660c56..f0270fbe7b7 100644 --- a/components/script/dom/imagedata.rs +++ b/components/script/dom/imagedata.rs @@ -2,10 +2,10 @@ * 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 core::nonzero::NonZero; 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; @@ -159,8 +159,8 @@ impl ImageDataMethods for ImageData { #[allow(unsafe_code)] // https://html.spec.whatwg.org/multipage/#dom-imagedata-data - unsafe fn Data(&self, _: *mut JSContext) -> NonZero<*mut JSObject> { + unsafe fn Data(&self, _: *mut JSContext) -> NonNullJSObjectPtr { assert!(!self.data.get().is_null()); - NonZero::new_unchecked(self.data.get()) + NonNullJSObjectPtr::new_unchecked(self.data.get()) } } diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 620394e69dd..62738fcf379 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -4,7 +4,6 @@ // check-tidy: no specs after this line -use core::nonzero::NonZero; use dom::bindings::callback::ExceptionHandling; use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener; use dom::bindings::codegen::Bindings::FunctionBinding::Function; @@ -22,6 +21,7 @@ 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}; @@ -151,20 +151,20 @@ impl TestBindingMethods for TestBinding { } fn SetUnion9Attribute(&self, _: ByteStringOrLong) {} #[allow(unsafe_code)] - unsafe fn ArrayAttribute(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> { + unsafe fn ArrayAttribute(&self, cx: *mut JSContext) -> NonNullJSObjectPtr { rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16)); assert!(!array.is_null()); - NonZero::new_unchecked(array.get()) + NonNullJSObjectPtr::new_unchecked(array.get()) } #[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) -> NonZero<*mut JSObject> { + unsafe fn ObjectAttribute(&self, cx: *mut JSContext) -> NonNullJSObjectPtr { rooted!(in(cx) let obj = JS_NewPlainObject(cx)); assert!(!obj.is_null()); - NonZero::new_unchecked(obj.get()) + NonNullJSObjectPtr::new_unchecked(obj.get()) } #[allow(unsafe_code)] unsafe fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {} @@ -220,7 +220,7 @@ impl TestBindingMethods for TestBinding { self.url.set(url); } #[allow(unsafe_code)] - unsafe fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> Option<NonZero<*mut JSObject>> { None } + unsafe fn GetObjectAttributeNullable(&self, _: *mut JSContext) -> Option<NonNullJSObjectPtr> { None } #[allow(unsafe_code)] unsafe fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {} fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> { @@ -272,7 +272,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) -> NonZero<*mut JSObject> { + unsafe fn ReceiveObject(&self, cx: *mut JSContext) -> NonNullJSObjectPtr { self.ObjectAttribute(cx) } fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) } @@ -316,7 +316,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<NonZero<*mut JSObject>> { + unsafe fn ReceiveNullableObject(&self, cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { self.GetObjectAttributeNullable(cx) } fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> { diff --git a/components/script/dom/textencoder.rs b/components/script/dom/textencoder.rs index 78ccbfcae0b..7ca2a429525 100644 --- a/components/script/dom/textencoder.rs +++ b/components/script/dom/textencoder.rs @@ -2,16 +2,16 @@ * 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 core::nonzero::NonZero; 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}; use dom::globalscope::GlobalScope; use dom_struct::dom_struct; -use js::jsapi::{JSContext, JSObject}; +use js::jsapi::JSContext; use js::typedarray::{Uint8Array, CreateWith}; use std::ptr; @@ -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) -> NonZero<*mut JSObject> { + unsafe fn Encode(&self, cx: *mut JSContext, input: USVString) -> NonNullJSObjectPtr { let encoded = input.0.as_bytes(); rooted!(in(cx) let mut js_object = ptr::null_mut()); assert!(Uint8Array::create(cx, CreateWith::Slice(&encoded), js_object.handle_mut()).is_ok()); - NonZero::new_unchecked(js_object.get()) + NonNullJSObjectPtr::new_unchecked(js_object.get()) } } diff --git a/components/script/dom/vreyeparameters.rs b/components/script/dom/vreyeparameters.rs index 2483a63e170..f29d0230de5 100644 --- a/components/script/dom/vreyeparameters.rs +++ b/components/script/dom/vreyeparameters.rs @@ -2,10 +2,10 @@ * 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 core::nonzero::NonZero; 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; @@ -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) -> NonZero<*mut JSObject> { - NonZero::new_unchecked(self.offset.get()) + unsafe fn Offset(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { + NonNullJSObjectPtr::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 fc7d3dee494..0c36536e4b7 100644 --- a/components/script/dom/vrframedata.rs +++ b/components/script/dom/vrframedata.rs @@ -2,10 +2,10 @@ * 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 core::nonzero::NonZero; 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}; @@ -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) -> NonZero<*mut JSObject> { - NonZero::new_unchecked(self.left_proj.get()) + unsafe fn LeftProjectionMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { + NonNullJSObjectPtr::new_unchecked(self.left_proj.get()) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrframedata-leftviewmatrix - unsafe fn LeftViewMatrix(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { - NonZero::new_unchecked(self.left_view.get()) + unsafe fn LeftViewMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { + NonNullJSObjectPtr::new_unchecked(self.left_view.get()) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrframedata-rightprojectionmatrix - unsafe fn RightProjectionMatrix(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { - NonZero::new_unchecked(self.right_proj.get()) + unsafe fn RightProjectionMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { + NonNullJSObjectPtr::new_unchecked(self.right_proj.get()) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrframedata-rightviewmatrix - unsafe fn RightViewMatrix(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { - NonZero::new_unchecked(self.right_view.get()) + unsafe fn RightViewMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { + NonNullJSObjectPtr::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 816929aa5c6..b6a9fad10a0 100644 --- a/components/script/dom/vrpose.rs +++ b/components/script/dom/vrpose.rs @@ -2,9 +2,9 @@ * 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 core::nonzero::NonZero; 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; @@ -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<NonZero<*mut JSObject>> { +fn heap_to_option(heap: &Heap<*mut JSObject>) -> Option<NonNullJSObjectPtr> { let js_object = heap.get(); if js_object.is_null() { None } else { unsafe { - Some(NonZero::new_unchecked(js_object)) + Some(NonNullJSObjectPtr::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<NonZero<*mut JSObject>> { + unsafe fn GetPosition(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { heap_to_option(&self.position) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrpose-linearvelocity - unsafe fn GetLinearVelocity(&self, _cx: *mut JSContext) -> Option<NonZero<*mut JSObject>> { + unsafe fn GetLinearVelocity(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { 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<NonZero<*mut JSObject>> { + unsafe fn GetLinearAcceleration(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { 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<NonZero<*mut JSObject>> { + unsafe fn GetOrientation(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { heap_to_option(&self.orientation) } #[allow(unsafe_code)] // https://w3c.github.io/webvr/#dom-vrpose-angularvelocity - unsafe fn GetAngularVelocity(&self, _cx: *mut JSContext) -> Option<NonZero<*mut JSObject>> { + unsafe fn GetAngularVelocity(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { 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<NonZero<*mut JSObject>> { + unsafe fn GetAngularAcceleration(&self, _cx: *mut JSContext) -> Option<NonNullJSObjectPtr> { heap_to_option(&self.angular_acc) } } diff --git a/components/script/dom/vrstageparameters.rs b/components/script/dom/vrstageparameters.rs index 8996f0fdbad..a2a185fd6cc 100644 --- a/components/script/dom/vrstageparameters.rs +++ b/components/script/dom/vrstageparameters.rs @@ -2,10 +2,10 @@ * 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 core::nonzero::NonZero; 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; @@ -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) -> NonZero<*mut JSObject> { - NonZero::new_unchecked(self.transform.get()) + unsafe fn SittingToStandingTransform(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr { + NonNullJSObjectPtr::new_unchecked(self.transform.get()) } // https://w3c.github.io/webvr/#dom-vrstageparameters-sizex diff --git a/components/script/dom/webgl_extensions/extensions.rs b/components/script/dom/webgl_extensions/extensions.rs index 7cb478f9fb0..0707407401e 100644 --- a/components/script/dom/webgl_extensions/extensions.rs +++ b/components/script/dom/webgl_extensions/extensions.rs @@ -4,18 +4,18 @@ use canvas_traits::webgl::WebGLError; use core::iter::FromIterator; -use core::nonzero::NonZero; 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 heapsize::HeapSizeOf; -use js::jsapi::{JSContext, JSObject}; +use js::jsapi::JSContext; use js::jsval::JSVal; use ref_filter_map::ref_filter_map; use std::cell::Ref; @@ -109,7 +109,7 @@ impl WebGLExtensions { .collect() } - pub fn get_or_init_extension(&self, name: &str, ctx: &WebGLRenderingContext) -> Option<NonZero<*mut JSObject>> { + pub fn get_or_init_extension(&self, name: &str, ctx: &WebGLRenderingContext) -> Option<NonNullJSObjectPtr> { 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 7b4452ad7dc..49d698bf14c 100644 --- a/components/script/dom/webgl_extensions/wrapper.rs +++ b/components/script/dom/webgl_extensions/wrapper.rs @@ -2,13 +2,12 @@ * 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 core::nonzero::NonZero; +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 heapsize::HeapSizeOf; -use js::jsapi::JSObject; use std::any::Any; use super::{WebGLExtension, WebGLExtensions}; @@ -18,7 +17,7 @@ pub trait WebGLExtensionWrapper: JSTraceable + HeapSizeOf { fn instance_or_init(&self, ctx: &WebGLRenderingContext, ext: &WebGLExtensions) - -> NonZero<*mut JSObject>; + -> NonNullJSObjectPtr; fn is_supported(&self, &WebGLExtensions) -> bool; fn is_enabled(&self) -> bool; fn enable(&self, ext: &WebGLExtensions); @@ -48,7 +47,7 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T> fn instance_or_init(&self, ctx: &WebGLRenderingContext, ext: &WebGLExtensions) - -> NonZero<*mut JSObject> { + -> NonNullJSObjectPtr { let mut enabled = true; let extension = self.extension.or_init(|| { enabled = false; @@ -58,7 +57,7 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T> self.enable(ext); } unsafe { - NonZero::new_unchecked(extension.reflector().get_jsobject().get()) + NonNullJSObjectPtr::new_unchecked(extension.reflector().get_jsobject().get()) } } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index c20b2273123..2ca8396c847 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -10,7 +10,6 @@ use canvas_traits::webgl::WebGLError::*; use canvas_traits::webgl::webgl_channel; use core::cell::Ref; use core::iter::FromIterator; -use core::nonzero::NonZero; use dom::bindings::cell::DomRefCell; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes}; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; @@ -19,6 +18,7 @@ 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; @@ -1377,7 +1377,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<NonZero<*mut JSObject>> { + -> Option<NonNullJSObjectPtr> { self.extension_manager.init_once(|| { self.get_gl_extensions() }); diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index a74cb88af6b..acbdea33582 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -2,11 +2,11 @@ * 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 core::nonzero::NonZero; 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; @@ -15,7 +15,7 @@ use dom::location::Location; use dom::node::Node; use dom::window::Window; use dom_struct::dom_struct; -use js::jsapi::{JSContext, JSObject}; +use js::jsapi::JSContext; use script_traits::DocumentActivity; use servo_url::{MutableOrigin, ServoUrl}; @@ -100,7 +100,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<NonZero<*mut JSObject>> { + unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonNullJSObjectPtr> { self.upcast::<Document>().NamedGetter(_cx, name) } } diff --git a/components/script/lib.rs b/components/script/lib.rs index 8922aa37e62..8ea44e68d77 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -67,6 +67,7 @@ extern crate mime_guess; extern crate mitochondria; extern crate msg; extern crate net_traits; +extern crate nonzero; extern crate num_traits; extern crate offscreen_gl_context; extern crate open; |