Permalink
Browse files

Don’t rely on unstable features in rust-mozjs, so we can remove them.

  • Loading branch information...
SimonSapin committed Oct 12, 2017
1 parent 01e2f3d commit 8ca7c3ef75314cad057b00381a74a8dd0799bbfd
Showing with 41 additions and 14 deletions.
  1. +12 −12 components/script/dom/bindings/codegen/CodegenRust.py
  2. +29 −2 components/script/dom/bindings/conversions.rs
@@ -2249,6 +2249,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
'dom::bindings::conversions::ConversionResult',
'dom::bindings::conversions::FromJSValConvertible',
'dom::bindings::conversions::ToJSValConvertible',
'dom::bindings::conversions::ToJSValConvertible2',
'dom::bindings::conversions::ConversionBehavior',
'dom::bindings::conversions::StringificationBehavior',
'dom::bindings::conversions::root_from_handlevalue',
@@ -3660,18 +3661,16 @@ def jitInfoInitializer(isTypedMethod):
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,
)
((JSJitInfo_OpType::${opType} as u8 as u32) << 0) |
((JSJitInfo_AliasSet::${aliasSet} as u8 as u32) << 4) |
((JSValueType::${returnType} as u8 as u32) << 8) |
((${isInfallible} as u32) << 16) |
((${isMovable} as u32) << 17) |
((${isEliminatable} as u32) << 18) |
((${isAlwaysInSlot} as u32) << 19) |
((${isLazilyCachedInSlot} as u32) << 20) |
((${isTypedMethod} as u32) << 21) |
((${slotIndex} as u32) << 22)
}
""",
opName=opName,
@@ -5760,6 +5759,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'dom::bindings::conversions::IDLInterface',
'dom::bindings::conversions::StringificationBehavior',
'dom::bindings::conversions::ToJSValConvertible',
'dom::bindings::conversions::ToJSValConvertible2',
'dom::bindings::conversions::is_array_like',
'dom::bindings::conversions::native_from_handlevalue',
'dom::bindings::conversions::native_from_object',
@@ -32,6 +32,7 @@
//! | sequences | `Vec<T>` |
//! | union types | `T` |
use core::nonzero::NonZero;
use dom::bindings::error::{Error, Fallible};
use dom::bindings::inheritance::Castable;
use dom::bindings::num::Finite;
@@ -52,13 +53,39 @@ use js::jsapi::{HandleId, HandleObject, HandleValue, JSContext, JSObject, JSStri
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetProperty, JS_GetReservedSlot};
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::jsval::{ObjectValue, StringValue, UndefinedValue, NullValue};
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;
use std::{char, ffi, ptr, slice};
/// Like js::conversions::ToJSValConvertible
pub trait ToJSValConvertible2 {
/// Convert `self` to a `JSVal`. JSAPI failure causes a panic.
#[inline]
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue);
}
// https://heycam.github.io/webidl/#es-object
impl ToJSValConvertible2 for NonZero<*mut JSObject> {
#[inline]
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
rval.set(ObjectValue(self.get()));
maybe_wrap_object_value(cx, rval);
}
}
impl<T: ToJSValConvertible2> ToJSValConvertible2 for Option<T> {
#[inline]
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
match self {
&Some(ref value) => value.to_jsval(cx, rval),
&None => rval.set(NullValue()),
}
}
}
/// A trait to check whether a given `JSObject` implements an IDL interface.
pub trait IDLInterface {
/// Returns whether the given DOM class derives that interface.

0 comments on commit 8ca7c3e

Please sign in to comment.