From e96bca0cb33c0fefbe907939025b6ce19f1dcb89 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Thu, 6 Nov 2025 17:04:25 +0100 Subject: [PATCH 1/2] squash Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- mozjs/benches/latin1_string_conversion.rs | 22 +- mozjs/examples/eval.rs | 10 +- mozjs/examples/minimal.rs | 6 +- mozjs/examples/wasm.rs | 76 +-- mozjs/src/context.rs | 164 ++++++ mozjs/src/gc/macros.rs | 6 + mozjs/src/generate_wrappers.sh | 74 ++- mozjs/src/glue2_wrappers.in.rs | 44 ++ mozjs/src/jsapi2_wrappers.in.rs | 666 ++++++++++++++++++++++ mozjs/src/lib.rs | 1 + mozjs/src/rust.rs | 245 ++++++-- mozjs/src/typedarray.rs | 3 + mozjs/tests/callback.rs | 34 +- mozjs/tests/capture_stack.rs | 12 +- mozjs/tests/custom_auto_rooter.rs | 7 +- mozjs/tests/custom_auto_rooter_macro.rs | 7 +- mozjs/tests/enforce_range.rs | 21 +- mozjs/tests/enumerate.rs | 23 +- mozjs/tests/evaluate.rs | 11 +- mozjs/tests/external_string.rs | 34 +- mozjs/tests/iterate_stack.rs | 27 +- mozjs/tests/jsvalue.rs | 50 +- mozjs/tests/panic.rs | 27 +- mozjs/tests/property_descriptor.rs | 31 +- mozjs/tests/rootable.rs | 17 +- mozjs/tests/rooting.rs | 29 +- mozjs/tests/runtime.rs | 13 +- mozjs/tests/stack_gc_vector.rs | 11 +- mozjs/tests/stack_limit.rs | 11 +- mozjs/tests/typedarray.rs | 58 +- mozjs/tests/typedarray_panic.rs | 15 +- mozjs/tests/vec_conversion.rs | 34 +- 32 files changed, 1478 insertions(+), 311 deletions(-) create mode 100644 mozjs/src/context.rs create mode 100644 mozjs/src/glue2_wrappers.in.rs create mode 100644 mozjs/src/jsapi2_wrappers.in.rs diff --git a/mozjs/benches/latin1_string_conversion.rs b/mozjs/benches/latin1_string_conversion.rs index db283ae5d6..3179b29a33 100644 --- a/mozjs/benches/latin1_string_conversion.rs +++ b/mozjs/benches/latin1_string_conversion.rs @@ -2,22 +2,22 @@ use criterion::measurement::WallTime; use criterion::{ criterion_group, criterion_main, BenchmarkGroup, BenchmarkId, Criterion, Throughput, }; +use mozjs::context::JSContext; use mozjs::conversions::jsstr_to_string; use mozjs::glue::{CreateJSExternalStringCallbacks, JSExternalStringCallbacksTraps}; -use mozjs::jsapi::{ - JSAutoRealm, JS_NewExternalStringLatin1, JS_NewGlobalObject, OnNewGlobalHookOption, -}; +use mozjs::jsapi::{JSAutoRealm, OnNewGlobalHookOption}; use mozjs::rooted; +use mozjs::rust::wrappers2::{JS_NewExternalStringLatin1, JS_NewGlobalObject}; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; -use mozjs_sys::jsapi::JSContext; use std::ffi::c_void; +use std::ptr::NonNull; use std::{iter, ptr}; // TODO: Create a trait for creating a latin1 string of a required length, so that we can // try different kinds of content. fn bench_str_repetition( group: &mut BenchmarkGroup, - context: *mut JSContext, + context: &mut JSContext, variant_name: &str, latin1str_16_bytes: &[u8], ) { @@ -39,7 +39,7 @@ fn bench_str_repetition( str_len as *mut c_void, ) }; - rooted!(in(context) let latin1_jsstr = unsafe { JS_NewExternalStringLatin1( + rooted!(&in(context) let latin1_jsstr = unsafe { JS_NewExternalStringLatin1( context, latin1_chars, str_len, @@ -51,7 +51,9 @@ fn bench_str_repetition( &latin1_jsstr, |b, js_str| { b.iter(|| { - unsafe { jsstr_to_string(context, js_str.get()) }; + unsafe { + jsstr_to_string(context.raw_cx(), NonNull::new(js_str.get()).unwrap()) + }; }) }, ); @@ -59,18 +61,18 @@ fn bench_str_repetition( } fn external_string(c: &mut Criterion) { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); - rooted!(in(context) let global = unsafe { JS_NewGlobalObject( + rooted!(&in(context) let global = unsafe { JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )}); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(unsafe { context.raw_cx() }, global.get()); let mut group = c.benchmark_group("Latin1 conversion"); diff --git a/mozjs/examples/eval.rs b/mozjs/examples/eval.rs index 51acec6cde..f6af979bac 100644 --- a/mozjs/examples/eval.rs +++ b/mozjs/examples/eval.rs @@ -15,15 +15,16 @@ use ::std::ptr; -use mozjs::jsapi::*; +use mozjs::jsapi::OnNewGlobalHookOption; use mozjs::jsval::UndefinedValue; use mozjs::rooted; +use mozjs::rust::wrappers2::*; use mozjs::rust::SIMPLE_GLOBAL_CLASS; use mozjs::rust::{JSEngine, RealmOptions, Runtime}; -fn run(rt: Runtime) { +fn run(mut rt: Runtime) { let options = RealmOptions::default(); - rooted!(in(rt.cx()) let global = unsafe { + rooted!(&in(rt.cx()) let global = unsafe { JS_NewGlobalObject(rt.cx(), &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), OnNewGlobalHookOption::FireOnNewGlobalHook, &*options) @@ -37,7 +38,7 @@ fn run(rt: Runtime) { * The return value comes back here. If it could be a GC thing, you must add it to the * GC's "root set" with the rooted! macro. */ - rooted!(in(rt.cx()) let mut rval = UndefinedValue()); + rooted!(&in(rt.cx()) let mut rval = UndefinedValue()); /* * Some example source in a string. This is equivalent to JS_EvaluateScript in C++. @@ -57,7 +58,6 @@ fn run(rt: Runtime) { fn main() { let engine = JSEngine::init().expect("failed to initalize JS engine"); let runtime = Runtime::new(engine.handle()); - assert!(!runtime.cx().is_null(), "failed to create JSContext"); run(runtime); } diff --git a/mozjs/examples/minimal.rs b/mozjs/examples/minimal.rs index c9bb72041d..778c0ccd78 100644 --- a/mozjs/examples/minimal.rs +++ b/mozjs/examples/minimal.rs @@ -16,6 +16,7 @@ use ::std::ptr; use mozjs::rooted; +use mozjs::rust::wrappers2::JS_NewGlobalObject; use mozjs::rust::SIMPLE_GLOBAL_CLASS; use mozjs::{jsapi::*, rust::JSEngine, rust::RealmOptions, rust::Runtime}; @@ -25,7 +26,6 @@ fn main() { // Create a Runtime -- wraps a JSContext in the C++ API. let runtime = Runtime::new(engine.handle()); - assert!(!runtime.cx().is_null(), "failed to create JSContext"); run(runtime); @@ -33,14 +33,14 @@ fn main() { // reference counts will clean up everything. } -fn run(rt: Runtime) { +fn run(mut rt: Runtime) { let cx = rt.cx(); // In addition to what the C++ interface requires, define a global scope for the code. // // This demonstrates the way Rust uses the C++ garbage collector: using the rooted! macro to // indicate when the GC can collect them. let options = RealmOptions::default(); - rooted!(in(cx) let _global = unsafe { + rooted!(&in(cx) let _global = unsafe { JS_NewGlobalObject(cx, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), OnNewGlobalHookOption::FireOnNewGlobalHook, &*options) diff --git a/mozjs/examples/wasm.rs b/mozjs/examples/wasm.rs index 93693c6716..752679d75c 100644 --- a/mozjs/examples/wasm.rs +++ b/mozjs/examples/wasm.rs @@ -16,9 +16,12 @@ use mozjs::jsapi::*; use mozjs::jsval::ObjectValue; use mozjs::jsval::UndefinedValue; use mozjs::rooted; -use mozjs::rust::wrappers::{Construct1, JS_GetProperty, JS_SetProperty}; +use mozjs::rust::wrappers2::{ + Call, Construct1, JS_DefineFunction, JS_GetProperty, JS_NewGlobalObject, JS_NewPlainObject, + JS_SetProperty, NewArrayBufferWithUserOwnedContents, +}; use mozjs::rust::SIMPLE_GLOBAL_CLASS; -use mozjs::rust::{IntoHandle, JSEngine, RealmOptions, Runtime}; +use mozjs::rust::{HandleValue, IntoHandle, JSEngine, RealmOptions, Runtime}; use mozjs_sys::jsgc::ValueArray; #[repr(align(8))] @@ -47,36 +50,37 @@ unsafe extern "C" fn bar(_cx: *mut JSContext, argc: u32, vp: *mut Value) -> bool true } -fn run(rt: Runtime) { +fn run(mut rt: Runtime) { let options = RealmOptions::default(); - rooted!(in(rt.cx()) let global = unsafe { - JS_NewGlobalObject(rt.cx(), &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), + let cx = rt.cx(); + rooted!(&in(cx) let global = unsafe { + JS_NewGlobalObject(cx, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), OnNewGlobalHookOption::FireOnNewGlobalHook, &*options) }); - let _ac = JSAutoRealm::new(rt.cx(), global.get()); + let _ac = JSAutoRealm::new(unsafe { cx.raw_cx() }, global.get()); // Get WebAssembly.Module and WebAssembly.Instance constructors. - rooted!(in(rt.cx()) let mut wasm = UndefinedValue()); - rooted!(in(rt.cx()) let mut wasm_module = UndefinedValue()); - rooted!(in(rt.cx()) let mut wasm_instance = UndefinedValue()); + rooted!(&in(cx) let mut wasm = UndefinedValue()); + rooted!(&in(cx) let mut wasm_module = UndefinedValue()); + rooted!(&in(cx) let mut wasm_instance = UndefinedValue()); unsafe { assert!(JS_GetProperty( - rt.cx(), + cx, global.handle(), c"WebAssembly".as_ptr(), wasm.handle_mut() )); - rooted!(in(rt.cx()) let mut wasm_obj = wasm.to_object()); + rooted!(&in(cx) let mut wasm_obj = wasm.to_object()); assert!(JS_GetProperty( - rt.cx(), + cx, wasm_obj.handle(), c"Module".as_ptr(), wasm_module.handle_mut() )); assert!(JS_GetProperty( - rt.cx(), + cx, wasm_obj.handle(), c"Instance".as_ptr(), wasm_instance.handle_mut() @@ -86,20 +90,17 @@ fn run(rt: Runtime) { assert!(HI_WASM.0.as_ptr() as usize % 8 == 0); // Construct Wasm module from bytes. - rooted!(in(rt.cx()) let mut module = null_mut::()); + rooted!(&in(cx) let mut module = null_mut::()); { - let array_buffer = JS::NewArrayBufferWithUserOwnedContents( - rt.cx(), - HI_WASM.0.len(), - HI_WASM.0.as_ptr() as _, - ); + let array_buffer = + NewArrayBufferWithUserOwnedContents(cx, HI_WASM.0.len(), HI_WASM.0.as_ptr() as _); assert!(!array_buffer.is_null()); - rooted!(in(rt.cx()) let val = ObjectValue(array_buffer)); + rooted!(&in(cx) let val = ObjectValue(array_buffer)); let args = HandleValueArray::from(val.handle().into_handle()); assert!(Construct1( - rt.cx(), + cx, wasm_module.handle(), &args, module.handle_mut() @@ -107,13 +108,13 @@ fn run(rt: Runtime) { } // Construct Wasm module instance with required imports. - rooted!(in(rt.cx()) let mut instance = null_mut::()); + rooted!(&in(cx) let mut instance = null_mut::()); { // Build "env" imports object. - rooted!(in(rt.cx()) let mut env_import_obj = JS_NewPlainObject(rt.cx())); + rooted!(&in(cx) let mut env_import_obj = JS_NewPlainObject(cx)); assert!(!env_import_obj.is_null()); let function = JS_DefineFunction( - rt.cx(), + cx, env_import_obj.handle().into(), c"bar".as_ptr(), Some(bar), @@ -121,21 +122,21 @@ fn run(rt: Runtime) { 0, ); assert!(!function.is_null()); - rooted!(in(rt.cx()) let mut env_import = ObjectValue(env_import_obj.get())); + rooted!(&in(cx) let mut env_import = ObjectValue(env_import_obj.get())); // Build imports bag. - rooted!(in(rt.cx()) let mut imports = JS_NewPlainObject(rt.cx())); + rooted!(&in(cx) let mut imports = JS_NewPlainObject(cx)); assert!(!imports.is_null()); assert!(JS_SetProperty( - rt.cx(), + cx, imports.handle(), c"env".as_ptr(), env_import.handle() )); - rooted!(in(rt.cx()) let mut args = ValueArray::new([ObjectValue(module.get()), ObjectValue(imports.get())])); + rooted!(&in(cx) let mut args = ValueArray::new([ObjectValue(module.get()), ObjectValue(imports.get())])); assert!(Construct1( - rt.cx(), + cx, wasm_instance.handle(), &HandleValueArray::from(&args), instance.handle_mut() @@ -143,29 +144,29 @@ fn run(rt: Runtime) { } // Find `foo` method in exports. - rooted!(in(rt.cx()) let mut exports = UndefinedValue()); + rooted!(&in(cx) let mut exports = UndefinedValue()); assert!(JS_GetProperty( - rt.cx(), + cx, instance.handle(), c"exports".as_ptr(), exports.handle_mut() )); - rooted!(in(rt.cx()) let mut exports_obj = exports.to_object()); - rooted!(in(rt.cx()) let mut foo = UndefinedValue()); + rooted!(&in(cx) let mut exports_obj = exports.to_object()); + rooted!(&in(cx) let mut foo = UndefinedValue()); assert!(JS_GetProperty( - rt.cx(), + cx, exports_obj.handle(), c"foo".as_ptr(), foo.handle_mut() )); // call foo and get its result - rooted!(in(rt.cx()) let mut rval = UndefinedValue()); + rooted!(&in(cx) let mut rval = UndefinedValue()); assert!(Call( - rt.cx(), - JS::UndefinedHandleValue, + cx, + HandleValue::undefined(), foo.handle().into(), &HandleValueArray::empty(), rval.handle_mut().into() @@ -180,7 +181,6 @@ fn run(rt: Runtime) { fn main() { let engine = JSEngine::init().expect("failed to initalize JS engine"); let runtime = Runtime::new(engine.handle()); - assert!(!runtime.cx().is_null(), "failed to create JSContext"); run(runtime); } diff --git a/mozjs/src/context.rs b/mozjs/src/context.rs new file mode 100644 index 0000000000..78ac4f13d9 --- /dev/null +++ b/mozjs/src/context.rs @@ -0,0 +1,164 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use std::marker::PhantomData; +use std::ptr::NonNull; + +pub use crate::jsapi::JSContext as RawJSContext; + +/// A wrapper for raw JSContext pointers that are strongly associated with the [Runtime] type. +/// +/// This type is fundamental for safe SpiderMonkey usage. +/// Each (SpiderMonkey) function which takes `&mut JSContext` as argument can trigger GC. +/// SpiderMonkey functions require take `&JSContext` are guaranteed to not trigger GC. +/// We must not hold any unrooted or borrowed data while calling any functions that can trigger GC. +/// That can causes panics or UB. +/// Such types are derived from [NoGC] token which can be though of `&JSContext`, +/// so they are bounded to [JSContext]. +/// +/// ```rust +/// use std::marker::PhantomData; +/// use mozjs::context::*; +/// use mozjs::jsapi::JSContext as RawJSContext; +/// +/// struct ShouldNotBeHoldAcrossGC<'a>(PhantomData<&'a ()>); +/// +/// impl<'a> Drop for ShouldNotBeHoldAcrossGC<'a> { +/// fn drop(&mut self) {} +/// } +/// +/// fn something_that_should_not_hold_across_gc<'a>(_no_gc: &NoGC<'a>) -> ShouldNotBeHoldAcrossGC<'a> { +/// ShouldNotBeHoldAcrossGC(PhantomData) +/// } +/// +/// fn SM_function_that_can_trigger_gc(_cx: *mut RawJSContext) {} +/// +/// // this lives in mozjs +/// fn safe_wrapper_to_SM_function_that_can_trigger_gc(cx: &mut JSContext) { +/// unsafe { SM_function_that_can_trigger_gc(cx.raw_cx()) } +/// } +/// +/// fn can_cause_gc(cx: &mut JSContext) { +/// safe_wrapper_to_SM_function_that_can_trigger_gc(cx); +/// { +/// let t = something_that_should_not_hold_across_gc(&cx.no_gc()); +/// // do something with it +/// } // t get dropped +/// safe_wrapper_to_SM_function_that_can_trigger_gc(cx); // we can call GC again +/// } +/// ``` +/// +/// One cannot call any GC function, while any [NoGC] token is alive, +/// because [NoGC] token borrows [JSContext] (`&JSContext`) +/// and thus prevents calling any function that triggers GC, +/// because they require exclusive access to [JSContext] (`&mut JSContext`). +/// +/// ```compile_fail +/// use std::marker::PhantomData; +/// use mozjs::context::*; +/// use mozjs::jsapi::JSContext as RawJSContext; +/// +/// struct ShouldNotBeHoldAcrossGC<'a>(PhantomData<&'a ()>); +/// +/// impl<'a> Drop for ShouldNotBeHoldAcrossGC<'a> { +/// fn drop(&mut self) {} // make type not trivial, or else compiler can shorten it's lifetime +/// } +/// +/// fn something_that_should_not_hold_across_gc<'a>(_no_gc: &'a NoGC<'a>) -> ShouldNotBeHoldAcrossGC<'a> { +/// ShouldNotBeHoldAcrossGC(PhantomData) +/// } +/// +/// fn safe_wrapper_to_SM_function_that_can_trigger_gc(_cx: &mut JSContext) { +/// } +/// +/// fn can_cause_gc(cx: &mut JSContext) { +/// safe_wrapper_to_SM_function_that_can_trigger_gc(cx); +/// let t = something_that_should_not_hold_across_gc(&cx.no_gc()); +/// // this will create compile error, because we cannot hold NoGc across C triggering function. +/// // more specifically we cannot borrow `JSContext` as mutable because it is also borrowed as immutable (NoGC). +/// safe_wrapper_to_SM_function_that_can_trigger_gc(cx); +/// } +/// ``` +/// +/// ### WIP +/// +/// This model is still being incrementally introduced, so there are currently some escape hatches. +pub struct JSContext { + pub(crate) ptr: NonNull, +} + +impl JSContext { + /// Wrap an existing [RawJSContext] pointer. + /// + /// SAFETY: + /// - `cx` must be valid [RawJSContext] object. + /// - only one [JSContext] can be alive and it should not outlive [Runtime]. + /// This in turn means that [JSContext] always needs to be passed down as an argument, + /// but for the SpiderMonkey callbacks which provide [RawJSContext] it's safe to construct **one** from provided [RawJSContext]. + pub unsafe fn from_ptr(cx: NonNull) -> JSContext { + JSContext { ptr: cx } + } + + /// Returns [NoGC] token bounded to this [JSContext]. + /// No function that accepts `&mut JSContext` (read: triggers GC) + /// can be called while this is alive. + #[inline] + #[must_use] + pub fn no_gc<'cx>(&'cx self) -> &'cx NoGC<'cx> { + &NoGC(PhantomData) + } + + /// Obtain [RawJSContext] mutable pointer. + /// + /// # Safety + /// + /// No [NoGC] tokens should be constructed while returned pointer is available to user. + /// In practices this means that one should use the result + /// as direct argument to SpiderMonkey function and not store it in variable. + /// + /// ```rust + /// use mozjs::context::*; + /// use mozjs::jsapi::JSContext as RawJSContext; + /// + /// fn SM_function_that_can_trigger_gc(_cx: *mut RawJSContext) {} + /// + /// fn can_trigger_gc(cx: &mut JSContext) { + /// unsafe { SM_function_that_can_trigger_gc(cx.raw_cx()) } // returned pointer is immediately used + /// cx.no_gc(); // this is ok because no outstanding raw pointer is alive + /// } + /// ``` + pub unsafe fn raw_cx(&mut self) -> *mut RawJSContext { + self.ptr.as_ptr() + } + + /// Obtain [RawJSContext] mutable pointer, that will not be used for GC. + /// + /// # Safety + /// + /// No &mut calls should be done on [JSContext] while returned pointer is available. + /// In practices this means that one should use the result + /// as direct argument to SpiderMonkey function and not store it in variable. + /// + /// ```rust + /// use mozjs::context::*; + /// use mozjs::jsapi::JSContext as RawJSContext; + /// + /// fn SM_function_that_cannot_trigger_gc(_cx: *mut RawJSContext) {} + /// + /// fn f(cx: &mut JSContext) { + /// unsafe { SM_function_that_cannot_trigger_gc(cx.raw_cx_no_gc()) } // returned pointer is immediately used + /// } + /// ``` + pub unsafe fn raw_cx_no_gc(&self) -> *mut RawJSContext { + self.ptr.as_ptr() + } +} + +/// Token that ensures that no GC can happen while it is alive. +/// +/// Each function that trigger GC require mutable access to [JSContext], +/// so one cannot call them because [NoGC] lifetime is bounded to [JSContext]. +/// +/// For more info and examples see [JSContext]. +pub struct NoGC<'cx>(PhantomData<&'cx ()>); diff --git a/mozjs/src/gc/macros.rs b/mozjs/src/gc/macros.rs index 0fd70c9270..5dfbcbc540 100644 --- a/mozjs/src/gc/macros.rs +++ b/mozjs/src/gc/macros.rs @@ -1,5 +1,8 @@ #[macro_export] macro_rules! rooted { + (&in($cx:expr) $($t:tt)*) => { + rooted!(in(unsafe {$cx.raw_cx_no_gc()}) $($t)*); + }; (in($cx:expr) let $($var:ident)+ = $init:expr) => { let mut __root = ::std::mem::MaybeUninit::uninit(); let $($var)+ = $crate::gc::RootedGuard::new($cx, &mut __root, $init); @@ -38,6 +41,9 @@ macro_rules! rooted_vec { #[macro_export] macro_rules! auto_root { + (&in($cx:expr) $($t:tt)*) => { + auto_root!(in(unsafe {$cx.raw_cx_no_gc()}) $($t)*); + }; (in($cx:expr) let $($var:ident)+ = $init:expr) => { let mut __root = $crate::gc::CustomAutoRooter::new($init); let $($var)+ = __root.root($cx); diff --git a/mozjs/src/generate_wrappers.sh b/mozjs/src/generate_wrappers.sh index 1eba80434b..0b0116987a 100755 --- a/mozjs/src/generate_wrappers.sh +++ b/mozjs/src/generate_wrappers.sh @@ -3,8 +3,8 @@ gsed=$(type gsed >/dev/null 2>&1 && echo gsed || echo sed) # Detect gfind or find gfind=$(type gfind >/dev/null 2>&1 && echo gfind || echo find) -# This is one big heuristic but seems to work well enough -grep_heur() { + +grep_functions() { grep -v "link_name" "$1" | \ grep -v '"\]' | \ grep -F -v '/\*\*' | \ @@ -14,8 +14,13 @@ grep_heur() { grep -v '^\}$' | \ $gsed 's/^ *pub/pub/' | \ $gsed -z 's/\;\n/\n/g' | \ - grep 'pub fn' | \ - grep Handle | \ + grep 'pub fn' +} + +# This is one big heuristic but seems to work well enough +grep_heur() { + grep_functions "$1" | + grep -e Handle | \ grep -v roxyHandler | \ grep -v '\bIdVector\b' | # name clash between rust::IdVector and JS::IdVector \ grep -v 'pub fn Unbox' | # this function seems to be platform specific \ @@ -31,7 +36,7 @@ grep_heur() { grep -v 'MutableHandleObjectVector' # GetDebuggeeGlobals has it } -# usage find_latest_version_of_file_and_parse $input_file $out_wrapper_module_name +# usage find_latest_version_of_file_and_parse $input_file $out_wrapper_module_name $heur_fn find_latest_version_of_file_and_parse() { # clone file and reformat (this is needed for grep_heur to work properly) # this $(find) only gets last modified file @@ -39,8 +44,61 @@ find_latest_version_of_file_and_parse() { rustfmt "target/wrap_$1" --config max_width=1000 # parse reformated file - grep_heur "target/wrap_$1" | $gsed 's/\(.*\)/wrap!('"$2"': \1);/g' > "mozjs/src/$2_wrappers.in.rs" + ($3 "target/wrap_$1") | $gsed 's/\(.*\)/wrap!('"$2"': \1);/g' > "mozjs/src/$2$4_wrappers.in.rs" +} + +find_latest_version_of_file_and_parse jsapi.rs jsapi grep_heur +find_latest_version_of_file_and_parse gluebindings.rs glue grep_heur + +# This is one big heuristic but seems to work well enough +grep_heur2() { + grep_functions "$1" | + grep -e Handle -e JSContext | \ + grep -v roxyHandler | \ + grep -v '\bIdVector\b' | # name clash between rust::IdVector and JS::IdVector \ + # platform specific + grep -v 'pub fn Unbox' | + grep -v 'CopyAsyncStack' | + grep -F -v 'Opaque' | + grep -v 'pub fn JS_WrapPropertyDescriptor1' | + grep -v 'pub fn EncodeWideToUtf8' | + grep -v 'pub fn JS_NewContext' | # returns jscontext + # gc module causes problems in macro + grep -v 'pub fn NewMemoryInfo' | + grep -v 'pub fn GetGCContext' | + grep -v 'pub fn SetDebuggerMalloc' | + grep -v 'pub fn GetDebuggerMallocSizeOf' | + grep -v 'pub fn FireOnGarbageCollectionHookRequired' | + grep -v 'pub fn ShouldAvoidSideEffects' | + # vargs + grep -F -v '...' | + grep -F -v 'VA(' | + $gsed 's/root:://g' | + $gsed 's/JS:://g' | + $gsed 's/js:://g' | + $gsed 's/mozilla:://g' | + $gsed 's/\*mut JSContext/\&mut JSContext/g' | + $gsed 's/\*const JSContext/\&JSContext/g' | + grep -F -v '> Handle' | # We are only wrapping handles in args not in results + grep -v 'MutableHandleObjectVector' # GetDebuggeeGlobals has it +} + +find_latest_version_of_file_and_parse jsapi.rs jsapi grep_heur2 2 +find_latest_version_of_file_and_parse gluebindings.rs glue grep_heur2 2 + +# make functions that do not GC take &JSContext instead of &mut JSContext +mark_as_no_gc() { + # Functions with AutoRequireNoGC arg do not trigger GC + sed -i '/\*const AutoRequireNoGC/ s/\&mut JSContext/\&JSContext/' $1 + + # Functions that also do not trigger GC + for fn in \ + "JS_GetRuntime" \ + "JS_GetParentRuntime" \ + "JS_GetGCParameter" \ + ; do + sed -i "/pub fn $fn/ s/\&mut JSContext/\&JSContext/g" $1 + done } -find_latest_version_of_file_and_parse jsapi.rs jsapi -find_latest_version_of_file_and_parse gluebindings.rs glue +mark_as_no_gc mozjs/src/jsapi2_wrappers.in.rs \ No newline at end of file diff --git a/mozjs/src/glue2_wrappers.in.rs b/mozjs/src/glue2_wrappers.in.rs new file mode 100644 index 0000000000..b30c1b5183 --- /dev/null +++ b/mozjs/src/glue2_wrappers.in.rs @@ -0,0 +1,44 @@ +wrap!(glue: pub fn InvokeGetOwnPropertyDescriptor(handler: *const ::std::os::raw::c_void, cx: &mut JSContext, proxy: HandleObject, id: HandleId, desc: MutableHandle, isNone: *mut bool) -> bool); +wrap!(glue: pub fn InvokeHasOwn(handler: *const ::std::os::raw::c_void, cx: &mut JSContext, proxy: HandleObject, id: HandleId, bp: *mut bool) -> bool); +wrap!(glue: pub fn CallJitGetterOp(info: *const JSJitInfo, cx: &mut JSContext, thisObj: HandleObject, specializedThis: *mut ::std::os::raw::c_void, argc: ::std::os::raw::c_uint, vp: *mut Value) -> bool); +wrap!(glue: pub fn CallJitSetterOp(info: *const JSJitInfo, cx: &mut JSContext, thisObj: HandleObject, specializedThis: *mut ::std::os::raw::c_void, argc: ::std::os::raw::c_uint, vp: *mut Value) -> bool); +wrap!(glue: pub fn CallJitMethodOp(info: *const JSJitInfo, cx: &mut JSContext, thisObj: HandleObject, specializedThis: *mut ::std::os::raw::c_void, argc: u32, vp: *mut Value) -> bool); +wrap!(glue: pub fn NewCompileOptions(aCx: &mut JSContext, aFile: *const ::std::os::raw::c_char, aLine: ::std::os::raw::c_uint) -> *mut ReadOnlyCompileOptions); +wrap!(glue: pub fn NewProxyObject(aCx: &mut JSContext, aHandler: *const ::std::os::raw::c_void, aPriv: HandleValue, proto: *mut JSObject, aClass: *const JSClass, aLazyProto: bool) -> *mut JSObject); +wrap!(glue: pub fn WrapperNew(aCx: &mut JSContext, aObj: HandleObject, aHandler: *const ::std::os::raw::c_void, aClass: *const JSClass) -> *mut JSObject); +wrap!(glue: pub fn NewWindowProxy(aCx: &mut JSContext, aObj: HandleObject, aHandler: *const ::std::os::raw::c_void) -> *mut JSObject); +wrap!(glue: pub fn RUST_JSID_IS_INT(id: HandleId) -> bool); +wrap!(glue: pub fn int_to_jsid(i: i32, id: MutableHandleId)); +wrap!(glue: pub fn RUST_JSID_TO_INT(id: HandleId) -> i32); +wrap!(glue: pub fn RUST_JSID_IS_STRING(id: HandleId) -> bool); +wrap!(glue: pub fn RUST_JSID_TO_STRING(id: HandleId) -> *mut JSString); +wrap!(glue: pub fn RUST_SYMBOL_TO_JSID(sym: *mut Symbol, id: MutableHandleId)); +wrap!(glue: pub fn RUST_JSID_IS_VOID(id: HandleId) -> bool); +wrap!(glue: pub fn RUST_INTERNED_STRING_TO_JSID(cx: &mut JSContext, str_: *mut JSString, id: MutableHandleId)); +wrap!(glue: pub fn ReportErrorASCII(aCx: &mut JSContext, aError: *const ::std::os::raw::c_char)); +wrap!(glue: pub fn ReportErrorUTF8(aCx: &mut JSContext, aError: *const ::std::os::raw::c_char)); +wrap!(glue: pub fn UnwrapObjectDynamic(obj: *mut JSObject, cx: &mut JSContext, stopAtWindowProxy: bool) -> *mut JSObject); +wrap!(glue: pub fn CreateRootedIdVector(cx: &mut JSContext) -> *mut PersistentRootedIdVector); +wrap!(glue: pub fn AppendToIdVector(v: MutableHandleIdVector, id: HandleId) -> bool); +wrap!(glue: pub fn CreateRootedObjectVector(aCx: &mut JSContext) -> *mut PersistentRootedObjectVector); +wrap!(glue: pub fn CollectServoSizes(cx: &mut JSContext, sizes: *mut ServoSizes, gs: GetSize) -> bool); +wrap!(glue: pub fn JS_GetPromiseResult(promise: HandleObject, dest: MutableHandleValue)); +wrap!(glue: pub fn JS_GetScriptPrivate(script: *mut JSScript, dest: MutableHandleValue)); +wrap!(glue: pub fn JS_MaybeGetScriptPrivate(obj: *mut JSObject, dest: MutableHandleValue)); +wrap!(glue: pub fn JS_GetModulePrivate(module: *mut JSObject, dest: MutableHandleValue)); +wrap!(glue: pub fn JS_GetScriptedCallerPrivate(cx: &mut JSContext, dest: MutableHandleValue)); +wrap!(glue: pub fn JS_GetNaNValue(cx: &mut JSContext, dest: *mut Value)); +wrap!(glue: pub fn JS_GetPositiveInfinityValue(cx: &mut JSContext, dest: *mut Value)); +wrap!(glue: pub fn JS_GetEmptyStringValue(cx: &mut JSContext, dest: *mut Value)); +wrap!(glue: pub fn JS_GetRegExpFlags(cx: &mut JSContext, obj: HandleObject, flags: *mut RegExpFlags)); +wrap!(glue: pub fn EncodeStringToUTF8(cx: &mut JSContext, str_: HandleString, cb: EncodedStringCallback)); +wrap!(glue: pub fn SetUpEventLoopDispatch(cx: &mut JSContext, callback: RustDispatchToEventLoopCallback, closure: *mut ::std::os::raw::c_void)); +wrap!(glue: pub fn DispatchableRun(cx: &mut JSContext, ptr: *mut DispatchablePointer, mb: Dispatchable_MaybeShuttingDown)); +wrap!(glue: pub fn DescribeScriptedCaller(cx: &mut JSContext, buffer: *mut ::std::os::raw::c_char, buflen: usize, line: *mut u32, col: *mut u32) -> bool); +wrap!(glue: pub fn SetDataPropertyDescriptor(desc: MutableHandle, value: HandleValue, attrs: u32)); +wrap!(glue: pub fn SetAccessorPropertyDescriptor(desc: MutableHandle, getter: HandleObject, setter: HandleObject, attrs: u32)); +wrap!(glue: pub fn DumpJSStack(cx: &mut JSContext, showArgs: bool, showLocals: bool, showThisProps: bool)); +wrap!(glue: pub fn StackGCVectorValueLength(vec: Handle>) -> u32); +wrap!(glue: pub fn StackGCVectorStringLength(vec: Handle>) -> u32); +wrap!(glue: pub fn StackGCVectorValueAtIndex(vec: Handle>, index: u32) -> *const Value); +wrap!(glue: pub fn StackGCVectorStringAtIndex(vec: Handle>, index: u32) -> *const *mut JSString); diff --git a/mozjs/src/jsapi2_wrappers.in.rs b/mozjs/src/jsapi2_wrappers.in.rs new file mode 100644 index 0000000000..51ada7f6fa --- /dev/null +++ b/mozjs/src/jsapi2_wrappers.in.rs @@ -0,0 +1,666 @@ +wrap!(jsapi: pub fn ReportOutOfMemory(cx: &mut JSContext)); +wrap!(jsapi: pub fn ReportLargeOutOfMemory(cx: &mut JSContext)); +wrap!(jsapi: pub fn SetContextProfilingStack(cx: &mut JSContext, profilingStack: *mut ProfilingStack)); +wrap!(jsapi: pub fn EnableContextProfilingStack(cx: &mut JSContext, enabled: bool)); +wrap!(jsapi: pub fn RegisterContextProfilingEventMarker(cx: &mut JSContext, mark: ::std::option::Option, interval: ::std::option::Option)); +wrap!(jsapi: pub fn SetStackFormat(cx: &mut JSContext, format: StackFormat)); +wrap!(jsapi: pub fn GetStackFormat(cx: &mut JSContext) -> StackFormat); +wrap!(jsapi: pub fn ToBooleanSlow(v: HandleValue) -> bool); +wrap!(jsapi: pub fn ToNumberSlow(cx: &mut JSContext, v: HandleValue, dp: *mut f64) -> bool); +wrap!(jsapi: pub fn ToInt8Slow(cx: &mut JSContext, v: HandleValue, out: *mut i8) -> bool); +wrap!(jsapi: pub fn ToUint8Slow(cx: &mut JSContext, v: HandleValue, out: *mut u8) -> bool); +wrap!(jsapi: pub fn ToInt16Slow(cx: &mut JSContext, v: HandleValue, out: *mut i16) -> bool); +wrap!(jsapi: pub fn ToInt32Slow(cx: &mut JSContext, v: HandleValue, out: *mut i32) -> bool); +wrap!(jsapi: pub fn ToUint32Slow(cx: &mut JSContext, v: HandleValue, out: *mut u32) -> bool); +wrap!(jsapi: pub fn ToUint16Slow(cx: &mut JSContext, v: HandleValue, out: *mut u16) -> bool); +wrap!(jsapi: pub fn ToInt64Slow(cx: &mut JSContext, v: HandleValue, out: *mut i64) -> bool); +wrap!(jsapi: pub fn ToUint64Slow(cx: &mut JSContext, v: HandleValue, out: *mut u64) -> bool); +wrap!(jsapi: pub fn ToStringSlow(cx: &mut JSContext, v: HandleValue) -> *mut JSString); +wrap!(jsapi: pub fn ToObjectSlow(cx: &mut JSContext, v: HandleValue, reportScanStack: bool) -> *mut JSObject); +wrap!(jsapi: pub fn NukeNonCCWProxy(cx: &mut JSContext, proxy: HandleObject)); +wrap!(jsapi: pub fn NukeRemovedCrossCompartmentWrapper(cx: &mut JSContext, wrapper: *mut JSObject)); +wrap!(jsapi: pub fn GetFirstSubsumedSavedFrame(cx: &mut JSContext, principals: *mut JSPrincipals, savedFrame: Handle<*mut JSObject>, selfHosted: SavedFrameSelfHosted) -> *mut JSObject); +wrap!(jsapi: pub fn TransparentObjectWrapper(cx: &mut JSContext, existing: HandleObject, obj: HandleObject) -> *mut JSObject); +wrap!(jsapi: pub fn CheckedUnwrapDynamic(obj: *mut JSObject, cx: &mut JSContext, stopAtWindowProxy: bool) -> *mut JSObject); +wrap!(jsapi: pub fn UnwrapOneCheckedDynamic(obj: HandleObject, cx: &mut JSContext, stopAtWindowProxy: bool) -> *mut JSObject); +wrap!(jsapi: pub fn ReportAccessDenied(cx: &mut JSContext)); +wrap!(jsapi: pub fn NukeCrossCompartmentWrapper(cx: &mut JSContext, wrapper: *mut JSObject)); +wrap!(jsapi: pub fn NukeCrossCompartmentWrapperIfExists(cx: &mut JSContext, source: *mut Compartment, target: *mut JSObject)); +wrap!(jsapi: pub fn RemapWrapper(cx: &mut JSContext, wobj: *mut JSObject, newTarget: *mut JSObject)); +wrap!(jsapi: pub fn RemapDeadWrapper(cx: &mut JSContext, wobj: HandleObject, newTarget: HandleObject)); +wrap!(jsapi: pub fn RemapAllWrappersForObject(cx: &mut JSContext, oldTarget: HandleObject, newTarget: HandleObject) -> bool); +wrap!(jsapi: pub fn RecomputeWrappers(cx: &mut JSContext, sourceFilter: *const CompartmentFilter, targetFilter: *const CompartmentFilter) -> bool); +wrap!(jsapi: pub fn SetWindowProxyClass(cx: &mut JSContext, clasp: *const JSClass)); +wrap!(jsapi: pub fn SetWindowProxy(cx: &mut JSContext, global: Handle<*mut JSObject>, windowProxy: Handle<*mut JSObject>)); +wrap!(jsapi: pub fn IsArgumentsObject(obj: HandleObject) -> bool); +wrap!(jsapi: pub fn AddRawValueRoot(cx: &mut JSContext, vp: *mut Value, name: *const ::std::os::raw::c_char) -> bool); +wrap!(jsapi: pub fn RemoveRawValueRoot(cx: &mut JSContext, vp: *mut Value)); +wrap!(jsapi: pub fn UseInternalJobQueues(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn EnqueueJob(cx: &mut JSContext, job: HandleObject) -> bool); +wrap!(jsapi: pub fn StopDrainingJobQueue(cx: &mut JSContext)); +wrap!(jsapi: pub fn RestartDrainingJobQueue(cx: &mut JSContext)); +wrap!(jsapi: pub fn RunJobs(cx: &mut JSContext)); +wrap!(jsapi: pub fn ShouldIgnorePropertyDefinition(cx: &mut JSContext, key: JSProtoKey, id: jsid) -> bool); +wrap!(jsapi: pub fn AssertSameCompartment(cx: &mut JSContext, obj: *mut JSObject)); +wrap!(jsapi: pub fn AssertSameCompartment1(cx: &mut JSContext, v: HandleValue)); +wrap!(jsapi: pub fn DefineFunctionWithReserved(cx: &mut JSContext, obj: *mut JSObject, name: *const ::std::os::raw::c_char, call: JSNative, nargs: ::std::os::raw::c_uint, attrs: ::std::os::raw::c_uint) -> *mut JSFunction); +wrap!(jsapi: pub fn NewFunctionWithReserved(cx: &mut JSContext, call: JSNative, nargs: ::std::os::raw::c_uint, flags: ::std::os::raw::c_uint, name: *const ::std::os::raw::c_char) -> *mut JSFunction); +wrap!(jsapi: pub fn NewFunctionByIdWithReserved(cx: &mut JSContext, native: JSNative, nargs: ::std::os::raw::c_uint, flags: ::std::os::raw::c_uint, id: jsid) -> *mut JSFunction); +wrap!(jsapi: pub fn NewFunctionByIdWithReservedAndProto(cx: &mut JSContext, native: JSNative, proto: Handle<*mut JSObject>, nargs: ::std::os::raw::c_uint, flags: ::std::os::raw::c_uint, id: jsid) -> *mut JSFunction); +wrap!(jsapi: pub fn GetObjectProto(cx: &mut JSContext, obj: HandleObject, proto: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn GetRealmOriginalEval(cx: &mut JSContext, eval: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn GetPropertyKeys(cx: &mut JSContext, obj: HandleObject, flags: ::std::os::raw::c_uint, props: MutableHandleIdVector) -> bool); +wrap!(jsapi: pub fn SetPreserveWrapperCallbacks(cx: &mut JSContext, preserveWrapper: PreserveWrapperCallback, hasReleasedWrapper: HasReleasedWrapperCallback)); +wrap!(jsapi: pub fn IsObjectInContextCompartment(obj: *mut JSObject, cx: &JSContext) -> bool); +wrap!(jsapi: pub fn SetDOMCallbacks(cx: &mut JSContext, callbacks: *const DOMCallbacks)); +wrap!(jsapi: pub fn GetDOMCallbacks(cx: &mut JSContext) -> *const DOMCallbacks); +wrap!(jsapi: pub fn GetTestingFunctions(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetErrorTypeName(cx: &mut JSContext, exnType: i16) -> *mut JSLinearString); +wrap!(jsapi: pub fn NukeCrossCompartmentWrappers(cx: &mut JSContext, sourceFilter: *const CompartmentFilter, target: *mut Realm, nukeReferencesToWindow: NukeReferencesToWindow, nukeReferencesFromTarget: NukeReferencesFromTarget) -> bool); +wrap!(jsapi: pub fn DateIsValid(cx: &mut JSContext, obj: HandleObject, isValid: *mut bool) -> bool); +wrap!(jsapi: pub fn DateGetMsecSinceEpoch(cx: &mut JSContext, obj: HandleObject, msecSinceEpoch: *mut f64) -> bool); +wrap!(jsapi: pub fn PrepareScriptEnvironmentAndInvoke(cx: &mut JSContext, global: HandleObject, closure: *mut ScriptEnvironmentPreparer_Closure)); +wrap!(jsapi: pub fn SetScriptEnvironmentPreparer(cx: &mut JSContext, preparer: *mut ScriptEnvironmentPreparer)); +wrap!(jsapi: pub fn SetAllocationMetadataBuilder(cx: &mut JSContext, callback: *const AllocationMetadataBuilder)); +wrap!(jsapi: pub fn GetElementsWithAdder(cx: &mut JSContext, obj: HandleObject, receiver: HandleObject, begin: u32, end: u32, adder: *mut ElementAdder) -> bool); +wrap!(jsapi: pub fn ForwardToNative(cx: &mut JSContext, native: JSNative, args: *const CallArgs) -> bool); +wrap!(jsapi: pub fn ExecuteInFrameScriptEnvironment(cx: &mut JSContext, obj: HandleObject, script: HandleScript, scope: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn ReportIsNotFunction(cx: &mut JSContext, v: HandleValue) -> bool); +wrap!(jsapi: pub fn GetGCHeapUsage(cx: &mut JSContext) -> u64); +wrap!(jsapi: pub fn RemapRemoteWindowProxies(cx: &mut JSContext, callback: *mut CompartmentTransplantCallback, newTarget: MutableHandleObject)); +wrap!(jsapi: pub fn ComputeThis(cx: &mut JSContext, vp: *mut Value, thisObject: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn StringToLinearStringSlow(cx: &mut JSContext, str_: *mut JSString) -> *mut JSLinearString); +wrap!(jsapi: pub fn BigIntFromInt64(cx: &mut JSContext, num: i64) -> *mut BigInt); +wrap!(jsapi: pub fn BigIntFromUint64(cx: &mut JSContext, num: u64) -> *mut BigInt); +wrap!(jsapi: pub fn BigIntFromBool(cx: &mut JSContext, b: bool) -> *mut BigInt); +wrap!(jsapi: pub fn CallMethodIfWrapped(cx: &mut JSContext, test: IsAcceptableThis, impl_: NativeImpl, args: *const CallArgs) -> bool); +wrap!(jsapi: pub fn ReportSourceTooLong(cx: &mut JSContext)); +wrap!(jsapi: pub fn IsIncrementalBarrierNeeded(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn GetCurrentRealmOrNull(cx: &mut JSContext) -> *mut Realm); +wrap!(jsapi: pub fn SetDestroyRealmCallback(cx: &mut JSContext, callback: DestroyRealmCallback)); +wrap!(jsapi: pub fn SetRealmNameCallback(cx: &mut JSContext, callback: RealmNameCallback)); +wrap!(jsapi: pub fn InitRealmStandardClasses(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn MaybeFreezeCtorAndPrototype(cx: &mut JSContext, ctor: HandleObject, maybeProto: HandleObject) -> bool); +wrap!(jsapi: pub fn GetRealmObjectPrototype(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetRealmFunctionPrototype(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetRealmArrayPrototype(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetRealmErrorPrototype(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetRealmIteratorPrototype(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetRealmAsyncIteratorPrototype(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetRealmKeyObject(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetFunctionRealm(cx: &mut JSContext, objArg: HandleObject) -> *mut Realm); +wrap!(jsapi: pub fn EnterRealm(cx: &mut JSContext, target: *mut JSObject) -> *mut Realm); +wrap!(jsapi: pub fn LeaveRealm(cx: &mut JSContext, oldRealm: *mut Realm)); +wrap!(jsapi: pub fn ResetRealmMathRandomSeed(cx: &mut JSContext)); +wrap!(jsapi: pub fn Call(cx: &mut JSContext, thisv: Handle, fun: Handle, args: *const HandleValueArray, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn Construct(cx: &mut JSContext, fun: Handle, newTarget: Handle<*mut JSObject>, args: *const HandleValueArray, objp: MutableHandle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn Construct1(cx: &mut JSContext, fun: Handle, args: *const HandleValueArray, objp: MutableHandle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn LossyTwoByteCharsToNewLatin1CharsZ(cx: &mut JSContext, tbchars: *const Range) -> Latin1CharsZ); +wrap!(jsapi: pub fn UTF8CharsToNewTwoByteCharsZ(cx: &mut JSContext, utf8: *const UTF8Chars, outlen: *mut usize, destArenaId: arena_id_t) -> TwoByteCharsZ); +wrap!(jsapi: pub fn LossyUTF8CharsToNewTwoByteCharsZ(cx: &mut JSContext, utf8: *const UTF8Chars, outlen: *mut usize, destArenaId: arena_id_t) -> TwoByteCharsZ); +wrap!(jsapi: pub fn UTF8CharsToNewLatin1CharsZ(cx: &mut JSContext, utf8: *const UTF8Chars, outlen: *mut usize, destArenaId: arena_id_t) -> Latin1CharsZ); +wrap!(jsapi: pub fn EncodeNarrowToUtf8(cx: &mut JSContext, chars: *const ::std::os::raw::c_char) -> UniqueChars); +wrap!(jsapi: pub fn EncodeUtf8ToNarrow(cx: &mut JSContext, chars: *const ::std::os::raw::c_char) -> UniqueChars); +wrap!(jsapi: pub fn EncodeUtf8ToWide(cx: &mut JSContext, chars: *const ::std::os::raw::c_char) -> UniqueWideChars); +wrap!(jsapi: pub fn GetWellKnownSymbolKey(cx: &mut JSContext, which: SymbolCode) -> PropertyKey); +wrap!(jsapi: pub fn ToGetterId(cx: &mut JSContext, id: Handle, getterId: MutableHandle) -> bool); +wrap!(jsapi: pub fn ToSetterId(cx: &mut JSContext, id: Handle, setterId: MutableHandle) -> bool); +wrap!(jsapi: pub fn SetHostEnsureCanAddPrivateElementHook(cx: &mut JSContext, op: EnsureCanAddPrivateElementOp)); +wrap!(jsapi: pub fn SetBrittleMode(cx: &mut JSContext, setting: bool) -> bool); +wrap!(jsapi: pub fn PrepareZoneForGC(cx: &mut JSContext, zone: *mut Zone)); +wrap!(jsapi: pub fn PrepareForFullGC(cx: &mut JSContext)); +wrap!(jsapi: pub fn PrepareForIncrementalGC(cx: &mut JSContext)); +wrap!(jsapi: pub fn IsGCScheduled(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn SkipZoneForGC(cx: &mut JSContext, zone: *mut Zone)); +wrap!(jsapi: pub fn NonIncrementalGC(cx: &mut JSContext, options: GCOptions, reason: GCReason)); +wrap!(jsapi: pub fn StartIncrementalGC(cx: &mut JSContext, options: GCOptions, reason: GCReason, budget: *const SliceBudget)); +wrap!(jsapi: pub fn IncrementalGCSlice(cx: &mut JSContext, reason: GCReason, budget: *const SliceBudget)); +wrap!(jsapi: pub fn IncrementalGCHasForegroundWork(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn FinishIncrementalGC(cx: &mut JSContext, reason: GCReason)); +wrap!(jsapi: pub fn AbortIncrementalGC(cx: &mut JSContext)); +wrap!(jsapi: pub fn MinorGcToJSON(cx: &mut JSContext) -> UniqueChars); +wrap!(jsapi: pub fn SetGCSliceCallback(cx: &mut JSContext, callback: GCSliceCallback) -> GCSliceCallback); +wrap!(jsapi: pub fn AddGCNurseryCollectionCallback(cx: &mut JSContext, callback: GCNurseryCollectionCallback, data: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn RemoveGCNurseryCollectionCallback(cx: &mut JSContext, callback: GCNurseryCollectionCallback, data: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn SetDoCycleCollectionCallback(cx: &mut JSContext, callback: DoCycleCollectionCallback) -> DoCycleCollectionCallback); +wrap!(jsapi: pub fn SetCreateGCSliceBudgetCallback(cx: &mut JSContext, cb: CreateSliceBudgetCallback)); +wrap!(jsapi: pub fn IsIncrementalGCEnabled(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn IsIncrementalGCInProgress(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn SetLowMemoryState(cx: &mut JSContext, newState: bool)); +wrap!(jsapi: pub fn NotifyGCRootsRemoved(cx: &mut JSContext)); +wrap!(jsapi: pub fn SetHostCleanupFinalizationRegistryCallback(cx: &mut JSContext, cb: JSHostCleanupFinalizationRegistryCallback, data: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn ClearKeptObjects(cx: &mut JSContext)); +wrap!(jsapi: pub fn ReportUncatchableException(cx: &mut JSContext)); +wrap!(jsapi: pub fn GetPendingExceptionStack(cx: &mut JSContext, exceptionStack: *mut ExceptionStack) -> bool); +wrap!(jsapi: pub fn StealPendingExceptionStack(cx: &mut JSContext, exceptionStack: *mut ExceptionStack) -> bool); +wrap!(jsapi: pub fn SetPendingExceptionStack(cx: &mut JSContext, exceptionStack: *const ExceptionStack)); +wrap!(jsapi: pub fn ExceptionStackOrNull(obj: HandleObject) -> *mut JSObject); +wrap!(jsapi: pub fn CurrentGlobalOrNull(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn NewMapObject(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn MapSize(cx: &mut JSContext, obj: HandleObject) -> u32); +wrap!(jsapi: pub fn MapGet(cx: &mut JSContext, obj: HandleObject, key: HandleValue, rval: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn MapHas(cx: &mut JSContext, obj: HandleObject, key: HandleValue, rval: *mut bool) -> bool); +wrap!(jsapi: pub fn MapSet(cx: &mut JSContext, obj: HandleObject, key: HandleValue, val: HandleValue) -> bool); +wrap!(jsapi: pub fn MapDelete(cx: &mut JSContext, obj: HandleObject, key: HandleValue, rval: *mut bool) -> bool); +wrap!(jsapi: pub fn MapClear(cx: &mut JSContext, obj: HandleObject) -> bool); +wrap!(jsapi: pub fn MapKeys(cx: &mut JSContext, obj: HandleObject, rval: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn MapValues(cx: &mut JSContext, obj: HandleObject, rval: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn MapEntries(cx: &mut JSContext, obj: HandleObject, rval: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn MapForEach(cx: &mut JSContext, obj: HandleObject, callbackFn: HandleValue, thisVal: HandleValue) -> bool); +wrap!(jsapi: pub fn NewSetObject(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn SetSize(cx: &mut JSContext, obj: HandleObject) -> u32); +wrap!(jsapi: pub fn SetHas(cx: &mut JSContext, obj: HandleObject, key: HandleValue, rval: *mut bool) -> bool); +wrap!(jsapi: pub fn SetDelete(cx: &mut JSContext, obj: HandleObject, key: HandleValue, rval: *mut bool) -> bool); +wrap!(jsapi: pub fn SetAdd(cx: &mut JSContext, obj: HandleObject, key: HandleValue) -> bool); +wrap!(jsapi: pub fn SetClear(cx: &mut JSContext, obj: HandleObject) -> bool); +wrap!(jsapi: pub fn SetKeys(cx: &mut JSContext, obj: HandleObject, rval: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn SetValues(cx: &mut JSContext, obj: HandleObject, rval: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn SetEntries(cx: &mut JSContext, obj: HandleObject, rval: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn SetForEach(cx: &mut JSContext, obj: HandleObject, callbackFn: HandleValue, thisVal: HandleValue) -> bool); +wrap!(jsapi: pub fn SetOutOfMemoryCallback(cx: &mut JSContext, cb: OutOfMemoryCallback, data: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn ToCompletePropertyDescriptor(cx: &mut JSContext, descriptor: Handle, desc: MutableHandle) -> bool); +wrap!(jsapi: pub fn NewSymbol(cx: &mut JSContext, description: Handle<*mut JSString>) -> *mut Symbol); +wrap!(jsapi: pub fn GetSymbolFor(cx: &mut JSContext, key: Handle<*mut JSString>) -> *mut Symbol); +wrap!(jsapi: pub fn GetSymbolDescription(symbol: Handle<*mut Symbol>) -> *mut JSString); +wrap!(jsapi: pub fn GetSymbolCode(symbol: Handle<*mut Symbol>) -> SymbolCode); +wrap!(jsapi: pub fn GetWellKnownSymbol(cx: &mut JSContext, which: SymbolCode) -> *mut Symbol); +wrap!(jsapi: pub fn IterateRealms(cx: &mut JSContext, data: *mut ::std::os::raw::c_void, realmCallback: IterateRealmCallback)); +wrap!(jsapi: pub fn IterateRealmsWithPrincipals(cx: &mut JSContext, principals: *mut JSPrincipals, data: *mut ::std::os::raw::c_void, realmCallback: IterateRealmCallback)); +wrap!(jsapi: pub fn IterateRealmsInCompartment(cx: &mut JSContext, compartment: *mut Compartment, data: *mut ::std::os::raw::c_void, realmCallback: IterateRealmCallback)); +wrap!(jsapi: pub fn RealmCreationOptionsRef1(cx: &mut JSContext) -> *const RealmCreationOptions); +wrap!(jsapi: pub fn RealmBehaviorsRef1(cx: &mut JSContext) -> *const RealmBehaviors); +wrap!(jsapi: pub fn CaptureCurrentStack(cx: &mut JSContext, stackp: MutableHandleObject, capture: *mut StackCapture, startAfter: HandleObject) -> bool); +wrap!(jsapi: pub fn IsAsyncStackCaptureEnabledForRealm(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn BuildStackString(cx: &mut JSContext, principals: *mut JSPrincipals, stack: HandleObject, stringp: MutableHandleString, indent: usize, stackFormat: StackFormat) -> bool); +wrap!(jsapi: pub fn InitConsumeStreamCallback(cx: &mut JSContext, consume: ConsumeStreamCallback, report: ReportStreamErrorCallback)); +wrap!(jsapi: pub fn NewStringFromLatin1Buffer(cx: &mut JSContext, buffer: RefPtr, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn NewStringFromKnownLiveLatin1Buffer(cx: &mut JSContext, buffer: *mut StringBuffer, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn NewStringFromTwoByteBuffer(cx: &mut JSContext, buffer: RefPtr, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn NewStringFromKnownLiveTwoByteBuffer(cx: &mut JSContext, buffer: *mut StringBuffer, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn NewStringFromUTF8Buffer(cx: &mut JSContext, buffer: RefPtr, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn NewStringFromKnownLiveUTF8Buffer(cx: &mut JSContext, buffer: *mut StringBuffer, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn GetJSTimers(cx: &mut JSContext) -> JSTimers); +wrap!(jsapi: pub fn NewWeakMapObject(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetWeakMapEntry(cx: &mut JSContext, mapObj: HandleObject, key: HandleValue, val: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn SetWeakMapEntry(cx: &mut JSContext, mapObj: HandleObject, key: HandleValue, val: HandleValue) -> bool); +wrap!(jsapi: pub fn ProtoKeyToId(cx: &mut JSContext, key: JSProtoKey, idp: MutableHandleId)); +wrap!(jsapi: pub fn ToPrimitive(cx: &mut JSContext, obj: HandleObject, hint: JSType, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn GetFirstArgumentAsTypeHint(cx: &mut JSContext, args: *const CallArgs, result: *mut JSType) -> bool); +wrap!(jsapi: pub fn OrdinaryHasInstance(cx: &mut JSContext, objArg: HandleObject, v: HandleValue, bp: *mut bool) -> bool); +wrap!(jsapi: pub fn IsMapObject(cx: &mut JSContext, obj: HandleObject, isMap: *mut bool) -> bool); +wrap!(jsapi: pub fn IsSetObject(cx: &mut JSContext, obj: HandleObject, isSet: *mut bool) -> bool); +wrap!(jsapi: pub fn GetSelfHostedFunction(cx: &mut JSContext, selfHostedName: *const ::std::os::raw::c_char, id: HandleId, nargs: ::std::os::raw::c_uint) -> *mut JSFunction); +wrap!(jsapi: pub fn NewFunctionFromSpec(cx: &mut JSContext, fs: *const JSFunctionSpec, id: HandleId) -> *mut JSFunction); +wrap!(jsapi: pub fn NewFunctionFromSpec1(cx: &mut JSContext, fs: *const JSFunctionSpec) -> *mut JSFunction); +wrap!(jsapi: pub fn PropertySpecNameEqualsId(name: JSPropertySpec_Name, id: HandleId) -> bool); +wrap!(jsapi: pub fn PropertySpecNameToPermanentId(cx: &mut JSContext, name: JSPropertySpec_Name, idp: *mut jsid) -> bool); +wrap!(jsapi: pub fn GetScriptedCallerGlobal(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn HideScriptedCaller(cx: &mut JSContext)); +wrap!(jsapi: pub fn UnhideScriptedCaller(cx: &mut JSContext)); +wrap!(jsapi: pub fn NewArrayBuffer(cx: &mut JSContext, nbytes: usize) -> *mut JSObject); +wrap!(jsapi: pub fn CopyArrayBuffer(cx: &mut JSContext, maybeArrayBuffer: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn NewArrayBufferWithUserOwnedContents(cx: &mut JSContext, nbytes: usize, contents: *mut ::std::os::raw::c_void) -> *mut JSObject); +wrap!(jsapi: pub fn NewMappedArrayBufferWithContents(cx: &mut JSContext, nbytes: usize, contents: *mut ::std::os::raw::c_void) -> *mut JSObject); +wrap!(jsapi: pub fn DetachArrayBuffer(cx: &mut JSContext, obj: Handle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn HasDefinedArrayBufferDetachKey(cx: &mut JSContext, obj: Handle<*mut JSObject>, isDefined: *mut bool) -> bool); +wrap!(jsapi: pub fn StealArrayBufferContents(cx: &mut JSContext, obj: Handle<*mut JSObject>) -> *mut ::std::os::raw::c_void); +wrap!(jsapi: pub fn ArrayBufferCopyData(cx: &mut JSContext, toBlock: Handle<*mut JSObject>, toIndex: usize, fromBlock: Handle<*mut JSObject>, fromIndex: usize, count: usize) -> bool); +wrap!(jsapi: pub fn ArrayBufferClone(cx: &mut JSContext, srcBuffer: Handle<*mut JSObject>, srcByteOffset: usize, srcLength: usize) -> *mut JSObject); +wrap!(jsapi: pub fn NumberToBigInt(cx: &mut JSContext, num: f64) -> *mut BigInt); +wrap!(jsapi: pub fn StringToBigInt(cx: &mut JSContext, chars: *const Range) -> *mut BigInt); +wrap!(jsapi: pub fn StringToBigInt1(cx: &mut JSContext, chars: *const Range) -> *mut BigInt); +wrap!(jsapi: pub fn ToBigInt(cx: &mut JSContext, val: Handle) -> *mut BigInt); +wrap!(jsapi: pub fn BigIntToString(cx: &mut JSContext, bi: Handle<*mut BigInt>, radix: u8) -> *mut JSString); +wrap!(jsapi: pub fn Evaluate(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn Evaluate1(cx: &mut JSContext, envChain: *const EnvironmentChain, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn Evaluate2(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn EvaluateUtf8Path(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, filename: *const ::std::os::raw::c_char, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn Compile(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> *mut JSScript); +wrap!(jsapi: pub fn Compile1(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> *mut JSScript); +wrap!(jsapi: pub fn CompileUtf8File(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, file: *mut FILE) -> *mut JSScript); +wrap!(jsapi: pub fn CompileUtf8Path(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, filename: *const ::std::os::raw::c_char) -> *mut JSScript); +wrap!(jsapi: pub fn CompileFunction(cx: &mut JSContext, envChain: *const EnvironmentChain, options: *const ReadOnlyCompileOptions, name: *const ::std::os::raw::c_char, nargs: ::std::os::raw::c_uint, argnames: *const *const ::std::os::raw::c_char, srcBuf: *mut SourceText) -> *mut JSFunction); +wrap!(jsapi: pub fn CompileFunction1(cx: &mut JSContext, envChain: *const EnvironmentChain, options: *const ReadOnlyCompileOptions, name: *const ::std::os::raw::c_char, nargs: ::std::os::raw::c_uint, argnames: *const *const ::std::os::raw::c_char, srcBuf: *mut SourceText) -> *mut JSFunction); +wrap!(jsapi: pub fn CompileFunctionUtf8(cx: &mut JSContext, envChain: *const EnvironmentChain, options: *const ReadOnlyCompileOptions, name: *const ::std::os::raw::c_char, nargs: ::std::os::raw::c_uint, argnames: *const *const ::std::os::raw::c_char, utf8: *const ::std::os::raw::c_char, length: usize) -> *mut JSFunction); +wrap!(jsapi: pub fn ExposeScriptToDebugger(cx: &mut JSContext, script: Handle<*mut JSScript>)); +wrap!(jsapi: pub fn UpdateDebugMetadata(cx: &mut JSContext, script: Handle<*mut JSScript>, options: *const InstantiateOptions, privateValue: HandleValue, elementAttributeName: HandleString, introScript: HandleScript, scriptOrModule: HandleScript) -> bool); +wrap!(jsapi: pub fn ContextOptionsRef(cx: &mut JSContext) -> *mut ContextOptions); +wrap!(jsapi: pub fn OrdinaryToPrimitive(cx: &mut JSContext, obj: HandleObject, type_: JSType, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn NewDateObject(cx: &mut JSContext, time: ClippedTime) -> *mut JSObject); +wrap!(jsapi: pub fn NewDateObject1(cx: &mut JSContext, year: ::std::os::raw::c_int, mon: ::std::os::raw::c_int, mday: ::std::os::raw::c_int, hour: ::std::os::raw::c_int, min: ::std::os::raw::c_int, sec: ::std::os::raw::c_int) -> *mut JSObject); +wrap!(jsapi: pub fn ObjectIsDate(cx: &mut JSContext, obj: Handle<*mut JSObject>, isDate: *mut bool) -> bool); +wrap!(jsapi: pub fn IsISOStyleDate(cx: &mut JSContext, str_: *const Latin1Chars) -> bool); +wrap!(jsapi: pub fn StrictlyEqual(cx: &mut JSContext, v1: Handle, v2: Handle, equal: *mut bool) -> bool); +wrap!(jsapi: pub fn LooselyEqual(cx: &mut JSContext, v1: Handle, v2: Handle, equal: *mut bool) -> bool); +wrap!(jsapi: pub fn SameValue(cx: &mut JSContext, v1: Handle, v2: Handle, same: *mut bool) -> bool); +wrap!(jsapi: pub fn InitSelfHostedCode(cx: &mut JSContext, cache: SelfHostedCache, writer: SelfHostedWriter) -> bool); +wrap!(jsapi: pub fn ToJSONMaybeSafely(cx: &mut JSContext, input: Handle<*mut JSObject>, callback: JSONWriteCallback, data: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn ToJSON(cx: &mut JSContext, value: Handle, replacer: Handle<*mut JSObject>, space: Handle, callback: JSONWriteCallback, data: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn ParseJSONWithHandler(chars: *const Latin1Char, len: u32, handler: *mut JSONParseHandler) -> bool); +wrap!(jsapi: pub fn ParseJSONWithHandler1(chars: *const u16, len: u32, handler: *mut JSONParseHandler) -> bool); +wrap!(jsapi: pub fn CollectRuntimeStats(cx: &mut JSContext, rtStats: *mut RuntimeStats, opv: *mut ObjectPrivateVisitor, anonymize: bool) -> bool); +wrap!(jsapi: pub fn SystemCompartmentCount(cx: &mut JSContext) -> usize); +wrap!(jsapi: pub fn UserCompartmentCount(cx: &mut JSContext) -> usize); +wrap!(jsapi: pub fn SystemRealmCount(cx: &mut JSContext) -> usize); +wrap!(jsapi: pub fn UserRealmCount(cx: &mut JSContext) -> usize); +wrap!(jsapi: pub fn PeakSizeOfTemporary(cx: &JSContext) -> usize); +wrap!(jsapi: pub fn AddSizeOfTab(cx: &mut JSContext, obj: HandleObject, mallocSizeOf: MallocSizeOf, opv: *mut ObjectPrivateVisitor, sizes: *mut TabSizes) -> bool); +wrap!(jsapi: pub fn AddServoSizeOf(cx: &mut JSContext, mallocSizeOf: MallocSizeOf, opv: *mut ObjectPrivateVisitor, sizes: *mut ServoSizes) -> bool); +wrap!(jsapi: pub fn FinishDynamicModuleImport(cx: &mut JSContext, evaluationPromise: Handle<*mut JSObject>, referencingPrivate: Handle, moduleRequest: Handle<*mut JSObject>, promise: Handle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn CompileModule(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> *mut JSObject); +wrap!(jsapi: pub fn CompileModule1(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> *mut JSObject); +wrap!(jsapi: pub fn CompileJsonModule(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> *mut JSObject); +wrap!(jsapi: pub fn CompileJsonModule1(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> *mut JSObject); +wrap!(jsapi: pub fn ModuleLink(cx: &mut JSContext, moduleRecord: Handle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn ModuleEvaluate(cx: &mut JSContext, moduleRecord: Handle<*mut JSObject>, rval: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn ThrowOnModuleEvaluationFailure(cx: &mut JSContext, evaluationPromise: Handle<*mut JSObject>, errorBehaviour: ModuleErrorBehaviour) -> bool); +wrap!(jsapi: pub fn GetRequestedModulesCount(cx: &mut JSContext, moduleRecord: Handle<*mut JSObject>) -> u32); +wrap!(jsapi: pub fn GetRequestedModuleSpecifier(cx: &mut JSContext, moduleRecord: Handle<*mut JSObject>, index: u32) -> *mut JSString); +wrap!(jsapi: pub fn GetRequestedModuleSourcePos(cx: &mut JSContext, moduleRecord: Handle<*mut JSObject>, index: u32, lineNumber: *mut u32, columnNumber: *mut ColumnNumberOneOrigin)); +wrap!(jsapi: pub fn GetRequestedModuleType(cx: &mut JSContext, moduleRecord: Handle<*mut JSObject>, index: u32) -> ModuleType); +wrap!(jsapi: pub fn GetModuleScript(moduleRecord: Handle<*mut JSObject>) -> *mut JSScript); +wrap!(jsapi: pub fn CreateModuleRequest(cx: &mut JSContext, specifierArg: Handle<*mut JSString>, moduleType: ModuleType) -> *mut JSObject); +wrap!(jsapi: pub fn GetModuleRequestSpecifier(cx: &mut JSContext, moduleRequestArg: Handle<*mut JSObject>) -> *mut JSString); +wrap!(jsapi: pub fn GetModuleRequestType(cx: &mut JSContext, moduleRequestArg: Handle<*mut JSObject>) -> ModuleType); +wrap!(jsapi: pub fn GetModuleObject(moduleScript: Handle<*mut JSScript>) -> *mut JSObject); +wrap!(jsapi: pub fn GetModuleNamespace(cx: &mut JSContext, moduleRecord: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn GetModuleForNamespace(cx: &mut JSContext, moduleNamespace: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn GetModuleEnvironment(cx: &mut JSContext, moduleObj: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn GetBuiltinClass(cx: &mut JSContext, obj: Handle<*mut JSObject>, cls: *mut ESClass) -> bool); +wrap!(jsapi: pub fn SetJobQueue(cx: &mut JSContext, queue: *mut JobQueue)); +wrap!(jsapi: pub fn SetPromiseRejectionTrackerCallback(cx: &mut JSContext, callback: PromiseRejectionTrackerCallback, data: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn JobQueueIsEmpty(cx: &mut JSContext)); +wrap!(jsapi: pub fn JobQueueMayNotBeEmpty(cx: &mut JSContext)); +wrap!(jsapi: pub fn NewPromiseObject(cx: &mut JSContext, executor: HandleObject) -> *mut JSObject); +wrap!(jsapi: pub fn IsPromiseObject(obj: HandleObject) -> bool); +wrap!(jsapi: pub fn GetPromiseConstructor(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetPromisePrototype(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn GetPromiseState(promise: HandleObject) -> PromiseState); +wrap!(jsapi: pub fn GetPromiseID(promise: HandleObject) -> u64); +wrap!(jsapi: pub fn GetPromiseIsHandled(promise: HandleObject) -> bool); +wrap!(jsapi: pub fn SetSettledPromiseIsHandled(cx: &mut JSContext, promise: HandleObject) -> bool); +wrap!(jsapi: pub fn SetAnyPromiseIsHandled(cx: &mut JSContext, promise: HandleObject) -> bool); +wrap!(jsapi: pub fn GetPromiseAllocationSite(promise: HandleObject) -> *mut JSObject); +wrap!(jsapi: pub fn GetPromiseResolutionSite(promise: HandleObject) -> *mut JSObject); +wrap!(jsapi: pub fn CallOriginalPromiseResolve(cx: &mut JSContext, resolutionValue: HandleValue) -> *mut JSObject); +wrap!(jsapi: pub fn CallOriginalPromiseReject(cx: &mut JSContext, rejectionValue: HandleValue) -> *mut JSObject); +wrap!(jsapi: pub fn ResolvePromise(cx: &mut JSContext, promiseObj: HandleObject, resolutionValue: HandleValue) -> bool); +wrap!(jsapi: pub fn RejectPromise(cx: &mut JSContext, promiseObj: HandleObject, rejectionValue: HandleValue) -> bool); +wrap!(jsapi: pub fn CallOriginalPromiseThen(cx: &mut JSContext, promise: HandleObject, onFulfilled: HandleObject, onRejected: HandleObject) -> *mut JSObject); +wrap!(jsapi: pub fn AddPromiseReactions(cx: &mut JSContext, promise: HandleObject, onFulfilled: HandleObject, onRejected: HandleObject) -> bool); +wrap!(jsapi: pub fn AddPromiseReactionsIgnoringUnhandledRejection(cx: &mut JSContext, promise: HandleObject, onFulfilled: HandleObject, onRejected: HandleObject) -> bool); +wrap!(jsapi: pub fn GetPromiseUserInputEventHandlingState(promise: HandleObject) -> PromiseUserInputEventHandlingState); +wrap!(jsapi: pub fn SetPromiseUserInputEventHandlingState(promise: HandleObject, state: PromiseUserInputEventHandlingState) -> bool); +wrap!(jsapi: pub fn GetWaitForAllPromise(cx: &mut JSContext, promises: HandleObjectVector) -> *mut JSObject); +wrap!(jsapi: pub fn InitDispatchsToEventLoop(cx: &mut JSContext, callback: DispatchToEventLoopCallback, delayedCallback: DelayedDispatchToEventLoopCallback, closure: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn ShutdownAsyncTasks(cx: &mut JSContext)); +wrap!(jsapi: pub fn NewArrayObject(cx: &mut JSContext, contents: *const HandleValueArray) -> *mut JSObject); +wrap!(jsapi: pub fn NewArrayObject1(cx: &mut JSContext, length: usize) -> *mut JSObject); +wrap!(jsapi: pub fn IsArrayObject(cx: &mut JSContext, value: Handle, isArray: *mut bool) -> bool); +wrap!(jsapi: pub fn IsArrayObject1(cx: &mut JSContext, obj: Handle<*mut JSObject>, isArray: *mut bool) -> bool); +wrap!(jsapi: pub fn GetArrayLength(cx: &mut JSContext, obj: Handle<*mut JSObject>, lengthp: *mut u32) -> bool); +wrap!(jsapi: pub fn SetArrayLength(cx: &mut JSContext, obj: Handle<*mut JSObject>, length: u32) -> bool); +wrap!(jsapi: pub fn IsArray(cx: &mut JSContext, obj: Handle<*mut JSObject>, isArray: *mut bool) -> bool); +wrap!(jsapi: pub fn IsArray1(cx: &mut JSContext, obj: Handle<*mut JSObject>, answer: *mut IsArrayAnswer) -> bool); +wrap!(jsapi: pub fn NewRegExpObject(cx: &mut JSContext, bytes: *const ::std::os::raw::c_char, length: usize, flags: RegExpFlags) -> *mut JSObject); +wrap!(jsapi: pub fn NewUCRegExpObject(cx: &mut JSContext, chars: *const u16, length: usize, flags: RegExpFlags) -> *mut JSObject); +wrap!(jsapi: pub fn SetRegExpInput(cx: &mut JSContext, obj: Handle<*mut JSObject>, input: Handle<*mut JSString>) -> bool); +wrap!(jsapi: pub fn ClearRegExpStatics(cx: &mut JSContext, obj: Handle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn ExecuteRegExp(cx: &mut JSContext, obj: Handle<*mut JSObject>, reobj: Handle<*mut JSObject>, chars: *const u16, length: usize, indexp: *mut usize, test: bool, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn ExecuteRegExpNoStatics(cx: &mut JSContext, reobj: Handle<*mut JSObject>, chars: *const u16, length: usize, indexp: *mut usize, test: bool, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn ObjectIsRegExp(cx: &mut JSContext, obj: Handle<*mut JSObject>, isRegExp: *mut bool) -> bool); +wrap!(jsapi: pub fn GetRegExpSource(cx: &mut JSContext, obj: Handle<*mut JSObject>) -> *mut JSString); +wrap!(jsapi: pub fn CheckRegExpSyntax(cx: &mut JSContext, chars: *const u16, length: usize, flags: RegExpFlags, error: MutableHandle) -> bool); +wrap!(jsapi: pub fn GetSavedFrameSource(cx: &mut JSContext, principals: *mut JSPrincipals, savedFrame: Handle<*mut JSObject>, sourcep: MutableHandle<*mut JSString>, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); +wrap!(jsapi: pub fn GetSavedFrameSourceId(cx: &mut JSContext, principals: *mut JSPrincipals, savedFrame: Handle<*mut JSObject>, sourceIdp: *mut u32, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); +wrap!(jsapi: pub fn GetSavedFrameLine(cx: &mut JSContext, principals: *mut JSPrincipals, savedFrame: Handle<*mut JSObject>, linep: *mut u32, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); +wrap!(jsapi: pub fn GetSavedFrameColumn(cx: &mut JSContext, principals: *mut JSPrincipals, savedFrame: Handle<*mut JSObject>, columnp: *mut TaggedColumnNumberOneOrigin, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); +wrap!(jsapi: pub fn GetSavedFrameFunctionDisplayName(cx: &mut JSContext, principals: *mut JSPrincipals, savedFrame: Handle<*mut JSObject>, namep: MutableHandle<*mut JSString>, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); +wrap!(jsapi: pub fn GetSavedFrameAsyncCause(cx: &mut JSContext, principals: *mut JSPrincipals, savedFrame: Handle<*mut JSObject>, asyncCausep: MutableHandle<*mut JSString>, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); +wrap!(jsapi: pub fn GetSavedFrameAsyncParent(cx: &mut JSContext, principals: *mut JSPrincipals, savedFrame: Handle<*mut JSObject>, asyncParentp: MutableHandle<*mut JSObject>, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); +wrap!(jsapi: pub fn GetSavedFrameParent(cx: &mut JSContext, principals: *mut JSPrincipals, savedFrame: Handle<*mut JSObject>, parentp: MutableHandle<*mut JSObject>, selfHosted: SavedFrameSelfHosted) -> SavedFrameResult); +wrap!(jsapi: pub fn ConvertSavedFrameToPlainObject(cx: &mut JSContext, savedFrame: HandleObject, selfHosted: SavedFrameSelfHosted) -> *mut JSObject); +wrap!(jsapi: pub fn NewSharedArrayBuffer(cx: &mut JSContext, nbytes: usize) -> *mut JSObject); +wrap!(jsapi: pub fn ContainsSharedArrayBuffer(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn GetWarningReporter(cx: &mut JSContext) -> WarningReporter); +wrap!(jsapi: pub fn SetWarningReporter(cx: &mut JSContext, reporter: WarningReporter) -> WarningReporter); +wrap!(jsapi: pub fn IsWasmModuleObject(obj: HandleObject) -> bool); +wrap!(jsapi: pub fn GetWasmModule(obj: HandleObject) -> RefPtr); +wrap!(jsapi: pub fn CompileGlobalScriptToStencil(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> already_AddRefed); +wrap!(jsapi: pub fn CompileGlobalScriptToStencil1(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> already_AddRefed); +wrap!(jsapi: pub fn CompileModuleScriptToStencil(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> already_AddRefed); +wrap!(jsapi: pub fn CompileModuleScriptToStencil1(cx: &mut JSContext, options: *const ReadOnlyCompileOptions, srcBuf: *mut SourceText) -> already_AddRefed); +wrap!(jsapi: pub fn InstantiateGlobalStencil(cx: &mut JSContext, options: *const InstantiateOptions, stencil: *mut Stencil, storage: *mut InstantiationStorage) -> *mut JSScript); +wrap!(jsapi: pub fn InstantiateModuleStencil(cx: &mut JSContext, options: *const InstantiateOptions, stencil: *mut Stencil, storage: *mut InstantiationStorage) -> *mut JSObject); +wrap!(jsapi: pub fn DecodeStencil(cx: &mut JSContext, options: *const ReadOnlyDecodeOptions, range: *const TranscodeRange, stencilOut: *mut *mut Stencil) -> TranscodeResult); +wrap!(jsapi: pub fn StartCollectingDelazifications(cx: &mut JSContext, script: Handle<*mut JSScript>, stencil: *mut Stencil, alreadyStarted: *mut bool) -> bool); +wrap!(jsapi: pub fn StartCollectingDelazifications1(cx: &mut JSContext, module: Handle<*mut JSObject>, stencil: *mut Stencil, alreadyStarted: *mut bool) -> bool); +wrap!(jsapi: pub fn FinishCollectingDelazifications(cx: &mut JSContext, script: Handle<*mut JSScript>, buffer: *mut TranscodeBuffer) -> bool); +wrap!(jsapi: pub fn FinishCollectingDelazifications1(cx: &mut JSContext, module: Handle<*mut JSObject>, buffer: *mut TranscodeBuffer) -> bool); +wrap!(jsapi: pub fn FinishCollectingDelazifications2(cx: &mut JSContext, script: Handle<*mut JSScript>, stencilOut: *mut *mut Stencil) -> bool); +wrap!(jsapi: pub fn AbortCollectingDelazifications(script: Handle<*mut JSScript>)); +wrap!(jsapi: pub fn AbortCollectingDelazifications1(module: Handle<*mut JSObject>)); +wrap!(jsapi: pub fn EnsureNonInlineArrayBufferOrView(cx: &mut JSContext, obj: *mut JSObject) -> bool); +wrap!(jsapi: pub fn ForceLexicalInitialization(cx: &mut JSContext, obj: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_ReportOutOfMemory(cx: &mut JSContext)); +wrap!(jsapi: pub fn JS_CallFunctionValue(cx: &mut JSContext, obj: Handle<*mut JSObject>, fval: Handle, args: *const HandleValueArray, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_CallFunction(cx: &mut JSContext, obj: Handle<*mut JSObject>, fun: Handle<*mut JSFunction>, args: *const HandleValueArray, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_CallFunctionName(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, args: *const HandleValueArray, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_EncodeStringToLatin1(cx: &mut JSContext, str_: *mut JSString) -> UniqueChars); +wrap!(jsapi: pub fn JS_EncodeStringToUTF8(cx: &mut JSContext, str_: Handle<*mut JSString>) -> UniqueChars); +wrap!(jsapi: pub fn JS_EncodeStringToASCII(cx: &mut JSContext, str_: *mut JSString) -> UniqueChars); +wrap!(jsapi: pub fn JS_DestroyContext(cx: &mut JSContext)); +wrap!(jsapi: pub fn JS_GetContextPrivate(cx: &mut JSContext) -> *mut ::std::os::raw::c_void); +wrap!(jsapi: pub fn JS_SetContextPrivate(cx: &mut JSContext, data: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn JS_GetParentRuntime(cx: &JSContext) -> *mut JSRuntime); +wrap!(jsapi: pub fn JS_GetRuntime(cx: &JSContext) -> *mut JSRuntime); +wrap!(jsapi: pub fn JS_SetFutexCanWait(cx: &mut JSContext)); +wrap!(jsapi: pub fn JS_AddExtraGCRootsTracer(cx: &mut JSContext, traceOp: JSTraceDataOp, data: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn JS_RemoveExtraGCRootsTracer(cx: &mut JSContext, traceOp: JSTraceDataOp, data: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn JS_GC(cx: &mut JSContext, reason: GCReason)); +wrap!(jsapi: pub fn JS_MaybeGC(cx: &mut JSContext)); +wrap!(jsapi: pub fn JS_SetGCCallback(cx: &mut JSContext, cb: JSGCCallback, data: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn JS_SetObjectsTenuredCallback(cx: &mut JSContext, cb: JSObjectsTenuredCallback, data: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn JS_AddFinalizeCallback(cx: &mut JSContext, cb: JSFinalizeCallback, data: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn JS_RemoveFinalizeCallback(cx: &mut JSContext, cb: JSFinalizeCallback)); +wrap!(jsapi: pub fn JS_AddWeakPointerZonesCallback(cx: &mut JSContext, cb: JSWeakPointerZonesCallback, data: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn JS_RemoveWeakPointerZonesCallback(cx: &mut JSContext, cb: JSWeakPointerZonesCallback)); +wrap!(jsapi: pub fn JS_AddWeakPointerCompartmentCallback(cx: &mut JSContext, cb: JSWeakPointerCompartmentCallback, data: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn JS_RemoveWeakPointerCompartmentCallback(cx: &mut JSContext, cb: JSWeakPointerCompartmentCallback)); +wrap!(jsapi: pub fn JS_SetGCParameter(cx: &mut JSContext, key: JSGCParamKey, value: u32)); +wrap!(jsapi: pub fn JS_ResetGCParameter(cx: &mut JSContext, key: JSGCParamKey)); +wrap!(jsapi: pub fn JS_GetGCParameter(cx: &JSContext, key: JSGCParamKey) -> u32); +wrap!(jsapi: pub fn JS_SetGCParametersBasedOnAvailableMemory(cx: &mut JSContext, availMemMB: u32)); +wrap!(jsapi: pub fn JS_NewExternalStringLatin1(cx: &mut JSContext, chars: *const Latin1Char, length: usize, callbacks: *const JSExternalStringCallbacks) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewExternalUCString(cx: &mut JSContext, chars: *const u16, length: usize, callbacks: *const JSExternalStringCallbacks) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewMaybeExternalStringLatin1(cx: &mut JSContext, chars: *const Latin1Char, length: usize, callbacks: *const JSExternalStringCallbacks, allocatedExternal: *mut bool) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewMaybeExternalUCString(cx: &mut JSContext, chars: *const u16, length: usize, callbacks: *const JSExternalStringCallbacks, allocatedExternal: *mut bool) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewMaybeExternalStringUTF8(cx: &mut JSContext, utf8: *const UTF8Chars, callbacks: *const JSExternalStringCallbacks, allocatedExternal: *mut bool) -> *mut JSString); +wrap!(jsapi: pub fn JS_DefineDebuggerObject(cx: &mut JSContext, obj: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_TracerEnterLabelLatin1(cx: &mut JSContext, label: *const ::std::os::raw::c_char)); +wrap!(jsapi: pub fn JS_TracerEnterLabelTwoByte(cx: &mut JSContext, label: *const u16)); +wrap!(jsapi: pub fn JS_TracerIsTracing(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn JS_TracerLeaveLabelLatin1(cx: &mut JSContext, label: *const ::std::os::raw::c_char)); +wrap!(jsapi: pub fn JS_TracerLeaveLabelTwoByte(cx: &mut JSContext, label: *const u16)); +wrap!(jsapi: pub fn JS_ReportErrorNumberUTF8Array(cx: &mut JSContext, errorCallback: JSErrorCallback, userRef: *mut ::std::os::raw::c_void, errorNumber: ::std::os::raw::c_uint, args: *mut *const ::std::os::raw::c_char)); +wrap!(jsapi: pub fn JS_ReportErrorNumberUCArray(cx: &mut JSContext, errorCallback: JSErrorCallback, userRef: *mut ::std::os::raw::c_void, errorNumber: ::std::os::raw::c_uint, args: *mut *const u16)); +wrap!(jsapi: pub fn JS_ReportAllocationOverflow(cx: &mut JSContext)); +wrap!(jsapi: pub fn JS_IsExceptionPending(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn JS_IsThrowingOutOfMemory(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn JS_GetPendingException(cx: &mut JSContext, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_SetPendingException(cx: &mut JSContext, v: HandleValue, behavior: ExceptionStackBehavior)); +wrap!(jsapi: pub fn JS_ClearPendingException(cx: &mut JSContext)); +wrap!(jsapi: pub fn JS_ErrorFromException(cx: &mut JSContext, obj: HandleObject) -> *mut JSErrorReport); +wrap!(jsapi: pub fn JS_NewGlobalObject(cx: &mut JSContext, clasp: *const JSClass, principals: *mut JSPrincipals, hookOption: OnNewGlobalHookOption, options: *const RealmOptions) -> *mut JSObject); +wrap!(jsapi: pub fn JS_FireOnNewGlobalObject(cx: &mut JSContext, global: HandleObject)); +wrap!(jsapi: pub fn JS_CheckForInterrupt(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn JS_AddInterruptCallback(cx: &mut JSContext, callback: JSInterruptCallback) -> bool); +wrap!(jsapi: pub fn JS_DisableInterruptCallback(cx: &mut JSContext) -> bool); +wrap!(jsapi: pub fn JS_ResetInterruptCallback(cx: &mut JSContext, enable: bool)); +wrap!(jsapi: pub fn JS_RequestInterruptCallback(cx: &mut JSContext)); +wrap!(jsapi: pub fn JS_RequestInterruptCallbackCanWait(cx: &mut JSContext)); +wrap!(jsapi: pub fn JS_malloc(cx: &mut JSContext, nbytes: usize) -> *mut ::std::os::raw::c_void); +wrap!(jsapi: pub fn JS_realloc(cx: &mut JSContext, p: *mut ::std::os::raw::c_void, oldBytes: usize, newBytes: usize) -> *mut ::std::os::raw::c_void); +wrap!(jsapi: pub fn JS_free(cx: &mut JSContext, p: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn JS_string_malloc(cx: &mut JSContext, nbytes: usize) -> *mut ::std::os::raw::c_void); +wrap!(jsapi: pub fn JS_string_realloc(cx: &mut JSContext, p: *mut ::std::os::raw::c_void, oldBytes: usize, newBytes: usize) -> *mut ::std::os::raw::c_void); +wrap!(jsapi: pub fn JS_string_free(cx: &mut JSContext, p: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn JS_DropPrincipals(cx: &mut JSContext, principals: *mut JSPrincipals)); +wrap!(jsapi: pub fn JS_SetSecurityCallbacks(cx: &mut JSContext, callbacks: *const JSSecurityCallbacks)); +wrap!(jsapi: pub fn JS_GetSecurityCallbacks(cx: &mut JSContext) -> *const JSSecurityCallbacks); +wrap!(jsapi: pub fn JS_SetTrustedPrincipals(cx: &mut JSContext, prin: *mut JSPrincipals)); +wrap!(jsapi: pub fn JS_InitDestroyPrincipalsCallback(cx: &mut JSContext, destroyPrincipals: JSDestroyPrincipalsOp)); +wrap!(jsapi: pub fn JS_InitReadPrincipalsCallback(cx: &mut JSContext, read: JSReadPrincipalsOp)); +wrap!(jsapi: pub fn JS_DefinePropertyById(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, desc: Handle, result: *mut ObjectOpResult) -> bool); +wrap!(jsapi: pub fn JS_DefinePropertyById1(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, desc: Handle) -> bool); +wrap!(jsapi: pub fn JS_DefinePropertyById2(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, value: Handle, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefinePropertyById3(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, getter: JSNative, setter: JSNative, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefinePropertyById4(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, getter: Handle<*mut JSObject>, setter: Handle<*mut JSObject>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefinePropertyById5(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, value: Handle<*mut JSObject>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefinePropertyById6(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, value: Handle<*mut JSString>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefinePropertyById7(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, value: i32, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefinePropertyById8(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, value: u32, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefinePropertyById9(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, value: f64, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, value: Handle, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineProperty1(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, getter: JSNative, setter: JSNative, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineProperty2(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, getter: Handle<*mut JSObject>, setter: Handle<*mut JSObject>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineProperty3(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, value: Handle<*mut JSObject>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineProperty4(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, value: Handle<*mut JSString>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineProperty5(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, value: i32, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineProperty6(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, value: u32, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineProperty7(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, value: f64, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineUCProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, desc: Handle, result: *mut ObjectOpResult) -> bool); +wrap!(jsapi: pub fn JS_DefineUCProperty1(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, desc: Handle) -> bool); +wrap!(jsapi: pub fn JS_DefineUCProperty2(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, value: Handle, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineUCProperty3(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, getter: Handle<*mut JSObject>, setter: Handle<*mut JSObject>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineUCProperty4(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, value: Handle<*mut JSObject>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineUCProperty5(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, value: Handle<*mut JSString>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineUCProperty6(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, value: i32, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineUCProperty7(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, value: u32, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineUCProperty8(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, value: f64, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineElement(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, value: Handle, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineElement1(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, getter: Handle<*mut JSObject>, setter: Handle<*mut JSObject>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineElement2(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, value: Handle<*mut JSObject>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineElement3(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, value: Handle<*mut JSString>, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineElement4(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, value: i32, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineElement5(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, value: u32, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_DefineElement6(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, value: f64, attrs: ::std::os::raw::c_uint) -> bool); +wrap!(jsapi: pub fn JS_HasPropertyById(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, foundp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_HasProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, foundp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_HasUCProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, vp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_HasElement(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, foundp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_HasOwnPropertyById(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, foundp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_HasOwnProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, foundp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_ForwardGetPropertyTo(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, receiver: Handle, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_ForwardGetElementTo(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, receiver: Handle<*mut JSObject>, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_GetPropertyById(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_GetProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_GetUCProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_GetElement(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_ForwardSetPropertyTo(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, v: Handle, receiver: Handle, result: *mut ObjectOpResult) -> bool); +wrap!(jsapi: pub fn JS_SetPropertyById(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, v: Handle) -> bool); +wrap!(jsapi: pub fn JS_SetProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, v: Handle) -> bool); +wrap!(jsapi: pub fn JS_SetUCProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, v: Handle) -> bool); +wrap!(jsapi: pub fn JS_SetElement(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, v: Handle) -> bool); +wrap!(jsapi: pub fn JS_SetElement1(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, v: Handle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn JS_SetElement2(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, v: Handle<*mut JSString>) -> bool); +wrap!(jsapi: pub fn JS_SetElement3(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, v: i32) -> bool); +wrap!(jsapi: pub fn JS_SetElement4(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, v: u32) -> bool); +wrap!(jsapi: pub fn JS_SetElement5(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, v: f64) -> bool); +wrap!(jsapi: pub fn JS_DeletePropertyById(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, result: *mut ObjectOpResult) -> bool); +wrap!(jsapi: pub fn JS_DeleteProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, result: *mut ObjectOpResult) -> bool); +wrap!(jsapi: pub fn JS_DeleteUCProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, result: *mut ObjectOpResult) -> bool); +wrap!(jsapi: pub fn JS_DeleteElement(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, result: *mut ObjectOpResult) -> bool); +wrap!(jsapi: pub fn JS_DeletePropertyById1(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle) -> bool); +wrap!(jsapi: pub fn JS_DeleteProperty1(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char) -> bool); +wrap!(jsapi: pub fn JS_DeleteElement1(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32) -> bool); +wrap!(jsapi: pub fn JS_DefineObject(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, clasp: *const JSClass, attrs: ::std::os::raw::c_uint) -> *mut JSObject); +wrap!(jsapi: pub fn JS_DefineProperties(cx: &mut JSContext, obj: Handle<*mut JSObject>, ps: *const JSPropertySpec) -> bool); +wrap!(jsapi: pub fn JS_AlreadyHasOwnPropertyById(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, foundp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_AlreadyHasOwnProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, foundp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_AlreadyHasOwnUCProperty(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, foundp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_AlreadyHasOwnElement(cx: &mut JSContext, obj: Handle<*mut JSObject>, index: u32, foundp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_DefineFunctions(cx: &mut JSContext, obj: Handle<*mut JSObject>, fs: *const JSFunctionSpec) -> bool); +wrap!(jsapi: pub fn JS_DefineFunction(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, call: JSNative, nargs: ::std::os::raw::c_uint, attrs: ::std::os::raw::c_uint) -> *mut JSFunction); +wrap!(jsapi: pub fn JS_DefineUCFunction(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const u16, namelen: usize, call: JSNative, nargs: ::std::os::raw::c_uint, attrs: ::std::os::raw::c_uint) -> *mut JSFunction); +wrap!(jsapi: pub fn JS_DefineFunctionById(cx: &mut JSContext, obj: Handle<*mut JSObject>, id: Handle, call: JSNative, nargs: ::std::os::raw::c_uint, attrs: ::std::os::raw::c_uint) -> *mut JSFunction); +wrap!(jsapi: pub fn JS_IterateCompartments(cx: &mut JSContext, data: *mut ::std::os::raw::c_void, compartmentCallback: JSIterateCompartmentCallback)); +wrap!(jsapi: pub fn JS_IterateCompartmentsInZone(cx: &mut JSContext, zone: *mut Zone, data: *mut ::std::os::raw::c_void, compartmentCallback: JSIterateCompartmentCallback)); +wrap!(jsapi: pub fn JS_SetNativeStackQuota(cx: &mut JSContext, systemCodeStackSize: NativeStackSize, trustedScriptStackSize: NativeStackSize, untrustedScriptStackSize: NativeStackSize)); +wrap!(jsapi: pub fn JS_GetEmptyString(cx: &mut JSContext) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewStringCopyN(cx: &mut JSContext, s: *const ::std::os::raw::c_char, n: usize) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewStringCopyZ(cx: &mut JSContext, s: *const ::std::os::raw::c_char) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewStringCopyUTF8Z(cx: &mut JSContext, s: ConstUTF8CharsZ) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewStringCopyUTF8N(cx: &mut JSContext, s: *const UTF8Chars) -> *mut JSString); +wrap!(jsapi: pub fn JS_AtomizeStringN(cx: &mut JSContext, s: *const ::std::os::raw::c_char, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn JS_AtomizeString(cx: &mut JSContext, s: *const ::std::os::raw::c_char) -> *mut JSString); +wrap!(jsapi: pub fn JS_AtomizeAndPinStringN(cx: &mut JSContext, s: *const ::std::os::raw::c_char, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn JS_AtomizeAndPinString(cx: &mut JSContext, s: *const ::std::os::raw::c_char) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewUCStringCopyN(cx: &mut JSContext, s: *const u16, n: usize) -> *mut JSString); +wrap!(jsapi: pub fn JS_NewUCStringCopyZ(cx: &mut JSContext, s: *const u16) -> *mut JSString); +wrap!(jsapi: pub fn JS_AtomizeUCStringN(cx: &mut JSContext, s: *const u16, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn JS_AtomizeUCString(cx: &mut JSContext, s: *const u16) -> *mut JSString); +wrap!(jsapi: pub fn JS_CompareStrings(cx: &mut JSContext, str1: *mut JSString, str2: *mut JSString, result: *mut i32) -> bool); +wrap!(jsapi: pub fn JS_StringEqualsAscii(cx: &mut JSContext, str_: *mut JSString, asciiBytes: *const ::std::os::raw::c_char, match_: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_StringEqualsAscii1(cx: &mut JSContext, str_: *mut JSString, asciiBytes: *const ::std::os::raw::c_char, length: usize, match_: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_PutEscapedString(cx: &mut JSContext, buffer: *mut ::std::os::raw::c_char, size: usize, str_: *mut JSString, quote: ::std::os::raw::c_char) -> usize); +wrap!(jsapi: pub fn JS_GetLatin1StringCharsAndLength(cx: &JSContext, nogc: *const AutoRequireNoGC, str_: *mut JSString, length: *mut usize) -> *const Latin1Char); +wrap!(jsapi: pub fn JS_GetTwoByteStringCharsAndLength(cx: &JSContext, nogc: *const AutoRequireNoGC, str_: *mut JSString, length: *mut usize) -> *const u16); +wrap!(jsapi: pub fn JS_GetStringCharAt(cx: &mut JSContext, str_: *mut JSString, index: usize, res: *mut u16) -> bool); +wrap!(jsapi: pub fn JS_CopyStringChars(cx: &mut JSContext, dest: *const Range, str_: *mut JSString) -> bool); +wrap!(jsapi: pub fn JS_CopyStringCharsZ(cx: &mut JSContext, str_: *mut JSString) -> UniqueTwoByteChars); +wrap!(jsapi: pub fn JS_EnsureLinearString(cx: &mut JSContext, str_: *mut JSString) -> *mut JSLinearString); +wrap!(jsapi: pub fn JS_NewDependentString(cx: &mut JSContext, str_: Handle<*mut JSString>, start: usize, length: usize) -> *mut JSString); +wrap!(jsapi: pub fn JS_ConcatStrings(cx: &mut JSContext, left: Handle<*mut JSString>, right: Handle<*mut JSString>) -> *mut JSString); +wrap!(jsapi: pub fn JS_DecodeBytes(cx: &mut JSContext, src: *const ::std::os::raw::c_char, srclen: usize, dst: *mut u16, dstlenp: *mut usize) -> bool); +wrap!(jsapi: pub fn JS_GetStringEncodingLength(cx: &mut JSContext, str_: *mut JSString) -> usize); +wrap!(jsapi: pub fn JS_EncodeStringToBuffer(cx: &mut JSContext, str_: *mut JSString, buffer: *mut ::std::os::raw::c_char, length: usize) -> bool); +wrap!(jsapi: pub fn JS_SetDestroyZoneCallback(cx: &mut JSContext, callback: JSDestroyZoneCallback)); +wrap!(jsapi: pub fn JS_SetDestroyCompartmentCallback(cx: &mut JSContext, callback: JSDestroyCompartmentCallback)); +wrap!(jsapi: pub fn JS_SetSizeOfIncludingThisCompartmentCallback(cx: &mut JSContext, callback: JSSizeOfIncludingThisCompartmentCallback)); +wrap!(jsapi: pub fn JS_RefreshCrossCompartmentWrappers(cx: &mut JSContext, obj: Handle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn JS_MarkCrossZoneId(cx: &mut JSContext, id: jsid)); +wrap!(jsapi: pub fn JS_MarkCrossZoneIdValue(cx: &mut JSContext, value: *const Value)); +wrap!(jsapi: pub fn JS_StringHasBeenPinned(cx: &mut JSContext, str_: *mut JSString) -> bool); +wrap!(jsapi: pub fn JS_ValueToObject(cx: &mut JSContext, v: HandleValue, objp: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn JS_ValueToFunction(cx: &mut JSContext, v: HandleValue) -> *mut JSFunction); +wrap!(jsapi: pub fn JS_ValueToConstructor(cx: &mut JSContext, v: HandleValue) -> *mut JSFunction); +wrap!(jsapi: pub fn JS_ValueToSource(cx: &mut JSContext, v: Handle) -> *mut JSString); +wrap!(jsapi: pub fn JS_TypeOfValue(cx: &mut JSContext, v: Handle) -> JSType); +wrap!(jsapi: pub fn JS_SetWrapObjectCallbacks(cx: &mut JSContext, callbacks: *const JSWrapObjectCallbacks)); +wrap!(jsapi: pub fn JS_WrapObject(cx: &mut JSContext, objp: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn JS_WrapValue(cx: &mut JSContext, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_TransplantObject(cx: &mut JSContext, origobj: HandleObject, target: HandleObject) -> *mut JSObject); +wrap!(jsapi: pub fn JS_ResolveStandardClass(cx: &mut JSContext, obj: HandleObject, id: HandleId, resolved: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_EnumerateStandardClasses(cx: &mut JSContext, obj: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_NewEnumerateStandardClasses(cx: &mut JSContext, obj: HandleObject, properties: MutableHandleIdVector, enumerableOnly: bool) -> bool); +wrap!(jsapi: pub fn JS_NewEnumerateStandardClassesIncludingResolved(cx: &mut JSContext, obj: HandleObject, properties: MutableHandleIdVector, enumerableOnly: bool) -> bool); +wrap!(jsapi: pub fn JS_GetClassObject(cx: &mut JSContext, key: JSProtoKey, objp: MutableHandle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn JS_GetClassPrototype(cx: &mut JSContext, key: JSProtoKey, objp: MutableHandle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn JS_IdToProtoKey(cx: &mut JSContext, id: HandleId) -> JSProtoKey); +wrap!(jsapi: pub fn JS_InitReflectParse(cx: &mut JSContext, global: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_DefineProfilingFunctions(cx: &mut JSContext, obj: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_ValueToId(cx: &mut JSContext, v: HandleValue, idp: MutableHandleId) -> bool); +wrap!(jsapi: pub fn JS_StringToId(cx: &mut JSContext, s: HandleString, idp: MutableHandleId) -> bool); +wrap!(jsapi: pub fn JS_IdToValue(cx: &mut JSContext, id: jsid, vp: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_InitClass(cx: &mut JSContext, obj: HandleObject, protoClass: *const JSClass, protoProto: HandleObject, name: *const ::std::os::raw::c_char, constructor: JSNative, nargs: ::std::os::raw::c_uint, ps: *const JSPropertySpec, fs: *const JSFunctionSpec, static_ps: *const JSPropertySpec, static_fs: *const JSFunctionSpec) -> *mut JSObject); +wrap!(jsapi: pub fn JS_LinkConstructorAndPrototype(cx: &mut JSContext, ctor: Handle<*mut JSObject>, proto: Handle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn JS_InstanceOf(cx: &mut JSContext, obj: Handle<*mut JSObject>, clasp: *const JSClass, args: *mut CallArgs) -> bool); +wrap!(jsapi: pub fn JS_HasInstance(cx: &mut JSContext, obj: Handle<*mut JSObject>, v: Handle, bp: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_GetConstructor(cx: &mut JSContext, proto: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewObject(cx: &mut JSContext, clasp: *const JSClass) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewObjectWithGivenProto(cx: &mut JSContext, clasp: *const JSClass, proto: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewPlainObject(cx: &mut JSContext) -> *mut JSObject); +wrap!(jsapi: pub fn JS_DeepFreezeObject(cx: &mut JSContext, obj: Handle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn JS_FreezeObject(cx: &mut JSContext, obj: Handle<*mut JSObject>) -> bool); +wrap!(jsapi: pub fn JS_GetPrototype(cx: &mut JSContext, obj: HandleObject, result: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn JS_GetPrototypeIfOrdinary(cx: &mut JSContext, obj: HandleObject, isOrdinary: *mut bool, result: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn JS_SetPrototype(cx: &mut JSContext, obj: HandleObject, proto: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_IsExtensible(cx: &mut JSContext, obj: HandleObject, extensible: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_PreventExtensions(cx: &mut JSContext, obj: HandleObject, result: *mut ObjectOpResult) -> bool); +wrap!(jsapi: pub fn JS_SetImmutablePrototype(cx: &mut JSContext, obj: HandleObject, succeeded: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_AssignObject(cx: &mut JSContext, target: HandleObject, src: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_SetAllNonReservedSlotsToUndefined(obj: HandleObject)); +wrap!(jsapi: pub fn JS_NewFunction(cx: &mut JSContext, call: JSNative, nargs: ::std::os::raw::c_uint, flags: ::std::os::raw::c_uint, name: *const ::std::os::raw::c_char) -> *mut JSFunction); +wrap!(jsapi: pub fn JS_GetFunctionId(cx: &mut JSContext, fun: Handle<*mut JSFunction>, name: MutableHandle<*mut JSString>) -> bool); +wrap!(jsapi: pub fn JS_GetFunctionDisplayId(cx: &mut JSContext, fun: Handle<*mut JSFunction>, name: MutableHandle<*mut JSString>) -> bool); +wrap!(jsapi: pub fn JS_GetFunctionLength(cx: &mut JSContext, fun: HandleFunction, length: *mut u16) -> bool); +wrap!(jsapi: pub fn JS_GetScriptBaseLineNumber(cx: &mut JSContext, script: *mut JSScript) -> ::std::os::raw::c_uint); +wrap!(jsapi: pub fn JS_GetFunctionScript(cx: &mut JSContext, fun: HandleFunction) -> *mut JSScript); +wrap!(jsapi: pub fn JS_DecompileScript(cx: &mut JSContext, script: Handle<*mut JSScript>) -> *mut JSString); +wrap!(jsapi: pub fn JS_DecompileFunction(cx: &mut JSContext, fun: Handle<*mut JSFunction>) -> *mut JSString); +wrap!(jsapi: pub fn JS_AbortIfWrongThread(cx: &mut JSContext)); +wrap!(jsapi: pub fn JS_NewObjectForConstructor(cx: &mut JSContext, clasp: *const JSClass, args: *const CallArgs) -> *mut JSObject); +wrap!(jsapi: pub fn JS_SetOffthreadBaselineCompilationEnabled(cx: &mut JSContext, enabled: bool)); +wrap!(jsapi: pub fn JS_SetOffthreadIonCompilationEnabled(cx: &mut JSContext, enabled: bool)); +wrap!(jsapi: pub fn JS_SetGlobalJitCompilerOption(cx: &mut JSContext, opt: JSJitCompilerOption, value: u32)); +wrap!(jsapi: pub fn JS_GetGlobalJitCompilerOption(cx: &mut JSContext, opt: JSJitCompilerOption, valueOut: *mut u32) -> bool); +wrap!(jsapi: pub fn JS_IndexToId(cx: &mut JSContext, index: u32, arg1: MutableHandleId) -> bool); +wrap!(jsapi: pub fn JS_CharsToId(cx: &mut JSContext, chars: TwoByteChars, arg1: MutableHandleId) -> bool); +wrap!(jsapi: pub fn JS_IsIdentifier(cx: &mut JSContext, str_: HandleString, isIdentifier: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_Utf8BufferIsCompilableUnit(cx: &mut JSContext, obj: Handle<*mut JSObject>, utf8: *const ::std::os::raw::c_char, length: usize) -> bool); +wrap!(jsapi: pub fn JS_ExecuteScript(cx: &mut JSContext, script: Handle<*mut JSScript>, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_ExecuteScript1(cx: &mut JSContext, script: Handle<*mut JSScript>) -> bool); +wrap!(jsapi: pub fn JS_ExecuteScript2(cx: &mut JSContext, envChain: *const EnvironmentChain, script: Handle<*mut JSScript>, rval: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_ExecuteScript3(cx: &mut JSContext, envChain: *const EnvironmentChain, script: Handle<*mut JSScript>) -> bool); +wrap!(jsapi: pub fn JS_Stringify(cx: &mut JSContext, value: MutableHandle, replacer: Handle<*mut JSObject>, space: Handle, callback: JSONWriteCallback, data: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn JS_StringifyWithLengthHint(cx: &mut JSContext, value: MutableHandle, replacer: Handle<*mut JSObject>, space: Handle, callback: JSONWriteCallback, data: *mut ::std::os::raw::c_void, lengthHint: usize) -> bool); +wrap!(jsapi: pub fn JS_ParseJSON(cx: &mut JSContext, chars: *const u16, len: u32, vp: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_ParseJSON1(cx: &mut JSContext, str_: Handle<*mut JSString>, vp: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_ParseJSON2(cx: &mut JSContext, chars: *const Latin1Char, len: u32, vp: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_ParseJSONWithReviver(cx: &mut JSContext, chars: *const u16, len: u32, reviver: Handle, vp: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_ParseJSONWithReviver1(cx: &mut JSContext, str_: Handle<*mut JSString>, reviver: Handle, vp: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_ReadStructuredClone(cx: &mut JSContext, data: *const JSStructuredCloneData, version: u32, scope: StructuredCloneScope, vp: MutableHandleValue, cloneDataPolicy: *const CloneDataPolicy, optionalCallbacks: *const JSStructuredCloneCallbacks, closure: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn JS_WriteStructuredClone(cx: &mut JSContext, v: HandleValue, data: *mut JSStructuredCloneData, scope: StructuredCloneScope, cloneDataPolicy: *const CloneDataPolicy, optionalCallbacks: *const JSStructuredCloneCallbacks, closure: *mut ::std::os::raw::c_void, transferable: HandleValue) -> bool); +wrap!(jsapi: pub fn JS_StructuredClone(cx: &mut JSContext, v: HandleValue, vp: MutableHandleValue, optionalCallbacks: *const JSStructuredCloneCallbacks, closure: *mut ::std::os::raw::c_void) -> bool); +wrap!(jsapi: pub fn JS_ReadString(r: *mut JSStructuredCloneReader, str_: MutableHandleString) -> bool); +wrap!(jsapi: pub fn JS_ReadTypedArray(r: *mut JSStructuredCloneReader, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_WriteString(w: *mut JSStructuredCloneWriter, str_: HandleString) -> bool); +wrap!(jsapi: pub fn JS_WriteTypedArray(w: *mut JSStructuredCloneWriter, v: HandleValue) -> bool); +wrap!(jsapi: pub fn JS_ObjectNotWritten(w: *mut JSStructuredCloneWriter, obj: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_NewInt8Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewInt8ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewInt8ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint8Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint8ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint8ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewInt16Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewInt16ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewInt16ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint16Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint16ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint16ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewInt32Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewInt32ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewInt32ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint32Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint32ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint32ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewFloat32Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewFloat32ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewFloat32ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewFloat64Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewFloat64ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewFloat64ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint8ClampedArray(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint8ClampedArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewUint8ClampedArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewBigInt64Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewBigInt64ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewBigInt64ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewBigUint64Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewBigUint64ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewBigUint64ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewFloat16Array(cx: &mut JSContext, nelements: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewFloat16ArrayFromArray(cx: &mut JSContext, array: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewFloat16ArrayWithBuffer(cx: &mut JSContext, arrayBuffer: Handle<*mut JSObject>, byteOffset: usize, length: i64) -> *mut JSObject); +wrap!(jsapi: pub fn JS_GetArrayBufferViewBuffer(cx: &mut JSContext, obj: Handle<*mut JSObject>, isSharedMemory: *mut bool) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewDataView(cx: &mut JSContext, buffer: Handle<*mut JSObject>, byteOffset: usize, byteLength: usize) -> *mut JSObject); +wrap!(jsapi: pub fn JS_SetGrayGCRootsTracer(cx: &mut JSContext, traceOp: JSGrayRootsTracer, data: *mut ::std::os::raw::c_void)); +wrap!(jsapi: pub fn JS_FindCompilationScope(cx: &mut JSContext, obj: HandleObject) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NewObjectWithoutMetadata(cx: &mut JSContext, clasp: *const JSClass, proto: Handle<*mut JSObject>) -> *mut JSObject); +wrap!(jsapi: pub fn JS_NondeterministicGetWeakMapKeys(cx: &mut JSContext, obj: HandleObject, ret: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn JS_NondeterministicGetWeakSetKeys(cx: &mut JSContext, obj: HandleObject, ret: MutableHandleObject) -> bool); +wrap!(jsapi: pub fn JS_NewDeadWrapper(cx: &mut JSContext, origObject: *mut JSObject) -> *mut JSObject); +wrap!(jsapi: pub fn JS_CloneObject(cx: &mut JSContext, obj: HandleObject, proto: HandleObject) -> *mut JSObject); +wrap!(jsapi: pub fn JS_InitializePropertiesFromCompatibleNativeObject(cx: &mut JSContext, dst: HandleObject, src: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_CopyOwnPropertiesAndPrivateFields(cx: &mut JSContext, target: HandleObject, obj: HandleObject) -> bool); +wrap!(jsapi: pub fn JS_WrapPropertyDescriptor(cx: &mut JSContext, desc: MutableHandle) -> bool); +wrap!(jsapi: pub fn JS_DefineFunctionsWithHelp(cx: &mut JSContext, obj: HandleObject, fs: *const JSFunctionSpecWithHelp) -> bool); +wrap!(jsapi: pub fn JS_NewOwningCompileOptions(cx: &mut JSContext) -> *mut OwningCompileOptions); +wrap!(jsapi: pub fn JS_StackCapture_FirstSubsumedFrame(cx: &mut JSContext, ignoreSelfHostedFrames: bool, capture: *mut StackCapture)); +wrap!(jsapi: pub fn NewExternalArrayBuffer(cx: &mut JSContext, nbytes: usize, contents: *mut ::std::os::raw::c_void, freeFunc: BufferContentsFreeFunc, freeUserData: *mut ::std::os::raw::c_void) -> *mut JSObject); +wrap!(jsapi: pub fn NewArrayBufferWithContents(cx: &mut JSContext, nbytes: usize, contents: *mut ::std::os::raw::c_void) -> *mut JSObject); +wrap!(jsapi: pub fn JS_ForOfIteratorInit(iterator: *mut ForOfIterator, iterable: HandleValue, nonIterableBehavior: ForOfIterator_NonIterableBehavior) -> bool); +wrap!(jsapi: pub fn JS_ForOfIteratorNext(iterator: *mut ForOfIterator, val: MutableHandleValue, done: *mut bool) -> bool); +wrap!(jsapi: pub fn FromPropertyDescriptor(cx: &mut JSContext, desc_: Handle, vp: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn JS_GetPropertyDescriptor(cx: &mut JSContext, obj: Handle<*mut JSObject>, name: *const ::std::os::raw::c_char, desc: MutableHandle, holder: MutableHandle<*mut JSObject>, isNone: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_GetOwnPropertyDescriptorById(cx: &mut JSContext, obj: HandleObject, id: HandleId, desc: MutableHandle, isNone: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_GetOwnPropertyDescriptor(cx: &mut JSContext, obj: HandleObject, name: *const ::std::os::raw::c_char, desc: MutableHandle, isNone: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_GetOwnUCPropertyDescriptor(cx: &mut JSContext, obj: HandleObject, name: *const u16, namelen: usize, desc: MutableHandle, isNone: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_GetPropertyDescriptorById(cx: &mut JSContext, obj: HandleObject, id: HandleId, desc: MutableHandle, holder: MutableHandleObject, isNone: *mut bool) -> bool); +wrap!(jsapi: pub fn JS_GetUCPropertyDescriptor(cx: &mut JSContext, obj: HandleObject, name: *const u16, namelen: usize, desc: MutableHandle, holder: MutableHandleObject, isNone: *mut bool) -> bool); +wrap!(jsapi: pub fn SetPropertyIgnoringNamedGetter(cx: &mut JSContext, obj: HandleObject, id: HandleId, v: HandleValue, receiver: HandleValue, ownDesc: *const Handle, result: *mut ObjectOpResult) -> bool); +wrap!(jsapi: pub fn CreateError(cx: &mut JSContext, type_: JSExnType, stack: HandleObject, fileName: HandleString, lineNumber: u32, columnNumber: u32, report: *mut JSErrorReport, message: HandleString, cause: HandleValue, rval: MutableHandleValue) -> bool); +wrap!(jsapi: pub fn GetExceptionCause(exc: *mut JSObject, dest: MutableHandleValue)); +wrap!(jsapi: pub fn NewEnvironmentChain(cx: &mut JSContext, supportUnscopables: SupportUnscopables) -> *mut EnvironmentChain); diff --git a/mozjs/src/lib.rs b/mozjs/src/lib.rs index d2754d7d3a..89d8b2b699 100644 --- a/mozjs/src/lib.rs +++ b/mozjs/src/lib.rs @@ -48,6 +48,7 @@ pub mod jsapi { pub mod rust; mod consts; +pub mod context; pub mod conversions; pub mod error; pub mod gc; diff --git a/mozjs/src/rust.rs b/mozjs/src/rust.rs index 98aeb39a51..e63a84b223 100644 --- a/mozjs/src/rust.rs +++ b/mozjs/src/rust.rs @@ -154,7 +154,7 @@ impl Drop for RealmOptions { } } -thread_local!(static CONTEXT: Cell<*mut JSContext> = Cell::new(ptr::null_mut())); +thread_local!(static CONTEXT: Cell>> = Cell::new(None)); #[derive(PartialEq)] enum EngineState { @@ -283,8 +283,8 @@ unsafe impl Send for ParentRuntime {} /// A wrapper for the `JSContext` structure in SpiderMonkey. pub struct Runtime { - /// Raw pointer to the underlying SpiderMonkey context. - cx: *mut JSContext, + /// Safe SpiderMonkey context. + cx: crate::context::JSContext, /// The engine that this runtime is associated with. engine: JSEngineHandle, /// If this Runtime was created with a parent, this member exists to ensure @@ -301,18 +301,21 @@ pub struct Runtime { /// An `Option` that holds the same pointer as `cx`. /// This is shared with all [`ThreadSafeJSContext`]s, so /// they can detect when it's destroyed on the main thread. - thread_safe_handle: Arc>>, + thread_safe_handle: Arc>>>, } impl Runtime { /// Get the `JSContext` for this thread. + /// + /// This will eventually be removed for in favour of [crate::context::JSContext] pub fn get() -> Option> { - let cx = CONTEXT.with(|context| context.get()); - NonNull::new(cx) + CONTEXT.with(|context| context.get()) } /// Create a [`ThreadSafeJSContext`] that can detect when this `Runtime` is destroyed. pub fn thread_safe_js_context(&self) -> ThreadSafeJSContext { + // Existence of `ThreadSafeJSContext` does not actually break invariant of + // JSContext, because it can be used for limited subset of methods and they do not trigger GC ThreadSafeJSContext(self.thread_safe_handle.clone()) } @@ -347,28 +350,31 @@ impl Runtime { unsafe fn create(engine: JSEngineHandle, parent: Option) -> Runtime { let parent_runtime = parent.as_ref().map_or(ptr::null_mut(), |r| r.parent); - let js_context = JS_NewContext(default_heapsize + (ChunkSize as u32), parent_runtime); - assert!(!js_context.is_null()); + let js_context = NonNull::new(JS_NewContext( + default_heapsize + (ChunkSize as u32), + parent_runtime, + )) + .unwrap(); // Unconstrain the runtime's threshold on nominal heap size, to avoid // triggering GC too often if operating continuously near an arbitrary // 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.as_ptr(), JSGCParamKey::JSGC_MAX_BYTES, u32::MAX); - JS_AddExtraGCRootsTracer(js_context, Some(trace_traceables), ptr::null_mut()); + JS_AddExtraGCRootsTracer(js_context.as_ptr(), Some(trace_traceables), ptr::null_mut()); JS_SetNativeStackQuota( - js_context, + js_context.as_ptr(), STACK_QUOTA, STACK_QUOTA - SYSTEM_CODE_BUFFER, STACK_QUOTA - SYSTEM_CODE_BUFFER - TRUSTED_SCRIPT_BUFFER, ); CONTEXT.with(|context| { - assert!(context.get().is_null()); - context.set(js_context); + assert!(context.get().is_none()); + context.set(Some(js_context)); }); #[cfg(target_pointer_width = "64")] @@ -376,14 +382,14 @@ impl Runtime { #[cfg(target_pointer_width = "32")] let cache = crate::jsapi::__BindgenOpaqueArray::::default(); - InitSelfHostedCode(js_context, cache, None); + InitSelfHostedCode(js_context.as_ptr(), cache, None); - SetWarningReporter(js_context, Some(report_warning)); + SetWarningReporter(js_context.as_ptr(), Some(report_warning)); Runtime { engine, _parent_child_count: parent.map(|p| p.children_of_parent), - cx: js_context, + cx: crate::context::JSContext::from_ptr(js_context), outstanding_children: Arc::new(()), thread_safe_handle: Arc::new(RwLock::new(Some(js_context))), } @@ -391,16 +397,22 @@ impl Runtime { /// Returns the `JSRuntime` object. pub fn rt(&self) -> *mut JSRuntime { - unsafe { JS_GetRuntime(self.cx) } + // SAFETY: JS_GetRuntime does not trigger GC + unsafe { JS_GetRuntime(self.cx.raw_cx_no_gc()) } } /// Returns the `JSContext` object. - pub fn cx(&self) -> *mut JSContext { - self.cx + pub fn cx<'rt>(&'rt mut self) -> &'rt mut crate::context::JSContext { + &mut self.cx + } + + /// Returns the `JSContext` object. + pub fn cx_no_gc<'rt>(&'rt self) -> &'rt crate::context::JSContext { + &self.cx } pub fn evaluate_script( - &self, + &mut self, glob: HandleObject, script: &str, rval: MutableHandleValue, @@ -412,11 +424,11 @@ impl Runtime { script ); - let _ac = JSAutoRealm::new(self.cx(), glob.get()); + let _ac = JSAutoRealm::new(unsafe { self.cx().raw_cx() }, glob.get()); unsafe { let mut source = transform_str_to_source_text(&script); - if !Evaluate2(self.cx(), options.ptr, &mut source, rval.into()) { + if !Evaluate2(self.cx().raw_cx(), options.ptr, &mut source, rval.into()) { debug!("...err!"); maybe_resume_unwind(); Err(()) @@ -429,9 +441,9 @@ impl Runtime { } } - pub fn new_compile_options(&self, filename: &str, line: u32) -> CompileOptionsWrapper { + pub fn new_compile_options(&mut self, filename: &str, line: u32) -> CompileOptionsWrapper { // SAFETY: `cx` argument points to a non-null, valid JSContext - unsafe { CompileOptionsWrapper::new(self.cx(), filename, line) } + unsafe { CompileOptionsWrapper::new(self.cx().raw_cx(), filename, line) } } } @@ -443,11 +455,10 @@ impl Drop for Runtime { "This runtime still has live children." ); unsafe { - JS_DestroyContext(self.cx); + JS_DestroyContext(self.cx.raw_cx()); CONTEXT.with(|context| { - assert_eq!(context.get(), self.cx); - context.set(ptr::null_mut()); + assert!(context.take().is_some()); }); } } @@ -457,7 +468,7 @@ impl Drop for Runtime { /// `Send` and `Sync`. This should only ever expose operations that are marked as /// thread-safe by the SpiderMonkey API, ie ones that only atomic fields in JSContext. #[derive(Clone)] -pub struct ThreadSafeJSContext(Arc>>); +pub struct ThreadSafeJSContext(Arc>>>); unsafe impl Send for ThreadSafeJSContext {} unsafe impl Sync for ThreadSafeJSContext {} @@ -467,9 +478,9 @@ impl ThreadSafeJSContext { /// This is thread-safe according to /// pub fn request_interrupt_callback(&self) { - if let Some(&cx) = self.0.read().unwrap().as_ref() { + if let Some(cx) = self.0.read().unwrap().as_ref() { unsafe { - JS_RequestInterruptCallback(cx); + JS_RequestInterruptCallback(cx.as_ptr()); } } } @@ -478,9 +489,9 @@ impl ThreadSafeJSContext { /// This is thread-safe according to /// pub fn request_interrupt_callback_can_wait(&self) { - if let Some(&cx) = self.0.read().unwrap().as_ref() { + if let Some(cx) = self.0.read().unwrap().as_ref() { unsafe { - JS_RequestInterruptCallbackCanWait(cx); + JS_RequestInterruptCallbackCanWait(cx.as_ptr()); } } } @@ -1112,6 +1123,9 @@ impl<'a> CapturedJSStack<'a> { #[macro_export] macro_rules! capture_stack { + (&in($cx:expr) $($t:tt)*) => { + capture_stack!(in(unsafe {$cx.raw_cx_no_gc()}) $($t)*); + }; (in($cx:expr) let $name:ident = with max depth($max_frame_count:expr)) => { rooted!(in($cx) let mut __obj = ::std::ptr::null_mut()); let $name = $crate::rust::CapturedJSStack::new($cx, __obj, Some($max_frame_count)); @@ -1338,3 +1352,170 @@ pub mod wrappers { include!("jsapi_wrappers.in.rs"); include!("glue_wrappers.in.rs"); } + +/// Wrappers for JSAPI/glue methods that accept lifetimed [crate::rust::Handle] and [crate::rust::MutableHandle] arguments and [crate::context::JSContext] +pub mod wrappers2 { + macro_rules! wrap { + // The invocation of @inner has the following form: + // @inner (input args) <> (arg signture accumulator) <> (arg expr accumulator) <> unparsed tokens + // when `unparsed tokens == \eps`, accumulator contains the final result + + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: *const Handle<$gentype:ty>, $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: *const Handle<$gentype>) <> ($($arg_expr_acc,)* if $arg.is_null() { ::std::ptr::null() } else { &(*$arg).into() },) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: Handle<$gentype:ty>, $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: Handle<$gentype>) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: MutableHandle<$gentype:ty>, $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: MutableHandle<$gentype>) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: Handle, $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: Handle) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: MutableHandle, $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: MutableHandle) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: HandleFunction , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: HandleFunction) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: HandleId , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: HandleId) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: HandleObject , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: HandleObject) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: HandleScript , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: HandleScript) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: HandleString , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: HandleString) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: HandleSymbol , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: HandleSymbol) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: HandleValue , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: HandleValue) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: MutableHandleFunction , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: MutableHandleFunction) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: MutableHandleId , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: MutableHandleId) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: MutableHandleObject , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: MutableHandleObject) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: MutableHandleScript , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: MutableHandleScript) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: MutableHandleString , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: MutableHandleString) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: MutableHandleSymbol , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: MutableHandleSymbol) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: MutableHandleValue , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: MutableHandleValue) <> ($($arg_expr_acc,)* $arg.into(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: &mut JSContext , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: &mut JSContext) <> ($($arg_expr_acc,)* $arg.raw_cx(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: &JSContext , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: &JSContext) <> ($($arg_expr_acc,)* $arg.raw_cx_no_gc(),) <> $($rest)*); + }; + // functions that take *const AutoRequireNoGC already have &JSContext, so we can remove this mareker argument + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: *const AutoRequireNoGC , $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)*) <> ($($arg_expr_acc,)* ::std::ptr::null(),) <> $($rest)*); + }; + (@inner $saved:tt <> ($($arg_sig_acc:tt)*) <> ($($arg_expr_acc:expr,)*) <> $arg:ident: $type:ty, $($rest:tt)*) => { + wrap!(@inner $saved <> ($($arg_sig_acc)* , $arg: $type) <> ($($arg_expr_acc,)* $arg,) <> $($rest)*); + }; + (@inner ($module:tt: $func_name:ident -> $outtype:ty) <> (, $($args:tt)*) <> ($($argexprs:expr,)*) <> ) => { + #[inline] + pub unsafe fn $func_name($($args)*) -> $outtype { + $module::$func_name($($argexprs),*) + } + }; + ($module:tt: pub fn $func_name:ident($($args:tt)*) -> $outtype:ty) => { + wrap!(@inner ($module: $func_name -> $outtype) <> () <> () <> $($args)* ,); + }; + ($module:tt: pub fn $func_name:ident($($args:tt)*)) => { + wrap!($module: pub fn $func_name($($args)*) -> ()); + } + } + + use super::*; + use super::{ + Handle, HandleFunction, HandleId, HandleObject, HandleScript, HandleString, HandleValue, + HandleValueArray, MutableHandle, MutableHandleId, MutableHandleObject, MutableHandleString, + MutableHandleValue, StackGCVector, + }; + use crate::context::JSContext; + use crate::glue; + use crate::glue::*; + use crate::jsapi; + use crate::jsapi::js::TempAllocPolicy; + use crate::jsapi::mozilla::Utf8Unit; + use crate::jsapi::mozilla::*; + use crate::jsapi::BigInt; + use crate::jsapi::CallArgs; + use crate::jsapi::CloneDataPolicy; + use crate::jsapi::ColumnNumberOneOrigin; + use crate::jsapi::CompartmentTransplantCallback; + use crate::jsapi::ESClass; + use crate::jsapi::EnvironmentChain; + use crate::jsapi::ExceptionStackBehavior; + use crate::jsapi::ForOfIterator; + use crate::jsapi::ForOfIterator_NonIterableBehavior; + use crate::jsapi::HandleObjectVector; + use crate::jsapi::InstantiateOptions; + use crate::jsapi::JSClass; + use crate::jsapi::JSErrorReport; + use crate::jsapi::JSExnType; + use crate::jsapi::JSFunctionSpecWithHelp; + use crate::jsapi::JSJitInfo; + use crate::jsapi::JSONParseHandler; + use crate::jsapi::JSONWriteCallback; + use crate::jsapi::JSPrincipals; + use crate::jsapi::JSPropertySpec; + use crate::jsapi::JSPropertySpec_Name; + use crate::jsapi::JSProtoKey; + use crate::jsapi::JSScript; + use crate::jsapi::JSStructuredCloneData; + use crate::jsapi::JSType; + use crate::jsapi::Latin1Char; + use crate::jsapi::ModuleErrorBehaviour; + use crate::jsapi::ModuleType; + use crate::jsapi::MutableHandleIdVector; + use crate::jsapi::PromiseState; + use crate::jsapi::PromiseUserInputEventHandlingState; + use crate::jsapi::PropertyKey; + use crate::jsapi::ReadOnlyCompileOptions; + use crate::jsapi::Realm; + use crate::jsapi::RealmOptions; + use crate::jsapi::RefPtr; + use crate::jsapi::RegExpFlags; + use crate::jsapi::ScriptEnvironmentPreparer_Closure; + use crate::jsapi::SourceText; + use crate::jsapi::StackCapture; + use crate::jsapi::Stencil; + use crate::jsapi::StructuredCloneScope; + use crate::jsapi::Symbol; + use crate::jsapi::SymbolCode; + use crate::jsapi::TaggedColumnNumberOneOrigin; + use crate::jsapi::TranscodeBuffer; + use crate::jsapi::TwoByteChars; + use crate::jsapi::UniqueChars; + use crate::jsapi::Value; + use crate::jsapi::WasmModule; + use crate::jsapi::*; + use crate::jsapi::{ElementAdder, IsArrayAnswer, PropertyDescriptor}; + use crate::jsapi::{JSFunction, JSNative, JSObject, JSString}; + use crate::jsapi::{ + JSStructuredCloneCallbacks, JSStructuredCloneReader, JSStructuredCloneWriter, + }; + use crate::jsapi::{MallocSizeOf, ObjectOpResult, ObjectPrivateVisitor, TabSizes}; + use crate::jsapi::{SavedFrameResult, SavedFrameSelfHosted}; + include!("jsapi2_wrappers.in.rs"); + include!("glue2_wrappers.in.rs"); +} diff --git a/mozjs/src/typedarray.rs b/mozjs/src/typedarray.rs index d94dabdce7..9e88a41e6a 100644 --- a/mozjs/src/typedarray.rs +++ b/mozjs/src/typedarray.rs @@ -448,6 +448,9 @@ impl TypedArray { #[macro_export] macro_rules! typedarray { + (&in($cx:expr) $($t:tt)*) => { + typedarray!(in(unsafe {$cx.raw_cx_no_gc()}) $($t)*); + }; (in($cx:expr) let $name:ident : $ty:ident = $init:expr) => { let mut __array = $crate::typedarray::$ty::from($init).map($crate::rust::CustomAutoRooter::new); diff --git a/mozjs/tests/callback.rs b/mozjs/tests/callback.rs index 9dcb96fe65..d3126cc693 100644 --- a/mozjs/tests/callback.rs +++ b/mozjs/tests/callback.rs @@ -4,36 +4,37 @@ use std::ffi::CStr; use std::ptr; +use std::ptr::NonNull; use std::str; -use mozjs::glue::EncodeStringToUTF8; -use mozjs::jsapi::{CallArgs, JSAutoRealm, JSContext, OnNewGlobalHookOption, Value}; -use mozjs::jsapi::{JS_DefineFunction, JS_NewGlobalObject, JS_ReportErrorASCII}; +use mozjs::context::{JSContext, RawJSContext}; +use mozjs::jsapi::{CallArgs, JSAutoRealm, JS_ReportErrorASCII, OnNewGlobalHookOption, Value}; use mozjs::jsval::UndefinedValue; use mozjs::rooted; +use mozjs::rust::wrappers2::{EncodeStringToUTF8, JS_DefineFunction, JS_NewGlobalObject}; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] fn callback() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); let function = JS_DefineFunction( context, @@ -46,7 +47,8 @@ fn callback() { assert!(!function.is_null()); let javascript = "puts('Test Iñtërnâtiônàlizætiøn ┬─┬ノ( º _ ºノ) ');"; - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); + // Rust automagically drops context here, so we can continue to use runtime here let options = runtime.new_compile_options("test.js", 0); assert!(runtime .evaluate_script(global.handle(), javascript, rval.handle_mut(), options) @@ -54,24 +56,30 @@ fn callback() { } } -unsafe extern "C" fn puts(context: *mut JSContext, argc: u32, vp: *mut Value) -> bool { +unsafe extern "C" fn puts(context: *mut RawJSContext, argc: u32, vp: *mut Value) -> bool { + // SAFETY: This is safe because we are in callback (so this is only access to context) + // and we shadow the ptr, so it cannot be used anymore + let mut context = JSContext::from_ptr(NonNull::new(context).unwrap()); let args = CallArgs::from_vp(vp, argc); if args.argc_ != 1 { - JS_ReportErrorASCII(context, c"puts() requires exactly 1 argument".as_ptr()); + JS_ReportErrorASCII( + context.raw_cx(), + c"puts() requires exactly 1 argument".as_ptr(), + ); return false; } let arg = mozjs::rust::Handle::from_raw(args.get(0)); - let js = mozjs::rust::ToString(context, arg); - rooted!(in(context) let message_root = js); + let js = mozjs::rust::ToString(context.raw_cx(), arg); + rooted!(&in(context) let message_root = js); unsafe extern "C" fn cb(message: *const core::ffi::c_char) { let message = CStr::from_ptr(message); let message = str::from_utf8(message.to_bytes()).unwrap(); assert_eq!(message, "Test Iñtërnâtiônàlizætiøn ┬─┬ノ( º _ ºノ) "); println!("{}", message); } - EncodeStringToUTF8(context, message_root.handle().into(), cb); + EncodeStringToUTF8(&mut context, message_root.handle().into(), cb); args.rval().set(UndefinedValue()); true diff --git a/mozjs/tests/capture_stack.rs b/mozjs/tests/capture_stack.rs index 592e30651f..2cbdad177f 100644 --- a/mozjs/tests/capture_stack.rs +++ b/mozjs/tests/capture_stack.rs @@ -6,9 +6,9 @@ use std::ptr; use mozjs::capture_stack; use mozjs::jsapi::{CallArgs, JSAutoRealm, JSContext, OnNewGlobalHookOption, StackFormat, Value}; -use mozjs::jsapi::{JS_DefineFunction, JS_NewGlobalObject}; use mozjs::jsval::UndefinedValue; use mozjs::rooted; +use mozjs::rust::wrappers2::{JS_DefineFunction, JS_NewGlobalObject}; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] @@ -32,24 +32,24 @@ fn capture_stack() { } let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); let function = JS_DefineFunction( context, @@ -71,7 +71,7 @@ fn capture_stack() { foo(\"arg1-value\"); "; - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); let options = runtime.new_compile_options("test.js", 0); assert!(runtime .evaluate_script(global.handle(), javascript, rval.handle_mut(), options) diff --git a/mozjs/tests/custom_auto_rooter.rs b/mozjs/tests/custom_auto_rooter.rs index c970734978..a445a48d97 100644 --- a/mozjs/tests/custom_auto_rooter.rs +++ b/mozjs/tests/custom_auto_rooter.rs @@ -4,7 +4,8 @@ use std::cell::Cell; -use mozjs::jsapi::{GCReason, JSTracer, JS_GC}; +use mozjs::jsapi::{GCReason, JSTracer}; +use mozjs::rust::wrappers2::JS_GC; use mozjs::rust::{CustomAutoRooter, CustomTrace, JSEngine, Runtime}; struct TraceCheck { @@ -31,11 +32,11 @@ unsafe impl CustomTrace for TraceCheck { #[test] fn virtual_trace_called() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); let mut rooter = CustomAutoRooter::new(TraceCheck::new()); - let guard = rooter.root(context); + let guard = rooter.root(unsafe { context.raw_cx() }); unsafe { JS_GC(context, GCReason::API); diff --git a/mozjs/tests/custom_auto_rooter_macro.rs b/mozjs/tests/custom_auto_rooter_macro.rs index 5e18e97f8f..8c547bbdc5 100644 --- a/mozjs/tests/custom_auto_rooter_macro.rs +++ b/mozjs/tests/custom_auto_rooter_macro.rs @@ -5,7 +5,8 @@ use std::cell::Cell; use mozjs::auto_root; -use mozjs::jsapi::{GCReason, JSTracer, JS_GC}; +use mozjs::jsapi::{GCReason, JSTracer}; +use mozjs::rust::wrappers2::JS_GC; use mozjs::rust::{CustomTrace, JSEngine, Runtime}; struct TraceCheck { @@ -29,10 +30,10 @@ unsafe impl CustomTrace for TraceCheck { #[test] fn custom_auto_rooter_macro() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); - auto_root!(in(context) let vec = vec![TraceCheck::new(), TraceCheck::new()]); + auto_root!(&in(context) let vec = vec![TraceCheck::new(), TraceCheck::new()]); unsafe { JS_GC(context, GCReason::API); diff --git a/mozjs/tests/enforce_range.rs b/mozjs/tests/enforce_range.rs index 6a1d2fd09e..6eb36a8640 100644 --- a/mozjs/tests/enforce_range.rs +++ b/mozjs/tests/enforce_range.rs @@ -6,10 +6,10 @@ use std::ptr; use mozjs::conversions::{ConversionBehavior, ConversionResult, FromJSValConvertible}; use mozjs::jsapi::JSAutoRealm; -use mozjs::jsapi::{Heap, JSObject, JS_NewGlobalObject, OnNewGlobalHookOption}; -use mozjs::jsapi::{JS_ClearPendingException, JS_IsExceptionPending}; +use mozjs::jsapi::{Heap, JSObject, OnNewGlobalHookOption}; use mozjs::jsval::UndefinedValue; use mozjs::rooted; +use mozjs::rust::wrappers2::{JS_ClearPendingException, JS_IsExceptionPending, JS_NewGlobalObject}; use mozjs::rust::{HandleObject, JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; struct SM { @@ -22,22 +22,22 @@ struct SM { impl SM { fn new() -> Self { let engine = JSEngine::init().unwrap(); - let rt = Runtime::new(engine.handle()); + let mut rt = Runtime::new(engine.handle()); let cx = rt.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(cx, 2, 1); + mozjs::jsapi::SetGCZeal(cx.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); - rooted!(in(cx) let global = unsafe {JS_NewGlobalObject( + rooted!(&in(cx) let global = unsafe {JS_NewGlobalObject( cx, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )}); - let _ac = JSAutoRealm::new(cx, global.get()); + let _ac = JSAutoRealm::new(unsafe { cx.raw_cx() }, global.get()); Self { _engine: engine, rt, @@ -48,11 +48,11 @@ impl SM { /// Returns value or (Type)Error fn obtain>( - &self, + &mut self, js: &str, ) -> Result { let cx = self.rt.cx(); - rooted!(in(cx) let mut rval = UndefinedValue()); + rooted!(&in(cx) let mut rval = UndefinedValue()); unsafe { let options = self.rt.new_compile_options("test", 1); self.rt @@ -63,9 +63,10 @@ impl SM { options, ) .unwrap(); + let cx = self.rt.cx(); assert!(!JS_IsExceptionPending(cx)); match ::from_jsval( - cx, + cx.raw_cx(), rval.handle(), ConversionBehavior::EnforceRange, ) { @@ -83,7 +84,7 @@ impl SM { #[test] fn conversion() { - let sm = SM::new(); + let mut sm = SM::new(); // u64 = unsigned long long // use `AbortSignal.timeout(u64)` to test for TypeError in browser diff --git a/mozjs/tests/enumerate.rs b/mozjs/tests/enumerate.rs index 2af52da17c..1e874ccbc6 100644 --- a/mozjs/tests/enumerate.rs +++ b/mozjs/tests/enumerate.rs @@ -4,28 +4,26 @@ use std::ptr; -use mozjs::jsapi::JSITER_OWNONLY; -use mozjs::jsapi::{ - GetPropertyKeys, JS_NewGlobalObject, JS_StringEqualsAscii, OnNewGlobalHookOption, -}; +use mozjs::jsapi::{OnNewGlobalHookOption, JSITER_OWNONLY}; use mozjs::jsval::UndefinedValue; use mozjs::rooted; +use mozjs::rust::wrappers2::{GetPropertyKeys, JS_NewGlobalObject, JS_StringEqualsAscii}; use mozjs::rust::{IdVector, JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] fn enumerate() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), @@ -33,15 +31,16 @@ fn enumerate() { &*c_option, )); - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); let options = runtime.new_compile_options("test", 1); assert!(runtime .evaluate_script(global.handle(), "({ 'a': 7 })", rval.handle_mut(), options,) .is_ok()); + let context = runtime.cx(); assert!(rval.is_object()); - rooted!(in(context) let object = rval.to_object()); - let mut ids = IdVector::new(context); + rooted!(&in(context) let object = rval.to_object()); + let mut ids = IdVector::new(context.raw_cx()); assert!(GetPropertyKeys( context, object.handle().into(), @@ -50,10 +49,10 @@ fn enumerate() { )); assert_eq!(ids.len(), 1); - rooted!(in(context) let id = ids[0]); + rooted!(&in(context) let id = ids[0]); assert!(id.is_string()); - rooted!(in(context) let id = id.to_string()); + rooted!(&in(context) let id = id.to_string()); let mut matches = false; assert!(JS_StringEqualsAscii( diff --git a/mozjs/tests/evaluate.rs b/mozjs/tests/evaluate.rs index 3d84449023..adf0967009 100644 --- a/mozjs/tests/evaluate.rs +++ b/mozjs/tests/evaluate.rs @@ -4,25 +4,26 @@ use std::ptr; -use mozjs::jsapi::{JS_NewGlobalObject, OnNewGlobalHookOption}; +use mozjs::jsapi::OnNewGlobalHookOption; use mozjs::jsval::UndefinedValue; use mozjs::rooted; +use mozjs::rust::wrappers2::JS_NewGlobalObject; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] fn evaluate() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), @@ -30,7 +31,7 @@ fn evaluate() { &*c_option, )); - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); let options = runtime.new_compile_options("test", 1); assert!(runtime .evaluate_script(global.handle(), "1 + 1", rval.handle_mut(), options) diff --git a/mozjs/tests/external_string.rs b/mozjs/tests/external_string.rs index 4bc8d3af6d..2470ad5a73 100644 --- a/mozjs/tests/external_string.rs +++ b/mozjs/tests/external_string.rs @@ -6,36 +6,38 @@ use std::ffi::c_void; use std::ptr; use std::ptr::NonNull; +#[cfg(test)] +use mozjs::context::JSContext; use mozjs::conversions::jsstr_to_string; use mozjs::glue::{CreateJSExternalStringCallbacks, JSExternalStringCallbacksTraps}; -use mozjs::jsapi::{ - JSAutoRealm, JS_NewExternalStringLatin1, JS_NewExternalUCString, JS_NewGlobalObject, - OnNewGlobalHookOption, -}; +use mozjs::jsapi::{JSAutoRealm, OnNewGlobalHookOption}; use mozjs::rooted; +use mozjs::rust::wrappers2::{ + JS_NewExternalStringLatin1, JS_NewExternalUCString, JS_NewGlobalObject, +}; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] fn external_string() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); test_latin1_string(context, "test latin1"); test_latin1_string(context, "abcdefghijklmnop"); // exactly 16 bytes @@ -89,21 +91,21 @@ fn external_string() { &EXTERNAL_STRING_CALLBACKS_TRAPS, utf16_len as *mut c_void, ); - rooted!(in(context) let utf16_jsstr = JS_NewExternalUCString( + rooted!(&in(context) let utf16_jsstr = JS_NewExternalUCString( context, utf16_chars, utf16_len, callbacks )); assert_eq!( - jsstr_to_string(context, NonNull::new(utf16_jsstr.get()).unwrap()), + jsstr_to_string(context.raw_cx(), NonNull::new(utf16_jsstr.get()).unwrap()), utf16_base ); } } #[cfg(test)] -unsafe fn test_latin1_string(context: *mut mozjs::jsapi::JSContext, latin1_base: &str) { +unsafe fn test_latin1_string(context: &mut JSContext, latin1_base: &str) { let latin1_boxed = latin1_base.as_bytes().to_vec().into_boxed_slice(); let latin1_chars = Box::into_raw(latin1_boxed).cast::(); @@ -111,20 +113,20 @@ unsafe fn test_latin1_string(context: *mut mozjs::jsapi::JSContext, latin1_base: &EXTERNAL_STRING_CALLBACKS_TRAPS, latin1_base.len() as *mut c_void, ); - rooted!(in(context) let latin1_jsstr = JS_NewExternalStringLatin1( + rooted!(&in(context) let latin1_jsstr = JS_NewExternalStringLatin1( context, latin1_chars, latin1_base.len(), callbacks )); assert_eq!( - jsstr_to_string(context, NonNull::new(latin1_jsstr.get()).unwrap()), + jsstr_to_string(context.raw_cx(), NonNull::new(latin1_jsstr.get()).unwrap()), latin1_base ); } #[cfg(test)] -unsafe fn test_latin1_string_bytes(context: *mut mozjs::jsapi::JSContext, latin1_base: &[u8]) { +unsafe fn test_latin1_string_bytes(context: &mut JSContext, latin1_base: &[u8]) { let latin1_boxed = latin1_base.to_vec().into_boxed_slice(); let latin1_chars = Box::into_raw(latin1_boxed).cast::(); @@ -132,14 +134,14 @@ unsafe fn test_latin1_string_bytes(context: *mut mozjs::jsapi::JSContext, latin1 &EXTERNAL_STRING_CALLBACKS_TRAPS, latin1_base.len() as *mut c_void, ); - rooted!(in(context) let latin1_jsstr = JS_NewExternalStringLatin1( + rooted!(&in(context) let latin1_jsstr = JS_NewExternalStringLatin1( context, latin1_chars, latin1_base.len(), callbacks )); assert_eq!( - jsstr_to_string(context, NonNull::new(latin1_jsstr.get()).unwrap()), + jsstr_to_string(context.raw_cx(), NonNull::new(latin1_jsstr.get()).unwrap()), encoding_rs::mem::decode_latin1(latin1_base) ); } diff --git a/mozjs/tests/iterate_stack.rs b/mozjs/tests/iterate_stack.rs index b814df0f66..a0ca2760ca 100644 --- a/mozjs/tests/iterate_stack.rs +++ b/mozjs/tests/iterate_stack.rs @@ -1,11 +1,11 @@ -use std::ptr; +use std::ptr::{self, NonNull}; use mozjs::{ capture_stack, jsapi::{self, JSAutoRealm, JSContext, OnNewGlobalHookOption, Value}, jsval::UndefinedValue, rooted, - rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}, + rust::{wrappers2, JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}, }; #[test] @@ -15,15 +15,16 @@ fn iterate_stack_frames() { _argc: u32, _vp: *mut Value, ) -> bool { + let mut context = mozjs::context::JSContext::from_ptr(NonNull::new(context).unwrap()); let mut function_names = vec![]; - capture_stack!(in(context) let stack); + capture_stack!(&in(context) let stack); stack.unwrap().for_each_stack_frame(|frame| { - rooted!(in(context) let mut result: *mut jsapi::JSString = ptr::null_mut()); + rooted!(&in(context) let mut result: *mut jsapi::JSString = ptr::null_mut()); // Get function name unsafe { - jsapi::GetSavedFrameFunctionDisplayName( - context, + wrappers2::GetSavedFrameFunctionDisplayName( + &mut context, ptr::null_mut(), frame.into(), result.handle_mut().into(), @@ -32,7 +33,7 @@ fn iterate_stack_frames() { } let buffer = if !result.is_null() { let mut buffer = vec![0; 3]; - jsapi::JS_EncodeStringToBuffer(context, *result, buffer.as_mut_ptr(), 3); + wrappers2::JS_EncodeStringToBuffer(&mut context, *result, buffer.as_mut_ptr(), 3); Some(buffer.into_iter().map(|c| c as u8).collect()) } else { None @@ -50,26 +51,26 @@ fn iterate_stack_frames() { } let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = jsapi::JS_NewGlobalObject( + rooted!(&in(context) let global = wrappers2::JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); - let function = jsapi::JS_DefineFunction( + let function = wrappers2::JS_DefineFunction( context, global.handle().into(), c"assert_stack_state".as_ptr(), @@ -91,7 +92,7 @@ fn iterate_stack_frames() { } foo(); "; - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); let options = runtime.new_compile_options("test.js", 0); assert!(runtime .evaluate_script(global.handle(), javascript, rval.handle_mut(), options) diff --git a/mozjs/tests/jsvalue.rs b/mozjs/tests/jsvalue.rs index bd4bd7cf56..dd0f2f353b 100644 --- a/mozjs/tests/jsvalue.rs +++ b/mozjs/tests/jsvalue.rs @@ -4,16 +4,17 @@ use std::ptr; -use mozjs::jsapi::{JS_NewGlobalObject, OnNewGlobalHookOption}; +use mozjs::jsapi::OnNewGlobalHookOption; use mozjs::jsval::{BooleanValue, DoubleValue, Int32Value, NullValue, UndefinedValue}; use mozjs::rooted; +use mozjs::rust::wrappers2::JS_NewGlobalObject; use mozjs::rust::{ HandleObject, JSEngine, RealmOptions, RootedGuard, Runtime, SIMPLE_GLOBAL_CLASS, }; use mozjs_sys::jsval::JSVal; unsafe fn tester)>( - rt: &Runtime, + rt: &mut Runtime, global: HandleObject, // js to be executed that needs to return jsval js: &str, @@ -21,32 +22,31 @@ unsafe fn tester)>( rust: JSVal, test: F, ) { - let cx = rt.cx(); - rooted!(in(cx) let mut rval = UndefinedValue()); + rooted!(&in(rt.cx()) let mut rval = UndefinedValue()); let options = rt.new_compile_options("test", 1); assert!(rt .evaluate_script(global, js, rval.handle_mut(), options) .is_ok()); test(rval); - rooted!(in(cx) let mut val = rust); + rooted!(&in(rt.cx()) let mut val = rust); test(val); } #[test] fn jsvalues() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), @@ -55,7 +55,7 @@ fn jsvalues() { )); tester( - &runtime, + &mut runtime, global.handle(), "undefined", UndefinedValue(), @@ -65,7 +65,7 @@ fn jsvalues() { }, ); - tester(&runtime, global.handle(), "null", NullValue(), |val| { + tester(&mut runtime, global.handle(), "null", NullValue(), |val| { assert!(val.is_null()); assert!(val.is_null_or_undefined()); assert!(val.is_object_or_null()); @@ -74,7 +74,7 @@ fn jsvalues() { }); tester( - &runtime, + &mut runtime, global.handle(), "true", BooleanValue(true), @@ -87,7 +87,7 @@ fn jsvalues() { ); tester( - &runtime, + &mut runtime, global.handle(), "false", BooleanValue(false), @@ -99,7 +99,7 @@ fn jsvalues() { }, ); - tester(&runtime, global.handle(), "42", Int32Value(42), |val| { + tester(&mut runtime, global.handle(), "42", Int32Value(42), |val| { assert!(val.is_int32()); assert!(val.is_primitive()); assert!(val.is_number()); @@ -108,17 +108,23 @@ fn jsvalues() { assert_eq!(val.to_number(), 42.0); }); - tester(&runtime, global.handle(), "-42", Int32Value(-42), |val| { - assert!(val.is_int32()); - assert!(val.is_primitive()); - assert!(val.is_number()); + tester( + &mut runtime, + global.handle(), + "-42", + Int32Value(-42), + |val| { + assert!(val.is_int32()); + assert!(val.is_primitive()); + assert!(val.is_number()); - assert_eq!(val.to_int32(), -42); - assert_eq!(val.to_number(), -42.0); - }); + assert_eq!(val.to_int32(), -42); + assert_eq!(val.to_number(), -42.0); + }, + ); tester( - &runtime, + &mut runtime, global.handle(), "42.5", DoubleValue(42.5), @@ -133,7 +139,7 @@ fn jsvalues() { ); tester( - &runtime, + &mut runtime, global.handle(), "-42.5", DoubleValue(-42.5), diff --git a/mozjs/tests/panic.rs b/mozjs/tests/panic.rs index fc1965f4b0..09346a11f4 100644 --- a/mozjs/tests/panic.rs +++ b/mozjs/tests/panic.rs @@ -2,39 +2,39 @@ * 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 std::ptr; +use std::ptr::{self, NonNull}; +use mozjs::context::{JSContext, RawJSContext}; use mozjs::gc::HandleValue; -use mozjs::jsapi::{ExceptionStackBehavior, JSAutoRealm, JSContext, OnNewGlobalHookOption, Value}; -use mozjs::jsapi::{JS_DefineFunction, JS_NewGlobalObject}; +use mozjs::jsapi::{ExceptionStackBehavior, JSAutoRealm, OnNewGlobalHookOption, Value}; use mozjs::jsval::UndefinedValue; use mozjs::panic::wrap_panic; use mozjs::rooted; -use mozjs::rust::wrappers::JS_SetPendingException; +use mozjs::rust::wrappers2::{JS_DefineFunction, JS_NewGlobalObject, JS_SetPendingException}; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] #[should_panic] fn test_panic() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); let function = JS_DefineFunction( context, @@ -46,13 +46,14 @@ fn test_panic() { ); assert!(!function.is_null()); - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); let options = runtime.new_compile_options("test.js", 0); let _ = runtime.evaluate_script(global.handle(), "test();", rval.handle_mut(), options); } } -unsafe extern "C" fn test(cx: *mut JSContext, _argc: u32, _vp: *mut Value) -> bool { +unsafe extern "C" fn test(cx: *mut RawJSContext, _argc: u32, _vp: *mut Value) -> bool { + let mut cx = JSContext::from_ptr(NonNull::new(cx).unwrap()); let mut result = false; wrap_panic(&mut || { panic!(); @@ -62,7 +63,11 @@ unsafe extern "C" fn test(cx: *mut JSContext, _argc: u32, _vp: *mut Value) -> bo } }); if !result { - JS_SetPendingException(cx, HandleValue::null(), ExceptionStackBehavior::Capture); + JS_SetPendingException( + &mut cx, + HandleValue::null(), + ExceptionStackBehavior::Capture, + ); } result } diff --git a/mozjs/tests/property_descriptor.rs b/mozjs/tests/property_descriptor.rs index 963fa34333..d6db82dbab 100644 --- a/mozjs/tests/property_descriptor.rs +++ b/mozjs/tests/property_descriptor.rs @@ -5,43 +5,42 @@ use std::ptr; use mozjs::jsapi::JSObject; -use mozjs::jsapi::{ - FromPropertyDescriptor, JS_DefineProperty, JS_GetPropertyDescriptor, JS_NewGlobalObject, - JS_NewPlainObject, -}; use mozjs::jsapi::{JSAutoRealm, OnNewGlobalHookOption, PropertyDescriptor}; use mozjs::jsapi::{JSPROP_ENUMERATE, JSPROP_PERMANENT, JSPROP_READONLY}; use mozjs::jsval::{Int32Value, NullValue}; use mozjs::rooted; +use mozjs::rust::wrappers2::{ + FromPropertyDescriptor, JS_DefineProperty, JS_GetProperty, JS_GetPropertyDescriptor, + JS_NewGlobalObject, JS_NewPlainObject, +}; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; -use mozjs_sys::jsapi::JS_GetProperty; #[test] fn property_descriptor() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); - rooted!(in(context) let object = JS_NewPlainObject(context)); - rooted!(in(context) let property = Int32Value(32)); + rooted!(&in(context) let object = JS_NewPlainObject(context)); + rooted!(&in(context) let property = Int32Value(32)); let attrs = (JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY) as u32; assert!(JS_DefineProperty( @@ -52,9 +51,9 @@ fn property_descriptor() { attrs )); - rooted!(in(context) let mut descriptor: PropertyDescriptor); + rooted!(&in(context) let mut descriptor: PropertyDescriptor); - rooted!(in(context) let mut holder: *mut JSObject = ptr::null_mut()); + rooted!(&in(context) let mut holder: *mut JSObject = ptr::null_mut()); let mut is_none = true; assert!(JS_GetPropertyDescriptor( context, @@ -69,15 +68,15 @@ fn property_descriptor() { assert!(!descriptor.get().writable_()); assert_eq!(descriptor.get().value_.to_int32(), 32); - rooted!(in(context) let mut desc = NullValue()); + rooted!(&in(context) let mut desc = NullValue()); assert!(FromPropertyDescriptor( context, descriptor.handle().into(), desc.handle_mut().into() )); - rooted!(in(context) let desc_object = desc.to_object()); + rooted!(&in(context) let desc_object = desc.to_object()); - rooted!(in(context) let mut rval = NullValue()); + rooted!(&in(context) let mut rval = NullValue()); assert!(JS_GetProperty( context, desc_object.handle().into(), diff --git a/mozjs/tests/rootable.rs b/mozjs/tests/rootable.rs index c885bcacc4..488b35825f 100644 --- a/mozjs/tests/rootable.rs +++ b/mozjs/tests/rootable.rs @@ -6,10 +6,11 @@ use std::ptr; -use mozjs::jsapi::{GetRealmObjectPrototype, JS_NewGlobalObject, SetGCZeal}; +use mozjs::jsapi::SetGCZeal; use mozjs::jsapi::{JSAutoRealm, JSTracer, OnNewGlobalHookOption, Value}; use mozjs::jsval::ObjectValue; use mozjs::rooted; +use mozjs::rust::wrappers2::{GetRealmObjectPrototype, JS_NewGlobalObject}; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; impl mozjs::gc::Rootable for ContainsGCValue {} @@ -32,27 +33,27 @@ struct ContainsGCValue { #[test] fn rooting() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - SetGCZeal(context, 2, 1); - rooted!(in(context) let global = JS_NewGlobalObject( + SetGCZeal(context.raw_cx(), 2, 1); + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); - rooted!(in(context) let prototype_proto = GetRealmObjectPrototype(context)); - rooted!(in(context) let some_container = ContainsGCValue { + rooted!(&in(context) let prototype_proto = GetRealmObjectPrototype(context)); + rooted!(&in(context) let some_container = ContainsGCValue { val: ObjectValue(prototype_proto.get()) }); - rooted!(in(context) let some_optional_container = Some(ContainsGCValue { + rooted!(&in(context) let some_optional_container = Some(ContainsGCValue { val: ObjectValue(prototype_proto.get()) })); assert_eq!(some_container.val.to_object(), prototype_proto.get()); diff --git a/mozjs/tests/rooting.rs b/mozjs/tests/rooting.rs index 156d04f2ad..91e3b4f89f 100644 --- a/mozjs/tests/rooting.rs +++ b/mozjs/tests/rooting.rs @@ -6,51 +6,52 @@ use std::ptr; +use mozjs::jsapi::SetGCZeal; use mozjs::jsapi::JSPROP_ENUMERATE; -use mozjs::jsapi::{ - GetRealmObjectPrototype, JS_NewGlobalObject, JS_NewObjectWithGivenProto, SetGCZeal, -}; use mozjs::jsapi::{ JSAutoRealm, JSClass, JSContext, JSFunction, JSFunctionSpec, JSNativeWrapper, JSObject, JSPropertySpec_Name, JSString, OnNewGlobalHookOption, Value, }; use mozjs::jsval::JSVal; use mozjs::rooted; +use mozjs::rust::wrappers2::{ + GetRealmObjectPrototype, JS_NewGlobalObject, JS_NewObjectWithGivenProto, +}; use mozjs::rust::{define_methods, JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] fn rooting() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - SetGCZeal(context, 2, 1); - rooted!(in(context) let global = JS_NewGlobalObject( + SetGCZeal(context.raw_cx(), 2, 1); + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); - rooted!(in(context) let prototype_proto = GetRealmObjectPrototype(context)); - rooted!(in(context) let proto = JS_NewObjectWithGivenProto(context, &CLASS as *const _, prototype_proto.handle().into())); - define_methods(context, proto.handle(), METHODS).unwrap(); + rooted!(&in(context) let prototype_proto = GetRealmObjectPrototype(context)); + rooted!(&in(context) let proto = JS_NewObjectWithGivenProto(context, &CLASS as *const _, prototype_proto.handle().into())); + define_methods(context.raw_cx(), proto.handle(), METHODS).unwrap(); - rooted!(in(context) let root: JSVal); + rooted!(&in(context) let root: JSVal); assert_eq!(root.get().is_undefined(), true); - rooted!(in(context) let root: *mut JSObject); + rooted!(&in(context) let root: *mut JSObject); assert_eq!(root.get().is_null(), true); - rooted!(in(context) let root: *mut JSString); + rooted!(&in(context) let root: *mut JSString); assert_eq!(root.get().is_null(), true); - rooted!(in(context) let root: *mut JSFunction); + rooted!(&in(context) let root: *mut JSFunction); assert_eq!(root.get().is_null(), true); } } diff --git a/mozjs/tests/runtime.rs b/mozjs/tests/runtime.rs index fe2993655c..5535db70c1 100644 --- a/mozjs/tests/runtime.rs +++ b/mozjs/tests/runtime.rs @@ -8,34 +8,35 @@ use std::ptr; use std::sync::mpsc::channel; use std::thread; +use mozjs::jsapi::GCContext; use mozjs::jsapi::JSCLASS_FOREGROUND_FINALIZE; -use mozjs::jsapi::{GCContext, JS_NewGlobalObject, JS_NewObject}; use mozjs::jsapi::{JSAutoRealm, JSClass, JSClassOps, JSObject, OnNewGlobalHookOption}; use mozjs::rooted; +use mozjs::rust::wrappers2::{JS_NewGlobalObject, JS_NewObject}; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] fn runtime() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); - rooted!(in(context) let _object = JS_NewObject(context, &CLASS as *const _)); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); + rooted!(&in(context) let _object = JS_NewObject(context, &CLASS as *const _)); } let parent = runtime.prepare_for_new_child(); diff --git a/mozjs/tests/stack_gc_vector.rs b/mozjs/tests/stack_gc_vector.rs index 4e9d7ef4d6..d62e42403c 100644 --- a/mozjs/tests/stack_gc_vector.rs +++ b/mozjs/tests/stack_gc_vector.rs @@ -9,10 +9,11 @@ use mozjs::conversions::jsstr_to_string; use mozjs::gc::StackGCVector; use mozjs::jsapi::{ CompilationType, Handle, HandleString, HandleValue, JSContext, JSSecurityCallbacks, JSString, - JS_NewGlobalObject, JS_SetSecurityCallbacks, OnNewGlobalHookOption, RuntimeCode, + OnNewGlobalHookOption, RuntimeCode, }; use mozjs::jsval::{JSVal, UndefinedValue}; use mozjs::rooted; +use mozjs::rust::wrappers2::{JS_NewGlobalObject, JS_SetSecurityCallbacks}; use mozjs::rust::{Handle as SafeHandle, JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; static SECURITY_CALLBACKS: JSSecurityCallbacks = JSSecurityCallbacks { @@ -66,11 +67,11 @@ static RAN_CSP_CALLBACK: LazyLock> = LazyLock::new(|| Mutex::new(fal #[test] fn csp_allow_arguments() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); @@ -78,7 +79,7 @@ fn csp_allow_arguments() { unsafe { JS_SetSecurityCallbacks(context, &SECURITY_CALLBACKS); - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), @@ -86,7 +87,7 @@ fn csp_allow_arguments() { &*c_option, )); - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); let options = runtime.new_compile_options("test", 1); assert!(runtime .evaluate_script( diff --git a/mozjs/tests/stack_limit.rs b/mozjs/tests/stack_limit.rs index 3a93115d4a..7f1e65c931 100644 --- a/mozjs/tests/stack_limit.rs +++ b/mozjs/tests/stack_limit.rs @@ -4,32 +4,33 @@ use std::ptr; -use mozjs::jsapi::{JS_NewGlobalObject, OnNewGlobalHookOption}; +use mozjs::jsapi::OnNewGlobalHookOption; use mozjs::jsval::UndefinedValue; use mozjs::rooted; +use mozjs::rust::wrappers2::JS_NewGlobalObject; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] fn stack_limit() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); let options = runtime.new_compile_options("test", 1); assert!(runtime .evaluate_script( diff --git a/mozjs/tests/typedarray.rs b/mozjs/tests/typedarray.rs index 938f4635be..d23ada4383 100644 --- a/mozjs/tests/typedarray.rs +++ b/mozjs/tests/typedarray.rs @@ -4,9 +4,10 @@ use std::ptr; -use mozjs::jsapi::{JSAutoRealm, JSObject, JS_NewGlobalObject, OnNewGlobalHookOption, Type}; +use mozjs::jsapi::{JSAutoRealm, JSObject, OnNewGlobalHookOption, Type}; use mozjs::jsval::UndefinedValue; use mozjs::rooted; +use mozjs::rust::wrappers2::JS_NewGlobalObject; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; use mozjs::typedarray; use mozjs::typedarray::{CreateWith, Uint32Array}; @@ -14,26 +15,26 @@ use mozjs::typedarray::{CreateWith, Uint32Array}; #[test] fn typedarray() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); let options = runtime.new_compile_options("test", 1); assert!(runtime .evaluate_script( @@ -45,51 +46,58 @@ fn typedarray() { .is_ok()); assert!(rval.is_object()); - typedarray!(in(context) let array: Uint8Array = rval.to_object()); + let context = runtime.cx(); + + typedarray!(&in(context) let array: Uint8Array = rval.to_object()); assert_eq!(array.unwrap().as_slice(), &[0, 2, 4][..]); - typedarray!(in(context) let array: Uint8Array = rval.to_object()); + typedarray!(&in(context) let array: Uint8Array = rval.to_object()); assert_eq!(array.unwrap().len(), 3); - typedarray!(in(context) let array: Uint8Array = rval.to_object()); + typedarray!(&in(context) let array: Uint8Array = rval.to_object()); assert_eq!(array.unwrap().to_vec(), vec![0, 2, 4]); - typedarray!(in(context) let array: Uint16Array = rval.to_object()); + typedarray!(&in(context) let array: Uint16Array = rval.to_object()); assert!(array.is_err()); - typedarray!(in(context) let view: ArrayBufferView = rval.to_object()); + typedarray!(&in(context) let view: ArrayBufferView = rval.to_object()); assert_eq!(view.unwrap().get_array_type(), Type::Uint8); - rooted!(in(context) let mut rval = ptr::null_mut::()); - assert!( - Uint32Array::create(context, CreateWith::Slice(&[1, 3, 5]), rval.handle_mut()).is_ok() - ); + rooted!(&in(context) let mut rval = ptr::null_mut::()); + assert!(Uint32Array::create( + context.raw_cx(), + CreateWith::Slice(&[1, 3, 5]), + rval.handle_mut() + ) + .is_ok()); - typedarray!(in(context) let array: Uint32Array = rval.get()); + typedarray!(&in(context) let array: Uint32Array = rval.get()); assert_eq!(array.unwrap().as_slice(), &[1, 3, 5][..]); - typedarray!(in(context) let mut array: Uint32Array = rval.get()); + typedarray!(&in(context) let mut array: Uint32Array = rval.get()); array.as_mut().unwrap().update(&[2, 4, 6]); assert_eq!(array.unwrap().as_slice(), &[2, 4, 6][..]); - rooted!(in(context) let rval = ptr::null_mut::()); - typedarray!(in(context) let array: Uint8Array = rval.get()); + rooted!(&in(context) let rval = ptr::null_mut::()); + typedarray!(&in(context) let array: Uint8Array = rval.get()); assert!(array.is_err()); - rooted!(in(context) let mut rval = ptr::null_mut::()); - assert!(Uint32Array::create(context, CreateWith::Length(5), rval.handle_mut()).is_ok()); + rooted!(&in(context) let mut rval = ptr::null_mut::()); + assert!( + Uint32Array::create(context.raw_cx(), CreateWith::Length(5), rval.handle_mut()).is_ok() + ); - typedarray!(in(context) let array: Uint32Array = rval.get()); + typedarray!(&in(context) let array: Uint32Array = rval.get()); assert_eq!(array.unwrap().as_slice(), &[0, 0, 0, 0, 0]); - typedarray!(in(context) let mut array: Uint32Array = rval.get()); + typedarray!(&in(context) let mut array: Uint32Array = rval.get()); array.as_mut().unwrap().update(&[0, 1, 2, 3]); assert_eq!(array.unwrap().as_slice(), &[0, 1, 2, 3, 0]); - typedarray!(in(context) let view: ArrayBufferView = rval.get()); + typedarray!(&in(context) let view: ArrayBufferView = rval.get()); assert_eq!(view.unwrap().get_array_type(), Type::Uint32); - typedarray!(in(context) let view: ArrayBufferView = rval.get()); + typedarray!(&in(context) let view: ArrayBufferView = rval.get()); assert_eq!(view.unwrap().is_shared(), false); } } diff --git a/mozjs/tests/typedarray_panic.rs b/mozjs/tests/typedarray_panic.rs index edcc715d79..7de958d1b2 100644 --- a/mozjs/tests/typedarray_panic.rs +++ b/mozjs/tests/typedarray_panic.rs @@ -4,8 +4,9 @@ use std::ptr; -use mozjs::jsapi::{JSAutoRealm, JSObject, JS_NewGlobalObject, OnNewGlobalHookOption}; +use mozjs::jsapi::{JSAutoRealm, JSObject, OnNewGlobalHookOption}; use mozjs::rooted; +use mozjs::rust::wrappers2::JS_NewGlobalObject; use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; use mozjs::typedarray; use mozjs::typedarray::{CreateWith, Uint32Array}; @@ -14,28 +15,28 @@ use mozjs::typedarray::{CreateWith, Uint32Array}; #[should_panic] fn typedarray_update_panic() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); - rooted!(in(context) let mut rval = ptr::null_mut::()); + rooted!(&in(context) let mut rval = ptr::null_mut::()); let _ = Uint32Array::create( - context, + context.raw_cx(), CreateWith::Slice(&[1, 2, 3, 4, 5]), rval.handle_mut(), ); - typedarray!(in(context) let mut array: Uint32Array = rval.get()); + typedarray!(&in(context) let mut array: Uint32Array = rval.get()); array.as_mut().unwrap().update(&[0, 2, 4, 6, 8, 10]); } } diff --git a/mozjs/tests/vec_conversion.rs b/mozjs/tests/vec_conversion.rs index 4f84d04769..cedad5da32 100644 --- a/mozjs/tests/vec_conversion.rs +++ b/mozjs/tests/vec_conversion.rs @@ -7,50 +7,50 @@ use std::ptr; use mozjs::conversions::{ ConversionBehavior, ConversionResult, FromJSValConvertible, ToJSValConvertible, }; -use mozjs::jsapi::{ - InitRealmStandardClasses, JSAutoRealm, JS_NewGlobalObject, OnNewGlobalHookOption, -}; +use mozjs::jsapi::{JSAutoRealm, OnNewGlobalHookOption}; use mozjs::jsval::UndefinedValue; use mozjs::rooted; -use mozjs::rust::{CompileOptionsWrapper, JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; +use mozjs::rust::wrappers2::{InitRealmStandardClasses, JS_NewGlobalObject}; +use mozjs::rust::{JSEngine, RealmOptions, Runtime, SIMPLE_GLOBAL_CLASS}; #[test] fn vec_conversion() { let engine = JSEngine::init().unwrap(); - let runtime = Runtime::new(engine.handle()); + let mut runtime = Runtime::new(engine.handle()); let context = runtime.cx(); #[cfg(feature = "debugmozjs")] unsafe { - mozjs::jsapi::SetGCZeal(context, 2, 1); + mozjs::jsapi::SetGCZeal(context.raw_cx(), 2, 1); } let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook; let c_option = RealmOptions::default(); unsafe { - rooted!(in(context) let global = JS_NewGlobalObject( + rooted!(&in(context) let global = JS_NewGlobalObject( context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &*c_option, )); - let _ac = JSAutoRealm::new(context, global.get()); + let _ac = JSAutoRealm::new(context.raw_cx(), global.get()); assert!(InitRealmStandardClasses(context)); - rooted!(in(context) let mut rval = UndefinedValue()); + rooted!(&in(context) let mut rval = UndefinedValue()); let orig_vec: Vec = vec![1.0, 2.9, 3.0]; - orig_vec.to_jsval(context, rval.handle_mut()); - let converted = Vec::::from_jsval(context, rval.handle(), ()).unwrap(); + orig_vec.to_jsval(context.raw_cx(), rval.handle_mut()); + let converted = Vec::::from_jsval(context.raw_cx(), rval.handle(), ()).unwrap(); assert_eq!(&orig_vec, converted.get_success_value().unwrap()); let orig_vec: Vec = vec![1, 2, 3]; - orig_vec.to_jsval(context, rval.handle_mut()); + orig_vec.to_jsval(context.raw_cx(), rval.handle_mut()); let converted = - Vec::::from_jsval(context, rval.handle(), ConversionBehavior::Default).unwrap(); + Vec::::from_jsval(context.raw_cx(), rval.handle(), ConversionBehavior::Default) + .unwrap(); assert_eq!(&orig_vec, converted.get_success_value().unwrap()); @@ -63,8 +63,10 @@ fn vec_conversion() { options, ) .is_ok()); + let context = runtime.cx(); let converted = - Vec::::from_jsval(context, rval.handle(), ConversionBehavior::Default).unwrap(); + Vec::::from_jsval(context.raw_cx(), rval.handle(), ConversionBehavior::Default) + .unwrap(); assert_eq!(&orig_vec, converted.get_success_value().unwrap()); @@ -72,7 +74,9 @@ fn vec_conversion() { assert!(runtime .evaluate_script(global.handle(), "({})", rval.handle_mut(), options) .is_ok()); - let converted = Vec::::from_jsval(context, rval.handle(), ConversionBehavior::Default); + let context = runtime.cx(); + let converted = + Vec::::from_jsval(context.raw_cx(), rval.handle(), ConversionBehavior::Default); assert!(match converted { Ok(ConversionResult::Failure(_)) => true, _ => false, From 19b4ee8eee43ed5322beca18a1e354d1c394d1eb Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Thu, 6 Nov 2025 17:19:53 +0100 Subject: [PATCH 2/2] run doc test on linux Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 121a687f1d..cff01764c5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,7 +38,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v6 with: - python-version: '3.13' + python-version: "3.13" - name: Install deps run: | brew install llvm yasm @@ -90,9 +90,11 @@ jobs: - name: Run sccache-cache uses: mozilla-actions/sccache-action@v0.0.9 - name: Build + # doc tests on mozjs_sys fail because they include stuff from SpiderMonkey run: | cargo +${{ steps.toolchain.outputs.name }} build --verbose --features ${{ matrix.features }} cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose --features ${{ matrix.features }} + cargo +${{ steps.toolchain.outputs.name }} test --doc -p mozjs --verbose --features ${{ matrix.features }} - name: Check wrappers integrity # we generate wrappers only without debugmozjs if: ${{ matrix.features != 'debugmozjs' }}