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

3
Cargo.lock generated
View file

@ -1457,7 +1457,7 @@ dependencies = [
[[package]] [[package]]
name = "js" name = "js"
version = "0.1.6" version = "0.1.6"
source = "git+https://github.com/servo/rust-mozjs#3de4ff3d52361a47a17e3b4fcb02c779b99d93d4" source = "git+https://github.com/servo/rust-mozjs#cdb9570900b74cf4e0ba129eeb8bf527cee3ddb5"
dependencies = [ dependencies = [
"cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2618,6 +2618,7 @@ dependencies = [
"mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"net_traits 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)", "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)", "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)", "open 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use euclid::Size2D; use euclid::Size2D;
use nonzero::NonZeroU32; use nonzero::NonZero;
use offscreen_gl_context::{GLContextAttributes, GLLimits}; use offscreen_gl_context::{GLContextAttributes, GLLimits};
use std::fmt; use std::fmt;
use webrender_api::{DocumentId, ImageKey, PipelineId}; use webrender_api::{DocumentId, ImageKey, PipelineId};
@ -253,13 +253,13 @@ pub enum WebGLCommand {
macro_rules! define_resource_id_struct { macro_rules! define_resource_id_struct {
($name:ident) => { ($name:ident) => {
#[derive(Clone, Copy, Eq, Hash, PartialEq)] #[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct $name(NonZeroU32); pub struct $name(NonZero<u32>);
impl $name { impl $name {
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[inline] #[inline]
pub unsafe fn new(id: u32) -> Self { pub unsafe fn new(id: u32) -> Self {
$name(NonZeroU32::new_unchecked(id)) $name(NonZero::new_unchecked(id))
} }
#[inline] #[inline]

View file

@ -13,7 +13,7 @@ use image::{DynamicImage, ImageFormat, RgbImage};
use ipc_channel::ipc::{self, IpcSharedMemory}; use ipc_channel::ipc::{self, IpcSharedMemory};
use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId}; use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId};
use net_traits::image::base::{Image, PixelFormat}; use net_traits::image::base::{Image, PixelFormat};
use nonzero::NonZeroU32; use nonzero::NonZero;
use profile_traits::time::{self, ProfilerCategory, profile}; use profile_traits::time::{self, ProfilerCategory, profile};
use script_traits::{AnimationState, AnimationTickType, ConstellationControlMsg}; use script_traits::{AnimationState, AnimationTickType, ConstellationControlMsg};
use script_traits::{ConstellationMsg, LayoutControlMsg, MouseButton}; use script_traits::{ConstellationMsg, LayoutControlMsg, MouseButton};
@ -62,7 +62,7 @@ impl ConvertPipelineIdFromWebRender for webrender_api::PipelineId {
fn from_webrender(&self) -> PipelineId { fn from_webrender(&self) -> PipelineId {
PipelineId { PipelineId {
namespace_id: PipelineNamespaceId(self.0), namespace_id: PipelineNamespaceId(self.0),
index: PipelineIndex(NonZeroU32::new(self.1).expect("Webrender pipeline zero?")), index: PipelineIndex(NonZero::new(self.1).expect("Webrender pipeline zero?")),
} }
} }
} }

View file

@ -36,7 +36,7 @@ use html5ever::{LocalName, Namespace};
use layout::data::StyleAndLayoutData; use layout::data::StyleAndLayoutData;
use layout::wrapper::GetRawData; use layout::wrapper::GetRawData;
use msg::constellation_msg::{BrowsingContextId, PipelineId}; use msg::constellation_msg::{BrowsingContextId, PipelineId};
use nonzero::NonZeroUsize; use nonzero::NonZero;
use range::Range; use range::Range;
use script::layout_exports::{CAN_BE_FRAGMENTED, HAS_DIRTY_DESCENDANTS, IS_IN_DOC}; use script::layout_exports::{CAN_BE_FRAGMENTED, HAS_DIRTY_DESCENDANTS, IS_IN_DOC};
use script::layout_exports::{CharacterDataTypeId, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use script::layout_exports::{CharacterDataTypeId, ElementTypeId, HTMLElementTypeId, NodeTypeId};
@ -235,8 +235,7 @@ impl<'ln> LayoutNode for ServoLayoutNode<'ln> {
let ptr: *mut StyleAndLayoutData = let ptr: *mut StyleAndLayoutData =
Box::into_raw(Box::new(StyleAndLayoutData::new())); Box::into_raw(Box::new(StyleAndLayoutData::new()));
let opaque = OpaqueStyleAndLayoutData { let opaque = OpaqueStyleAndLayoutData {
ptr: NonZeroUsize::new_unchecked(ptr as usize), ptr: NonZero::new_unchecked(ptr as *mut StyleData),
phantom: PhantomData,
}; };
self.init_style_and_layout_data(opaque); self.init_style_and_layout_data(opaque);
}; };

View file

@ -5,7 +5,7 @@
//! The high-level interface from script to constellation. Using this abstract interface helps //! The high-level interface from script to constellation. Using this abstract interface helps
//! reduce coupling between these two components. //! reduce coupling between these two components.
use nonzero::NonZeroU32; use nonzero::NonZero;
use std::cell::Cell; use std::cell::Cell;
use std::fmt; use std::fmt;
use webrender_api; use webrender_api;
@ -195,9 +195,9 @@ impl PipelineNamespace {
}); });
} }
fn next_index(&mut self) -> NonZeroU32 { fn next_index(&mut self) -> NonZero<u32> {
self.index += 1; self.index += 1;
NonZeroU32::new(self.index).expect("pipeline id index wrapped!") NonZero::new(self.index).expect("pipeline id index wrapped!")
} }
fn next_pipeline_id(&mut self) -> PipelineId { fn next_pipeline_id(&mut self) -> PipelineId {
@ -221,7 +221,7 @@ thread_local!(pub static PIPELINE_NAMESPACE: Cell<Option<PipelineNamespace>> = C
pub struct PipelineNamespaceId(pub u32); pub struct PipelineNamespaceId(pub u32);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct PipelineIndex(pub NonZeroU32); pub struct PipelineIndex(pub NonZero<u32>);
known_heap_size!(0, PipelineIndex); known_heap_size!(0, PipelineIndex);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
@ -264,7 +264,7 @@ impl fmt::Display for PipelineId {
} }
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct BrowsingContextIndex(pub NonZeroU32); pub struct BrowsingContextIndex(pub NonZero<u32>);
known_heap_size!(0, BrowsingContextIndex); known_heap_size!(0, BrowsingContextIndex);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
@ -340,13 +340,13 @@ impl PartialEq<BrowsingContextId> for TopLevelBrowsingContextId {
pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234); pub const TEST_NAMESPACE: PipelineNamespaceId = PipelineNamespaceId(1234);
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
pub const TEST_PIPELINE_INDEX: PipelineIndex = unsafe { PipelineIndex(NonZeroU32::new_unchecked(5678)) }; pub const TEST_PIPELINE_INDEX: PipelineIndex = unsafe { PipelineIndex(NonZero::new_unchecked(5678)) };
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
pub const TEST_PIPELINE_ID: PipelineId = PipelineId { namespace_id: TEST_NAMESPACE, index: TEST_PIPELINE_INDEX }; pub const TEST_PIPELINE_ID: PipelineId = PipelineId { namespace_id: TEST_NAMESPACE, index: TEST_PIPELINE_INDEX };
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
pub const TEST_BROWSING_CONTEXT_INDEX: BrowsingContextIndex = pub const TEST_BROWSING_CONTEXT_INDEX: BrowsingContextIndex =
unsafe { BrowsingContextIndex(NonZeroU32::new_unchecked(8765)) }; unsafe { BrowsingContextIndex(NonZero::new_unchecked(8765)) };
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId = pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId =
BrowsingContextId { namespace_id: TEST_NAMESPACE, index: TEST_BROWSING_CONTEXT_INDEX }; BrowsingContextId { namespace_id: TEST_NAMESPACE, index: TEST_BROWSING_CONTEXT_INDEX };

View file

@ -9,7 +9,7 @@
#![cfg_attr(feature = "unstable", feature(const_fn))] #![cfg_attr(feature = "unstable", feature(const_fn))]
#![cfg_attr(feature = "unstable", feature(const_nonzero_new))] #![cfg_attr(feature = "unstable", feature(const_nonzero_new))]
#[macro_use] #[cfg_attr(not(feature = "unstable"), macro_use)]
extern crate serde; extern crate serde;
pub use imp::*; pub use imp::*;
@ -17,105 +17,125 @@ pub use imp::*;
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
mod imp { mod imp {
extern crate core; extern crate core;
use self::core::nonzero::NonZero; use self::core::nonzero::NonZero as CoreNonZero;
use serde::{Serialize, Serializer, Deserialize, Deserializer};
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub use self::core::nonzero::Zeroable;
pub struct NonZeroU32(NonZero<u32>);
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NonZeroUsize(NonZero<usize>); pub struct NonZero<T: Zeroable>(CoreNonZero<T>);
impl NonZeroU32 { impl<T: Zeroable> NonZero<T> {
#[inline] pub const unsafe fn new_unchecked(x: u32) -> Self { NonZeroU32(NonZero::new_unchecked(x)) } #[inline]
#[inline] pub fn new(x: u32) -> Option<Self> { NonZero::new(x).map(NonZeroU32) } pub const unsafe fn new_unchecked(x: T) -> Self {
#[inline] pub fn get(self) -> u32 { self.0.get() } NonZero(CoreNonZero::new_unchecked(x))
}
#[inline]
pub fn new(x: T) -> Option<Self> {
CoreNonZero::new(x).map(NonZero)
}
#[inline]
pub fn get(self) -> T {
self.0.get()
}
} }
impl NonZeroUsize { // Not using derive because of the additional Clone bound required by the inner impl
#[inline] pub const unsafe fn new_unchecked(x: usize) -> Self { NonZeroUsize(NonZero::new_unchecked(x)) }
#[inline] pub fn new(x: usize) -> Option<Self> { NonZero::new(x).map(NonZeroUsize) } impl<T> Serialize for NonZero<T>
#[inline] pub fn get(self) -> usize { self.0.get() } where
T: Serialize + Zeroable + Clone,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
self.0.serialize(serializer)
}
}
impl<'de, T> Deserialize<'de> for NonZero<T>
where
T: Deserialize<'de> + Zeroable,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
CoreNonZero::deserialize(deserializer).map(NonZero)
}
} }
} }
#[cfg(not(feature = "unstable"))] #[cfg(not(feature = "unstable"))]
mod imp { mod imp {
use std::cmp;
use std::hash;
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct NonZeroU32(u32); pub struct NonZero<T: Zeroable>(T);
impl NonZeroU32 { impl<T: Zeroable> NonZero<T> {
#[inline] #[inline]
pub fn new(x: u32) -> Option<Self> { pub unsafe fn new_unchecked(x: T) -> Self {
if x != 0 { NonZero(x)
Some(NonZeroU32(x)) }
} else {
#[inline]
pub fn new(x: T) -> Option<Self> {
if x.is_zero() {
None None
} else {
Some(NonZero(x))
} }
} }
#[inline] #[inline]
pub unsafe fn new_unchecked(x: u32) -> Self { pub fn get(self) -> T {
NonZeroU32(x)
}
#[inline]
pub fn get(self) -> u32 {
self.0 self.0
} }
} }
#[derive(Clone, Copy, Debug, Eq)] /// Unsafe trait to indicate what types are usable with the NonZero struct
pub struct NonZeroUsize(&'static ()); pub unsafe trait Zeroable {
/// Whether this value is zero
fn is_zero(&self) -> bool;
}
impl NonZeroUsize { macro_rules! impl_zeroable_for_pointer_types {
#[inline] ( $( $Ptr: ty )+ ) => {
pub fn new(x: usize) -> Option<Self> { $(
if x != 0 { /// For fat pointers to be considered "zero", only the "data" part needs to be null.
Some(unsafe { Self::new_unchecked(x) }) unsafe impl<T: ?Sized> Zeroable for $Ptr {
} else { #[inline]
None fn is_zero(&self) -> bool {
} // Cast because `is_null` is only available on thin pointers
} (*self as *mut u8).is_null()
}
#[inline] }
pub unsafe fn new_unchecked(x: usize) -> Self { )+
NonZeroUsize(&*(x as *const ()))
}
#[inline]
pub fn get(self) -> usize {
self.0 as *const () as usize
} }
} }
impl PartialEq for NonZeroUsize { macro_rules! impl_zeroable_for_integer_types {
#[inline] ( $( $Int: ty )+ ) => {
fn eq(&self, other: &Self) -> bool { $(
self.get() == other.get() unsafe impl Zeroable for $Int {
#[inline]
fn is_zero(&self) -> bool {
*self == 0
}
}
)+
} }
} }
impl PartialOrd for NonZeroUsize { impl_zeroable_for_pointer_types! {
#[inline] *const T
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { *mut T
self.get().partial_cmp(&other.get())
}
} }
impl Ord for NonZeroUsize { impl_zeroable_for_integer_types! {
#[inline] usize u8 u16 u32 u64
fn cmp(&self, other: &Self) -> cmp::Ordering { isize i8 i16 i32 i64
self.get().cmp(&other.get())
}
}
impl hash::Hash for NonZeroUsize {
#[inline]
fn hash<H: hash::Hasher>(&self, hasher: &mut H) {
self.get().hash(hasher)
}
} }
} }

