mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Replace NonNullJSObjectPtr with std::ptr::NonNull<JSObject>
This commit is contained in:
parent
897a5b39c5
commit
52eda6082f
22 changed files with 79 additions and 111 deletions
|
@ -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',
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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>());
|
||||
|
@ -106,7 +106,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()) }
|
||||
unsafe { NonNull::new_unchecked(rval.get()) }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue