Auto merge of #18875 - servo:stable-js, r=nox,jdm

Remove the need for rust-mozjs to use unstable Rust features

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18875)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-10-16 17:07:50 -05:00 committed by GitHub
commit e8a6f2862c
44 changed files with 268 additions and 218 deletions

View file

@ -9,7 +9,7 @@ use style::thread_state;
/// A mutable field in the DOM.
///
/// This extends the API of `core::cell::RefCell` to allow unsafe access in
/// This extends the API of `std::cell::RefCell` to allow unsafe access in
/// certain situations, with dynamic checking in debug builds.
#[derive(Clone, Debug, Default, HeapSizeOf, PartialEq)]
pub struct DomRefCell<T> {
@ -57,7 +57,7 @@ impl<T> DomRefCell<T> {
}
}
// Functionality duplicated with `core::cell::RefCell`
// Functionality duplicated with `std::cell::RefCell`
// ===================================================
impl<T> DomRefCell<T> {
/// Create a new `DomRefCell` containing `value`.

View file

@ -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',
@ -3659,19 +3660,18 @@ class CGMemberJITInfo(CGThing):
call: ${opName} as *const os::raw::c_void,
protoID: PrototypeList::ID::${name} as u16,
depth: ${depth},
_bitfield_1:
JSJitInfo::new_bitfield_1(
JSJitInfo_OpType::${opType} as u8,
JSJitInfo_AliasSet::${aliasSet} as u8,
JSValueType::${returnType} as u8,
${isInfallible},
${isMovable},
${isEliminatable},
${isAlwaysInSlot},
${isLazilyCachedInSlot},
${isTypedMethod},
${slotIndex} as u16,
)
_bitfield_1: new_jsjitinfo_bitfield_1!(
JSJitInfo_OpType::${opType} as u8,
JSJitInfo_AliasSet::${aliasSet} as u8,
JSValueType::${returnType} as u8,
${isInfallible},
${isMovable},
${isEliminatable},
${isAlwaysInSlot},
${isLazilyCachedInSlot},
${isTypedMethod},
${slotIndex},
),
}
""",
opName=opName,
@ -5574,7 +5574,6 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
typedefs = []
return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, typedefs, [
'core::nonzero::NonZero',
'js',
'js::JSCLASS_GLOBAL_SLOT_COUNT',
'js::JSCLASS_IS_DOMJSCLASS',
@ -5785,6 +5784,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',

View file

@ -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;
@ -66,9 +67,19 @@ pub trait IDLInterface {
}
/// A trait to mark an IDL interface as deriving from another one.
#[rustc_on_unimplemented = "The IDL interface `{Self}` is not derived from `{T}`."]
#[cfg_attr(feature = "unstable",
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) {

View file

@ -134,8 +134,8 @@ impl NonCallbackInterfaceObjectClass {
name: b"Function\0" as *const _ as *const libc::c_char,
flags: 0,
cOps: &constructor_behavior.0,
spec: ptr::null(),
ext: ptr::null(),
spec: 0 as *const _,
ext: 0 as *const _,
oOps: &OBJECT_OPS,
},
proto_id: proto_id,

View file

@ -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()) }
})
}
}

View file

@ -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;

View file

@ -8,7 +8,6 @@ use dom::bindings::guard::Guard;
use dom::bindings::interface::{create_object, define_on_global_object};
use js::jsapi::{HandleObject, JSClass, JSContext, JSFunctionSpec, MutableHandleObject};
use libc;
use std::ptr;
/// The class of a namespace object.
#[derive(Clone, Copy)]
@ -22,8 +21,8 @@ impl NamespaceObjectClass {
NamespaceObjectClass(JSClass {
name: name as *const _ as *const libc::c_char,
flags: 0,
cOps: ptr::null_mut(),
reserved: [ptr::null_mut(); 3],
cOps: 0 as *mut _,
reserved: [0 as *mut _; 3],
})
}
}

View file

@ -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()
}
}

View file

@ -24,7 +24,6 @@
//! originating `DomRoot<T>`.
//!
use core::nonzero::NonZero;
use dom::bindings::conversions::DerivedFrom;
use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::{DomObject, Reflector};
@ -35,12 +34,11 @@ use heapsize::HeapSizeOf;
use js::jsapi::{JSObject, JSTracer, Heap};
use js::rust::GCMethods;
use mitochondria::OnceCell;
use nonzero::NonZero;
use script_layout_interface::TrustedNodeAddress;
use std::cell::{Cell, UnsafeCell};
use std::default::Default;
use std::hash::{Hash, Hasher};
#[cfg(debug_assertions)]
use std::intrinsics::type_name;
use std::marker::PhantomData;
use std::mem;
use std::ops::Deref;
@ -359,11 +357,11 @@ impl<T: DomObject> Deref for Dom<T> {
unsafe impl<T: DomObject> JSTraceable for Dom<T> {
unsafe fn trace(&self, trc: *mut JSTracer) {
#[cfg(debug_assertions)]
let trace_str = format!("for {} on heap", type_name::<T>());
#[cfg(debug_assertions)]
#[cfg(all(feature = "unstable", debug_assertions))]
let trace_str = format!("for {} on heap", ::std::intrinsics::type_name::<T>());
#[cfg(all(feature = "unstable", debug_assertions))]
let trace_info = &trace_str[..];
#[cfg(not(debug_assertions))]
#[cfg(not(all(feature = "unstable", debug_assertions)))]
let trace_info = "for DOM object on heap";
trace_reflector(trc,

View file

@ -11,7 +11,6 @@
//! slot. When all associated `WeakRef` values are dropped, the
//! `WeakBox` itself is dropped too.
use core::nonzero::NonZero;
use dom::bindings::reflector::DomObject;
use dom::bindings::root::DomRoot;
use dom::bindings::trace::JSTraceable;
@ -19,6 +18,7 @@ use heapsize::HeapSizeOf;
use js::jsapi::{JSTracer, JS_GetReservedSlot, JS_SetReservedSlot};
use js::jsval::PrivateValue;
use libc::c_void;
use nonzero::NonZero;
use std::cell::{Cell, UnsafeCell};
use std::mem;
use std::ops::{Deref, DerefMut, Drop};