View file

@ -14,7 +14,7 @@ extern crate nonzero;
#[macro_use] extern crate lazy_static; #[macro_use] extern crate lazy_static;
#[macro_use] extern crate log; #[macro_use] extern crate log;
use nonzero::NonZeroUsize; use nonzero::NonZero;
use std::cell::{Cell, UnsafeCell}; use std::cell::{Cell, UnsafeCell};
use std::ops::Deref; use std::ops::Deref;
use std::sync::{LockResult, Mutex, MutexGuard, PoisonError, TryLockError, TryLockResult}; use std::sync::{LockResult, Mutex, MutexGuard, PoisonError, TryLockError, TryLockResult};
@ -25,7 +25,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
// TODO: can we use the thread-id crate for this? // TODO: can we use the thread-id crate for this?
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct ThreadId(NonZeroUsize); pub struct ThreadId(NonZero<usize>);
lazy_static!{ static ref THREAD_COUNT: AtomicUsize = AtomicUsize::new(1); } lazy_static!{ static ref THREAD_COUNT: AtomicUsize = AtomicUsize::new(1); }
@ -33,7 +33,7 @@ impl ThreadId {
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn new() -> ThreadId { fn new() -> ThreadId {
let number = THREAD_COUNT.fetch_add(1, Ordering::SeqCst); let number = THREAD_COUNT.fetch_add(1, Ordering::SeqCst);
ThreadId(NonZeroUsize::new(number).unwrap()) ThreadId(NonZero::new(number).unwrap())
} }
pub fn current() -> ThreadId { pub fn current() -> ThreadId {
THREAD_ID.with(|tls| tls.clone()) THREAD_ID.with(|tls| tls.clone())
@ -57,13 +57,13 @@ impl AtomicOptThreadId {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn load(&self, ordering: Ordering) -> Option<ThreadId> { pub fn load(&self, ordering: Ordering) -> Option<ThreadId> {
let number = self.0.load(ordering); let number = self.0.load(ordering);
NonZeroUsize::new(number).map(ThreadId) NonZero::new(number).map(ThreadId)
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn swap(&self, value: Option<ThreadId>, ordering: Ordering) -> Option<ThreadId> { pub fn swap(&self, value: Option<ThreadId>, ordering: Ordering) -> Option<ThreadId> {
let number = value.map(|id| id.0.get()).unwrap_or(0); let number = value.map(|id| id.0.get()).unwrap_or(0);
let number = self.0.swap(number, ordering); let number = self.0.swap(number, ordering);
NonZeroUsize::new(number).map(ThreadId) NonZero::new(number).map(ThreadId)
} }
} }

View file

@ -13,6 +13,7 @@ path = "lib.rs"
[features] [features]
debugmozjs = ['js/debugmozjs'] debugmozjs = ['js/debugmozjs']
unstable = []
[build-dependencies] [build-dependencies]
cmake = "0.1" cmake = "0.1"
@ -61,6 +62,7 @@ mime = "0.2.1"
mime_guess = "1.8.0" mime_guess = "1.8.0"
msg = {path = "../msg"} msg = {path = "../msg"}
net_traits = {path = "../net_traits"} net_traits = {path = "../net_traits"}
nonzero = {path = "../nonzero"}
num-traits = "0.1.32" num-traits = "0.1.32"
offscreen_gl_context = { version = "0.11", features = ["serde"] } offscreen_gl_context = { version = "0.11", features = ["serde"] }
open = "1.1.1" open = "1.1.1"

View file

@ -9,7 +9,7 @@ use style::thread_state;
/// A mutable field in the DOM. /// 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. /// certain situations, with dynamic checking in debug builds.
#[derive(Clone, Debug, Default, HeapSizeOf, PartialEq)] #[derive(Clone, Debug, Default, HeapSizeOf, PartialEq)]
pub struct DomRefCell<T> { 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> { impl<T> DomRefCell<T> {
/// Create a new `DomRefCell` containing `value`. /// Create a new `DomRefCell` containing `value`.

View file

@ -1407,7 +1407,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
if returnType.isAny(): if returnType.isAny():
return CGGeneric("JSVal") return CGGeneric("JSVal")
if returnType.isObject() or returnType.isSpiderMonkeyInterface(): if returnType.isObject() or returnType.isSpiderMonkeyInterface():
result = CGGeneric("NonZero<*mut JSObject>") result = CGGeneric("NonNullJSObjectPtr")
if returnType.nullable(): if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">") result = CGWrapper(result, pre="Option<", post=">")
return result return result
@ -2253,6 +2253,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
'dom::bindings::conversions::StringificationBehavior', 'dom::bindings::conversions::StringificationBehavior',
'dom::bindings::conversions::root_from_handlevalue', 'dom::bindings::conversions::root_from_handlevalue',
'dom::bindings::error::throw_not_in_union', 'dom::bindings::error::throw_not_in_union',
'dom::bindings::nonnull::NonNullJSObjectPtr',
'dom::bindings::mozmap::MozMap', 'dom::bindings::mozmap::MozMap',
'dom::bindings::root::DomRoot', 'dom::bindings::root::DomRoot',
'dom::bindings::str::ByteString', 'dom::bindings::str::ByteString',
@ -3659,19 +3660,18 @@ class CGMemberJITInfo(CGThing):
call: ${opName} as *const os::raw::c_void, call: ${opName} as *const os::raw::c_void,
protoID: PrototypeList::ID::${name} as u16, protoID: PrototypeList::ID::${name} as u16,
depth: ${depth}, depth: ${depth},
_bitfield_1: _bitfield_1: new_jsjitinfo_bitfield_1!(
JSJitInfo::new_bitfield_1( JSJitInfo_OpType::${opType} as u8,
JSJitInfo_OpType::${opType} as u8, JSJitInfo_AliasSet::${aliasSet} as u8,
JSJitInfo_AliasSet::${aliasSet} as u8, JSValueType::${returnType} as u8,
JSValueType::${returnType} as u8, ${isInfallible},
${isInfallible}, ${isMovable},
${isMovable}, ${isEliminatable},
${isEliminatable}, ${isAlwaysInSlot},
${isAlwaysInSlot}, ${isLazilyCachedInSlot},
${isLazilyCachedInSlot}, ${isTypedMethod},
${isTypedMethod}, ${slotIndex},
${slotIndex} as u16, ),
)
} }
""", """,
opName=opName, opName=opName,
@ -5574,7 +5574,6 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
typedefs = [] typedefs = []
return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, typedefs, [ return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, typedefs, [
'core::nonzero::NonZero',
'js', 'js',
'js::JSCLASS_GLOBAL_SLOT_COUNT', 'js::JSCLASS_GLOBAL_SLOT_COUNT',
'js::JSCLASS_IS_DOMJSCLASS', '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_expando_object',
'dom::bindings::proxyhandler::get_property_descriptor', 'dom::bindings::proxyhandler::get_property_descriptor',
'dom::bindings::mozmap::MozMap', 'dom::bindings::mozmap::MozMap',
'dom::bindings::nonnull::NonNullJSObjectPtr',
'dom::bindings::num::Finite', 'dom::bindings::num::Finite',
'dom::bindings::str::ByteString', 'dom::bindings::str::ByteString',
'dom::bindings::str::DOMString', 'dom::bindings::str::DOMString',

View file

@ -34,6 +34,7 @@
use dom::bindings::error::{Error, Fallible}; use dom::bindings::error::{Error, Fallible};
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
use dom::bindings::reflector::{DomObject, Reflector}; use dom::bindings::reflector::{DomObject, Reflector};
use dom::bindings::root::DomRoot; 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_GetTwoByteStringCharsAndLength, JS_IsArrayObject, JS_IsExceptionPending};
use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars, MutableHandleValue}; use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars, MutableHandleValue};
use js::jsval::{ObjectValue, StringValue, UndefinedValue}; 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 libc;
use num_traits::Float; use num_traits::Float;
use servo_config::opts; use servo_config::opts;
@ -66,9 +67,19 @@ pub trait IDLInterface {
} }
/// A trait to mark an IDL interface as deriving from another one. /// 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 {} 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> { impl<T: Float + ToJSValConvertible> ToJSValConvertible for Finite<T> {
#[inline] #[inline]
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) { 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, name: b"Function\0" as *const _ as *const libc::c_char,
flags: 0, flags: 0,
cOps: &constructor_behavior.0, cOps: &constructor_behavior.0,
spec: ptr::null(), spec: 0 as *const _,
ext: ptr::null(), ext: 0 as *const _,
oOps: &OBJECT_OPS, oOps: &OBJECT_OPS,
}, },
proto_id: proto_id, proto_id: proto_id,

