Use explicit reborrows with mozjs::MutableHandle (#35892)

* Explicitly reborrow MutableHandles

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

* Unify jsapi_wrappers

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

* Format mozjs changes

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

* Update mozjs version

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>

---------

Signed-off-by: Greg Morenz <greg-morenz@droid.cafe>
This commit is contained in:
Greg Morenz 2025-03-22 21:23:52 -04:00 committed by GitHub
parent 40270cb626
commit 4ecf0909e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 67 additions and 44 deletions

View file

@ -620,13 +620,15 @@ unsafe impl<T> crate::dom::bindings::trace::JSTraceable for HeapBufferSource<T>
pub(crate) fn create_buffer_source<T>(
cx: JSContext,
data: &[T::Element],
dest: MutableHandleObject,
mut dest: MutableHandleObject,
_can_gc: CanGc,
) -> Result<TypedArray<T, *mut JSObject>, ()>
where
T: TypedArrayElement + TypedArrayElementCreator,
{
let res = unsafe { TypedArray::<T, *mut JSObject>::create(*cx, CreateWith::Slice(data), dest) };
let res = unsafe {
TypedArray::<T, *mut JSObject>::create(*cx, CreateWith::Slice(data), dest.reborrow())
};
if res.is_err() {
Err(())
@ -638,13 +640,15 @@ where
fn create_buffer_source_with_length<T>(
cx: JSContext,
len: usize,
dest: MutableHandleObject,
mut dest: MutableHandleObject,
_can_gc: CanGc,
) -> Result<TypedArray<T, *mut JSObject>, ()>
where
T: TypedArrayElement + TypedArrayElementCreator,
{
let res = unsafe { TypedArray::<T, *mut JSObject>::create(*cx, CreateWith::Length(len), dest) };
let res = unsafe {
TypedArray::<T, *mut JSObject>::create(*cx, CreateWith::Length(len), dest.reborrow())
};
if res.is_err() {
Err(())

View file

@ -36,7 +36,7 @@ impl CachedFrozenArray {
}
let array = f();
to_frozen_array(array.as_slice(), cx, retval, can_gc);
to_frozen_array(array.as_slice(), cx, retval.reborrow(), can_gc);
// Safety: need to create the Heap value in its final memory location before setting it.
*self.frozen_value.borrow_mut() = Some(Heap::default());

View file

@ -241,7 +241,7 @@ pub(crate) fn create_interface_prototype_object(
regular_properties: &[Guard<&'static [JSPropertySpec]>],
constants: &[Guard<&[ConstantSpec]>],
unscopable_names: &[&CStr],
rval: MutableHandleObject,
mut rval: MutableHandleObject,
) {
create_object(
cx,
@ -251,7 +251,7 @@ pub(crate) fn create_interface_prototype_object(
regular_methods,
regular_properties,
constants,
rval,
rval.reborrow(),
);
if !unscopable_names.is_empty() {
@ -289,7 +289,7 @@ pub(crate) fn create_noncallback_interface_object(
name: &CStr,
length: u32,
legacy_window_alias_names: &[&CStr],
rval: MutableHandleObject,
mut rval: MutableHandleObject,
) {
create_object(
cx,
@ -299,7 +299,7 @@ pub(crate) fn create_noncallback_interface_object(
static_methods,
static_properties,
constants,
rval,
rval.reborrow(),
);
unsafe {
assert!(JS_LinkConstructorAndPrototype(
@ -694,7 +694,7 @@ pub(crate) fn get_desired_proto(
global.handle(),
ProtoOrIfaceIndex::ID(proto_id),
creator,
desired_proto,
desired_proto.reborrow(),
);
if desired_proto.is_null() {
return Err(());

View file

@ -45,8 +45,17 @@ pub(crate) fn create_namespace_object(
methods: &[Guard<&'static [JSFunctionSpec]>],
constants: &[Guard<&'static [ConstantSpec]>],
name: &CStr,
rval: MutableHandleObject,
mut rval: MutableHandleObject,
) {
create_object(cx, global, proto, &class.0, methods, &[], constants, rval);
create_object(
cx,
global,
proto,
&class.0,
methods,
&[],
constants,
rval.reborrow(),
);
define_on_global_object(cx, global, name, rval.handle());
}

View file

@ -172,7 +172,7 @@ pub(crate) unsafe fn ensure_expando_object(
mut expando: MutableHandleObject,
) {
assert!(is_dom_proxy(obj.get()));
get_expando_object(obj, expando);
get_expando_object(obj, expando.reborrow());
if expando.is_null() {
expando.set(JS_NewObjectWithGivenProto(
cx,

View file

@ -122,10 +122,10 @@ pub(crate) use script_bindings::utils::{DOMClass, DOMJSClass};
pub(crate) fn to_frozen_array<T: ToJSValConvertible>(
convertibles: &[T],
cx: SafeJSContext,
rval: MutableHandleValue,
mut rval: MutableHandleValue,
_can_gc: CanGc,
) {
unsafe { convertibles.to_jsval(*cx, rval) };
unsafe { convertibles.to_jsval(*cx, rval.reborrow()) };
rooted!(in(*cx) let obj = rval.to_object());
unsafe { JS_FreezeObject(*cx, RawHandleObject::from(obj.handle())) };