зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1617369 - Reformat js/ using rustfmt r=arai,bbouvier
Differential Revision: https://phabricator.services.mozilla.com/D63952 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
fff839290a
Коммит
31e4471215
|
@ -28,8 +28,7 @@ fn build_jsglue_cpp() {
|
|||
|
||||
/// Find the public include directory within our mozjs-sys crate dependency.
|
||||
fn get_mozjs_include_dir() -> path::PathBuf {
|
||||
let out_dir = env::var("OUT_DIR")
|
||||
.expect("cargo should invoke us with the OUT_DIR env var set");
|
||||
let out_dir = env::var("OUT_DIR").expect("cargo should invoke us with the OUT_DIR env var set");
|
||||
|
||||
let mut target_build_dir = path::PathBuf::from(out_dir);
|
||||
target_build_dir.push("../../");
|
||||
|
@ -37,12 +36,13 @@ fn get_mozjs_include_dir() -> path::PathBuf {
|
|||
let mut include_dir_glob = target_build_dir.display().to_string();
|
||||
include_dir_glob.push_str("mozjs_sys-*/out/dist/include");
|
||||
|
||||
let entries = glob::glob(&include_dir_glob)
|
||||
.expect("Should find entries for mozjs-sys include dir");
|
||||
let entries =
|
||||
glob::glob(&include_dir_glob).expect("Should find entries for mozjs-sys include dir");
|
||||
|
||||
for entry in entries {
|
||||
if let Ok(path) = entry {
|
||||
return path.canonicalize()
|
||||
return path
|
||||
.canonicalize()
|
||||
.expect("Should canonicalize include path");
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,8 @@ fn build_jsapi_bindings() {
|
|||
}
|
||||
|
||||
let include_dir = get_mozjs_include_dir();
|
||||
let include_dir = include_dir.to_str()
|
||||
let include_dir = include_dir
|
||||
.to_str()
|
||||
.expect("Path to mozjs include dir should be utf-8");
|
||||
builder = builder.clang_arg("-I");
|
||||
builder = builder.clang_arg(include_dir);
|
||||
|
@ -115,16 +116,19 @@ fn build_jsapi_bindings() {
|
|||
builder = builder.blacklist_type(ty);
|
||||
}
|
||||
|
||||
let bindings = builder.generate()
|
||||
let bindings = builder
|
||||
.generate()
|
||||
.expect("Should generate JSAPI bindings OK");
|
||||
|
||||
let out = path::PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
|
||||
if cfg!(feature = "debugmozjs") {
|
||||
bindings.write_to_file(out.join("jsapi_debug.rs"))
|
||||
bindings
|
||||
.write_to_file(out.join("jsapi_debug.rs"))
|
||||
.expect("Should write bindings to file OK");
|
||||
} else {
|
||||
bindings.write_to_file(out.join("jsapi.rs"))
|
||||
bindings
|
||||
.write_to_file(out.join("jsapi.rs"))
|
||||
.expect("Should write bindings to file OK");
|
||||
}
|
||||
|
||||
|
@ -142,7 +146,8 @@ const UNSAFE_IMPL_SYNC_TYPES: &'static [&'static str] = &[
|
|||
|
||||
/// Flags passed through bindgen directly to Clang.
|
||||
const EXTRA_CLANG_FLAGS: &'static [&'static str] = &[
|
||||
"-x", "c++",
|
||||
"-x",
|
||||
"c++",
|
||||
"-std=gnu++17",
|
||||
"-fno-sized-deallocation",
|
||||
"-fno-aligned-new",
|
||||
|
|
|
@ -11,50 +11,30 @@ pub struct AutoRealm(JSAutoRealm);
|
|||
|
||||
impl AutoRealm {
|
||||
#[cfg(feature = "debugmozjs")]
|
||||
pub unsafe fn with_obj(cx: *mut JSContext,
|
||||
target: *mut JSObject)
|
||||
-> AutoRealm
|
||||
{
|
||||
pub unsafe fn with_obj(cx: *mut JSContext, target: *mut JSObject) -> AutoRealm {
|
||||
let mut notifier = mozilla::detail::GuardObjectNotifier {
|
||||
mStatementDone: ptr::null_mut(),
|
||||
};
|
||||
|
||||
AutoRealm(
|
||||
JSAutoRealm::new(
|
||||
cx,
|
||||
target,
|
||||
&mut notifier as *mut _))
|
||||
AutoRealm(JSAutoRealm::new(cx, target, &mut notifier as *mut _))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "debugmozjs"))]
|
||||
pub unsafe fn with_obj(cx: *mut JSContext,
|
||||
target: *mut JSObject)
|
||||
-> AutoRealm
|
||||
{
|
||||
pub unsafe fn with_obj(cx: *mut JSContext, target: *mut JSObject) -> AutoRealm {
|
||||
AutoRealm(JSAutoRealm::new(cx, target))
|
||||
}
|
||||
|
||||
#[cfg(feature = "debugmozjs")]
|
||||
pub unsafe fn with_script(cx: *mut JSContext,
|
||||
target: *mut JSScript)
|
||||
-> AutoRealm
|
||||
{
|
||||
pub unsafe fn with_script(cx: *mut JSContext, target: *mut JSScript) -> AutoRealm {
|
||||
let mut notifier = mozilla::detail::GuardObjectNotifier {
|
||||
mStatementDone: ptr::null_mut(),
|
||||
};
|
||||
|
||||
AutoRealm(
|
||||
JSAutoRealm::new1(
|
||||
cx,
|
||||
target,
|
||||
&mut notifier as *mut _))
|
||||
AutoRealm(JSAutoRealm::new1(cx, target, &mut notifier as *mut _))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "debugmozjs"))]
|
||||
pub unsafe fn with_script(cx: *mut JSContext,
|
||||
target: *mut JSScript)
|
||||
-> AutoRealm
|
||||
{
|
||||
pub unsafe fn with_script(cx: *mut JSContext, target: *mut JSScript) -> AutoRealm {
|
||||
AutoRealm(JSAutoRealm::new1(cx, target))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,11 +35,11 @@ use glue::RUST_JS_NumberValue;
|
|||
use heap::Heap;
|
||||
use jsapi::root::*;
|
||||
use jsval::{BooleanValue, Int32Value, NullValue, UInt32Value, UndefinedValue};
|
||||
use jsval::{ObjectValue, ObjectOrNullValue, StringValue};
|
||||
use rust::{ToBoolean, ToInt32, ToInt64, ToNumber, ToUint16, ToUint32, ToUint64};
|
||||
use rust::{ToString, maybe_wrap_object_or_null_value, maybe_wrap_value};
|
||||
use jsval::{ObjectOrNullValue, ObjectValue, StringValue};
|
||||
use libc;
|
||||
use num_traits::{Bounded, Zero};
|
||||
use rust::{maybe_wrap_object_or_null_value, maybe_wrap_value, ToString};
|
||||
use rust::{ToBoolean, ToInt32, ToInt64, ToNumber, ToUint16, ToUint32, ToUint64};
|
||||
use std::borrow::Cow;
|
||||
use std::rc::Rc;
|
||||
use std::{ptr, slice};
|
||||
|
@ -49,13 +49,13 @@ trait As<O>: Copy {
|
|||
}
|
||||
|
||||
macro_rules! impl_as {
|
||||
($I:ty, $O:ty) => (
|
||||
($I:ty, $O:ty) => {
|
||||
impl As<$O> for $I {
|
||||
fn cast(self) -> $O {
|
||||
self as $O
|
||||
}
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
impl_as!(f64, u8);
|
||||
|
@ -105,7 +105,7 @@ impl<T> ConversionResult<T> {
|
|||
/// Map a function over the `Success` value.
|
||||
pub fn map<F, U>(self, mut f: F) -> ConversionResult<U>
|
||||
where
|
||||
F: FnMut(T) -> U
|
||||
F: FnMut(T) -> U,
|
||||
{
|
||||
match self {
|
||||
ConversionResult::Success(t) => ConversionResult::Success(f(t)),
|
||||
|
@ -131,10 +131,11 @@ pub trait FromJSValConvertible: Sized {
|
|||
/// argument.
|
||||
/// If it returns `Err(())`, a JSAPI exception is pending.
|
||||
/// If it returns `Ok(Failure(reason))`, there is no pending JSAPI exception.
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: Self::Config)
|
||||
-> Result<ConversionResult<Self>, ()>;
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: Self::Config,
|
||||
) -> Result<ConversionResult<Self>, ()>;
|
||||
}
|
||||
|
||||
/// Behavior for converting out-of-range integers.
|
||||
|
@ -154,11 +155,14 @@ pub struct Default<T>(pub T);
|
|||
|
||||
impl<T> FromJSValConvertible for Default<T>
|
||||
where
|
||||
T: FromJSValConvertible<Config = ConversionBehavior>
|
||||
T: FromJSValConvertible<Config = ConversionBehavior>,
|
||||
{
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(cx: *mut JSContext, val: JS::HandleValue, _: ())
|
||||
-> Result<ConversionResult<Self>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
_: (),
|
||||
) -> Result<ConversionResult<Self>, ()> {
|
||||
T::from_jsval(cx, val, ConversionBehavior::Default).map(|conv| conv.map(Default))
|
||||
}
|
||||
}
|
||||
|
@ -168,14 +172,16 @@ where
|
|||
pub struct EnforceRange<T>(pub T);
|
||||
|
||||
impl<T> FromJSValConvertible for EnforceRange<T>
|
||||
where
|
||||
T: FromJSValConvertible<Config = ConversionBehavior>
|
||||
where
|
||||
T: FromJSValConvertible<Config = ConversionBehavior>,
|
||||
{
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(cx: *mut JSContext, val: JS::HandleValue, _: ())
|
||||
-> Result<ConversionResult<Self>, ()> {
|
||||
T::from_jsval(cx, val, ConversionBehavior::EnforceRange)
|
||||
.map(|conv| conv.map(EnforceRange))
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
_: (),
|
||||
) -> Result<ConversionResult<Self>, ()> {
|
||||
T::from_jsval(cx, val, ConversionBehavior::EnforceRange).map(|conv| conv.map(EnforceRange))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,22 +190,25 @@ impl<T> FromJSValConvertible for EnforceRange<T>
|
|||
pub struct Clamp<T>(pub T);
|
||||
|
||||
impl<T> FromJSValConvertible for Clamp<T>
|
||||
where
|
||||
T: FromJSValConvertible<Config = ConversionBehavior>
|
||||
where
|
||||
T: FromJSValConvertible<Config = ConversionBehavior>,
|
||||
{
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(cx: *mut JSContext, val: JS::HandleValue, _: ())
|
||||
-> Result<ConversionResult<Self>, ()> {
|
||||
T::from_jsval(cx, val, ConversionBehavior::Clamp)
|
||||
.map(|conv| conv.map(Clamp))
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
_: (),
|
||||
) -> Result<ConversionResult<Self>, ()> {
|
||||
T::from_jsval(cx, val, ConversionBehavior::Clamp).map(|conv| conv.map(Clamp))
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to cast the number to a smaller type, but
|
||||
/// if it doesn't fit, it will return an error.
|
||||
unsafe fn enforce_range<D>(cx: *mut JSContext, d: f64) -> Result<ConversionResult<D>, ()>
|
||||
where D: Bounded + As<f64>,
|
||||
f64: As<D>
|
||||
where
|
||||
D: Bounded + As<f64>,
|
||||
f64: As<D>,
|
||||
{
|
||||
if d.is_infinite() {
|
||||
throw_type_error(cx, "value out of range in an EnforceRange argument");
|
||||
|
@ -219,8 +228,9 @@ unsafe fn enforce_range<D>(cx: *mut JSContext, d: f64) -> Result<ConversionResul
|
|||
/// round it to the MAX or MIN of the source type before casting it to
|
||||
/// the destination type.
|
||||
fn clamp_to<D>(d: f64) -> D
|
||||
where D: Bounded + As<f64> + Zero,
|
||||
f64: As<D>
|
||||
where
|
||||
D: Bounded + As<f64> + Zero,
|
||||
f64: As<D>,
|
||||
{
|
||||
if d.is_nan() {
|
||||
D::zero()
|
||||
|
@ -244,10 +254,11 @@ impl ToJSValConvertible for () {
|
|||
impl FromJSValConvertible for JS::HandleValue {
|
||||
type Config = ();
|
||||
#[inline]
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
_option: ())
|
||||
-> Result<ConversionResult<JS::HandleValue>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
_option: (),
|
||||
) -> Result<ConversionResult<JS::HandleValue>, ()> {
|
||||
if value.is_object() {
|
||||
js::AssertSameCompartment(cx, value.to_object());
|
||||
}
|
||||
|
@ -257,21 +268,25 @@ impl FromJSValConvertible for JS::HandleValue {
|
|||
|
||||
impl FromJSValConvertible for JS::Value {
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(_cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
_option: ())
|
||||
-> Result<ConversionResult<JS::Value>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
_cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
_option: (),
|
||||
) -> Result<ConversionResult<JS::Value>, ()> {
|
||||
Ok(ConversionResult::Success(value.get()))
|
||||
}
|
||||
}
|
||||
|
||||
impl FromJSValConvertible for Heap<JS::Value> {
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(_cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
_option: ())
|
||||
-> Result<ConversionResult<Self>, ()> {
|
||||
Ok(ConversionResult::Success(Heap::<JS::Value>::new(value.get())))
|
||||
unsafe fn from_jsval(
|
||||
_cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
_option: (),
|
||||
) -> Result<ConversionResult<Self>, ()> {
|
||||
Ok(ConversionResult::Success(Heap::<JS::Value>::new(
|
||||
value.get(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,18 +315,25 @@ impl ToJSValConvertible for Heap<JS::Value> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn convert_int_from_jsval<T, M>(cx: *mut JSContext, value: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
convert_fn: unsafe fn(*mut JSContext, JS::HandleValue) -> Result<M, ()>)
|
||||
-> Result<ConversionResult<T>, ()>
|
||||
where T: Bounded + Zero + As<f64>,
|
||||
M: Zero + As<T>,
|
||||
f64: As<T>
|
||||
unsafe fn convert_int_from_jsval<T, M>(
|
||||
cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
convert_fn: unsafe fn(*mut JSContext, JS::HandleValue) -> Result<M, ()>,
|
||||
) -> Result<ConversionResult<T>, ()>
|
||||
where
|
||||
T: Bounded + Zero + As<f64>,
|
||||
M: Zero + As<T>,
|
||||
f64: As<T>,
|
||||
{
|
||||
match option {
|
||||
ConversionBehavior::Default => Ok(ConversionResult::Success(try!(convert_fn(cx, value)).cast())),
|
||||
ConversionBehavior::Default => Ok(ConversionResult::Success(
|
||||
try!(convert_fn(cx, value)).cast(),
|
||||
)),
|
||||
ConversionBehavior::EnforceRange => enforce_range(cx, try!(ToNumber(cx, value))),
|
||||
ConversionBehavior::Clamp => Ok(ConversionResult::Success(clamp_to(try!(ToNumber(cx, value))))),
|
||||
ConversionBehavior::Clamp => Ok(ConversionResult::Success(clamp_to(try!(ToNumber(
|
||||
cx, value
|
||||
))))),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,7 +348,11 @@ impl ToJSValConvertible for bool {
|
|||
// https://heycam.github.io/webidl/#es-boolean
|
||||
impl FromJSValConvertible for bool {
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(_cx: *mut JSContext, val: JS::HandleValue, _option: ()) -> Result<ConversionResult<bool>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
_cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
_option: (),
|
||||
) -> Result<ConversionResult<bool>, ()> {
|
||||
Ok(ToBoolean(val)).map(ConversionResult::Success)
|
||||
}
|
||||
}
|
||||
|
@ -342,10 +368,11 @@ impl ToJSValConvertible for i8 {
|
|||
// https://heycam.github.io/webidl/#es-byte
|
||||
impl FromJSValConvertible for i8 {
|
||||
type Config = ConversionBehavior;
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior)
|
||||
-> Result<ConversionResult<i8>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
) -> Result<ConversionResult<i8>, ()> {
|
||||
convert_int_from_jsval(cx, val, option, ToInt32)
|
||||
}
|
||||
}
|
||||
|
@ -361,10 +388,11 @@ impl ToJSValConvertible for u8 {
|
|||
// https://heycam.github.io/webidl/#es-octet
|
||||
impl FromJSValConvertible for u8 {
|
||||
type Config = ConversionBehavior;
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior)
|
||||
-> Result<ConversionResult<u8>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
) -> Result<ConversionResult<u8>, ()> {
|
||||
convert_int_from_jsval(cx, val, option, ToInt32)
|
||||
}
|
||||
}
|
||||
|
@ -380,10 +408,11 @@ impl ToJSValConvertible for i16 {
|
|||
// https://heycam.github.io/webidl/#es-short
|
||||
impl FromJSValConvertible for i16 {
|
||||
type Config = ConversionBehavior;
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior)
|
||||
-> Result<ConversionResult<i16>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
) -> Result<ConversionResult<i16>, ()> {
|
||||
convert_int_from_jsval(cx, val, option, ToInt32)
|
||||
}
|
||||
}
|
||||
|
@ -399,10 +428,11 @@ impl ToJSValConvertible for u16 {
|
|||
// https://heycam.github.io/webidl/#es-unsigned-short
|
||||
impl FromJSValConvertible for u16 {
|
||||
type Config = ConversionBehavior;
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior)
|
||||
-> Result<ConversionResult<u16>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
) -> Result<ConversionResult<u16>, ()> {
|
||||
convert_int_from_jsval(cx, val, option, ToUint16)
|
||||
}
|
||||
}
|
||||
|
@ -418,10 +448,11 @@ impl ToJSValConvertible for i32 {
|
|||
// https://heycam.github.io/webidl/#es-long
|
||||
impl FromJSValConvertible for i32 {
|
||||
type Config = ConversionBehavior;
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior)
|
||||
-> Result<ConversionResult<i32>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
) -> Result<ConversionResult<i32>, ()> {
|
||||
convert_int_from_jsval(cx, val, option, ToInt32)
|
||||
}
|
||||
}
|
||||
|
@ -437,10 +468,11 @@ impl ToJSValConvertible for u32 {
|
|||
// https://heycam.github.io/webidl/#es-unsigned-long
|
||||
impl FromJSValConvertible for u32 {
|
||||
type Config = ConversionBehavior;
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior)
|
||||
-> Result<ConversionResult<u32>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
) -> Result<ConversionResult<u32>, ()> {
|
||||
convert_int_from_jsval(cx, val, option, ToUint32)
|
||||
}
|
||||
}
|
||||
|
@ -456,10 +488,11 @@ impl ToJSValConvertible for i64 {
|
|||
// https://heycam.github.io/webidl/#es-long-long
|
||||
impl FromJSValConvertible for i64 {
|
||||
type Config = ConversionBehavior;
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior)
|
||||
-> Result<ConversionResult<i64>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
) -> Result<ConversionResult<i64>, ()> {
|
||||
convert_int_from_jsval(cx, val, option, ToInt64)
|
||||
}
|
||||
}
|
||||
|
@ -475,10 +508,11 @@ impl ToJSValConvertible for u64 {
|
|||
// https://heycam.github.io/webidl/#es-unsigned-long-long
|
||||
impl FromJSValConvertible for u64 {
|
||||
type Config = ConversionBehavior;
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior)
|
||||
-> Result<ConversionResult<u64>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
option: ConversionBehavior,
|
||||
) -> Result<ConversionResult<u64>, ()> {
|
||||
convert_int_from_jsval(cx, val, option, ToUint64)
|
||||
}
|
||||
}
|
||||
|
@ -494,7 +528,11 @@ impl ToJSValConvertible for f32 {
|
|||
// https://heycam.github.io/webidl/#es-float
|
||||
impl FromJSValConvertible for f32 {
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(cx: *mut JSContext, val: JS::HandleValue, _option: ()) -> Result<ConversionResult<f32>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
_option: (),
|
||||
) -> Result<ConversionResult<f32>, ()> {
|
||||
let result = ToNumber(cx, val);
|
||||
result.map(|f| f as f32).map(ConversionResult::Success)
|
||||
}
|
||||
|
@ -511,7 +549,11 @@ impl ToJSValConvertible for f64 {
|
|||
// https://heycam.github.io/webidl/#es-double
|
||||
impl FromJSValConvertible for f64 {
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(cx: *mut JSContext, val: JS::HandleValue, _option: ()) -> Result<ConversionResult<f64>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
_option: (),
|
||||
) -> Result<ConversionResult<f64>, ()> {
|
||||
ToNumber(cx, val).map(ConversionResult::Success)
|
||||
}
|
||||
}
|
||||
|
@ -537,9 +579,11 @@ impl ToJSValConvertible for str {
|
|||
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: JS::MutableHandleValue) {
|
||||
let mut string_utf16: Vec<u16> = Vec::with_capacity(self.len());
|
||||
string_utf16.extend(self.encode_utf16());
|
||||
let jsstr = JS_NewUCStringCopyN(cx,
|
||||
string_utf16.as_ptr(),
|
||||
string_utf16.len() as libc::size_t);
|
||||
let jsstr = JS_NewUCStringCopyN(
|
||||
cx,
|
||||
string_utf16.as_ptr(),
|
||||
string_utf16.len() as libc::size_t,
|
||||
);
|
||||
if jsstr.is_null() {
|
||||
panic!("JS_NewUCStringCopyN failed");
|
||||
}
|
||||
|
@ -558,7 +602,11 @@ impl ToJSValConvertible for String {
|
|||
// https://heycam.github.io/webidl/#es-USVString
|
||||
impl FromJSValConvertible for String {
|
||||
type Config = ();
|
||||
unsafe fn from_jsval(cx: *mut JSContext, value: JS::HandleValue, _: ()) -> Result<ConversionResult<String>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
_: (),
|
||||
) -> Result<ConversionResult<String>, ()> {
|
||||
let jsstr = ToString(cx, value);
|
||||
if jsstr.is_null() {
|
||||
debug!("ToString failed");
|
||||
|
@ -595,17 +643,20 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Rc<T> {
|
|||
|
||||
impl<T: FromJSValConvertible> FromJSValConvertible for Option<T> {
|
||||
type Config = T::Config;
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
option: T::Config)
|
||||
-> Result<ConversionResult<Option<T>>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
option: T::Config,
|
||||
) -> Result<ConversionResult<Option<T>>, ()> {
|
||||
if value.get().is_null_or_undefined() {
|
||||
Ok(ConversionResult::Success(None))
|
||||
} else {
|
||||
Ok(match try!(FromJSValConvertible::from_jsval(cx, value, option)) {
|
||||
ConversionResult::Success(v) => ConversionResult::Success(Some(v)),
|
||||
ConversionResult::Failure(v) => ConversionResult::Failure(v),
|
||||
})
|
||||
Ok(
|
||||
match try!(FromJSValConvertible::from_jsval(cx, value, option)) {
|
||||
ConversionResult::Success(v) => ConversionResult::Success(Some(v)),
|
||||
ConversionResult::Failure(v) => ConversionResult::Failure(v),
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -639,7 +690,7 @@ impl<T: ToJSValConvertible> ToJSValConvertible for Vec<T> {
|
|||
/// but borrows and allows access to the whole ForOfIterator, so
|
||||
/// that methods on ForOfIterator can still be used through it.
|
||||
struct ForOfIteratorGuard<'a> {
|
||||
root: &'a mut JS::ForOfIterator
|
||||
root: &'a mut JS::ForOfIterator,
|
||||
}
|
||||
|
||||
impl<'a> ForOfIteratorGuard<'a> {
|
||||
|
@ -648,9 +699,7 @@ impl<'a> ForOfIteratorGuard<'a> {
|
|||
root.iterator.register_with_root_lists(cx);
|
||||
root.nextMethod.register_with_root_lists(cx);
|
||||
}
|
||||
ForOfIteratorGuard {
|
||||
root: root
|
||||
}
|
||||
ForOfIteratorGuard { root: root }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -663,13 +712,14 @@ impl<'a> Drop for ForOfIteratorGuard<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C: Clone, T: FromJSValConvertible<Config=C>> FromJSValConvertible for Vec<T> {
|
||||
impl<C: Clone, T: FromJSValConvertible<Config = C>> FromJSValConvertible for Vec<T> {
|
||||
type Config = C;
|
||||
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
option: C)
|
||||
-> Result<ConversionResult<Vec<T>>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
value: JS::HandleValue,
|
||||
option: C,
|
||||
) -> Result<ConversionResult<Vec<T>>, ()> {
|
||||
let mut iterator = JS::ForOfIterator {
|
||||
cx_: cx,
|
||||
iterator: JS::RootedObject::new_unrooted(),
|
||||
|
@ -679,8 +729,11 @@ impl<C: Clone, T: FromJSValConvertible<Config=C>> FromJSValConvertible for Vec<T
|
|||
let iterator = ForOfIteratorGuard::new(cx, &mut iterator);
|
||||
let iterator = &mut *iterator.root;
|
||||
|
||||
if !iterator.init(value, JS::ForOfIterator_NonIterableBehavior::AllowNonIterable) {
|
||||
return Err(())
|
||||
if !iterator.init(
|
||||
value,
|
||||
JS::ForOfIterator_NonIterableBehavior::AllowNonIterable,
|
||||
) {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
if iterator.iterator.ptr.is_null() {
|
||||
|
@ -693,17 +746,19 @@ impl<C: Clone, T: FromJSValConvertible<Config=C>> FromJSValConvertible for Vec<T
|
|||
let mut done = false;
|
||||
rooted!(in(cx) let mut val = UndefinedValue());
|
||||
if !iterator.next(val.handle_mut(), &mut done) {
|
||||
return Err(())
|
||||
return Err(());
|
||||
}
|
||||
|
||||
if done {
|
||||
break;
|
||||
}
|
||||
|
||||
ret.push(match try!(T::from_jsval(cx, val.handle(), option.clone())) {
|
||||
ConversionResult::Success(v) => v,
|
||||
ConversionResult::Failure(e) => return Ok(ConversionResult::Failure(e)),
|
||||
});
|
||||
ret.push(
|
||||
match try!(T::from_jsval(cx, val.handle(), option.clone())) {
|
||||
ConversionResult::Success(v) => v,
|
||||
ConversionResult::Failure(e) => return Ok(ConversionResult::Failure(e)),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Ok(ret).map(ConversionResult::Success)
|
||||
|
@ -778,10 +833,11 @@ impl ToJSValConvertible for JS::Handle<*mut JSFunction> {
|
|||
impl FromJSValConvertible for *mut JSFunction {
|
||||
type Config = ();
|
||||
|
||||
unsafe fn from_jsval(cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
_: ())
|
||||
-> Result<ConversionResult<Self>, ()> {
|
||||
unsafe fn from_jsval(
|
||||
cx: *mut JSContext,
|
||||
val: JS::HandleValue,
|
||||
_: (),
|
||||
) -> Result<ConversionResult<Self>, ()> {
|
||||
let func = JS_ValueToFunction(cx, val);
|
||||
if func.is_null() {
|
||||
Ok(ConversionResult::Failure("value is not a function".into()))
|
||||
|
|
|
@ -37,15 +37,18 @@ static mut RANGE_ERROR_FORMAT_STRING: JSErrorFormatString = JSErrorFormatString
|
|||
|
||||
/// Callback used to throw javascript errors.
|
||||
/// See throw_js_error for info about error_number.
|
||||
unsafe extern "C" fn get_error_message(_user_ref: *mut os::raw::c_void,
|
||||
error_number: libc::c_uint)
|
||||
-> *const JSErrorFormatString {
|
||||
unsafe extern "C" fn get_error_message(
|
||||
_user_ref: *mut os::raw::c_void,
|
||||
error_number: libc::c_uint,
|
||||
) -> *const JSErrorFormatString {
|
||||
let num: JSExnType = mem::transmute(error_number);
|
||||
match num {
|
||||
JSExnType::JSEXN_TYPEERR => &TYPE_ERROR_FORMAT_STRING as *const JSErrorFormatString,
|
||||
JSExnType::JSEXN_RANGEERR => &RANGE_ERROR_FORMAT_STRING as *const JSErrorFormatString,
|
||||
_ => panic!("Bad js error number given to get_error_message: {}",
|
||||
error_number),
|
||||
_ => panic!(
|
||||
"Bad js error number given to get_error_message: {}",
|
||||
error_number
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,11 +58,13 @@ unsafe extern "C" fn get_error_message(_user_ref: *mut os::raw::c_void,
|
|||
/// c_uint is u32, so this cast is safe, as is casting to/from i32 from there.
|
||||
unsafe fn throw_js_error(cx: *mut JSContext, error: &str, error_number: u32) {
|
||||
let error = CString::new(error).unwrap();
|
||||
JS_ReportErrorNumberUTF8(cx,
|
||||
Some(get_error_message),
|
||||
ptr::null_mut(),
|
||||
error_number,
|
||||
error.as_ptr());
|
||||
JS_ReportErrorNumberUTF8(
|
||||
cx,
|
||||
Some(get_error_message),
|
||||
ptr::null_mut(),
|
||||
error_number,
|
||||
error.as_ptr(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Throw a `TypeError` with the given message.
|
||||
|
|
|
@ -2,137 +2,197 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use jsapi::root::*;
|
||||
use heap::Heap;
|
||||
use jsapi::root::*;
|
||||
use std::os::raw::c_void;
|
||||
|
||||
|
||||
pub enum Action { }
|
||||
pub enum Action {}
|
||||
unsafe impl Sync for ProxyTraps {}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct ProxyTraps {
|
||||
pub enter: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
action: Action,
|
||||
bp: *mut bool)
|
||||
-> bool>,
|
||||
pub getOwnPropertyDescriptor:
|
||||
::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
desc: JS::MutableHandle<JS::PropertyDescriptor>)
|
||||
-> bool>,
|
||||
pub defineProperty:
|
||||
::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
desc: JS::Handle<JS::PropertyDescriptor>,
|
||||
result: *mut JS::ObjectOpResult)
|
||||
-> bool>,
|
||||
pub ownPropertyKeys: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
props: JS::MutableHandleIdVector)
|
||||
-> bool>,
|
||||
pub delete_: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
result: *mut JS::ObjectOpResult)
|
||||
-> bool>,
|
||||
pub enumerate: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
objp: JS::MutableHandleObject)
|
||||
-> bool>,
|
||||
pub getPrototypeIfOrdinary:
|
||||
::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
isOrdinary: *mut bool,
|
||||
protop: JS::MutableHandleObject)
|
||||
-> bool>,
|
||||
pub preventExtensions:
|
||||
::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
result: *mut JS::ObjectOpResult)
|
||||
-> bool>,
|
||||
pub isExtensible: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
succeeded: *mut bool)
|
||||
-> bool>,
|
||||
pub has: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
bp: *mut bool)
|
||||
-> bool>,
|
||||
pub get: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
receiver: JS::HandleValue,
|
||||
id: JS::HandleId,
|
||||
vp: JS::MutableHandleValue)
|
||||
-> bool>,
|
||||
pub set: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
v: JS::HandleValue,
|
||||
receiver: JS::HandleValue,
|
||||
result: *mut JS::ObjectOpResult)
|
||||
-> bool>,
|
||||
pub call: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
args: *const JS::CallArgs)
|
||||
-> bool>,
|
||||
pub construct: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
args: *const JS::CallArgs)
|
||||
-> bool>,
|
||||
pub hasOwn: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
bp: *mut bool)
|
||||
-> bool>,
|
||||
pub getOwnEnumerablePropertyKeys:
|
||||
::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
props: JS::MutableHandleIdVector)
|
||||
-> bool>,
|
||||
pub nativeCall: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
test: JS::IsAcceptableThis,
|
||||
_impl: JS::NativeImpl,
|
||||
args: JS::CallArgs)
|
||||
-> bool>,
|
||||
pub hasInstance: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
v: JS::MutableHandleValue,
|
||||
bp: *mut bool)
|
||||
-> bool>,
|
||||
pub objectClassIs: ::std::option::Option<unsafe extern "C" fn(obj: JS::HandleObject,
|
||||
classValue: js::ESClass,
|
||||
cx: *mut JSContext)
|
||||
-> bool>,
|
||||
pub className: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject)
|
||||
-> *const i8>,
|
||||
pub fun_toString: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
indent: u32)
|
||||
-> *mut JSString>,
|
||||
pub boxedValue_unbox: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
vp: JS::MutableHandleValue)
|
||||
-> bool>,
|
||||
pub defaultValue: ::std::option::Option<unsafe extern "C" fn(cx: *mut JSContext,
|
||||
obj: JS::HandleObject,
|
||||
hint: JSType,
|
||||
vp: JS::MutableHandleValue)
|
||||
-> bool>,
|
||||
pub enter: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
action: Action,
|
||||
bp: *mut bool,
|
||||
) -> bool,
|
||||
>,
|
||||
pub getOwnPropertyDescriptor: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
desc: JS::MutableHandle<JS::PropertyDescriptor>,
|
||||
) -> bool,
|
||||
>,
|
||||
pub defineProperty: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
desc: JS::Handle<JS::PropertyDescriptor>,
|
||||
result: *mut JS::ObjectOpResult,
|
||||
) -> bool,
|
||||
>,
|
||||
pub ownPropertyKeys: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
props: JS::MutableHandleIdVector,
|
||||
) -> bool,
|
||||
>,
|
||||
pub delete_: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
result: *mut JS::ObjectOpResult,
|
||||
) -> bool,
|
||||
>,
|
||||
pub enumerate: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
objp: JS::MutableHandleObject,
|
||||
) -> bool,
|
||||
>,
|
||||
pub getPrototypeIfOrdinary: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
isOrdinary: *mut bool,
|
||||
protop: JS::MutableHandleObject,
|
||||
) -> bool,
|
||||
>,
|
||||
pub preventExtensions: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
result: *mut JS::ObjectOpResult,
|
||||
) -> bool,
|
||||
>,
|
||||
pub isExtensible: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
succeeded: *mut bool,
|
||||
) -> bool,
|
||||
>,
|
||||
pub has: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
bp: *mut bool,
|
||||
) -> bool,
|
||||
>,
|
||||
pub get: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
receiver: JS::HandleValue,
|
||||
id: JS::HandleId,
|
||||
vp: JS::MutableHandleValue,
|
||||
) -> bool,
|
||||
>,
|
||||
pub set: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
v: JS::HandleValue,
|
||||
receiver: JS::HandleValue,
|
||||
result: *mut JS::ObjectOpResult,
|
||||
) -> bool,
|
||||
>,
|
||||
pub call: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
args: *const JS::CallArgs,
|
||||
) -> bool,
|
||||
>,
|
||||
pub construct: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
args: *const JS::CallArgs,
|
||||
) -> bool,
|
||||
>,
|
||||
pub hasOwn: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
bp: *mut bool,
|
||||
) -> bool,
|
||||
>,
|
||||
pub getOwnEnumerablePropertyKeys: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
props: JS::MutableHandleIdVector,
|
||||
) -> bool,
|
||||
>,
|
||||
pub nativeCall: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
test: JS::IsAcceptableThis,
|
||||
_impl: JS::NativeImpl,
|
||||
args: JS::CallArgs,
|
||||
) -> bool,
|
||||
>,
|
||||
pub hasInstance: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
v: JS::MutableHandleValue,
|
||||
bp: *mut bool,
|
||||
) -> bool,
|
||||
>,
|
||||
pub objectClassIs: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
obj: JS::HandleObject,
|
||||
classValue: js::ESClass,
|
||||
cx: *mut JSContext,
|
||||
) -> bool,
|
||||
>,
|
||||
pub className: ::std::option::Option<
|
||||
unsafe extern "C" fn(cx: *mut JSContext, proxy: JS::HandleObject) -> *const i8,
|
||||
>,
|
||||
pub fun_toString: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
indent: u32,
|
||||
) -> *mut JSString,
|
||||
>,
|
||||
pub boxedValue_unbox: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
vp: JS::MutableHandleValue,
|
||||
) -> bool,
|
||||
>,
|
||||
pub defaultValue: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
cx: *mut JSContext,
|
||||
obj: JS::HandleObject,
|
||||
hint: JSType,
|
||||
vp: JS::MutableHandleValue,
|
||||
) -> bool,
|
||||
>,
|
||||
pub trace:
|
||||
::std::option::Option<unsafe extern "C" fn(trc: *mut JSTracer, proxy: *mut JSObject)>,
|
||||
pub finalize:
|
||||
::std::option::Option<unsafe extern "C" fn(fop: *mut JSFreeOp, proxy: *mut JSObject)>,
|
||||
pub objectMoved:
|
||||
::std::option::Option<unsafe extern "C" fn(proxy: *mut JSObject,
|
||||
old: *mut JSObject) -> usize>,
|
||||
pub objectMoved: ::std::option::Option<
|
||||
unsafe extern "C" fn(proxy: *mut JSObject, old: *mut JSObject) -> usize,
|
||||
>,
|
||||
pub isCallable: ::std::option::Option<unsafe extern "C" fn(obj: *mut JSObject) -> bool>,
|
||||
pub isConstructor: ::std::option::Option<unsafe extern "C" fn(obj: *mut JSObject) -> bool>,
|
||||
}
|
||||
|
@ -164,80 +224,89 @@ impl ::std::default::Default for ForwardingProxyHandler {
|
|||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn InvokeGetOwnPropertyDescriptor(handler: *const ::libc::c_void,
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
desc: JS::MutableHandle<JS::PropertyDescriptor>)
|
||||
-> bool;
|
||||
pub fn InvokeHasOwn(handler: *const ::libc::c_void,
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
bp: *mut bool)
|
||||
-> bool;
|
||||
pub fn InvokeGetOwnPropertyDescriptor(
|
||||
handler: *const ::libc::c_void,
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
desc: JS::MutableHandle<JS::PropertyDescriptor>,
|
||||
) -> bool;
|
||||
pub fn InvokeHasOwn(
|
||||
handler: *const ::libc::c_void,
|
||||
cx: *mut JSContext,
|
||||
proxy: JS::HandleObject,
|
||||
id: JS::HandleId,
|
||||
bp: *mut bool,
|
||||
) -> bool;
|
||||
pub fn RUST_JS_NumberValue(d: f64) -> JS::Value;
|
||||
pub fn RUST_FUNCTION_VALUE_TO_JITINFO(v: JS::Value) -> *const JSJitInfo;
|
||||
pub fn CreateCallArgsFromVp(argc: u32, v: *mut JS::Value) -> JS::CallArgs;
|
||||
pub fn CallJitGetterOp(info: *const JSJitInfo,
|
||||
cx: *mut JSContext,
|
||||
thisObj: JS::HandleObject,
|
||||
specializedThis: *mut ::libc::c_void,
|
||||
argc: u32,
|
||||
vp: *mut JS::Value)
|
||||
-> bool;
|
||||
pub fn CallJitSetterOp(info: *const JSJitInfo,
|
||||
cx: *mut JSContext,
|
||||
thisObj: JS::HandleObject,
|
||||
specializedThis: *mut ::libc::c_void,
|
||||
argc: u32,
|
||||
vp: *mut JS::Value)
|
||||
-> bool;
|
||||
pub fn CallJitMethodOp(info: *const JSJitInfo,
|
||||
cx: *mut JSContext,
|
||||
thisObj: JS::HandleObject,
|
||||
specializedThis: *mut ::libc::c_void,
|
||||
argc: u32,
|
||||
vp: *mut JS::Value)
|
||||
-> bool;
|
||||
pub fn CreateProxyHandler(aTraps: *const ProxyTraps,
|
||||
aExtra: *const ::libc::c_void)
|
||||
-> *const ::libc::c_void;
|
||||
pub fn CallJitGetterOp(
|
||||
info: *const JSJitInfo,
|
||||
cx: *mut JSContext,
|
||||
thisObj: JS::HandleObject,
|
||||
specializedThis: *mut ::libc::c_void,
|
||||
argc: u32,
|
||||
vp: *mut JS::Value,
|
||||
) -> bool;
|
||||
pub fn CallJitSetterOp(
|
||||
info: *const JSJitInfo,
|
||||
cx: *mut JSContext,
|
||||
thisObj: JS::HandleObject,
|
||||
specializedThis: *mut ::libc::c_void,
|
||||
argc: u32,
|
||||
vp: *mut JS::Value,
|
||||
) -> bool;
|
||||
pub fn CallJitMethodOp(
|
||||
info: *const JSJitInfo,
|
||||
cx: *mut JSContext,
|
||||
thisObj: JS::HandleObject,
|
||||
specializedThis: *mut ::libc::c_void,
|
||||
argc: u32,
|
||||
vp: *mut JS::Value,
|
||||
) -> bool;
|
||||
pub fn CreateProxyHandler(
|
||||
aTraps: *const ProxyTraps,
|
||||
aExtra: *const ::libc::c_void,
|
||||
) -> *const ::libc::c_void;
|
||||
pub fn CreateWrapperProxyHandler(aTraps: *const ProxyTraps) -> *const ::libc::c_void;
|
||||
pub fn CreateRustJSPrincipal(origin: *const ::libc::c_void,
|
||||
destroy: Option<unsafe extern "C" fn
|
||||
(principal: *mut JSPrincipals)>,
|
||||
write: Option<unsafe extern "C" fn
|
||||
(cx: *mut JSContext,
|
||||
writer: *mut JSStructuredCloneWriter)
|
||||
-> bool>)
|
||||
-> *mut JSPrincipals;
|
||||
pub fn CreateRustJSPrincipal(
|
||||
origin: *const ::libc::c_void,
|
||||
destroy: Option<unsafe extern "C" fn(principal: *mut JSPrincipals)>,
|
||||
write: Option<
|
||||
unsafe extern "C" fn(cx: *mut JSContext, writer: *mut JSStructuredCloneWriter) -> bool,
|
||||
>,
|
||||
) -> *mut JSPrincipals;
|
||||
pub fn GetPrincipalOrigin(principal: *const JSPrincipals) -> *const ::libc::c_void;
|
||||
pub fn GetCrossCompartmentWrapper() -> *const ::libc::c_void;
|
||||
pub fn GetSecurityWrapper() -> *const ::libc::c_void;
|
||||
pub fn NewCompileOptions(aCx: *mut JSContext,
|
||||
aFile: *const ::libc::c_char,
|
||||
aLine: u32)
|
||||
-> *mut JS::ReadOnlyCompileOptions;
|
||||
pub fn NewCompileOptions(
|
||||
aCx: *mut JSContext,
|
||||
aFile: *const ::libc::c_char,
|
||||
aLine: u32,
|
||||
) -> *mut JS::ReadOnlyCompileOptions;
|
||||
pub fn DeleteCompileOptions(aOpts: *mut JS::ReadOnlyCompileOptions);
|
||||
pub fn NewProxyObject(aCx: *mut JSContext,
|
||||
aHandler: *const ::libc::c_void,
|
||||
aPriv: JS::HandleValue,
|
||||
proto: *mut JSObject,
|
||||
parent: *mut JSObject,
|
||||
call: *mut JSObject,
|
||||
construct: *mut JSObject)
|
||||
-> *mut JSObject;
|
||||
pub fn WrapperNew(aCx: *mut JSContext,
|
||||
aObj: JS::HandleObject,
|
||||
aHandler: *const ::libc::c_void,
|
||||
aClass: *const JSClass,
|
||||
aSingleton: bool)
|
||||
-> *mut JSObject;
|
||||
pub fn NewWindowProxy(aCx: *mut JSContext,
|
||||
aObj: JS::HandleObject,
|
||||
aHandler: *const ::libc::c_void)
|
||||
-> *mut JSObject;
|
||||
pub fn NewProxyObject(
|
||||
aCx: *mut JSContext,
|
||||
aHandler: *const ::libc::c_void,
|
||||
aPriv: JS::HandleValue,
|
||||
proto: *mut JSObject,
|
||||
parent: *mut JSObject,
|
||||
call: *mut JSObject,
|
||||
construct: *mut JSObject,
|
||||
) -> *mut JSObject;
|
||||
pub fn WrapperNew(
|
||||
aCx: *mut JSContext,
|
||||
aObj: JS::HandleObject,
|
||||
aHandler: *const ::libc::c_void,
|
||||
aClass: *const JSClass,
|
||||
aSingleton: bool,
|
||||
) -> *mut JSObject;
|
||||
pub fn NewWindowProxy(
|
||||
aCx: *mut JSContext,
|
||||
aObj: JS::HandleObject,
|
||||
aHandler: *const ::libc::c_void,
|
||||
) -> *mut JSObject;
|
||||
pub fn GetWindowProxyClass() -> *const JSClass;
|
||||
pub fn GetProxyPrivate(obj: *mut JSObject) -> JS::Value;
|
||||
pub fn SetProxyPrivate(obj: *mut JSObject, private: *const JS::Value);
|
||||
|
@ -251,9 +320,10 @@ extern "C" {
|
|||
pub fn RUST_SYMBOL_TO_JSID(sym: *mut JS::Symbol) -> jsid;
|
||||
pub fn RUST_SET_JITINFO(func: *mut JSFunction, info: *const JSJitInfo);
|
||||
pub fn RUST_INTERNED_STRING_TO_JSID(cx: *mut JSContext, str: *mut JSString) -> jsid;
|
||||
pub fn RUST_js_GetErrorMessage(userRef: *mut ::libc::c_void,
|
||||
errorNumber: u32)
|
||||
-> *const JSErrorFormatString;
|
||||
pub fn RUST_js_GetErrorMessage(
|
||||
userRef: *mut ::libc::c_void,
|
||||
errorNumber: u32,
|
||||
) -> *const JSErrorFormatString;
|
||||
pub fn IsProxyHandlerFamily(obj: *mut JSObject) -> u8;
|
||||
pub fn GetProxyHandlerExtra(obj: *mut JSObject) -> *const ::libc::c_void;
|
||||
pub fn GetProxyHandler(obj: *mut JSObject) -> *const ::libc::c_void;
|
||||
|
@ -263,89 +333,132 @@ extern "C" {
|
|||
pub fn UncheckedUnwrapObject(obj: *mut JSObject, stopAtOuter: u8) -> *mut JSObject;
|
||||
pub fn CreateRootedIdVector(cx: *mut JSContext) -> *mut JS::PersistentRootedIdVector;
|
||||
pub fn AppendToRootedIdVector(v: *mut JS::PersistentRootedIdVector, id: jsid) -> bool;
|
||||
pub fn SliceRootedIdVector(v: *const JS::PersistentRootedIdVector, length: *mut usize) -> *const jsid;
|
||||
pub fn SliceRootedIdVector(
|
||||
v: *const JS::PersistentRootedIdVector,
|
||||
length: *mut usize,
|
||||
) -> *const jsid;
|
||||
pub fn DestroyRootedIdVector(v: *mut JS::PersistentRootedIdVector);
|
||||
pub fn GetMutableHandleIdVector(v: *mut JS::PersistentRootedIdVector)-> JS::MutableHandleIdVector;
|
||||
pub fn GetMutableHandleIdVector(
|
||||
v: *mut JS::PersistentRootedIdVector,
|
||||
) -> JS::MutableHandleIdVector;
|
||||
pub fn CreateRootedObjectVector(aCx: *mut JSContext) -> *mut JS::PersistentRootedObjectVector;
|
||||
pub fn AppendToRootedObjectVector(v: *mut JS::PersistentRootedObjectVector, obj: *mut JSObject) -> bool;
|
||||
pub fn AppendToRootedObjectVector(
|
||||
v: *mut JS::PersistentRootedObjectVector,
|
||||
obj: *mut JSObject,
|
||||
) -> bool;
|
||||
pub fn DeleteRootedObjectVector(v: *mut JS::PersistentRootedObjectVector);
|
||||
pub fn CollectServoSizes(rt: *mut JSRuntime, sizes: *mut JS::ServoSizes) -> bool;
|
||||
pub fn CallIdTracer(trc: *mut JSTracer, idp: *mut Heap<jsid>, name: *const ::libc::c_char);
|
||||
pub fn CallValueTracer(trc: *mut JSTracer,
|
||||
valuep: *mut Heap<JS::Value>,
|
||||
name: *const ::libc::c_char);
|
||||
pub fn CallObjectTracer(trc: *mut JSTracer,
|
||||
objp: *mut Heap<*mut JSObject>,
|
||||
name: *const ::libc::c_char);
|
||||
pub fn CallStringTracer(trc: *mut JSTracer,
|
||||
strp: *mut Heap<*mut JSString>,
|
||||
name: *const ::libc::c_char);
|
||||
pub fn CallValueTracer(
|
||||
trc: *mut JSTracer,
|
||||
valuep: *mut Heap<JS::Value>,
|
||||
name: *const ::libc::c_char,
|
||||
);
|
||||
pub fn CallObjectTracer(
|
||||
trc: *mut JSTracer,
|
||||
objp: *mut Heap<*mut JSObject>,
|
||||
name: *const ::libc::c_char,
|
||||
);
|
||||
pub fn CallStringTracer(
|
||||
trc: *mut JSTracer,
|
||||
strp: *mut Heap<*mut JSString>,
|
||||
name: *const ::libc::c_char,
|
||||
);
|
||||
#[cfg(feature = "bigint")]
|
||||
pub fn CallBigIntTracer(trc: *mut JSTracer,
|
||||
bip: *mut Heap<*mut JS::BigInt>,
|
||||
name: *const ::libc::c_char);
|
||||
pub fn CallScriptTracer(trc: *mut JSTracer,
|
||||
scriptp: *mut Heap<*mut JSScript>,
|
||||
name: *const ::libc::c_char);
|
||||
pub fn CallFunctionTracer(trc: *mut JSTracer,
|
||||
funp: *mut Heap<*mut JSFunction>,
|
||||
name: *const ::libc::c_char);
|
||||
pub fn CallUnbarrieredObjectTracer(trc: *mut JSTracer,
|
||||
objp: *mut *mut JSObject,
|
||||
name: *const ::libc::c_char);
|
||||
pub fn CallBigIntTracer(
|
||||
trc: *mut JSTracer,
|
||||
bip: *mut Heap<*mut JS::BigInt>,
|
||||
name: *const ::libc::c_char,
|
||||
);
|
||||
pub fn CallScriptTracer(
|
||||
trc: *mut JSTracer,
|
||||
scriptp: *mut Heap<*mut JSScript>,
|
||||
name: *const ::libc::c_char,
|
||||
);
|
||||
pub fn CallFunctionTracer(
|
||||
trc: *mut JSTracer,
|
||||
funp: *mut Heap<*mut JSFunction>,
|
||||
name: *const ::libc::c_char,
|
||||
);
|
||||
pub fn CallUnbarrieredObjectTracer(
|
||||
trc: *mut JSTracer,
|
||||
objp: *mut *mut JSObject,
|
||||
name: *const ::libc::c_char,
|
||||
);
|
||||
pub fn GetProxyHandlerFamily() -> *const c_void;
|
||||
|
||||
pub fn GetInt8ArrayLengthAndData(obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut i8);
|
||||
pub fn GetUint8ArrayLengthAndData(obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut u8);
|
||||
pub fn GetUint8ClampedArrayLengthAndData(obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut u8);
|
||||
pub fn GetInt16ArrayLengthAndData(obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut i16);
|
||||
pub fn GetUint16ArrayLengthAndData(obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut u16);
|
||||
pub fn GetInt32ArrayLengthAndData(obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut i32);
|
||||
pub fn GetUint32ArrayLengthAndData(obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut u32);
|
||||
pub fn GetFloat32ArrayLengthAndData(obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut f32);
|
||||
pub fn GetFloat64ArrayLengthAndData(obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut f64);
|
||||
pub fn GetInt8ArrayLengthAndData(
|
||||
obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut i8,
|
||||
);
|
||||
pub fn GetUint8ArrayLengthAndData(
|
||||
obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut u8,
|
||||
);
|
||||
pub fn GetUint8ClampedArrayLengthAndData(
|
||||
obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut u8,
|
||||
);
|
||||
pub fn GetInt16ArrayLengthAndData(
|
||||
obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut i16,
|
||||
);
|
||||
pub fn GetUint16ArrayLengthAndData(
|
||||
obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut u16,
|
||||
);
|
||||
pub fn GetInt32ArrayLengthAndData(
|
||||
obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut i32,
|
||||
);
|
||||
pub fn GetUint32ArrayLengthAndData(
|
||||
obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut u32,
|
||||
);
|
||||
pub fn GetFloat32ArrayLengthAndData(
|
||||
obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut f32,
|
||||
);
|
||||
pub fn GetFloat64ArrayLengthAndData(
|
||||
obj: *mut JSObject,
|
||||
length: *mut u32,
|
||||
isSharedMemory: *mut bool,
|
||||
data: *mut *mut f64,
|
||||
);
|
||||
|
||||
pub fn NewJSAutoStructuredCloneBuffer(scope: JS::StructuredCloneScope,
|
||||
callbacks: *const JSStructuredCloneCallbacks)
|
||||
-> *mut JSAutoStructuredCloneBuffer;
|
||||
pub fn NewJSAutoStructuredCloneBuffer(
|
||||
scope: JS::StructuredCloneScope,
|
||||
callbacks: *const JSStructuredCloneCallbacks,
|
||||
) -> *mut JSAutoStructuredCloneBuffer;
|
||||
pub fn DeleteJSAutoStructuredCloneBuffer(buf: *mut JSAutoStructuredCloneBuffer);
|
||||
pub fn GetLengthOfJSStructuredCloneData(data: *mut JSStructuredCloneData) -> usize;
|
||||
pub fn CopyJSStructuredCloneData(src: *mut JSStructuredCloneData, dest: *mut u8);
|
||||
pub fn WriteBytesToJSStructuredCloneData(src: *const u8,
|
||||
len: usize,
|
||||
dest: *mut JSStructuredCloneData)
|
||||
-> bool;
|
||||
pub fn WriteBytesToJSStructuredCloneData(
|
||||
src: *const u8,
|
||||
len: usize,
|
||||
dest: *mut JSStructuredCloneData,
|
||||
) -> bool;
|
||||
|
||||
pub fn JSEncodeStringToUTF8(cx: *mut JSContext,
|
||||
string: JS::HandleString)
|
||||
-> *mut ::libc::c_char;
|
||||
pub fn JSEncodeStringToUTF8(
|
||||
cx: *mut JSContext,
|
||||
string: JS::HandleString,
|
||||
) -> *mut ::libc::c_char;
|
||||
|
||||
pub fn IsDebugBuild() -> bool;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,8 @@ pub struct Heap<T: GCMethods + Copy> {
|
|||
|
||||
impl<T: GCMethods + Copy> Heap<T> {
|
||||
pub fn new(v: T) -> Heap<T>
|
||||
where Heap<T>: Default
|
||||
where
|
||||
Heap<T>: Default,
|
||||
{
|
||||
let ptr = Heap::default();
|
||||
ptr.set(v);
|
||||
|
@ -68,9 +69,7 @@ impl<T: GCMethods + Copy> Heap<T> {
|
|||
}
|
||||
|
||||
pub fn get(&self) -> T {
|
||||
unsafe {
|
||||
*self.ptr.get()
|
||||
}
|
||||
unsafe { *self.ptr.get() }
|
||||
}
|
||||
|
||||
pub unsafe fn get_unsafe(&self) -> *mut T {
|
||||
|
@ -78,20 +77,17 @@ impl<T: GCMethods + Copy> Heap<T> {
|
|||
}
|
||||
|
||||
pub fn handle(&self) -> JS::Handle<T> {
|
||||
unsafe {
|
||||
JS::Handle::from_marked_location(self.ptr.get() as *const _)
|
||||
}
|
||||
unsafe { JS::Handle::from_marked_location(self.ptr.get() as *const _) }
|
||||
}
|
||||
|
||||
pub fn handle_mut(&self) -> JS::MutableHandle<T> {
|
||||
unsafe {
|
||||
JS::MutableHandle::from_marked_location(self.ptr.get())
|
||||
}
|
||||
unsafe { JS::MutableHandle::from_marked_location(self.ptr.get()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: GCMethods + Copy> Clone for Heap<T>
|
||||
where Heap<T>: Default
|
||||
where
|
||||
Heap<T>: Default,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Heap::new(self.get())
|
||||
|
@ -105,11 +101,12 @@ impl<T: GCMethods + Copy + PartialEq> PartialEq for Heap<T> {
|
|||
}
|
||||
|
||||
impl<T> Default for Heap<*mut T>
|
||||
where *mut T: GCMethods + Copy
|
||||
where
|
||||
*mut T: GCMethods + Copy,
|
||||
{
|
||||
fn default() -> Heap<*mut T> {
|
||||
Heap {
|
||||
ptr: UnsafeCell::new(ptr::null_mut())
|
||||
ptr: UnsafeCell::new(ptr::null_mut()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +114,7 @@ impl<T> Default for Heap<*mut T>
|
|||
impl Default for Heap<JS::Value> {
|
||||
fn default() -> Heap<JS::Value> {
|
||||
Heap {
|
||||
ptr: UnsafeCell::new(JS::Value::default())
|
||||
ptr: UnsafeCell::new(JS::Value::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +132,7 @@ impl<T: GCMethods + Copy> Drop for Heap<T> {
|
|||
macro_rules! c_str {
|
||||
($str:expr) => {
|
||||
concat!($str, "\0").as_ptr() as *const ::std::os::raw::c_char
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
unsafe impl Trace for Heap<*mut JSFunction> {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
use jsapi::root::*;
|
||||
use libc::c_void;
|
||||
use std::mem;
|
||||
|
@ -21,16 +20,16 @@ const JSVAL_TAG_CLEAR: u32 = 0xFFFFFF80;
|
|||
#[allow(dead_code)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum ValueTag {
|
||||
INT32 = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_INT32 as u32),
|
||||
INT32 = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_INT32 as u32),
|
||||
UNDEFINED = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_UNDEFINED as u32),
|
||||
STRING = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_STRING as u32),
|
||||
SYMBOL = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_SYMBOL as u32),
|
||||
STRING = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_STRING as u32),
|
||||
SYMBOL = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_SYMBOL as u32),
|
||||
#[cfg(feature = "bigint")]
|
||||
BIGINT = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_BIGINT as u32),
|
||||
BOOLEAN = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_BOOLEAN as u32),
|
||||
MAGIC = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_MAGIC as u32),
|
||||
NULL = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_NULL as u32),
|
||||
OBJECT = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_OBJECT as u32),
|
||||
BIGINT = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_BIGINT as u32),
|
||||
BOOLEAN = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_BOOLEAN as u32),
|
||||
MAGIC = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_MAGIC as u32),
|
||||
NULL = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_NULL as u32),
|
||||
OBJECT = JSVAL_TAG_MAX_DOUBLE | (JSValueType::JSVAL_TYPE_OBJECT as u32),
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
|
@ -38,17 +37,17 @@ enum ValueTag {
|
|||
#[allow(dead_code)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum ValueTag {
|
||||
PRIVATE = 0,
|
||||
INT32 = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_INT32 as u32),
|
||||
PRIVATE = 0,
|
||||
INT32 = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_INT32 as u32),
|
||||
UNDEFINED = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_UNDEFINED as u32),
|
||||
STRING = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_STRING as u32),
|
||||
SYMBOL = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_SYMBOL as u32),
|
||||
STRING = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_STRING as u32),
|
||||
SYMBOL = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_SYMBOL as u32),
|
||||
#[cfg(feature = "bigint")]
|
||||
BIGINT = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_BIGINT as u32),
|
||||
BOOLEAN = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_BOOLEAN as u32),
|
||||
MAGIC = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_MAGIC as u32),
|
||||
NULL = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_NULL as u32),
|
||||
OBJECT = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_OBJECT as u32),
|
||||
BIGINT = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_BIGINT as u32),
|
||||
BOOLEAN = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_BOOLEAN as u32),
|
||||
MAGIC = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_MAGIC as u32),
|
||||
NULL = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_NULL as u32),
|
||||
OBJECT = JSVAL_TAG_CLEAR as u32 | (JSValueType::JSVAL_TYPE_OBJECT as u32),
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
|
@ -57,27 +56,24 @@ enum ValueTag {
|
|||
#[derive(Clone, Copy, Debug)]
|
||||
enum ValueShiftedTag {
|
||||
MAX_DOUBLE = (((JSVAL_TAG_MAX_DOUBLE as u64) << JSVAL_TAG_SHIFT) | 0xFFFFFFFFu64),
|
||||
INT32 = ((ValueTag::INT32 as u64) << JSVAL_TAG_SHIFT),
|
||||
UNDEFINED = ((ValueTag::UNDEFINED as u64) << JSVAL_TAG_SHIFT),
|
||||
STRING = ((ValueTag::STRING as u64) << JSVAL_TAG_SHIFT),
|
||||
SYMBOL = ((ValueTag::SYMBOL as u64) << JSVAL_TAG_SHIFT),
|
||||
INT32 = ((ValueTag::INT32 as u64) << JSVAL_TAG_SHIFT),
|
||||
UNDEFINED = ((ValueTag::UNDEFINED as u64) << JSVAL_TAG_SHIFT),
|
||||
STRING = ((ValueTag::STRING as u64) << JSVAL_TAG_SHIFT),
|
||||
SYMBOL = ((ValueTag::SYMBOL as u64) << JSVAL_TAG_SHIFT),
|
||||
#[cfg(feature = "bigint")]
|
||||
BIGINT = ((ValueTag::BIGINT as u64) << JSVAL_TAG_SHIFT),
|
||||
BOOLEAN = ((ValueTag::BOOLEAN as u64) << JSVAL_TAG_SHIFT),
|
||||
MAGIC = ((ValueTag::MAGIC as u64) << JSVAL_TAG_SHIFT),
|
||||
NULL = ((ValueTag::NULL as u64) << JSVAL_TAG_SHIFT),
|
||||
OBJECT = ((ValueTag::OBJECT as u64) << JSVAL_TAG_SHIFT),
|
||||
BIGINT = ((ValueTag::BIGINT as u64) << JSVAL_TAG_SHIFT),
|
||||
BOOLEAN = ((ValueTag::BOOLEAN as u64) << JSVAL_TAG_SHIFT),
|
||||
MAGIC = ((ValueTag::MAGIC as u64) << JSVAL_TAG_SHIFT),
|
||||
NULL = ((ValueTag::NULL as u64) << JSVAL_TAG_SHIFT),
|
||||
OBJECT = ((ValueTag::OBJECT as u64) << JSVAL_TAG_SHIFT),
|
||||
}
|
||||
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
const JSVAL_PAYLOAD_MASK: u64 = 0x00007FFFFFFFFFFF;
|
||||
|
||||
#[inline(always)]
|
||||
fn AsJSVal(val: u64) -> JS::Value {
|
||||
JS::Value {
|
||||
asBits_: val,
|
||||
}
|
||||
JS::Value { asBits_: val }
|
||||
}
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
|
@ -219,33 +215,25 @@ impl JS::Value {
|
|||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_undefined(&self) -> bool {
|
||||
unsafe {
|
||||
self.asBits() == ValueShiftedTag::UNDEFINED as u64
|
||||
}
|
||||
unsafe { self.asBits() == ValueShiftedTag::UNDEFINED as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_undefined(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> 32) == ValueTag::UNDEFINED as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) == ValueTag::UNDEFINED as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_null(&self) -> bool {
|
||||
unsafe {
|
||||
self.asBits() == ValueShiftedTag::NULL as u64
|
||||
}
|
||||
unsafe { self.asBits() == ValueShiftedTag::NULL as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_null(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> 32) == ValueTag::NULL as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) == ValueTag::NULL as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -256,101 +244,77 @@ impl JS::Value {
|
|||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_boolean(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::BOOLEAN as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::BOOLEAN as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_boolean(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> 32) == ValueTag::BOOLEAN as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) == ValueTag::BOOLEAN as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_int32(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::INT32 as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::INT32 as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_int32(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> 32) == ValueTag::INT32 as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) == ValueTag::INT32 as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_double(&self) -> bool {
|
||||
unsafe {
|
||||
self.asBits() <= ValueShiftedTag::MAX_DOUBLE as u64
|
||||
}
|
||||
unsafe { self.asBits() <= ValueShiftedTag::MAX_DOUBLE as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_double(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> 32) <= JSVAL_TAG_CLEAR as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) <= JSVAL_TAG_CLEAR as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_number(&self) -> bool {
|
||||
const JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET: u64 = ValueShiftedTag::UNDEFINED as u64;
|
||||
unsafe {
|
||||
self.asBits() < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET
|
||||
}
|
||||
unsafe { self.asBits() < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_NUMBER_SET }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_number(&self) -> bool {
|
||||
const JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET: u64 = ValueTag::INT32 as u64;
|
||||
unsafe {
|
||||
(self.asBits() >> 32) <= JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) <= JSVAL_UPPER_INCL_TAG_OF_NUMBER_SET }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_primitive(&self) -> bool {
|
||||
const JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET: u64 = ValueShiftedTag::OBJECT as u64;
|
||||
unsafe {
|
||||
self.asBits() < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET
|
||||
}
|
||||
unsafe { self.asBits() < JSVAL_UPPER_EXCL_SHIFTED_TAG_OF_PRIMITIVE_SET }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_primitive(&self) -> bool {
|
||||
const JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET: u64 = ValueTag::OBJECT as u64;
|
||||
unsafe {
|
||||
(self.asBits() >> 32) < JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) < JSVAL_UPPER_EXCL_TAG_OF_PRIMITIVE_SET }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_string(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::STRING as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::STRING as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_string(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> 32) == ValueTag::STRING as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) == ValueTag::STRING as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -365,69 +329,53 @@ impl JS::Value {
|
|||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_object(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> 32) == ValueTag::OBJECT as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) == ValueTag::OBJECT as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_symbol(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::SYMBOL as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::SYMBOL as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_symbol(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> 32) == ValueTag::SYMBOL as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) == ValueTag::SYMBOL as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(feature = "bigint")]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_bigint(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::BIGINT as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> JSVAL_TAG_SHIFT) == ValueTag::BIGINT as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(feature = "bigint")]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_bigint(&self) -> bool {
|
||||
unsafe {
|
||||
(self.asBits() >> 32) == ValueTag::BIGINT as u64
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) == ValueTag::BIGINT as u64 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn to_boolean(&self) -> bool {
|
||||
assert!(self.is_boolean());
|
||||
unsafe {
|
||||
(self.asBits() & JSVAL_PAYLOAD_MASK) != 0
|
||||
}
|
||||
unsafe { (self.asBits() & JSVAL_PAYLOAD_MASK) != 0 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn to_boolean(&self) -> bool {
|
||||
assert!(self.is_boolean());
|
||||
unsafe {
|
||||
(self.asBits() & 0x00000000FFFFFFFF) != 0
|
||||
}
|
||||
unsafe { (self.asBits() & 0x00000000FFFFFFFF) != 0 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn to_int32(&self) -> i32 {
|
||||
assert!(self.is_int32());
|
||||
unsafe {
|
||||
(self.asBits() & 0x00000000FFFFFFFF) as i32
|
||||
}
|
||||
unsafe { (self.asBits() & 0x00000000FFFFFFFF) as i32 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -536,18 +484,14 @@ impl JS::Value {
|
|||
#[cfg(target_pointer_width = "64")]
|
||||
pub fn is_gcthing(&self) -> bool {
|
||||
const JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET: u64 = ValueShiftedTag::STRING as u64;
|
||||
unsafe {
|
||||
self.asBits() >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET
|
||||
}
|
||||
unsafe { self.asBits() >= JSVAL_LOWER_INCL_SHIFTED_TAG_OF_GCTHING_SET }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
pub fn is_gcthing(&self) -> bool {
|
||||
const JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET: u64 = ValueTag::STRING as u64;
|
||||
unsafe {
|
||||
(self.asBits() >> 32) >= JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET
|
||||
}
|
||||
unsafe { (self.asBits() >> 32) >= JSVAL_LOWER_INCL_TAG_OF_GCTHING_SET }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
|
@ -4,10 +4,13 @@
|
|||
|
||||
#![crate_name = "js"]
|
||||
#![crate_type = "rlib"]
|
||||
|
||||
#![cfg_attr(feature = "nonzero", feature(nonzero))]
|
||||
|
||||
#![allow(non_upper_case_globals, non_camel_case_types, non_snake_case, improper_ctypes)]
|
||||
#![allow(
|
||||
non_upper_case_globals,
|
||||
non_camel_case_types,
|
||||
non_snake_case,
|
||||
improper_ctypes
|
||||
)]
|
||||
|
||||
#[cfg(feature = "nonzero")]
|
||||
extern crate core;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use std::any::Any;
|
||||
use std::cell::RefCell;
|
||||
use std::panic::{UnwindSafe, catch_unwind, resume_unwind};
|
||||
use std::panic::{catch_unwind, resume_unwind, UnwindSafe};
|
||||
|
||||
thread_local!(static PANIC_RESULT: RefCell<Option<Box<Any + Send>>> = RefCell::new(None));
|
||||
|
||||
|
@ -17,7 +17,8 @@ pub fn maybe_resume_unwind() {
|
|||
|
||||
/// Generic wrapper for JS engine callbacks panic-catching
|
||||
pub fn wrap_panic<F, R>(function: F, generic_return_type: R) -> R
|
||||
where F: FnOnce() -> R + UnwindSafe
|
||||
where
|
||||
F: FnOnce() -> R + UnwindSafe,
|
||||
{
|
||||
let result = catch_unwind(function);
|
||||
match result {
|
||||
|
|
|
@ -5,27 +5,32 @@
|
|||
//! Rust wrappers around the raw JS apis
|
||||
|
||||
use ar::AutoRealm;
|
||||
use libc::c_uint;
|
||||
use std::cell::{Cell, UnsafeCell};
|
||||
use std::char;
|
||||
use std::ffi;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use std::mem;
|
||||
use std::u32;
|
||||
use std::default::Default;
|
||||
use std::marker;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::sync::{Once, ONCE_INIT, Arc, Mutex};
|
||||
use std::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering};
|
||||
use std::sync::mpsc::{SyncSender, sync_channel};
|
||||
use std::thread;
|
||||
use glue::{
|
||||
AppendToRootedObjectVector, CreateCallArgsFromVp, CreateRootedObjectVector,
|
||||
DeleteRootedObjectVector, IsDebugBuild,
|
||||
};
|
||||
use glue::{
|
||||
CreateRootedIdVector, DestroyRootedIdVector, GetMutableHandleIdVector, SliceRootedIdVector,
|
||||
};
|
||||
use glue::{DeleteCompileOptions, NewCompileOptions};
|
||||
use jsapi::root::*;
|
||||
use jsval::{self, UndefinedValue};
|
||||
use glue::{CreateRootedObjectVector, CreateCallArgsFromVp, AppendToRootedObjectVector, DeleteRootedObjectVector, IsDebugBuild};
|
||||
use glue::{CreateRootedIdVector, SliceRootedIdVector, DestroyRootedIdVector, GetMutableHandleIdVector};
|
||||
use glue::{NewCompileOptions, DeleteCompileOptions};
|
||||
use libc::c_uint;
|
||||
use panic;
|
||||
use std::cell::{Cell, UnsafeCell};
|
||||
use std::char;
|
||||
use std::default::Default;
|
||||
use std::ffi;
|
||||
use std::marker;
|
||||
use std::mem;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use std::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering};
|
||||
use std::sync::mpsc::{sync_channel, SyncSender};
|
||||
use std::sync::{Arc, Mutex, Once, ONCE_INIT};
|
||||
use std::thread;
|
||||
use std::u32;
|
||||
|
||||
const DEFAULT_HEAPSIZE: u32 = 32_u32 * 1024_u32 * 1024_u32;
|
||||
|
||||
|
@ -77,9 +82,7 @@ pub struct Runtime {
|
|||
impl Runtime {
|
||||
/// Get the `JSContext` for this thread.
|
||||
pub fn get() -> *mut JSContext {
|
||||
let cx = CONTEXT.with(|context| {
|
||||
context.get()
|
||||
});
|
||||
let cx = CONTEXT.with(|context| context.get());
|
||||
assert!(!cx.is_null());
|
||||
cx
|
||||
}
|
||||
|
@ -112,9 +115,7 @@ impl Runtime {
|
|||
}
|
||||
|
||||
fn as_atomic(&self) -> &AtomicPtr<JSContext> {
|
||||
unsafe {
|
||||
mem::transmute(&self.0)
|
||||
}
|
||||
unsafe { mem::transmute(&self.0) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,12 +133,13 @@ impl Runtime {
|
|||
let is_debug_mozjs = cfg!(feature = "debugmozjs");
|
||||
let diagnostic = JS::detail::InitWithFailureDiagnostic(is_debug_mozjs);
|
||||
if !diagnostic.is_null() {
|
||||
panic!("JS::detail::InitWithFailureDiagnostic failed: {}",
|
||||
ffi::CStr::from_ptr(diagnostic).to_string_lossy());
|
||||
panic!(
|
||||
"JS::detail::InitWithFailureDiagnostic failed: {}",
|
||||
ffi::CStr::from_ptr(diagnostic).to_string_lossy()
|
||||
);
|
||||
}
|
||||
|
||||
let context = JS_NewContext(
|
||||
DEFAULT_HEAPSIZE, ptr::null_mut());
|
||||
let context = JS_NewContext(DEFAULT_HEAPSIZE, ptr::null_mut());
|
||||
assert!(!context.is_null());
|
||||
JS::InitSelfHostedCode(context);
|
||||
PARENT.set(context);
|
||||
|
@ -159,8 +161,7 @@ impl Runtime {
|
|||
|
||||
assert_eq!(IsDebugBuild(), cfg!(feature = "debugmozjs"));
|
||||
|
||||
let js_context = JS_NewContext(DEFAULT_HEAPSIZE,
|
||||
JS_GetParentRuntime(PARENT.get()));
|
||||
let js_context = JS_NewContext(DEFAULT_HEAPSIZE, JS_GetParentRuntime(PARENT.get()));
|
||||
assert!(!js_context.is_null());
|
||||
|
||||
// Unconstrain the runtime's threshold on nominal heap size, to avoid
|
||||
|
@ -168,14 +169,14 @@ impl Runtime {
|
|||
// finite threshold. This leaves the maximum-JS_malloc-bytes threshold
|
||||
// still in effect to cause periodical, and we hope hygienic,
|
||||
// last-ditch GCs from within the GC's allocator.
|
||||
JS_SetGCParameter(
|
||||
js_context, JSGCParamKey::JSGC_MAX_BYTES, u32::MAX);
|
||||
JS_SetGCParameter(js_context, JSGCParamKey::JSGC_MAX_BYTES, u32::MAX);
|
||||
|
||||
JS_SetNativeStackQuota(
|
||||
js_context,
|
||||
STACK_QUOTA,
|
||||
STACK_QUOTA - SYSTEM_CODE_BUFFER,
|
||||
STACK_QUOTA - SYSTEM_CODE_BUFFER - TRUSTED_SCRIPT_BUFFER);
|
||||
STACK_QUOTA - SYSTEM_CODE_BUFFER - TRUSTED_SCRIPT_BUFFER,
|
||||
);
|
||||
|
||||
CONTEXT.with(|context| {
|
||||
assert!(context.get().is_null());
|
||||
|
@ -190,9 +191,7 @@ impl Runtime {
|
|||
|
||||
JS::SetWarningReporter(js_context, Some(report_warning));
|
||||
|
||||
Ok(Runtime {
|
||||
cx: js_context,
|
||||
})
|
||||
Ok(Runtime { cx: js_context })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,17 +202,23 @@ impl Runtime {
|
|||
|
||||
/// Returns the underlying `JSContext`'s `JSRuntime`.
|
||||
pub fn rt(&self) -> *mut JSRuntime {
|
||||
unsafe {
|
||||
JS_GetRuntime(self.cx)
|
||||
}
|
||||
unsafe { JS_GetRuntime(self.cx) }
|
||||
}
|
||||
|
||||
pub fn evaluate_script(&self, glob: JS::HandleObject, script: &str, filename: &str,
|
||||
line_num: u32, rval: JS::MutableHandleValue)
|
||||
-> Result<(),()> {
|
||||
pub fn evaluate_script(
|
||||
&self,
|
||||
glob: JS::HandleObject,
|
||||
script: &str,
|
||||
filename: &str,
|
||||
line_num: u32,
|
||||
rval: JS::MutableHandleValue,
|
||||
) -> Result<(), ()> {
|
||||
let script_utf16: Vec<u16> = script.encode_utf16().collect();
|
||||
let filename_cstr = ffi::CString::new(filename.as_bytes()).unwrap();
|
||||
debug!("Evaluating script from {} with content {}", filename, script);
|
||||
debug!(
|
||||
"Evaluating script from {} with content {}",
|
||||
filename, script
|
||||
);
|
||||
// SpiderMonkey does not approve of null pointers.
|
||||
let (ptr, len) = if script_utf16.len() == 0 {
|
||||
static empty: &'static [u16] = &[];
|
||||
|
@ -230,7 +235,7 @@ impl Runtime {
|
|||
units_: ptr,
|
||||
length_: len as _,
|
||||
ownsUnits_: false,
|
||||
_phantom_0: marker::PhantomData
|
||||
_phantom_0: marker::PhantomData,
|
||||
};
|
||||
if !JS::Evaluate(self.cx(), options.ptr, &mut srcBuf, rval) {
|
||||
debug!("...err!");
|
||||
|
@ -280,53 +285,72 @@ pub trait RootKind {
|
|||
|
||||
impl RootKind for *mut JSObject {
|
||||
#[inline(always)]
|
||||
fn rootKind() -> JS::RootKind { JS::RootKind::Object }
|
||||
fn rootKind() -> JS::RootKind {
|
||||
JS::RootKind::Object
|
||||
}
|
||||
}
|
||||
|
||||
impl RootKind for *mut JSLinearString {
|
||||
#[inline(always)]
|
||||
fn rootKind() -> JS::RootKind { JS::RootKind::String }
|
||||
fn rootKind() -> JS::RootKind {
|
||||
JS::RootKind::String
|
||||
}
|
||||
}
|
||||
|
||||
impl RootKind for *mut JSFunction {
|
||||
#[inline(always)]
|
||||
fn rootKind() -> JS::RootKind { JS::RootKind::Object }
|
||||
fn rootKind() -> JS::RootKind {
|
||||
JS::RootKind::Object
|
||||
}
|
||||
}
|
||||
|
||||
impl RootKind for *mut JSString {
|
||||
#[inline(always)]
|
||||
fn rootKind() -> JS::RootKind { JS::RootKind::String }
|
||||
fn rootKind() -> JS::RootKind {
|
||||
JS::RootKind::String
|
||||
}
|
||||
}
|
||||
|
||||
impl RootKind for *mut JS::Symbol {
|
||||
#[inline(always)]
|
||||
fn rootKind() -> JS::RootKind { JS::RootKind::Symbol }
|
||||
fn rootKind() -> JS::RootKind {
|
||||
JS::RootKind::Symbol
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "bigint")]
|
||||
impl RootKind for *mut JS::BigInt {
|
||||
#[inline(always)]
|
||||
fn rootKind() -> JS::RootKind { JS::RootKind::BigInt }
|
||||
fn rootKind() -> JS::RootKind {
|
||||
JS::RootKind::BigInt
|
||||
}
|
||||
}
|
||||
|
||||
impl RootKind for *mut JSScript {
|
||||
#[inline(always)]
|
||||
fn rootKind() -> JS::RootKind { JS::RootKind::Script }
|
||||
fn rootKind() -> JS::RootKind {
|
||||
JS::RootKind::Script
|
||||
}
|
||||
}
|
||||
|
||||
impl RootKind for jsid {
|
||||
#[inline(always)]
|
||||
fn rootKind() -> JS::RootKind { JS::RootKind::Id }
|
||||
fn rootKind() -> JS::RootKind {
|
||||
JS::RootKind::Id
|
||||
}
|
||||
}
|
||||
|
||||
impl RootKind for JS::Value {
|
||||
#[inline(always)]
|
||||
fn rootKind() -> JS::RootKind { JS::RootKind::Value }
|
||||
fn rootKind() -> JS::RootKind {
|
||||
JS::RootKind::Value
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> JS::Rooted<T> {
|
||||
pub fn new_unrooted() -> JS::Rooted<T>
|
||||
where T: GCMethods,
|
||||
where
|
||||
T: GCMethods,
|
||||
{
|
||||
JS::Rooted {
|
||||
stack: ptr::null_mut(),
|
||||
|
@ -340,9 +364,11 @@ impl<T> JS::Rooted<T> {
|
|||
mem::transmute(cx)
|
||||
}
|
||||
|
||||
unsafe fn get_root_stack(cx: *mut JSContext)
|
||||
-> *mut *mut JS::Rooted<*mut ::std::os::raw::c_void>
|
||||
where T: RootKind
|
||||
unsafe fn get_root_stack(
|
||||
cx: *mut JSContext,
|
||||
) -> *mut *mut JS::Rooted<*mut ::std::os::raw::c_void>
|
||||
where
|
||||
T: RootKind,
|
||||
{
|
||||
let kind = T::rootKind() as usize;
|
||||
let rooting_cx = Self::get_rooting_context(cx);
|
||||
|
@ -350,7 +376,8 @@ impl<T> JS::Rooted<T> {
|
|||
}
|
||||
|
||||
pub unsafe fn register_with_root_lists(&mut self, cx: *mut JSContext)
|
||||
where T: RootKind
|
||||
where
|
||||
T: RootKind,
|
||||
{
|
||||
self.stack = Self::get_root_stack(cx);
|
||||
let stack = self.stack.as_mut().unwrap();
|
||||
|
@ -369,7 +396,7 @@ impl<T> JS::Rooted<T> {
|
|||
/// Example usage: `rooted!(in(cx) let x = UndefinedValue());`.
|
||||
/// `RootedGuard::new` also works, but the macro is preferred.
|
||||
pub struct RootedGuard<'a, T: 'a + RootKind + GCMethods> {
|
||||
root: &'a mut JS::Rooted<T>
|
||||
root: &'a mut JS::Rooted<T>,
|
||||
}
|
||||
|
||||
impl<'a, T: 'a + RootKind + GCMethods> RootedGuard<'a, T> {
|
||||
|
@ -378,24 +405,21 @@ impl<'a, T: 'a + RootKind + GCMethods> RootedGuard<'a, T> {
|
|||
unsafe {
|
||||
root.register_with_root_lists(cx);
|
||||
}
|
||||
RootedGuard {
|
||||
root: root
|
||||
}
|
||||
RootedGuard { root: root }
|
||||
}
|
||||
|
||||
pub fn handle(&self) -> JS::Handle<T> {
|
||||
unsafe {
|
||||
JS::Handle::from_marked_location(&self.root.ptr)
|
||||
}
|
||||
unsafe { JS::Handle::from_marked_location(&self.root.ptr) }
|
||||
}
|
||||
|
||||
pub fn handle_mut(&mut self) -> JS::MutableHandle<T> {
|
||||
unsafe {
|
||||
JS::MutableHandle::from_marked_location(&mut self.root.ptr)
|
||||
}
|
||||
unsafe { JS::MutableHandle::from_marked_location(&mut self.root.ptr) }
|
||||
}
|
||||
|
||||
pub fn get(&self) -> T where T: Copy {
|
||||
pub fn get(&self) -> T
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
self.root.ptr
|
||||
}
|
||||
|
||||
|
@ -435,12 +459,13 @@ macro_rules! rooted {
|
|||
(in($cx:expr) let mut $name:ident = $init:expr) => {
|
||||
let mut __root = $crate::jsapi::JS::Rooted::new_unrooted();
|
||||
let mut $name = $crate::rust::RootedGuard::new($cx, &mut __root, $init);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl<T> JS::Handle<T> {
|
||||
pub fn get(&self) -> T
|
||||
where T: Copy
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
unsafe { *self.ptr }
|
||||
}
|
||||
|
@ -470,19 +495,19 @@ impl<T> JS::MutableHandle<T> {
|
|||
}
|
||||
|
||||
pub fn handle(&self) -> JS::Handle<T> {
|
||||
unsafe {
|
||||
JS::Handle::from_marked_location(self.ptr as *const _)
|
||||
}
|
||||
unsafe { JS::Handle::from_marked_location(self.ptr as *const _) }
|
||||
}
|
||||
|
||||
pub fn get(&self) -> T
|
||||
where T: Copy
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
unsafe { *self.ptr }
|
||||
}
|
||||
|
||||
pub fn set(&self, v: T)
|
||||
where T: Copy
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
unsafe { *self.ptr = v }
|
||||
}
|
||||
|
@ -504,15 +529,11 @@ impl<T> DerefMut for JS::MutableHandle<T> {
|
|||
|
||||
impl JS::HandleValue {
|
||||
pub fn null() -> JS::HandleValue {
|
||||
unsafe {
|
||||
JS::NullHandleValue
|
||||
}
|
||||
unsafe { JS::NullHandleValue }
|
||||
}
|
||||
|
||||
pub fn undefined() -> JS::HandleValue {
|
||||
unsafe {
|
||||
JS::UndefinedHandleValue
|
||||
}
|
||||
unsafe { JS::UndefinedHandleValue }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -527,7 +548,7 @@ impl JS::HandleValueArray {
|
|||
pub unsafe fn from_rooted_slice(values: &[JS::Value]) -> JS::HandleValueArray {
|
||||
JS::HandleValueArray {
|
||||
length_: values.len(),
|
||||
elements_: values.as_ptr()
|
||||
elements_: values.as_ptr(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -536,9 +557,7 @@ const ConstNullValue: *mut JSObject = 0 as *mut JSObject;
|
|||
|
||||
impl JS::HandleObject {
|
||||
pub fn null() -> JS::HandleObject {
|
||||
unsafe {
|
||||
JS::HandleObject::from_marked_location(&ConstNullValue)
|
||||
}
|
||||
unsafe { JS::HandleObject::from_marked_location(&ConstNullValue) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -551,11 +570,15 @@ impl Default for jsid {
|
|||
}
|
||||
|
||||
impl Default for JS::Value {
|
||||
fn default() -> JS::Value { jsval::UndefinedValue() }
|
||||
fn default() -> JS::Value {
|
||||
jsval::UndefinedValue()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for JS::RealmOptions {
|
||||
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
|
||||
fn default() -> Self {
|
||||
unsafe { ::std::mem::zeroed() }
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GCMethods {
|
||||
|
@ -564,55 +587,74 @@ pub trait GCMethods {
|
|||
}
|
||||
|
||||
impl GCMethods for jsid {
|
||||
unsafe fn initial() -> jsid { Default::default() }
|
||||
unsafe fn initial() -> jsid {
|
||||
Default::default()
|
||||
}
|
||||
unsafe fn write_barriers(_: *mut jsid, _: jsid, _: jsid) {}
|
||||
}
|
||||
|
||||
#[cfg(feature = "bigint")]
|
||||
impl GCMethods for *mut JS::BigInt {
|
||||
unsafe fn initial() -> *mut JS::BigInt { ptr::null_mut() }
|
||||
unsafe fn write_barriers(v: *mut *mut JS::BigInt, prev: *mut JS::BigInt,
|
||||
next: *mut JS::BigInt) {
|
||||
unsafe fn initial() -> *mut JS::BigInt {
|
||||
ptr::null_mut()
|
||||
}
|
||||
unsafe fn write_barriers(
|
||||
v: *mut *mut JS::BigInt,
|
||||
prev: *mut JS::BigInt,
|
||||
next: *mut JS::BigInt,
|
||||
) {
|
||||
JS::HeapBigIntWriteBarriers(v, prev, next);
|
||||
}
|
||||
}
|
||||
|
||||
impl GCMethods for *mut JSObject {
|
||||
unsafe fn initial() -> *mut JSObject { ptr::null_mut() }
|
||||
unsafe fn write_barriers(v: *mut *mut JSObject,
|
||||
prev: *mut JSObject, next: *mut JSObject) {
|
||||
unsafe fn initial() -> *mut JSObject {
|
||||
ptr::null_mut()
|
||||
}
|
||||
unsafe fn write_barriers(v: *mut *mut JSObject, prev: *mut JSObject, next: *mut JSObject) {
|
||||
JS::HeapObjectWriteBarriers(v, prev, next);
|
||||
}
|
||||
}
|
||||
|
||||
impl GCMethods for *mut JSString {
|
||||
unsafe fn initial() -> *mut JSString { ptr::null_mut() }
|
||||
unsafe fn write_barriers(v: *mut *mut JSString, prev: *mut JSString,
|
||||
next: *mut JSString) {
|
||||
unsafe fn initial() -> *mut JSString {
|
||||
ptr::null_mut()
|
||||
}
|
||||
unsafe fn write_barriers(v: *mut *mut JSString, prev: *mut JSString, next: *mut JSString) {
|
||||
JS::HeapStringWriteBarriers(v, prev, next);
|
||||
}
|
||||
}
|
||||
|
||||
impl GCMethods for *mut JSScript {
|
||||
unsafe fn initial() -> *mut JSScript { ptr::null_mut() }
|
||||
unsafe fn write_barriers(v: *mut *mut JSScript, prev: *mut JSScript,
|
||||
next: *mut JSScript) {
|
||||
unsafe fn initial() -> *mut JSScript {
|
||||
ptr::null_mut()
|
||||
}
|
||||
unsafe fn write_barriers(v: *mut *mut JSScript, prev: *mut JSScript, next: *mut JSScript) {
|
||||
JS::HeapScriptWriteBarriers(v, prev, next);
|
||||
}
|
||||
}
|
||||
|
||||
impl GCMethods for *mut JSFunction {
|
||||
unsafe fn initial() -> *mut JSFunction { ptr::null_mut() }
|
||||
unsafe fn write_barriers(v: *mut *mut JSFunction,
|
||||
prev: *mut JSFunction, next: *mut JSFunction) {
|
||||
JS::HeapObjectWriteBarriers(mem::transmute(v),
|
||||
mem::transmute(prev),
|
||||
mem::transmute(next));
|
||||
unsafe fn initial() -> *mut JSFunction {
|
||||
ptr::null_mut()
|
||||
}
|
||||
unsafe fn write_barriers(
|
||||
v: *mut *mut JSFunction,
|
||||
prev: *mut JSFunction,
|
||||
next: *mut JSFunction,
|
||||
) {
|
||||
JS::HeapObjectWriteBarriers(
|
||||
mem::transmute(v),
|
||||
mem::transmute(prev),
|
||||
mem::transmute(next),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl GCMethods for JS::Value {
|
||||
unsafe fn initial() -> JS::Value { UndefinedValue() }
|
||||
unsafe fn initial() -> JS::Value {
|
||||
UndefinedValue()
|
||||
}
|
||||
unsafe fn write_barriers(v: *mut JS::Value, prev: JS::Value, next: JS::Value) {
|
||||
JS::HeapValueWriteBarriers(v, &prev, &next);
|
||||
}
|
||||
|
@ -623,7 +665,9 @@ impl GCMethods for JS::Value {
|
|||
|
||||
impl Drop for JSAutoRealm {
|
||||
fn drop(&mut self) {
|
||||
unsafe { JS::LeaveRealm(self.cx_, self.oldRealm_); }
|
||||
unsafe {
|
||||
JS::LeaveRealm(self.cx_, self.oldRealm_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -642,24 +686,18 @@ impl JSJitMethodCallArgs {
|
|||
#[inline]
|
||||
pub fn index(&self, i: u32) -> JS::HandleValue {
|
||||
assert!(i < self._base.argc_);
|
||||
unsafe {
|
||||
JS::HandleValue::from_marked_location(self._base.argv_.offset(i as isize))
|
||||
}
|
||||
unsafe { JS::HandleValue::from_marked_location(self._base.argv_.offset(i as isize)) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn index_mut(&self, i: u32) -> JS::MutableHandleValue {
|
||||
assert!(i < self._base.argc_);
|
||||
unsafe {
|
||||
JS::MutableHandleValue::from_marked_location(self._base.argv_.offset(i as isize))
|
||||
}
|
||||
unsafe { JS::MutableHandleValue::from_marked_location(self._base.argv_.offset(i as isize)) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn rval(&self) -> JS::MutableHandleValue {
|
||||
unsafe {
|
||||
JS::MutableHandleValue::from_marked_location(self._base.argv_.offset(-2))
|
||||
}
|
||||
unsafe { JS::MutableHandleValue::from_marked_location(self._base.argv_.offset(-2)) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -674,17 +712,13 @@ impl JS::CallArgs {
|
|||
#[inline]
|
||||
pub fn index(&self, i: u32) -> JS::HandleValue {
|
||||
assert!(i < self._base.argc_);
|
||||
unsafe {
|
||||
JS::HandleValue::from_marked_location(self._base.argv_.offset(i as isize))
|
||||
}
|
||||
unsafe { JS::HandleValue::from_marked_location(self._base.argv_.offset(i as isize)) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn index_mut(&self, i: u32) -> JS::MutableHandleValue {
|
||||
assert!(i < self._base.argc_);
|
||||
unsafe {
|
||||
JS::MutableHandleValue::from_marked_location(self._base.argv_.offset(i as isize))
|
||||
}
|
||||
unsafe { JS::MutableHandleValue::from_marked_location(self._base.argv_.offset(i as isize)) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -700,23 +734,17 @@ impl JS::CallArgs {
|
|||
|
||||
#[inline]
|
||||
pub fn rval(&self) -> JS::MutableHandleValue {
|
||||
unsafe {
|
||||
JS::MutableHandleValue::from_marked_location(self._base.argv_.offset(-2))
|
||||
}
|
||||
unsafe { JS::MutableHandleValue::from_marked_location(self._base.argv_.offset(-2)) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn thisv(&self) -> JS::HandleValue {
|
||||
unsafe {
|
||||
JS::HandleValue::from_marked_location(self._base.argv_.offset(-1))
|
||||
}
|
||||
unsafe { JS::HandleValue::from_marked_location(self._base.argv_.offset(-1)) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn calleev(&self) -> JS::HandleValue {
|
||||
unsafe {
|
||||
JS::HandleValue::from_marked_location(self._base.argv_.offset(-2))
|
||||
}
|
||||
unsafe { JS::HandleValue::from_marked_location(self._base.argv_.offset(-2)) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -729,7 +757,8 @@ impl JS::CallArgs {
|
|||
assert!(self._base.constructing_());
|
||||
unsafe {
|
||||
JS::MutableHandleValue::from_marked_location(
|
||||
self._base.argv_.offset(self._base.argc_ as isize))
|
||||
self._base.argv_.offset(self._base.argc_ as isize),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -753,22 +782,18 @@ impl JSJitSetterCallArgs {
|
|||
// Wrappers around things in jsglue.cpp
|
||||
|
||||
pub struct RootedObjectVectorWrapper {
|
||||
pub ptr: *mut JS::PersistentRootedObjectVector
|
||||
pub ptr: *mut JS::PersistentRootedObjectVector,
|
||||
}
|
||||
|
||||
impl RootedObjectVectorWrapper {
|
||||
pub fn new(cx: *mut JSContext) -> RootedObjectVectorWrapper {
|
||||
RootedObjectVectorWrapper {
|
||||
ptr: unsafe {
|
||||
CreateRootedObjectVector(cx)
|
||||
}
|
||||
ptr: unsafe { CreateRootedObjectVector(cx) },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn append(&self, obj: *mut JSObject) -> bool {
|
||||
unsafe {
|
||||
AppendToRootedObjectVector(self.ptr, obj)
|
||||
}
|
||||
unsafe { AppendToRootedObjectVector(self.ptr, obj) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -779,13 +804,17 @@ impl Drop for RootedObjectVectorWrapper {
|
|||
}
|
||||
|
||||
pub struct CompileOptionsWrapper {
|
||||
pub ptr: *mut JS::ReadOnlyCompileOptions
|
||||
pub ptr: *mut JS::ReadOnlyCompileOptions,
|
||||
}
|
||||
|
||||
impl CompileOptionsWrapper {
|
||||
pub fn new(cx: *mut JSContext, file: *const ::libc::c_char, line: c_uint) -> CompileOptionsWrapper {
|
||||
pub fn new(
|
||||
cx: *mut JSContext,
|
||||
file: *const ::libc::c_char,
|
||||
line: c_uint,
|
||||
) -> CompileOptionsWrapper {
|
||||
CompileOptionsWrapper {
|
||||
ptr: unsafe { NewCompileOptions(cx, file, line) }
|
||||
ptr: unsafe { NewCompileOptions(cx, file, line) },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -846,9 +875,8 @@ pub unsafe fn ToNumber(cx: *mut JSContext, v: JS::HandleValue) -> Result<f64, ()
|
|||
unsafe fn convert_from_int32<T: Default + Copy>(
|
||||
cx: *mut JSContext,
|
||||
v: JS::HandleValue,
|
||||
conv_fn: unsafe extern "C" fn(*mut JSContext, JS::HandleValue, *mut T) -> bool)
|
||||
-> Result<T, ()> {
|
||||
|
||||
conv_fn: unsafe extern "C" fn(*mut JSContext, JS::HandleValue, *mut T) -> bool,
|
||||
) -> Result<T, ()> {
|
||||
let val = *v.ptr;
|
||||
if val.is_int32() {
|
||||
let intval: i64 = val.to_int32() as i64;
|
||||
|
@ -900,9 +928,12 @@ pub unsafe fn ToString(cx: *mut JSContext, v: JS::HandleValue) -> *mut JSString
|
|||
js::ToStringSlow(cx, v)
|
||||
}
|
||||
|
||||
pub unsafe extern fn report_warning(_cx: *mut JSContext, report: *mut JSErrorReport) {
|
||||
pub unsafe extern "C" fn report_warning(_cx: *mut JSContext, report: *mut JSErrorReport) {
|
||||
fn latin1_to_string(bytes: &[u8]) -> String {
|
||||
bytes.iter().map(|c| char::from_u32(*c as u32).unwrap()).collect()
|
||||
bytes
|
||||
.iter()
|
||||
.map(|c| char::from_u32(*c as u32).unwrap())
|
||||
.collect()
|
||||
}
|
||||
|
||||
let fnptr = (*report)._base.filename;
|
||||
|
@ -917,7 +948,9 @@ pub unsafe extern fn report_warning(_cx: *mut JSContext, report: *mut JSErrorRep
|
|||
let column = (*report)._base.column;
|
||||
|
||||
let msg_ptr = (*report)._base.message_.data_ as *const u16;
|
||||
let msg_len = (0usize..).find(|&i| *msg_ptr.offset(i as isize) == 0).unwrap();
|
||||
let msg_len = (0usize..)
|
||||
.find(|&i| *msg_ptr.offset(i as isize) == 0)
|
||||
.unwrap();
|
||||
let msg_slice = slice::from_raw_parts(msg_ptr, msg_len);
|
||||
let msg = String::from_utf16_lossy(msg_slice);
|
||||
|
||||
|
@ -932,30 +965,24 @@ impl JSNativeWrapper {
|
|||
}
|
||||
|
||||
pub struct RootedIdVectorWrapper {
|
||||
pub ptr: *mut JS::PersistentRootedIdVector
|
||||
pub ptr: *mut JS::PersistentRootedIdVector,
|
||||
}
|
||||
|
||||
impl RootedIdVectorWrapper {
|
||||
pub fn new(cx: *mut JSContext) -> RootedIdVectorWrapper {
|
||||
RootedIdVectorWrapper {
|
||||
ptr: unsafe {
|
||||
CreateRootedIdVector(cx)
|
||||
}
|
||||
ptr: unsafe { CreateRootedIdVector(cx) },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_mut(&self) -> JS::MutableHandleIdVector {
|
||||
unsafe {
|
||||
GetMutableHandleIdVector(self.ptr)
|
||||
}
|
||||
unsafe { GetMutableHandleIdVector(self.ptr) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RootedIdVectorWrapper {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
DestroyRootedIdVector(self.ptr)
|
||||
}
|
||||
unsafe { DestroyRootedIdVector(self.ptr) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -986,15 +1013,26 @@ impl Deref for RootedIdVectorWrapper {
|
|||
///
|
||||
/// - `cx` must be valid.
|
||||
/// - This function calls into unaudited C++ code.
|
||||
pub unsafe fn define_methods(cx: *mut JSContext, obj: JS::HandleObject,
|
||||
methods: &'static [JSFunctionSpec])
|
||||
-> Result<(), ()> {
|
||||
pub unsafe fn define_methods(
|
||||
cx: *mut JSContext,
|
||||
obj: JS::HandleObject,
|
||||
methods: &'static [JSFunctionSpec],
|
||||
) -> Result<(), ()> {
|
||||
assert!({
|
||||
match methods.last() {
|
||||
Some(&JSFunctionSpec { name: JSFunctionSpec_Name { string_: name, }, call, nargs, flags, selfHostedName }) => {
|
||||
name.is_null() && call.is_zeroed() && nargs == 0 && flags == 0 &&
|
||||
selfHostedName.is_null()
|
||||
},
|
||||
Some(&JSFunctionSpec {
|
||||
name: JSFunctionSpec_Name { string_: name },
|
||||
call,
|
||||
nargs,
|
||||
flags,
|
||||
selfHostedName,
|
||||
}) => {
|
||||
name.is_null()
|
||||
&& call.is_zeroed()
|
||||
&& nargs == 0
|
||||
&& flags == 0
|
||||
&& selfHostedName.is_null()
|
||||
}
|
||||
None => false,
|
||||
}
|
||||
});
|
||||
|
@ -1017,14 +1055,18 @@ pub unsafe fn define_methods(cx: *mut JSContext, obj: JS::HandleObject,
|
|||
///
|
||||
/// - `cx` must be valid.
|
||||
/// - This function calls into unaudited C++ code.
|
||||
pub unsafe fn define_properties(cx: *mut JSContext, obj: JS::HandleObject,
|
||||
properties: &'static [JSPropertySpec])
|
||||
-> Result<(), ()> {
|
||||
pub unsafe fn define_properties(
|
||||
cx: *mut JSContext,
|
||||
obj: JS::HandleObject,
|
||||
properties: &'static [JSPropertySpec],
|
||||
) -> Result<(), ()> {
|
||||
assert!(!properties.is_empty());
|
||||
assert!({
|
||||
let spec = properties.last().unwrap();
|
||||
let slice = slice::from_raw_parts(spec as *const _ as *const u8,
|
||||
mem::size_of::<JSPropertySpec>());
|
||||
let slice = slice::from_raw_parts(
|
||||
spec as *const _ as *const u8,
|
||||
mem::size_of::<JSPropertySpec>(),
|
||||
);
|
||||
slice.iter().all(|byte| *byte == 0)
|
||||
});
|
||||
|
||||
|
@ -1048,11 +1090,13 @@ static SIMPLE_GLOBAL_CLASS_OPS: JSClassOps = JSClassOps {
|
|||
/// This is a simple `JSClass` for global objects, primarily intended for tests.
|
||||
pub static SIMPLE_GLOBAL_CLASS: JSClass = JSClass {
|
||||
name: b"Global\0" as *const u8 as *const _,
|
||||
flags: (JSCLASS_IS_GLOBAL | ((JSCLASS_GLOBAL_SLOT_COUNT & JSCLASS_RESERVED_SLOTS_MASK) << JSCLASS_RESERVED_SLOTS_SHIFT)) as u32,
|
||||
flags: (JSCLASS_IS_GLOBAL
|
||||
| ((JSCLASS_GLOBAL_SLOT_COUNT & JSCLASS_RESERVED_SLOTS_MASK)
|
||||
<< JSCLASS_RESERVED_SLOTS_SHIFT)) as u32,
|
||||
cOps: &SIMPLE_GLOBAL_CLASS_OPS as *const JSClassOps,
|
||||
spec: 0 as *mut _,
|
||||
ext: 0 as *mut _,
|
||||
oOps: 0 as *mut _
|
||||
oOps: 0 as *mut _,
|
||||
};
|
||||
|
||||
#[inline]
|
||||
|
@ -1116,9 +1160,7 @@ pub unsafe fn maybe_wrap_object_value(cx: *mut JSContext, rval: JS::MutableHandl
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn maybe_wrap_object_or_null_value(
|
||||
cx: *mut JSContext,
|
||||
rval: JS::MutableHandleValue) {
|
||||
pub unsafe fn maybe_wrap_object_or_null_value(cx: *mut JSContext, rval: JS::MutableHandleValue) {
|
||||
assert!(rval.is_object_or_null());
|
||||
if !rval.is_null() {
|
||||
maybe_wrap_object_value(cx, rval);
|
||||
|
@ -1136,14 +1178,14 @@ pub unsafe fn maybe_wrap_value(cx: *mut JSContext, rval: JS::MutableHandleValue)
|
|||
|
||||
/// Equivalents of the JS_FN* macros.
|
||||
impl JSFunctionSpec {
|
||||
pub fn js_fs(name: *const ::std::os::raw::c_char,
|
||||
func: JSNative,
|
||||
nargs: u16,
|
||||
flags: u16) -> JSFunctionSpec {
|
||||
pub fn js_fs(
|
||||
name: *const ::std::os::raw::c_char,
|
||||
func: JSNative,
|
||||
nargs: u16,
|
||||
flags: u16,
|
||||
) -> JSFunctionSpec {
|
||||
JSFunctionSpec {
|
||||
name: JSFunctionSpec_Name {
|
||||
string_: name,
|
||||
},
|
||||
name: JSFunctionSpec_Name { string_: name },
|
||||
call: JSNativeWrapper {
|
||||
op: func,
|
||||
info: ptr::null(),
|
||||
|
@ -1154,14 +1196,14 @@ impl JSFunctionSpec {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn js_fn(name: *const ::std::os::raw::c_char,
|
||||
func: JSNative,
|
||||
nargs: u16,
|
||||
flags: u16) -> JSFunctionSpec {
|
||||
pub fn js_fn(
|
||||
name: *const ::std::os::raw::c_char,
|
||||
func: JSNative,
|
||||
nargs: u16,
|
||||
flags: u16,
|
||||
) -> JSFunctionSpec {
|
||||
JSFunctionSpec {
|
||||
name: JSFunctionSpec_Name {
|
||||
string_: name,
|
||||
},
|
||||
name: JSFunctionSpec_Name { string_: name },
|
||||
call: JSNativeWrapper {
|
||||
op: func,
|
||||
info: ptr::null(),
|
||||
|
@ -1188,13 +1230,14 @@ impl JSFunctionSpec {
|
|||
|
||||
/// Equivalents of the JS_PS* macros.
|
||||
impl JSPropertySpec {
|
||||
pub fn getter(name: *const ::std::os::raw::c_char, flags: u8, func: JSNative)
|
||||
-> JSPropertySpec {
|
||||
pub fn getter(
|
||||
name: *const ::std::os::raw::c_char,
|
||||
flags: u8,
|
||||
func: JSNative,
|
||||
) -> JSPropertySpec {
|
||||
debug_assert_eq!(flags & !(JSPROP_ENUMERATE | JSPROP_PERMANENT), 0);
|
||||
JSPropertySpec {
|
||||
name: JSPropertySpec_Name {
|
||||
string_: name,
|
||||
},
|
||||
name: JSPropertySpec_Name { string_: name },
|
||||
flags: flags,
|
||||
u: JSPropertySpec_AccessorsOrValue {
|
||||
accessors: JSPropertySpec_AccessorsOrValue_Accessors {
|
||||
|
@ -1209,22 +1252,21 @@ impl JSPropertySpec {
|
|||
op: None,
|
||||
info: ptr::null(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getter_setter(name: *const ::std::os::raw::c_char,
|
||||
flags: u8,
|
||||
g_f: JSNative,
|
||||
s_f: JSNative)
|
||||
-> JSPropertySpec {
|
||||
pub fn getter_setter(
|
||||
name: *const ::std::os::raw::c_char,
|
||||
flags: u8,
|
||||
g_f: JSNative,
|
||||
s_f: JSNative,
|
||||
) -> JSPropertySpec {
|
||||
debug_assert_eq!(flags & !(JSPROP_ENUMERATE | JSPROP_PERMANENT), 0);
|
||||
JSPropertySpec {
|
||||
name: JSPropertySpec_Name {
|
||||
string_: name,
|
||||
},
|
||||
name: JSPropertySpec_Name { string_: name },
|
||||
flags: flags,
|
||||
u: JSPropertySpec_AccessorsOrValue {
|
||||
accessors: JSPropertySpec_AccessorsOrValue_Accessors {
|
||||
|
@ -1239,9 +1281,9 @@ impl JSPropertySpec {
|
|||
op: s_f,
|
||||
info: ptr::null(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1250,7 +1292,7 @@ impl JSPropertySpec {
|
|||
string_: 0 as *const _,
|
||||
},
|
||||
flags: 0,
|
||||
u: JSPropertySpec_AccessorsOrValue{
|
||||
u: JSPropertySpec_AccessorsOrValue {
|
||||
accessors: JSPropertySpec_AccessorsOrValue_Accessors {
|
||||
getter: JSPropertySpec_Accessor {
|
||||
native: JSNativeWrapper {
|
||||
|
@ -1263,8 +1305,8 @@ impl JSPropertySpec {
|
|||
op: None,
|
||||
info: 0 as *const _,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -20,30 +20,23 @@ impl StructuredCloneBuffer {
|
|||
/// # Panics
|
||||
///
|
||||
/// Panics if the underlying JSAPI calls fail.
|
||||
pub fn new(scope: jsapi::JS::StructuredCloneScope,
|
||||
callbacks: &jsapi::JSStructuredCloneCallbacks)
|
||||
-> StructuredCloneBuffer {
|
||||
let raw = unsafe {
|
||||
glue::NewJSAutoStructuredCloneBuffer(scope, callbacks)
|
||||
};
|
||||
pub fn new(
|
||||
scope: jsapi::JS::StructuredCloneScope,
|
||||
callbacks: &jsapi::JSStructuredCloneCallbacks,
|
||||
) -> StructuredCloneBuffer {
|
||||
let raw = unsafe { glue::NewJSAutoStructuredCloneBuffer(scope, callbacks) };
|
||||
assert!(!raw.is_null());
|
||||
StructuredCloneBuffer {
|
||||
raw: raw,
|
||||
}
|
||||
StructuredCloneBuffer { raw: raw }
|
||||
}
|
||||
|
||||
/// Get the raw `*mut JSStructuredCloneData` owned by this buffer.
|
||||
pub fn data(&self) -> *mut jsapi::JSStructuredCloneData {
|
||||
unsafe {
|
||||
&mut (*self.raw).data_
|
||||
}
|
||||
unsafe { &mut (*self.raw).data_ }
|
||||
}
|
||||
|
||||
/// Copy this buffer's data into a vec.
|
||||
pub fn copy_to_vec(&self) -> Vec<u8> {
|
||||
let len = unsafe {
|
||||
glue::GetLengthOfJSStructuredCloneData(self.data())
|
||||
};
|
||||
let len = unsafe { glue::GetLengthOfJSStructuredCloneData(self.data()) };
|
||||
let mut vec = Vec::with_capacity(len);
|
||||
unsafe {
|
||||
glue::CopyJSStructuredCloneData(self.data(), vec.as_mut_ptr());
|
||||
|
@ -52,12 +45,22 @@ impl StructuredCloneBuffer {
|
|||
}
|
||||
|
||||
/// Read a JS value out of this buffer.
|
||||
pub fn read(&mut self,
|
||||
vp: jsapi::JS::MutableHandleValue,
|
||||
callbacks: &jsapi::JSStructuredCloneCallbacks)
|
||||
-> Result<(), ()> {
|
||||
pub fn read(
|
||||
&mut self,
|
||||
vp: jsapi::JS::MutableHandleValue,
|
||||
callbacks: &jsapi::JSStructuredCloneCallbacks,
|
||||
) -> Result<(), ()> {
|
||||
if unsafe {
|
||||
(*self.raw).read(Runtime::get(), vp, &jsapi::JS::CloneDataPolicy{ allowIntraClusterClonableSharedObjects_: false, allowSharedMemoryObjects_: false }, callbacks, ptr::null_mut())
|
||||
(*self.raw).read(
|
||||
Runtime::get(),
|
||||
vp,
|
||||
&jsapi::JS::CloneDataPolicy {
|
||||
allowIntraClusterClonableSharedObjects_: false,
|
||||
allowSharedMemoryObjects_: false,
|
||||
},
|
||||
callbacks,
|
||||
ptr::null_mut(),
|
||||
)
|
||||
} {
|
||||
Ok(())
|
||||
} else {
|
||||
|
@ -66,13 +69,12 @@ impl StructuredCloneBuffer {
|
|||
}
|
||||
|
||||
/// Write a JS value into this buffer.
|
||||
pub fn write(&mut self,
|
||||
v: jsapi::JS::HandleValue,
|
||||
callbacks: &jsapi::JSStructuredCloneCallbacks)
|
||||
-> Result<(), ()> {
|
||||
if unsafe {
|
||||
(*self.raw).write(Runtime::get(), v, callbacks, ptr::null_mut())
|
||||
} {
|
||||
pub fn write(
|
||||
&mut self,
|
||||
v: jsapi::JS::HandleValue,
|
||||
callbacks: &jsapi::JSStructuredCloneCallbacks,
|
||||
) -> Result<(), ()> {
|
||||
if unsafe { (*self.raw).write(Runtime::get(), v, callbacks, ptr::null_mut()) } {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
|
@ -83,9 +85,7 @@ impl StructuredCloneBuffer {
|
|||
pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), ()> {
|
||||
let len = bytes.len();
|
||||
let src = bytes.as_ptr();
|
||||
if unsafe {
|
||||
glue::WriteBytesToJSStructuredCloneData(src, len, self.data())
|
||||
} {
|
||||
if unsafe { glue::WriteBytesToJSStructuredCloneData(src, len, self.data()) } {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
|
|
|
@ -15,9 +15,9 @@ use glue::GetUint16ArrayLengthAndData;
|
|||
use glue::GetUint32ArrayLengthAndData;
|
||||
use glue::GetUint8ArrayLengthAndData;
|
||||
use glue::GetUint8ClampedArrayLengthAndData;
|
||||
use jsapi::*;
|
||||
use jsapi::js::*;
|
||||
use jsapi::JS::*;
|
||||
use jsapi::*;
|
||||
use rust::RootedGuard;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
|
@ -37,10 +37,11 @@ impl<'a, T: TypedArrayElement> TypedArray<'a, T> {
|
|||
/// Create a typed array representation that wraps an existing JS reflector.
|
||||
/// This operation will fail if attempted on a JS object that does not match
|
||||
/// the expected typed array details.
|
||||
pub fn from(cx: *mut JSContext,
|
||||
root: &'a mut Rooted<*mut JSObject>,
|
||||
object: *mut JSObject)
|
||||
-> Result<Self, ()> {
|
||||
pub fn from(
|
||||
cx: *mut JSContext,
|
||||
root: &'a mut Rooted<*mut JSObject>,
|
||||
object: *mut JSObject,
|
||||
) -> Result<Self, ()> {
|
||||
if object.is_null() {
|
||||
return Err(());
|
||||
}
|
||||
|
@ -94,10 +95,11 @@ impl<'a, T: TypedArrayElement> TypedArray<'a, T> {
|
|||
impl<'a, T: TypedArrayElementCreator + TypedArrayElement> TypedArray<'a, T> {
|
||||
/// Create a new JS typed array, optionally providing initial data that will
|
||||
/// be copied into the newly-allocated buffer. Returns the new JS reflector.
|
||||
pub unsafe fn create(cx: *mut JSContext,
|
||||
with: CreateWith<T::Element>,
|
||||
result: MutableHandleObject)
|
||||
-> Result<(), ()> {
|
||||
pub unsafe fn create(
|
||||
cx: *mut JSContext,
|
||||
with: CreateWith<T::Element>,
|
||||
result: MutableHandleObject,
|
||||
) -> Result<(), ()> {
|
||||
let length = match with {
|
||||
CreateWith::Length(len) => len,
|
||||
CreateWith::Slice(slice) => slice.len() as u32,
|
||||
|
@ -150,7 +152,7 @@ macro_rules! typed_array_element {
|
|||
($t: ident,
|
||||
$element: ty,
|
||||
$unwrap: ident,
|
||||
$length_and_data: ident) => (
|
||||
$length_and_data: ident) => {
|
||||
/// A kind of typed array.
|
||||
pub struct $t;
|
||||
|
||||
|
@ -169,14 +171,14 @@ macro_rules! typed_array_element {
|
|||
(data, len)
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
($t: ident,
|
||||
$element: ty,
|
||||
$unwrap: ident,
|
||||
$length_and_data: ident,
|
||||
$create_new: ident,
|
||||
$get_data: ident) => (
|
||||
$get_data: ident) => {
|
||||
typed_array_element!($t, $element, $unwrap, $length_and_data);
|
||||
|
||||
impl TypedArrayElementCreator for $t {
|
||||
|
@ -191,73 +193,95 @@ macro_rules! typed_array_element {
|
|||
data
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
typed_array_element!(Uint8,
|
||||
u8,
|
||||
UnwrapUint8Array,
|
||||
GetUint8ArrayLengthAndData,
|
||||
JS_NewUint8Array,
|
||||
JS_GetUint8ArrayData);
|
||||
typed_array_element!(Uint16,
|
||||
u16,
|
||||
UnwrapUint16Array,
|
||||
GetUint16ArrayLengthAndData,
|
||||
JS_NewUint16Array,
|
||||
JS_GetUint16ArrayData);
|
||||
typed_array_element!(Uint32,
|
||||
u32,
|
||||
UnwrapUint32Array,
|
||||
GetUint32ArrayLengthAndData,
|
||||
JS_NewUint32Array,
|
||||
JS_GetUint32ArrayData);
|
||||
typed_array_element!(Int8,
|
||||
i8,
|
||||
UnwrapInt8Array,
|
||||
GetInt8ArrayLengthAndData,
|
||||
JS_NewInt8Array,
|
||||
JS_GetInt8ArrayData);
|
||||
typed_array_element!(Int16,
|
||||
i16,
|
||||
UnwrapInt16Array,
|
||||
GetInt16ArrayLengthAndData,
|
||||
JS_NewInt16Array,
|
||||
JS_GetInt16ArrayData);
|
||||
typed_array_element!(Int32,
|
||||
i32,
|
||||
UnwrapInt32Array,
|
||||
GetInt32ArrayLengthAndData,
|
||||
JS_NewInt32Array,
|
||||
JS_GetInt32ArrayData);
|
||||
typed_array_element!(Float32,
|
||||
f32,
|
||||
UnwrapFloat32Array,
|
||||
GetFloat32ArrayLengthAndData,
|
||||
JS_NewFloat32Array,
|
||||
JS_GetFloat32ArrayData);
|
||||
typed_array_element!(Float64,
|
||||
f64,
|
||||
UnwrapFloat64Array,
|
||||
GetFloat64ArrayLengthAndData,
|
||||
JS_NewFloat64Array,
|
||||
JS_GetFloat64ArrayData);
|
||||
typed_array_element!(ClampedU8,
|
||||
u8,
|
||||
UnwrapUint8ClampedArray,
|
||||
GetUint8ClampedArrayLengthAndData,
|
||||
JS_NewUint8ClampedArray,
|
||||
JS_GetUint8ClampedArrayData);
|
||||
typed_array_element!(ArrayBufferU8,
|
||||
u8,
|
||||
UnwrapArrayBuffer,
|
||||
GetArrayBufferLengthAndData,
|
||||
NewArrayBuffer,
|
||||
GetArrayBufferData);
|
||||
typed_array_element!(ArrayBufferViewU8,
|
||||
u8,
|
||||
UnwrapArrayBufferView,
|
||||
GetArrayBufferViewLengthAndData);
|
||||
typed_array_element!(
|
||||
Uint8,
|
||||
u8,
|
||||
UnwrapUint8Array,
|
||||
GetUint8ArrayLengthAndData,
|
||||
JS_NewUint8Array,
|
||||
JS_GetUint8ArrayData
|
||||
);
|
||||
typed_array_element!(
|
||||
Uint16,
|
||||
u16,
|
||||
UnwrapUint16Array,
|
||||
GetUint16ArrayLengthAndData,
|
||||
JS_NewUint16Array,
|
||||
JS_GetUint16ArrayData
|
||||
);
|
||||
typed_array_element!(
|
||||
Uint32,
|
||||
u32,
|
||||
UnwrapUint32Array,
|
||||
GetUint32ArrayLengthAndData,
|
||||
JS_NewUint32Array,
|
||||
JS_GetUint32ArrayData
|
||||
);
|
||||
typed_array_element!(
|
||||
Int8,
|
||||
i8,
|
||||
UnwrapInt8Array,
|
||||
GetInt8ArrayLengthAndData,
|
||||
JS_NewInt8Array,
|
||||
JS_GetInt8ArrayData
|
||||
);
|
||||
typed_array_element!(
|
||||
Int16,
|
||||
i16,
|
||||
UnwrapInt16Array,
|
||||
GetInt16ArrayLengthAndData,
|
||||
JS_NewInt16Array,
|
||||
JS_GetInt16ArrayData
|
||||
);
|
||||
typed_array_element!(
|
||||
Int32,
|
||||
i32,
|
||||
UnwrapInt32Array,
|
||||
GetInt32ArrayLengthAndData,
|
||||
JS_NewInt32Array,
|
||||
JS_GetInt32ArrayData
|
||||
);
|
||||
typed_array_element!(
|
||||
Float32,
|
||||
f32,
|
||||
UnwrapFloat32Array,
|
||||
GetFloat32ArrayLengthAndData,
|
||||
JS_NewFloat32Array,
|
||||
JS_GetFloat32ArrayData
|
||||
);
|
||||
typed_array_element!(
|
||||
Float64,
|
||||
f64,
|
||||
UnwrapFloat64Array,
|
||||
GetFloat64ArrayLengthAndData,
|
||||
JS_NewFloat64Array,
|
||||
JS_GetFloat64ArrayData
|
||||
);
|
||||
typed_array_element!(
|
||||
ClampedU8,
|
||||
u8,
|
||||
UnwrapUint8ClampedArray,
|
||||
GetUint8ClampedArrayLengthAndData,
|
||||
JS_NewUint8ClampedArray,
|
||||
JS_GetUint8ClampedArrayData
|
||||
);
|
||||
typed_array_element!(
|
||||
ArrayBufferU8,
|
||||
u8,
|
||||
UnwrapArrayBuffer,
|
||||
GetArrayBufferLengthAndData,
|
||||
NewArrayBuffer,
|
||||
GetArrayBufferData
|
||||
);
|
||||
typed_array_element!(
|
||||
ArrayBufferViewU8,
|
||||
u8,
|
||||
UnwrapArrayBufferView,
|
||||
GetArrayBufferViewLengthAndData
|
||||
);
|
||||
|
||||
/// The Uint8ClampedArray type.
|
||||
pub type Uint8ClampedArray<'a> = TypedArray<'a, ClampedU8>;
|
||||
|
@ -297,5 +321,5 @@ macro_rules! typedarray {
|
|||
(in($cx:expr) let mut $name:ident : $ty:ident = $init:expr) => {
|
||||
let mut __root = $crate::jsapi::JS::Rooted::new_unrooted();
|
||||
let mut $name = $crate::typedarray::$ty::from($cx, &mut __root, $init);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#[macro_use]
|
||||
extern crate js;
|
||||
|
||||
use js::jsapi::root::JS::CompartmentOptions;
|
||||
use js::jsapi::root::JS_NewGlobalObject;
|
||||
use js::jsapi::root::JS::CompartmentOptions;
|
||||
use js::jsapi::root::JS::OnNewGlobalHookOption;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::{Runtime, SIMPLE_GLOBAL_CLASS};
|
||||
|
@ -22,8 +22,9 @@ fn is_bigint() {
|
|||
);
|
||||
|
||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||
assert!(rt.evaluate_script(global.handle(), "BigInt(0)",
|
||||
"test", 1, rval.handle_mut()).is_ok());
|
||||
assert!(rt
|
||||
.evaluate_script(global.handle(), "BigInt(0)", "test", 1, rval.handle_mut())
|
||||
.is_ok());
|
||||
assert!(rval.is_bigint());
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +42,15 @@ fn is_not_bigint() {
|
|||
);
|
||||
|
||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||
assert!(rt.evaluate_script(global.handle(), "'not a BigInt'",
|
||||
"test", 1, rval.handle_mut()).is_ok());
|
||||
assert!(rt
|
||||
.evaluate_script(
|
||||
global.handle(),
|
||||
"'not a BigInt'",
|
||||
"test",
|
||||
1,
|
||||
rval.handle_mut()
|
||||
)
|
||||
.is_ok());
|
||||
assert!(!rval.is_bigint());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ extern crate libc;
|
|||
|
||||
use js::ar::AutoRealm;
|
||||
use js::glue::JSEncodeStringToUTF8;
|
||||
use js::jsapi::root::JS::CallArgs;
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsapi::root::JSContext;
|
||||
use js::jsapi::root::JS_DefineFunction;
|
||||
use js::jsapi::root::JS_NewGlobalObject;
|
||||
use js::jsapi::root::JS_ReportErrorASCII;
|
||||
use js::jsapi::root::JS::CallArgs;
|
||||
use js::jsapi::root::JS::OnNewGlobalHookOption;
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsapi::root::JS::Value;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::{Runtime, SIMPLE_GLOBAL_CLASS};
|
||||
|
@ -31,12 +31,24 @@ fn callback() {
|
|||
let c_option = RealmOptions::default();
|
||||
|
||||
unsafe {
|
||||
let global = JS_NewGlobalObject(context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &c_option);
|
||||
let global = JS_NewGlobalObject(
|
||||
context,
|
||||
&SIMPLE_GLOBAL_CLASS,
|
||||
ptr::null_mut(),
|
||||
h_option,
|
||||
&c_option,
|
||||
);
|
||||
rooted!(in(context) let global_root = global);
|
||||
let global = global_root.handle();
|
||||
let _ar = AutoRealm::with_obj(context, global.get());
|
||||
let function = JS_DefineFunction(context, global, b"puts\0".as_ptr() as *const libc::c_char,
|
||||
Some(puts), 1, 0);
|
||||
let function = JS_DefineFunction(
|
||||
context,
|
||||
global,
|
||||
b"puts\0".as_ptr() as *const libc::c_char,
|
||||
Some(puts),
|
||||
1,
|
||||
0,
|
||||
);
|
||||
assert!(!function.is_null());
|
||||
let javascript = "puts('Test Iñtërnâtiônàlizætiøn ┬─┬ノ( º _ ºノ) ');";
|
||||
rooted!(in(context) let mut rval = UndefinedValue());
|
||||
|
@ -48,7 +60,10 @@ unsafe extern "C" fn puts(context: *mut JSContext, argc: u32, vp: *mut Value) ->
|
|||
let args = CallArgs::from_vp(vp, argc);
|
||||
|
||||
if args._base.argc_ != 1 {
|
||||
JS_ReportErrorASCII(context, b"puts() requires exactly 1 argument\0".as_ptr() as *const libc::c_char);
|
||||
JS_ReportErrorASCII(
|
||||
context,
|
||||
b"puts() requires exactly 1 argument\0".as_ptr() as *const libc::c_char,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ extern crate js;
|
|||
|
||||
use js::glue::RUST_JSID_IS_STRING;
|
||||
use js::glue::RUST_JSID_TO_STRING;
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsapi::root::js::GetPropertyKeys;
|
||||
use js::jsapi::root::JSITER_OWNONLY;
|
||||
use js::jsapi::root::JS_NewGlobalObject;
|
||||
use js::jsapi::root::JS_StringEqualsAscii;
|
||||
use js::jsapi::root::JS::OnNewGlobalHookOption;
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsapi::root::JSITER_OWNONLY;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::RootedIdVectorWrapper;
|
||||
use js::rust::Runtime;
|
||||
|
@ -32,13 +32,25 @@ fn enumerate() {
|
|||
);
|
||||
|
||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||
assert!(rt.evaluate_script(global.handle(), "({ 'a': 7 })",
|
||||
"test", 1, rval.handle_mut()).is_ok());
|
||||
assert!(rt
|
||||
.evaluate_script(
|
||||
global.handle(),
|
||||
"({ 'a': 7 })",
|
||||
"test",
|
||||
1,
|
||||
rval.handle_mut()
|
||||
)
|
||||
.is_ok());
|
||||
assert!(rval.is_object());
|
||||
|
||||
rooted!(in(cx) let object = rval.to_object());
|
||||
let ids = RootedIdVectorWrapper::new(cx);
|
||||
assert!(GetPropertyKeys(cx, object.handle(), JSITER_OWNONLY, ids.handle_mut()));
|
||||
assert!(GetPropertyKeys(
|
||||
cx,
|
||||
object.handle(),
|
||||
JSITER_OWNONLY,
|
||||
ids.handle_mut()
|
||||
));
|
||||
|
||||
assert_eq!(ids.len(), 1);
|
||||
rooted!(in(cx) let id = ids[0]);
|
||||
|
@ -47,10 +59,12 @@ fn enumerate() {
|
|||
rooted!(in(cx) let id = RUST_JSID_TO_STRING(id.handle()));
|
||||
|
||||
let mut matches = false;
|
||||
assert!(JS_StringEqualsAscii(cx,
|
||||
id.get(),
|
||||
b"a\0" as *const _ as *const _,
|
||||
&mut matches));
|
||||
assert!(JS_StringEqualsAscii(
|
||||
cx,
|
||||
id.get(),
|
||||
b"a\0" as *const _ as *const _,
|
||||
&mut matches
|
||||
));
|
||||
assert!(matches);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
#[macro_use]
|
||||
extern crate js;
|
||||
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsapi::root::JS_NewGlobalObject;
|
||||
use js::jsapi::root::JS::OnNewGlobalHookOption;
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::{Runtime, SIMPLE_GLOBAL_CLASS};
|
||||
|
||||
|
@ -19,14 +19,14 @@ fn evaluate() {
|
|||
let cx = rt.cx();
|
||||
|
||||
unsafe {
|
||||
|
||||
rooted!(in(cx) let global =
|
||||
JS_NewGlobalObject(cx, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(),
|
||||
OnNewGlobalHookOption::FireOnNewGlobalHook,
|
||||
&RealmOptions::default())
|
||||
);
|
||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||
assert!(rt.evaluate_script(global.handle(), "1 + 1",
|
||||
"test", 1, rval.handle_mut()).is_ok());
|
||||
assert!(rt
|
||||
.evaluate_script(global.handle(), "1 + 1", "test", 1, rval.handle_mut())
|
||||
.is_ok());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,23 +21,30 @@ fn panic() {
|
|||
let c_option = JS::RealmOptions::default();
|
||||
|
||||
unsafe {
|
||||
let global = JS_NewGlobalObject(context, &SIMPLE_GLOBAL_CLASS,
|
||||
ptr::null_mut(), h_option, &c_option);
|
||||
let global = JS_NewGlobalObject(
|
||||
context,
|
||||
&SIMPLE_GLOBAL_CLASS,
|
||||
ptr::null_mut(),
|
||||
h_option,
|
||||
&c_option,
|
||||
);
|
||||
rooted!(in(context) let global_root = global);
|
||||
let global = global_root.handle();
|
||||
let _ar = js::ar::AutoRealm::with_obj(context, global.get());
|
||||
let function = JS_DefineFunction(context, global,
|
||||
b"test\0".as_ptr() as *const _,
|
||||
Some(test), 0, 0);
|
||||
let function = JS_DefineFunction(
|
||||
context,
|
||||
global,
|
||||
b"test\0".as_ptr() as *const _,
|
||||
Some(test),
|
||||
0,
|
||||
0,
|
||||
);
|
||||
assert!(!function.is_null());
|
||||
rooted!(in(context) let mut rval = UndefinedValue());
|
||||
let _ = runtime.evaluate_script(global, "test();", "test.js", 0,
|
||||
rval.handle_mut());
|
||||
let _ = runtime.evaluate_script(global, "test();", "test.js", 0, rval.handle_mut());
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn test(_cx: *mut JSContext, _argc: u32, _vp: *mut JS::Value) -> bool {
|
||||
wrap_panic(|| {
|
||||
panic!()
|
||||
}, false)
|
||||
wrap_panic(|| panic!(), false)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ extern crate lazy_static;
|
|||
extern crate libc;
|
||||
|
||||
use js::jsapi::*;
|
||||
use js::rust::{Runtime, SIMPLE_GLOBAL_CLASS, define_methods};
|
||||
use js::rust::{define_methods, Runtime, SIMPLE_GLOBAL_CLASS};
|
||||
use std::ptr;
|
||||
|
||||
#[test]
|
||||
|
@ -48,7 +48,10 @@ lazy_static! {
|
|||
name: JSFunctionSpec_Name {
|
||||
string_: b"addEventListener\0" as *const u8 as *const libc::c_char,
|
||||
},
|
||||
call: JSNativeWrapper { op: Some(generic_method), info: ptr::null() },
|
||||
call: JSNativeWrapper {
|
||||
op: Some(generic_method),
|
||||
info: ptr::null()
|
||||
},
|
||||
nargs: 2,
|
||||
flags: JSPROP_ENUMERATE as u16,
|
||||
selfHostedName: 0 as *const libc::c_char
|
||||
|
@ -57,7 +60,10 @@ lazy_static! {
|
|||
name: JSFunctionSpec_Name {
|
||||
string_: b"removeEventListener\0" as *const u8 as *const libc::c_char,
|
||||
},
|
||||
call: JSNativeWrapper { op: Some(generic_method), info: ptr::null() },
|
||||
call: JSNativeWrapper {
|
||||
op: Some(generic_method),
|
||||
info: ptr::null()
|
||||
},
|
||||
nargs: 2,
|
||||
flags: JSPROP_ENUMERATE as u16,
|
||||
selfHostedName: 0 as *const libc::c_char
|
||||
|
@ -66,7 +72,10 @@ lazy_static! {
|
|||
name: JSFunctionSpec_Name {
|
||||
string_: b"dispatchEvent\0" as *const u8 as *const libc::c_char,
|
||||
},
|
||||
call: JSNativeWrapper { op: Some(generic_method), info: ptr::null() },
|
||||
call: JSNativeWrapper {
|
||||
op: Some(generic_method),
|
||||
info: ptr::null()
|
||||
},
|
||||
nargs: 1,
|
||||
flags: JSPROP_ENUMERATE as u16,
|
||||
selfHostedName: 0 as *const libc::c_char
|
||||
|
@ -75,7 +84,10 @@ lazy_static! {
|
|||
name: JSFunctionSpec_Name {
|
||||
string_: ptr::null(),
|
||||
},
|
||||
call: JSNativeWrapper { op: None, info: ptr::null() },
|
||||
call: JSNativeWrapper {
|
||||
op: None,
|
||||
info: ptr::null()
|
||||
},
|
||||
nargs: 0,
|
||||
flags: 0,
|
||||
selfHostedName: ptr::null()
|
||||
|
@ -89,5 +101,5 @@ static CLASS: JSClass = JSClass {
|
|||
cOps: 0 as *const _,
|
||||
spec: 0 as *mut _,
|
||||
ext: 0 as *mut _,
|
||||
oOps: 0 as *mut _
|
||||
oOps: 0 as *mut _,
|
||||
};
|
||||
|
|
|
@ -31,7 +31,7 @@ fn runtime() {
|
|||
assert!(Runtime::new(false).is_err());
|
||||
}
|
||||
|
||||
unsafe extern fn finalize(_fop: *mut JSFreeOp, _object: *mut JSObject) {
|
||||
unsafe extern "C" fn finalize(_fop: *mut JSFreeOp, _object: *mut JSObject) {
|
||||
assert!(!Runtime::get().is_null());
|
||||
}
|
||||
|
||||
|
@ -55,5 +55,5 @@ static CLASS: JSClass = JSClass {
|
|||
cOps: &CLASS_OPS as *const JSClassOps,
|
||||
spec: 0 as *mut _,
|
||||
ext: 0 as *mut _,
|
||||
oOps: 0 as *mut _
|
||||
oOps: 0 as *mut _,
|
||||
};
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
#[macro_use]
|
||||
extern crate js;
|
||||
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsapi::root::JS_NewGlobalObject;
|
||||
use js::jsapi::root::JS::OnNewGlobalHookOption;
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::{Runtime, SIMPLE_GLOBAL_CLASS};
|
||||
|
||||
|
@ -21,12 +21,24 @@ fn stack_limit() {
|
|||
unsafe {
|
||||
let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook;
|
||||
let c_option = RealmOptions::default();
|
||||
let global = JS_NewGlobalObject(cx, &SIMPLE_GLOBAL_CLASS,
|
||||
ptr::null_mut(), h_option, &c_option);
|
||||
let global = JS_NewGlobalObject(
|
||||
cx,
|
||||
&SIMPLE_GLOBAL_CLASS,
|
||||
ptr::null_mut(),
|
||||
h_option,
|
||||
&c_option,
|
||||
);
|
||||
rooted!(in(cx) let global_root = global);
|
||||
let global = global_root.handle();
|
||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||
assert!(rt.evaluate_script(global, "function f() { f.apply() } f()",
|
||||
"test", 1, rval.handle_mut()).is_err());
|
||||
assert!(rt
|
||||
.evaluate_script(
|
||||
global,
|
||||
"function f() { f.apply() } f()",
|
||||
"test",
|
||||
1,
|
||||
rval.handle_mut()
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,15 @@ fn typedarray() {
|
|||
let _ar = js::ar::AutoRealm::with_obj(cx, global.get());
|
||||
|
||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||
assert!(rt.evaluate_script(global.handle(), "new Uint8Array([0, 2, 4])",
|
||||
"test", 1, rval.handle_mut()).is_ok());
|
||||
assert!(rt
|
||||
.evaluate_script(
|
||||
global.handle(),
|
||||
"new Uint8Array([0, 2, 4])",
|
||||
"test",
|
||||
1,
|
||||
rval.handle_mut()
|
||||
)
|
||||
.is_ok());
|
||||
assert!(rval.is_object());
|
||||
|
||||
typedarray!(in(cx) let array: Uint8Array = rval.to_object());
|
||||
|
@ -38,7 +45,10 @@ fn typedarray() {
|
|||
assert!(array.is_err());
|
||||
|
||||
typedarray!(in(cx) let view: ArrayBufferView = rval.to_object());
|
||||
assert_eq!(view.unwrap().get_array_type(), js::jsapi::js::Scalar::Type::Uint8);
|
||||
assert_eq!(
|
||||
view.unwrap().get_array_type(),
|
||||
js::jsapi::js::Scalar::Type::Uint8
|
||||
);
|
||||
|
||||
rooted!(in(cx) let mut rval = ptr::null_mut());
|
||||
assert!(Uint32Array::create(cx, CreateWith::Slice(&[1, 3, 5]), rval.handle_mut()).is_ok());
|
||||
|
@ -65,7 +75,10 @@ fn typedarray() {
|
|||
assert_eq!(array.unwrap().as_slice(), &[0, 1, 2, 3, 0]);
|
||||
|
||||
typedarray!(in(cx) let view: ArrayBufferView = rval.get());
|
||||
assert_eq!(view.unwrap().get_array_type(), js::jsapi::js::Scalar::Type::Uint32);
|
||||
assert_eq!(
|
||||
view.unwrap().get_array_type(),
|
||||
js::jsapi::js::Scalar::Type::Uint32
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
#[macro_use]
|
||||
extern crate js;
|
||||
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsapi::root::JS_NewGlobalObject;
|
||||
use js::jsapi::root::JS::OnNewGlobalHookOption;
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::{Runtime, SIMPLE_GLOBAL_CLASS};
|
||||
|
||||
|
@ -25,8 +25,15 @@ fn is_symbol() {
|
|||
&RealmOptions::default())
|
||||
);
|
||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||
assert!(rt.evaluate_script(global.handle(), "Symbol('test')",
|
||||
"test", 1, rval.handle_mut()).is_ok());
|
||||
assert!(rt
|
||||
.evaluate_script(
|
||||
global.handle(),
|
||||
"Symbol('test')",
|
||||
"test",
|
||||
1,
|
||||
rval.handle_mut()
|
||||
)
|
||||
.is_ok());
|
||||
assert!(rval.is_symbol());
|
||||
}
|
||||
}
|
||||
|
@ -43,8 +50,15 @@ fn is_not_symbol() {
|
|||
&RealmOptions::default())
|
||||
);
|
||||
rooted!(in(cx) let mut rval = UndefinedValue());
|
||||
assert!(rt.evaluate_script(global.handle(), "'not a symbol'",
|
||||
"test", 1, rval.handle_mut()).is_ok());
|
||||
assert!(rt
|
||||
.evaluate_script(
|
||||
global.handle(),
|
||||
"'not a symbol'",
|
||||
"test",
|
||||
1,
|
||||
rval.handle_mut()
|
||||
)
|
||||
.is_ok());
|
||||
assert!(!rval.is_symbol());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,21 +10,18 @@ use js::conversions::ConversionBehavior;
|
|||
use js::conversions::ConversionResult;
|
||||
use js::conversions::FromJSValConvertible;
|
||||
use js::conversions::ToJSValConvertible;
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsapi::root::JS::InitRealmStandardClasses;
|
||||
use js::jsapi::root::JS_NewGlobalObject;
|
||||
use js::jsapi::root::JS::InitRealmStandardClasses;
|
||||
use js::jsapi::root::JS::OnNewGlobalHookOption;
|
||||
use js::jsapi::root::JS::RealmOptions;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::{Runtime, SIMPLE_GLOBAL_CLASS};
|
||||
|
||||
use std::ptr;
|
||||
|
||||
fn assert_is_array(cx: *mut js::jsapi::root::JSContext,
|
||||
val: js::jsapi::root::JS::HandleValue) {
|
||||
fn assert_is_array(cx: *mut js::jsapi::root::JSContext, val: js::jsapi::root::JS::HandleValue) {
|
||||
let mut is_array = false;
|
||||
assert!(unsafe {
|
||||
js::jsapi::root::JS::IsArrayObject(cx, val, &mut is_array as *mut _)
|
||||
});
|
||||
assert!(unsafe { js::jsapi::root::JS::IsArrayObject(cx, val, &mut is_array as *mut _) });
|
||||
assert!(is_array);
|
||||
}
|
||||
|
||||
|
@ -37,8 +34,13 @@ fn vec_conversion() {
|
|||
let c_option = RealmOptions::default();
|
||||
|
||||
unsafe {
|
||||
let global = JS_NewGlobalObject(cx, &SIMPLE_GLOBAL_CLASS,
|
||||
ptr::null_mut(), h_option, &c_option);
|
||||
let global = JS_NewGlobalObject(
|
||||
cx,
|
||||
&SIMPLE_GLOBAL_CLASS,
|
||||
ptr::null_mut(),
|
||||
h_option,
|
||||
&c_option,
|
||||
);
|
||||
rooted!(in(cx) let global_root = global);
|
||||
let global = global_root.handle();
|
||||
|
||||
|
@ -56,22 +58,21 @@ fn vec_conversion() {
|
|||
let orig_vec: Vec<i32> = vec![1, 2, 3];
|
||||
orig_vec.to_jsval(cx, rval.handle_mut());
|
||||
assert_is_array(cx, rval.handle());
|
||||
let converted = Vec::<i32>::from_jsval(cx, rval.handle(),
|
||||
ConversionBehavior::Default).unwrap();
|
||||
|
||||
assert_eq!(&orig_vec, converted.get_success_value().unwrap());
|
||||
|
||||
rt.evaluate_script(global, "new Set([1, 2, 3])",
|
||||
"test", 1, rval.handle_mut()).unwrap();
|
||||
let converted =
|
||||
Vec::<i32>::from_jsval(cx, rval.handle(),
|
||||
ConversionBehavior::Default).unwrap();
|
||||
Vec::<i32>::from_jsval(cx, rval.handle(), ConversionBehavior::Default).unwrap();
|
||||
|
||||
assert_eq!(&orig_vec, converted.get_success_value().unwrap());
|
||||
|
||||
rt.evaluate_script(global, "({})", "test", 1, rval.handle_mut()).unwrap();
|
||||
let converted = Vec::<i32>::from_jsval(cx, rval.handle(),
|
||||
ConversionBehavior::Default);
|
||||
rt.evaluate_script(global, "new Set([1, 2, 3])", "test", 1, rval.handle_mut())
|
||||
.unwrap();
|
||||
let converted =
|
||||
Vec::<i32>::from_jsval(cx, rval.handle(), ConversionBehavior::Default).unwrap();
|
||||
|
||||
assert_eq!(&orig_vec, converted.get_success_value().unwrap());
|
||||
|
||||
rt.evaluate_script(global, "({})", "test", 1, rval.handle_mut())
|
||||
.unwrap();
|
||||
let converted = Vec::<i32>::from_jsval(cx, rval.handle(), ConversionBehavior::Default);
|
||||
assert!(match converted {
|
||||
Ok(ConversionResult::Failure(_)) => true,
|
||||
_ => false,
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
// 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/.
|
||||
|
||||
extern crate num_cpus;
|
||||
extern crate glob;
|
||||
extern crate num_cpus;
|
||||
|
||||
use std::env;
|
||||
use std::path;
|
||||
|
@ -34,28 +34,29 @@ fn main() {
|
|||
|
||||
let python = env::var("PYTHON3").unwrap_or("python3".into());
|
||||
let mut cmd = Command::new(&python);
|
||||
cmd.args(&["./devtools/automation/autospider.py",
|
||||
// Only build SpiderMonkey, don't run all the tests.
|
||||
"--build-only",
|
||||
// Disable Mozilla's jemalloc; Rust has its own jemalloc that we
|
||||
// can swap in instead and everything using a single malloc is
|
||||
// good.
|
||||
"--no-jemalloc",
|
||||
// Don't try to clobber the output directory. Without
|
||||
// this option, the build will fail because the directory
|
||||
// already exists but wasn't created by autospider.
|
||||
"--dep",
|
||||
"--objdir", &out_dir,
|
||||
&variant])
|
||||
.env("NO_RUST_PANIC_HOOK", "1")
|
||||
.env("SOURCE", &js_src)
|
||||
.env("PWD", &js_src)
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit());
|
||||
cmd.args(&[
|
||||
"./devtools/automation/autospider.py",
|
||||
// Only build SpiderMonkey, don't run all the tests.
|
||||
"--build-only",
|
||||
// Disable Mozilla's jemalloc; Rust has its own jemalloc that we
|
||||
// can swap in instead and everything using a single malloc is
|
||||
// good.
|
||||
"--no-jemalloc",
|
||||
// Don't try to clobber the output directory. Without
|
||||
// this option, the build will fail because the directory
|
||||
// already exists but wasn't created by autospider.
|
||||
"--dep",
|
||||
"--objdir",
|
||||
&out_dir,
|
||||
&variant,
|
||||
])
|
||||
.env("NO_RUST_PANIC_HOOK", "1")
|
||||
.env("SOURCE", &js_src)
|
||||
.env("PWD", &js_src)
|
||||
.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit());
|
||||
println!("Running command: {:?}", cmd);
|
||||
let result = cmd
|
||||
.status()
|
||||
.expect("Should spawn autospider OK");
|
||||
let result = cmd.status().expect("Should spawn autospider OK");
|
||||
assert!(result.success(), "autospider should exit OK");
|
||||
|
||||
println!("cargo:rustc-link-search=native={}/js/src/build", out_dir);
|
||||
|
@ -82,8 +83,7 @@ fn main() {
|
|||
/// Find if Spidermonkey built the Spidermonkey Rust library, and add it to the
|
||||
/// link if it was the case.
|
||||
fn maybe_add_spidermonkey_rust_lib() {
|
||||
let out_dir = env::var("OUT_DIR")
|
||||
.expect("cargo should invoke us with the OUT_DIR env var set");
|
||||
let out_dir = env::var("OUT_DIR").expect("cargo should invoke us with the OUT_DIR env var set");
|
||||
|
||||
let mut target_build_dir = path::PathBuf::from(out_dir);
|
||||
target_build_dir.push("../../");
|
||||
|
@ -91,17 +91,19 @@ fn maybe_add_spidermonkey_rust_lib() {
|
|||
let mut build_dir = target_build_dir.display().to_string();
|
||||
build_dir.push_str("mozjs_sys-*/out/*/debug");
|
||||
|
||||
let entries = match glob::glob(&build_dir){
|
||||
Err(_) => { return; }
|
||||
Ok(entries) => entries
|
||||
let entries = match glob::glob(&build_dir) {
|
||||
Err(_) => {
|
||||
return;
|
||||
}
|
||||
Ok(entries) => entries,
|
||||
};
|
||||
|
||||
for entry in entries {
|
||||
if let Ok(path) = entry {
|
||||
let path = path.canonicalize()
|
||||
let path = path
|
||||
.canonicalize()
|
||||
.expect("Should canonicalize debug build path");
|
||||
let path = path.to_str()
|
||||
.expect("Should be utf8");
|
||||
let path = path.to_str().expect("Should be utf8");
|
||||
println!("cargo:rustc-link-search=native={}", path);
|
||||
println!("cargo:rustc-link-lib=static=jsrust");
|
||||
return;
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -3,7 +3,7 @@
|
|||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{ HashMap, HashSet };
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::rc::Rc;
|
||||
|
||||
/// A node in the reference graph
|
||||
|
@ -40,7 +40,7 @@ pub struct ReferenceGraph {
|
|||
impl ReferenceGraph {
|
||||
pub fn new() -> Self {
|
||||
ReferenceGraph {
|
||||
refnodes: HashMap::new()
|
||||
refnodes: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,8 +57,9 @@ impl ReferenceGraph {
|
|||
let mut next_edges: HashSet<Rc<String>> = HashSet::new();
|
||||
|
||||
for edge in edges {
|
||||
let refnode = self.refnodes.get(&edge)
|
||||
.unwrap_or_else(|| panic!("While computing dependencies, node {} doesn't exist", edge));
|
||||
let refnode = self.refnodes.get(&edge).unwrap_or_else(|| {
|
||||
panic!("While computing dependencies, node {} doesn't exist", edge)
|
||||
});
|
||||
if *refnode.used.borrow() {
|
||||
continue;
|
||||
}
|
||||
|
@ -83,12 +84,13 @@ impl ReferenceGraph {
|
|||
pub fn is_used(&self, name: Rc<String>) -> bool {
|
||||
match self.refnodes.get(&name) {
|
||||
Some(refnode) => *refnode.used.borrow(),
|
||||
None => false
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert a node with `name` to the graph.
|
||||
pub fn insert(&mut self, name: Rc<String>, edges: HashSet<Rc<String>>) {
|
||||
self.refnodes.insert(name, Rc::new(ReferenceGraphNode::new(edges)));
|
||||
self.refnodes
|
||||
.insert(name, Rc::new(ReferenceGraphNode::new(edges)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,4 +3,3 @@
|
|||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate libz_sys;
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
// We need to allow dead code because the Rustc compiler complains about variants never being
|
||||
// constructed in TypeCode, which is true because these values come from C++.
|
||||
#![allow(dead_code)]
|
||||
|
|
|
@ -4,7 +4,7 @@ rust:
|
|||
include:
|
||||
- build/workspace-hack/
|
||||
- gfx/wr/peek-poke/peek-poke-derive/
|
||||
- js/src/rust/shared/
|
||||
- js/
|
||||
- security/manager/ssl/osclientcerts/
|
||||
- servo/components/size_of_test/
|
||||
- servo/components/to_shmem_derive/
|
||||
|
@ -23,9 +23,6 @@ rust:
|
|||
- gfx/wr/peek-poke/
|
||||
- gfx/wr/webrender_build/
|
||||
- gfx/wr/wr_malloc_size_of/
|
||||
- js/src/
|
||||
- js/src/frontend/binast/
|
||||
- js/src/wasm/cranelift/
|
||||
- media/mp4parse-rust/mp4parse/
|
||||
- media/mp4parse-rust/mp4parse_capi/
|
||||
- media/mp4parse-rust/mp4parse_fallible/
|
||||
|
|
Загрузка…
Ссылка в новой задаче