View file

@ -6,17 +6,17 @@
//! Implementation of `iterable<...>` and `iterable<..., ...>` WebIDL declarations. //! Implementation of `iterable<...>` and `iterable<..., ...>` WebIDL declarations.
use core::nonzero::NonZero;
use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyAndValueResult; use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyAndValueResult;
use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyOrValueResult; use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyOrValueResult;
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::root::{Dom, DomRoot};
use dom::bindings::trace::JSTraceable; use dom::bindings::trace::JSTraceable;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use js::conversions::ToJSValConvertible; use js::conversions::ToJSValConvertible;
use js::jsapi::{HandleValue, Heap, JSContext, JSObject, MutableHandleObject}; use js::jsapi::{HandleValue, Heap, JSContext, MutableHandleObject};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use std::cell::Cell; use std::cell::Cell;
use std::ptr; use std::ptr;
@ -73,7 +73,7 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> {
/// Return the next value from the iterable object. /// Return the next value from the iterable object.
#[allow(non_snake_case)] #[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(); let index = self.index.get();
rooted!(in(cx) let mut value = UndefinedValue()); rooted!(in(cx) let mut value = UndefinedValue());
rooted!(in(cx) let mut rval = ptr::null_mut()); 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); self.index.set(index + 1);
result.map(|_| { result.map(|_| {
assert!(!rval.is_null()); 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 iterable;
pub mod mozmap; pub mod mozmap;
pub mod namespace; pub mod namespace;
pub mod nonnull;
pub mod num; pub mod num;
pub mod proxyhandler; pub mod proxyhandler;
pub mod refcounted; 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 dom::bindings::interface::{create_object, define_on_global_object};
use js::jsapi::{HandleObject, JSClass, JSContext, JSFunctionSpec, MutableHandleObject}; use js::jsapi::{HandleObject, JSClass, JSContext, JSFunctionSpec, MutableHandleObject};
use libc; use libc;
use std::ptr;
/// The class of a namespace object. /// The class of a namespace object.
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
@ -22,8 +21,8 @@ impl NamespaceObjectClass {
NamespaceObjectClass(JSClass { NamespaceObjectClass(JSClass {
name: name as *const _ as *const libc::c_char, name: name as *const _ as *const libc::c_char,
flags: 0, flags: 0,
cOps: ptr::null_mut(), cOps: 0 as *mut _,
reserved: [ptr::null_mut(); 3], 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>`. //! originating `DomRoot<T>`.
//! //!
use core::nonzero::NonZero;
use dom::bindings::conversions::DerivedFrom; use dom::bindings::conversions::DerivedFrom;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::reflector::{DomObject, Reflector}; use dom::bindings::reflector::{DomObject, Reflector};
@ -35,12 +34,11 @@ use heapsize::HeapSizeOf;
use js::jsapi::{JSObject, JSTracer, Heap}; use js::jsapi::{JSObject, JSTracer, Heap};
use js::rust::GCMethods; use js::rust::GCMethods;
use mitochondria::OnceCell; use mitochondria::OnceCell;
use nonzero::NonZero;
use script_layout_interface::TrustedNodeAddress; use script_layout_interface::TrustedNodeAddress;
use std::cell::{Cell, UnsafeCell}; use std::cell::{Cell, UnsafeCell};
use std::default::Default; use std::default::Default;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
#[cfg(debug_assertions)]
use std::intrinsics::type_name;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem; use std::mem;
use std::ops::Deref; use std::ops::Deref;
@ -359,11 +357,11 @@ impl<T: DomObject> Deref for Dom<T> {
unsafe impl<T: DomObject> JSTraceable for Dom<T> { unsafe impl<T: DomObject> JSTraceable for Dom<T> {
unsafe fn trace(&self, trc: *mut JSTracer) { unsafe fn trace(&self, trc: *mut JSTracer) {
#[cfg(debug_assertions)] #[cfg(all(feature = "unstable", debug_assertions))]
let trace_str = format!("for {} on heap", type_name::<T>()); let trace_str = format!("for {} on heap", ::std::intrinsics::type_name::<T>());
#[cfg(debug_assertions)] #[cfg(all(feature = "unstable", debug_assertions))]
let trace_info = &trace_str[..]; let trace_info = &trace_str[..];
#[cfg(not(debug_assertions))] #[cfg(not(all(feature = "unstable", debug_assertions)))]
let trace_info = "for DOM object on heap"; let trace_info = "for DOM object on heap";
trace_reflector(trc, trace_reflector(trc,

View file

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

View file

@ -7,7 +7,6 @@ use bluetooth_traits::{BluetoothResponse, BluetoothResponseResult};
use bluetooth_traits::blocklist::{Blocklist, uuid_is_blocklisted}; use bluetooth_traits::blocklist::{Blocklist, uuid_is_blocklisted};
use bluetooth_traits::scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence}; use bluetooth_traits::scanfilter::{BluetoothScanfilter, BluetoothScanfilterSequence};
use bluetooth_traits::scanfilter::{RequestDeviceoptions, ServiceUUIDSequence}; use bluetooth_traits::scanfilter::{RequestDeviceoptions, ServiceUUIDSequence};
use core::clone::Clone;
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothDataFilterInit, BluetoothLEScanFilterInit}; use dom::bindings::codegen::Bindings::BluetoothBinding::{self, BluetoothDataFilterInit, BluetoothLEScanFilterInit};
use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothMethods, RequestDeviceOptions}; use dom::bindings::codegen::Bindings::BluetoothBinding::{BluetoothMethods, RequestDeviceOptions};

View file

@ -2,11 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use core::nonzero::NonZero;
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::CryptoBinding; use dom::bindings::codegen::Bindings::CryptoBinding;
use dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods; use dom::bindings::codegen::Bindings::CryptoBinding::CryptoMethods;
use dom::bindings::error::{Error, Fallible}; use dom::bindings::error::{Error, Fallible};
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::DomRoot; use dom::bindings::root::DomRoot;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
@ -44,7 +44,7 @@ impl CryptoMethods for Crypto {
unsafe fn GetRandomValues(&self, unsafe fn GetRandomValues(&self,
_cx: *mut JSContext, _cx: *mut JSContext,
input: *mut JSObject) input: *mut JSObject)
-> Fallible<NonZero<*mut JSObject>> { -> Fallible<NonNullJSObjectPtr> {
assert!(!input.is_null()); assert!(!input.is_null());
typedarray!(in(_cx) let mut array_buffer_view: ArrayBufferView = input); typedarray!(in(_cx) let mut array_buffer_view: ArrayBufferView = input);
let (array_type, mut data) = match array_buffer_view.as_mut() { 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); self.rng.borrow_mut().fill_bytes(&mut data);
Ok(NonZero::new_unchecked(input)) Ok(NonNullJSObjectPtr::new_unchecked(input))
} }
} }

View file

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cookie_rs; use cookie_rs;
use core::nonzero::NonZero;
use devtools_traits::ScriptToDevtoolsControlMsg; use devtools_traits::ScriptToDevtoolsControlMsg;
use document_loader::{DocumentLoader, LoadType}; use document_loader::{DocumentLoader, LoadType};
use dom::activation::{ActivationSource, synthetic_click_activation}; 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::codegen::UnionTypes::NodeOrString;
use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId}; use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, NodeTypeId};
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
use dom::bindings::refcounted::{Trusted, TrustedPromise}; use dom::bindings::refcounted::{Trusted, TrustedPromise};
use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::reflector::{DomObject, reflect_dom_object};
@ -99,7 +99,7 @@ use html5ever::{LocalName, Namespace, QualName};
use hyper::header::{Header, SetCookie}; use hyper::header::{Header, SetCookie};
use hyper_serde::Serde; use hyper_serde::Serde;
use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::ipc::{self, IpcSender};
use js::jsapi::{JSContext, JSObject, JSRuntime}; use js::jsapi::{JSContext, JSRuntime};
use js::jsapi::JS_GetRuntime; use js::jsapi::JS_GetRuntime;
use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER};
use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId}; use msg::constellation_msg::{BrowsingContextId, Key, KeyModifiers, KeyState, TopLevelBrowsingContextId};
@ -3536,7 +3536,7 @@ impl DocumentMethods for Document {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter // 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)] #[derive(HeapSizeOf, JSTraceable)]
struct NamedElementFilter { struct NamedElementFilter {
name: Atom, name: Atom,
@ -3604,7 +3604,7 @@ impl DocumentMethods for Document {
if elements.peek().is_none() { if elements.peek().is_none() {
// TODO: Step 2. // TODO: Step 2.
// Step 3. // Step 3.
return Some(NonZero::new_unchecked(first.reflector().get_jsobject().get())); return Some(NonNullJSObjectPtr::new_unchecked(first.reflector().get_jsobject().get()));
} }
} else { } else {
return None; return None;
@ -3615,7 +3615,7 @@ impl DocumentMethods for Document {
name: name, name: name,
}; };
let collection = HTMLCollection::create(self.window(), root, Box::new(filter)); 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 // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names

View file

@ -2,10 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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;
use dom::bindings::codegen::Bindings::GamepadBinding::GamepadMethods; use dom::bindings::codegen::Bindings::GamepadBinding::GamepadMethods;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::root::{Dom, DomRoot};
@ -131,8 +131,8 @@ impl GamepadMethods for Gamepad {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/gamepad/#dom-gamepad-axes // https://w3c.github.io/gamepad/#dom-gamepad-axes
unsafe fn Axes(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { unsafe fn Axes(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr {
NonZero::new_unchecked(self.axes.get()) NonNullJSObjectPtr::new_unchecked(self.axes.get())
} }
// https://w3c.github.io/gamepad/#dom-gamepad-buttons // https://w3c.github.io/gamepad/#dom-gamepad-buttons

View file

@ -2,10 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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;
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods; use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
use dom::bindings::error::{Fallible, Error}; use dom::bindings::error::{Fallible, Error};
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::DomRoot; use dom::bindings::root::DomRoot;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
@ -159,8 +159,8 @@ impl ImageDataMethods for ImageData {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://html.spec.whatwg.org/multipage/#dom-imagedata-data // 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()); assert!(!self.data.get().is_null());
NonZero::new_unchecked(self.data.get()) NonNullJSObjectPtr::new_unchecked(self.data.get())
} }
} }

View file

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use body::{BodyOperations, BodyType, consume_body, consume_body_with_promise}; use body::{BodyOperations, BodyType, consume_body, consume_body_with_promise};
use core::cell::Cell;
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::HeadersBinding::{HeadersInit, HeadersMethods}; use dom::bindings::codegen::Bindings::HeadersBinding::{HeadersInit, HeadersMethods};
use dom::bindings::codegen::Bindings::ResponseBinding; use dom::bindings::codegen::Bindings::ResponseBinding;
@ -24,7 +23,7 @@ use hyper::status::StatusCode;
use hyper_serde::Serde; use hyper_serde::Serde;
use net_traits::response::{ResponseBody as NetTraitsResponseBody}; use net_traits::response::{ResponseBody as NetTraitsResponseBody};
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::cell::Ref; use std::cell::{Cell, Ref};
use std::mem; use std::mem;
use std::rc::Rc; use std::rc::Rc;
use std::str::FromStr; use std::str::FromStr;

View file

@ -4,7 +4,6 @@
// check-tidy: no specs after this line // check-tidy: no specs after this line
use core::nonzero::NonZero;
use dom::bindings::callback::ExceptionHandling; use dom::bindings::callback::ExceptionHandling;
use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener; use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
use dom::bindings::codegen::Bindings::FunctionBinding::Function; 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::codegen::UnionTypes::{StringOrUnsignedLong, StringOrBoolean, UnsignedLongOrBoolean};
use dom::bindings::error::{Error, Fallible}; use dom::bindings::error::{Error, Fallible};
use dom::bindings::mozmap::MozMap; use dom::bindings::mozmap::MozMap;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
use dom::bindings::refcounted::TrustedPromise; use dom::bindings::refcounted::TrustedPromise;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
@ -151,20 +151,20 @@ impl TestBindingMethods for TestBinding {
} }
fn SetUnion9Attribute(&self, _: ByteStringOrLong) {} fn SetUnion9Attribute(&self, _: ByteStringOrLong) {}
#[allow(unsafe_code)] #[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)); rooted!(in(cx) let array = JS_NewUint8ClampedArray(cx, 16));
assert!(!array.is_null()); assert!(!array.is_null());
NonZero::new_unchecked(array.get()) NonNullJSObjectPtr::new_unchecked(array.get())
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() } unsafe fn AnyAttribute(&self, _: *mut JSContext) -> JSVal { NullValue() }
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn SetAnyAttribute(&self, _: *mut JSContext, _: HandleValue) {} unsafe fn SetAnyAttribute(&self, _: *mut JSContext, _: HandleValue) {}
#[allow(unsafe_code)] #[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)); rooted!(in(cx) let obj = JS_NewPlainObject(cx));
assert!(!obj.is_null()); assert!(!obj.is_null());
NonZero::new_unchecked(obj.get()) NonNullJSObjectPtr::new_unchecked(obj.get())
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {} unsafe fn SetObjectAttribute(&self, _: *mut JSContext, _: *mut JSObject) {}
@ -220,7 +220,7 @@ impl TestBindingMethods for TestBinding {
self.url.set(url); self.url.set(url);
} }
#[allow(unsafe_code)] #[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)] #[allow(unsafe_code)]
unsafe fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {} unsafe fn SetObjectAttributeNullable(&self, _: *mut JSContext, _: *mut JSObject) {}
fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> { fn GetUnionAttributeNullable(&self) -> Option<HTMLElementOrLong> {
@ -272,7 +272,7 @@ impl TestBindingMethods for TestBinding {
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() } unsafe fn ReceiveAny(&self, _: *mut JSContext) -> JSVal { NullValue() }
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn ReceiveObject(&self, cx: *mut JSContext) -> NonZero<*mut JSObject> { unsafe fn ReceiveObject(&self, cx: *mut JSContext) -> NonNullJSObjectPtr {
self.ObjectAttribute(cx) self.ObjectAttribute(cx)
} }
fn ReceiveUnion(&self) -> HTMLElementOrLong { HTMLElementOrLong::Long(0) } 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())) Some(Blob::new(&self.global(), BlobImpl::new_from_bytes(vec![]), "".to_owned()))
} }
#[allow(unsafe_code)] #[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) self.GetObjectAttributeNullable(cx)
} }
fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> { fn ReceiveNullableUnion(&self) -> Option<HTMLElementOrLong> {

View file

@ -2,16 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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;
use dom::bindings::codegen::Bindings::TextEncoderBinding::TextEncoderMethods; use dom::bindings::codegen::Bindings::TextEncoderBinding::TextEncoderMethods;
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::DomRoot; use dom::bindings::root::DomRoot;
use dom::bindings::str::{DOMString, USVString}; use dom::bindings::str::{DOMString, USVString};
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use js::jsapi::{JSContext, JSObject}; use js::jsapi::JSContext;
use js::typedarray::{Uint8Array, CreateWith}; use js::typedarray::{Uint8Array, CreateWith};
use std::ptr; use std::ptr;
@ -47,12 +47,12 @@ impl TextEncoderMethods for TextEncoder {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://encoding.spec.whatwg.org/#dom-textencoder-encode // 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(); let encoded = input.0.as_bytes();
rooted!(in(cx) let mut js_object = ptr::null_mut()); rooted!(in(cx) let mut js_object = ptr::null_mut());
assert!(Uint8Array::create(cx, CreateWith::Slice(&encoded), js_object.handle_mut()).is_ok()); 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())
} }
} }

View file

@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use canvas_traits::webgl::{webgl_channel, WebGLReceiver, WebVRCommand}; use canvas_traits::webgl::{webgl_channel, WebGLReceiver, WebVRCommand};
use core::ops::Deref;
use dom::bindings::callback::ExceptionHandling; use dom::bindings::callback::ExceptionHandling;
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceBinding::PerformanceMethods; use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceBinding::PerformanceMethods;
@ -38,6 +37,7 @@ use script_runtime::CommonScriptMsg;
use script_runtime::ScriptThreadEventCategory::WebVREvent; use script_runtime::ScriptThreadEventCategory::WebVREvent;
use std::cell::Cell; use std::cell::Cell;
use std::mem; use std::mem;
use std::ops::Deref;
use std::rc::Rc; use std::rc::Rc;
use std::sync::mpsc; use std::sync::mpsc;
use std::thread; use std::thread;

View file

@ -2,10 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use core::nonzero::NonZero;
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::VREyeParametersBinding; use dom::bindings::codegen::Bindings::VREyeParametersBinding;
use dom::bindings::codegen::Bindings::VREyeParametersBinding::VREyeParametersMethods; use dom::bindings::codegen::Bindings::VREyeParametersBinding::VREyeParametersMethods;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::root::{Dom, DomRoot};
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
@ -60,8 +60,8 @@ impl VREyeParameters {
impl VREyeParametersMethods for VREyeParameters { impl VREyeParametersMethods for VREyeParameters {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vreyeparameters-offset // https://w3c.github.io/webvr/#dom-vreyeparameters-offset
unsafe fn Offset(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { unsafe fn Offset(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr {
NonZero::new_unchecked(self.offset.get()) NonNullJSObjectPtr::new_unchecked(self.offset.get())
} }
// https://w3c.github.io/webvr/#dom-vreyeparameters-fieldofview // https://w3c.github.io/webvr/#dom-vreyeparameters-fieldofview

View file

@ -2,10 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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;
use dom::bindings::codegen::Bindings::VRFrameDataBinding::VRFrameDataMethods; use dom::bindings::codegen::Bindings::VRFrameDataBinding::VRFrameDataMethods;
use dom::bindings::error::Fallible; use dom::bindings::error::Fallible;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot}; use dom::bindings::root::{Dom, DomRoot};
@ -118,26 +118,26 @@ impl VRFrameDataMethods for VRFrameData {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrframedata-leftprojectionmatrix // https://w3c.github.io/webvr/#dom-vrframedata-leftprojectionmatrix
unsafe fn LeftProjectionMatrix(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { unsafe fn LeftProjectionMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr {
NonZero::new_unchecked(self.left_proj.get()) NonNullJSObjectPtr::new_unchecked(self.left_proj.get())
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrframedata-leftviewmatrix // https://w3c.github.io/webvr/#dom-vrframedata-leftviewmatrix
unsafe fn LeftViewMatrix(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { unsafe fn LeftViewMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr {
NonZero::new_unchecked(self.left_view.get()) NonNullJSObjectPtr::new_unchecked(self.left_view.get())
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrframedata-rightprojectionmatrix // https://w3c.github.io/webvr/#dom-vrframedata-rightprojectionmatrix
unsafe fn RightProjectionMatrix(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { unsafe fn RightProjectionMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr {
NonZero::new_unchecked(self.right_proj.get()) NonNullJSObjectPtr::new_unchecked(self.right_proj.get())
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrframedata-rightviewmatrix // https://w3c.github.io/webvr/#dom-vrframedata-rightviewmatrix
unsafe fn RightViewMatrix(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { unsafe fn RightViewMatrix(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr {
NonZero::new_unchecked(self.right_view.get()) NonNullJSObjectPtr::new_unchecked(self.right_view.get())
} }
// https://w3c.github.io/webvr/#dom-vrframedata-pose // https://w3c.github.io/webvr/#dom-vrframedata-pose

View file

@ -2,9 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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;
use dom::bindings::codegen::Bindings::VRPoseBinding::VRPoseMethods; use dom::bindings::codegen::Bindings::VRPoseBinding::VRPoseMethods;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::DomRoot; use dom::bindings::root::DomRoot;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
@ -52,13 +52,13 @@ unsafe fn update_or_create_typed_array(cx: *mut JSContext,
#[inline] #[inline]
#[allow(unsafe_code)] #[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(); let js_object = heap.get();
if js_object.is_null() { if js_object.is_null() {
None None
} else { } else {
unsafe { unsafe {
Some(NonZero::new_unchecked(js_object)) Some(NonNullJSObjectPtr::new_unchecked(js_object))
} }
} }
} }
@ -101,37 +101,37 @@ impl VRPose {
impl VRPoseMethods for VRPose { impl VRPoseMethods for VRPose {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrpose-position // 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) heap_to_option(&self.position)
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrpose-linearvelocity // 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) heap_to_option(&self.linear_vel)
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrpose-linearacceleration // 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) heap_to_option(&self.linear_acc)
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrpose-orientation // 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) heap_to_option(&self.orientation)
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrpose-angularvelocity // 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) heap_to_option(&self.angular_vel)
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrpose-angularacceleration // 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) heap_to_option(&self.angular_acc)
} }
} }

View file

@ -2,10 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use core::nonzero::NonZero;
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::VRStageParametersBinding; use dom::bindings::codegen::Bindings::VRStageParametersBinding;
use dom::bindings::codegen::Bindings::VRStageParametersBinding::VRStageParametersMethods; use dom::bindings::codegen::Bindings::VRStageParametersBinding::VRStageParametersMethods;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::num::Finite; use dom::bindings::num::Finite;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::DomRoot; use dom::bindings::root::DomRoot;
@ -69,8 +69,8 @@ impl VRStageParameters {
impl VRStageParametersMethods for VRStageParameters { impl VRStageParametersMethods for VRStageParameters {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://w3c.github.io/webvr/#dom-vrstageparameters-sittingtostandingtransform // https://w3c.github.io/webvr/#dom-vrstageparameters-sittingtostandingtransform
unsafe fn SittingToStandingTransform(&self, _cx: *mut JSContext) -> NonZero<*mut JSObject> { unsafe fn SittingToStandingTransform(&self, _cx: *mut JSContext) -> NonNullJSObjectPtr {
NonZero::new_unchecked(self.transform.get()) NonNullJSObjectPtr::new_unchecked(self.transform.get())
} }
// https://w3c.github.io/webvr/#dom-vrstageparameters-sizex // https://w3c.github.io/webvr/#dom-vrstageparameters-sizex

View file

@ -3,8 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use canvas_traits::webgl::WebGLVertexArrayId; use canvas_traits::webgl::WebGLVertexArrayId;
use core::cell::Ref;
use core::iter::FromIterator;
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::WebGLVertexArrayObjectOESBinding; use dom::bindings::codegen::Bindings::WebGLVertexArrayObjectOESBinding;
use dom::bindings::reflector::reflect_dom_object; use dom::bindings::reflector::reflect_dom_object;
@ -13,8 +11,9 @@ use dom::globalscope::GlobalScope;
use dom::webglbuffer::WebGLBuffer; use dom::webglbuffer::WebGLBuffer;
use dom::webglobject::WebGLObject; use dom::webglobject::WebGLObject;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell; use std::cell::{Cell, Ref};
use std::collections::HashMap; use std::collections::HashMap;
use std::iter::FromIterator;
#[dom_struct] #[dom_struct]
pub struct WebGLVertexArrayObjectOES { pub struct WebGLVertexArrayObjectOES {

View file

@ -3,23 +3,23 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use canvas_traits::webgl::WebGLError; use canvas_traits::webgl::WebGLError;
use core::iter::FromIterator;
use core::nonzero::NonZero;
use dom::bindings::cell::DomRefCell; use dom::bindings::cell::DomRefCell;
use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants; use dom::bindings::codegen::Bindings::OESStandardDerivativesBinding::OESStandardDerivativesConstants;
use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants; use dom::bindings::codegen::Bindings::OESTextureHalfFloatBinding::OESTextureHalfFloatConstants;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::root::DomRoot; use dom::bindings::root::DomRoot;
use dom::bindings::trace::JSTraceable; use dom::bindings::trace::JSTraceable;
use dom::webglrenderingcontext::WebGLRenderingContext; use dom::webglrenderingcontext::WebGLRenderingContext;
use fnv::{FnvHashMap, FnvHashSet}; use fnv::{FnvHashMap, FnvHashSet};
use gleam::gl::GLenum; use gleam::gl::GLenum;
use heapsize::HeapSizeOf; use heapsize::HeapSizeOf;
use js::jsapi::{JSContext, JSObject}; use js::jsapi::JSContext;
use js::jsval::JSVal; use js::jsval::JSVal;
use ref_filter_map::ref_filter_map; use ref_filter_map::ref_filter_map;
use std::cell::Ref; use std::cell::Ref;
use std::collections::HashMap; use std::collections::HashMap;
use std::iter::FromIterator;
use super::{ext, WebGLExtension}; use super::{ext, WebGLExtension};
use super::wrapper::{WebGLExtensionWrapper, TypedWebGLExtensionWrapper}; use super::wrapper::{WebGLExtensionWrapper, TypedWebGLExtensionWrapper};
@ -109,7 +109,7 @@ impl WebGLExtensions {
.collect() .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(); let name = name.to_uppercase();
self.extensions.borrow().get(&name).and_then(|extension| { self.extensions.borrow().get(&name).and_then(|extension| {
if extension.is_supported(self) { if extension.is_supported(self) {

View file

@ -2,13 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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::reflector::DomObject;
use dom::bindings::root::{DomRoot, MutNullableDom}; use dom::bindings::root::{DomRoot, MutNullableDom};
use dom::bindings::trace::JSTraceable; use dom::bindings::trace::JSTraceable;
use dom::webglrenderingcontext::WebGLRenderingContext; use dom::webglrenderingcontext::WebGLRenderingContext;
use heapsize::HeapSizeOf; use heapsize::HeapSizeOf;
use js::jsapi::JSObject;
use std::any::Any; use std::any::Any;
use super::{WebGLExtension, WebGLExtensions}; use super::{WebGLExtension, WebGLExtensions};
@ -18,7 +17,7 @@ pub trait WebGLExtensionWrapper: JSTraceable + HeapSizeOf {
fn instance_or_init(&self, fn instance_or_init(&self,
ctx: &WebGLRenderingContext, ctx: &WebGLRenderingContext,
ext: &WebGLExtensions) ext: &WebGLExtensions)
-> NonZero<*mut JSObject>; -> NonNullJSObjectPtr;
fn is_supported(&self, &WebGLExtensions) -> bool; fn is_supported(&self, &WebGLExtensions) -> bool;
fn is_enabled(&self) -> bool; fn is_enabled(&self) -> bool;
fn enable(&self, ext: &WebGLExtensions); fn enable(&self, ext: &WebGLExtensions);
@ -48,7 +47,7 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T>
fn instance_or_init(&self, fn instance_or_init(&self,
ctx: &WebGLRenderingContext, ctx: &WebGLRenderingContext,
ext: &WebGLExtensions) ext: &WebGLExtensions)
-> NonZero<*mut JSObject> { -> NonNullJSObjectPtr {
let mut enabled = true; let mut enabled = true;
let extension = self.extension.or_init(|| { let extension = self.extension.or_init(|| {
enabled = false; enabled = false;
@ -58,7 +57,7 @@ impl<T> WebGLExtensionWrapper for TypedWebGLExtensionWrapper<T>
self.enable(ext); self.enable(ext);
} }
unsafe { unsafe {
NonZero::new_unchecked(extension.reflector().get_jsobject().get()) NonNullJSObjectPtr::new_unchecked(extension.reflector().get_jsobject().get())
} }
} }

View file

@ -9,9 +9,6 @@ use canvas_traits::webgl::{WebGLFramebufferBindingRequest, WebGLMsg, WebGLMsgSen
use canvas_traits::webgl::DOMToTextureCommand; use canvas_traits::webgl::DOMToTextureCommand;
use canvas_traits::webgl::WebGLError::*; use canvas_traits::webgl::WebGLError::*;
use canvas_traits::webgl::webgl_channel; 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::cell::DomRefCell;
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes}; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
@ -20,6 +17,7 @@ use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasE
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible}; use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
use dom::bindings::error::{Error, Fallible}; use dom::bindings::error::{Error, Fallible};
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object}; use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom}; use dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
@ -57,7 +55,8 @@ use net_traits::image_cache::ImageResponse;
use offscreen_gl_context::{GLContextAttributes, GLLimits}; use offscreen_gl_context::{GLContextAttributes, GLLimits};
use script_layout_interface::HTMLCanvasDataSource; use script_layout_interface::HTMLCanvasDataSource;
use servo_config::prefs::PREFS; use servo_config::prefs::PREFS;
use std::cell::Cell; use std::cell::{Cell, Ref};
use std::iter::FromIterator;
use webrender_api; use webrender_api;
type ImagePixelResult = Result<(Vec<u8>, Size2D<i32>, bool), ()>; type ImagePixelResult = Result<(Vec<u8>, Size2D<i32>, bool), ()>;
@ -1379,7 +1378,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14 // https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.14
unsafe fn GetExtension(&self, _cx: *mut JSContext, name: DOMString) unsafe fn GetExtension(&self, _cx: *mut JSContext, name: DOMString)
-> Option<NonZero<*mut JSObject>> { -> Option<NonNullJSObjectPtr> {
self.extension_manager.init_once(|| { self.extension_manager.init_once(|| {
self.get_gl_extensions() self.get_gl_extensions()
}); });

View file

@ -808,6 +808,7 @@ impl WindowMethods for Window {
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn Trap(&self) { fn Trap(&self) {
#[cfg(feature = "unstable")]
unsafe { ::std::intrinsics::breakpoint() } unsafe { ::std::intrinsics::breakpoint() }
} }

View file

@ -2,11 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use core::nonzero::NonZero;
use document_loader::DocumentLoader; use document_loader::DocumentLoader;
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::XMLDocumentBinding::{self, XMLDocumentMethods}; use dom::bindings::codegen::Bindings::XMLDocumentBinding::{self, XMLDocumentMethods};
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::nonnull::NonNullJSObjectPtr;
use dom::bindings::reflector::reflect_dom_object; use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::root::DomRoot; use dom::bindings::root::DomRoot;
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
@ -15,7 +15,7 @@ use dom::location::Location;
use dom::node::Node; use dom::node::Node;
use dom::window::Window; use dom::window::Window;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use js::jsapi::{JSContext, JSObject}; use js::jsapi::JSContext;
use script_traits::DocumentActivity; use script_traits::DocumentActivity;
use servo_url::{MutableOrigin, ServoUrl}; use servo_url::{MutableOrigin, ServoUrl};
@ -100,7 +100,7 @@ impl XMLDocumentMethods for XMLDocument {
#[allow(unsafe_code)] #[allow(unsafe_code)]
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter // 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) self.upcast::<Document>().NamedGetter(_cx, name)
} }
} }

View file

@ -2,14 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![cfg_attr(feature = "unstable", feature(core_intrinsics))]
#![cfg_attr(feature = "unstable", feature(on_unimplemented))]
#![feature(conservative_impl_trait)] #![feature(conservative_impl_trait)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(const_ptr_null)]
#![feature(const_ptr_null_mut)]
#![feature(core_intrinsics)]
#![feature(mpsc_select)] #![feature(mpsc_select)]
#![feature(nonzero)]
#![feature(on_unimplemented)]
#![feature(plugin)] #![feature(plugin)]
#![feature(proc_macro)] #![feature(proc_macro)]
@ -31,7 +28,6 @@ extern crate byteorder;
extern crate canvas_traits; extern crate canvas_traits;
extern crate caseless; extern crate caseless;
extern crate cookie as cookie_rs; extern crate cookie as cookie_rs;
extern crate core;
#[macro_use] extern crate cssparser; #[macro_use] extern crate cssparser;
#[macro_use] extern crate deny_public_fields; #[macro_use] extern crate deny_public_fields;
extern crate devtools_traits; extern crate devtools_traits;
@ -67,6 +63,7 @@ extern crate mime_guess;
extern crate mitochondria; extern crate mitochondria;
extern crate msg; extern crate msg;
extern crate net_traits; extern crate net_traits;
extern crate nonzero;
extern crate num_traits; extern crate num_traits;
extern crate offscreen_gl_context; extern crate offscreen_gl_context;
extern crate open; extern crate open;

View file

@ -5,7 +5,6 @@
//! Machinery for [tasks](https://html.spec.whatwg.org/multipage/#concept-task). //! Machinery for [tasks](https://html.spec.whatwg.org/multipage/#concept-task).
use std::fmt; use std::fmt;
use std::intrinsics;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -33,7 +32,10 @@ macro_rules! task {
pub trait TaskOnce: Send { pub trait TaskOnce: Send {
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn name(&self) -> &'static str { fn name(&self) -> &'static str {
unsafe { intrinsics::type_name::<Self>() } #[cfg(feature = "unstable")]
unsafe { ::std::intrinsics::type_name::<Self>() }
#[cfg(not(feature = "unstable"))]
{ "(task name unknown)" }
} }
fn run_once(self); fn run_once(self);

View file

@ -45,10 +45,9 @@ use canvas_traits::canvas::CanvasMsg;
use ipc_channel::ipc::IpcSender; use ipc_channel::ipc::IpcSender;
use libc::c_void; use libc::c_void;
use net_traits::image_cache::PendingImageId; use net_traits::image_cache::PendingImageId;
use nonzero::NonZeroUsize; use nonzero::NonZero;
use script_traits::UntrustedNodeAddress; use script_traits::UntrustedNodeAddress;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::marker::PhantomData;
use std::sync::atomic::AtomicIsize; use std::sync::atomic::AtomicIsize;
use style::data::ElementData; use style::data::ElementData;
@ -78,8 +77,7 @@ pub struct OpaqueStyleAndLayoutData {
// NB: We really store a `StyleAndLayoutData` here, so be careful! // NB: We really store a `StyleAndLayoutData` here, so be careful!
#[ignore_heap_size_of = "TODO(#6910) Box value that should be counted but \ #[ignore_heap_size_of = "TODO(#6910) Box value that should be counted but \
the type lives in layout"] the type lives in layout"]
pub ptr: NonZeroUsize, pub ptr: NonZero<*mut StyleData>,
pub phantom: PhantomData<*mut StyleData>,
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]

View file

@ -23,6 +23,7 @@ unstable = [
"gfx/unstable", "gfx/unstable",
"msg/unstable", "msg/unstable",
"profile/unstable", "profile/unstable",
"script/unstable",
] ]
[dependencies] [dependencies]

View file

@ -84,6 +84,7 @@ linux-dev:
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach test-unit - env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach test-unit
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach package --dev - env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach package --dev
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach build-cef - env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach build-cef
- env SERVO_RUSTC_LLVM_ASSERTIONS=1 ./mach build --dev --no-default-features --features default-except-unstable
- ./mach build-geckolib - ./mach build-geckolib
- ./mach test-stylo - ./mach test-stylo
- bash ./etc/ci/lockfile_changed.sh - bash ./etc/ci/lockfile_changed.sh

View file

@ -15,7 +15,7 @@
//! //!
//! [glutin]: https://github.com/tomaka/glutin //! [glutin]: https://github.com/tomaka/glutin
#![feature(core_intrinsics)] #![cfg_attr(feature = "unstable", feature(core_intrinsics))]
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
extern crate android_injected_glue; extern crate android_injected_glue;
@ -26,7 +26,7 @@ extern crate glutin_app as app;
extern crate log; extern crate log;
// The Servo engine // The Servo engine
extern crate servo; extern crate servo;
#[cfg(not(target_os = "android"))] #[cfg(all(feature = "unstable", not(target_os = "android")))]
#[macro_use] #[macro_use]
extern crate sig; extern crate sig;
@ -57,7 +57,7 @@ pub mod platform {
pub fn deinit() {} pub fn deinit() {}
} }
#[cfg(not(target_os = "android"))] #[cfg(all(feature = "unstable", not(target_os = "android")))]
fn install_crash_handler() { fn install_crash_handler() {
use backtrace::Backtrace; use backtrace::Backtrace;
use sig::ffi::Sig; use sig::ffi::Sig;
@ -83,7 +83,7 @@ fn install_crash_handler() {
signal!(Sig::BUS, handler); // handle invalid memory access signal!(Sig::BUS, handler); // handle invalid memory access
} }
#[cfg(target_os = "android")] #[cfg(any(not(feature = "unstable"), target_os = "android"))]
fn install_crash_handler() {} fn install_crash_handler() {}
fn main() { fn main() {

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![cfg(test)] #![cfg(test)]
#![feature(plugin, test)] #![feature(test)]
extern crate app_units; extern crate app_units;
extern crate cssparser; extern crate cssparser;