mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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:
parent
40270cb626
commit
4ecf0909e5
14 changed files with 67 additions and 44 deletions
23
Cargo.lock
generated
23
Cargo.lock
generated
|
@ -520,7 +520,7 @@ dependencies = [
|
|||
"bitflags 2.9.0",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"itertools 0.13.0",
|
||||
"itertools 0.10.5",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
|
@ -1065,7 +1065,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2031,7 +2031,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2557,7 +2557,7 @@ dependencies = [
|
|||
"gobject-sys",
|
||||
"libc",
|
||||
"system-deps",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4017,7 +4017,7 @@ checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9"
|
|||
dependencies = [
|
||||
"hermit-abi 0.5.0",
|
||||
"libc",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4702,11 +4702,10 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "mozjs"
|
||||
version = "0.14.1"
|
||||
source = "git+https://github.com/servo/mozjs#87cabf4e9ddf9fafe19713a3d6bc8c5e6105544c"
|
||||
source = "git+https://github.com/servo/mozjs#26c35182c1b2b7fb2fbfa93b82669533d92c3a60"
|
||||
dependencies = [
|
||||
"bindgen 0.71.1",
|
||||
"cc",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"mozjs_sys",
|
||||
|
@ -4714,8 +4713,8 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "mozjs_sys"
|
||||
version = "0.128.6-1"
|
||||
source = "git+https://github.com/servo/mozjs#87cabf4e9ddf9fafe19713a3d6bc8c5e6105544c"
|
||||
version = "0.128.9-0"
|
||||
source = "git+https://github.com/servo/mozjs#26c35182c1b2b7fb2fbfa93b82669533d92c3a60"
|
||||
dependencies = [
|
||||
"bindgen 0.71.1",
|
||||
"cc",
|
||||
|
@ -6190,7 +6189,7 @@ dependencies = [
|
|||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -7528,7 +7527,7 @@ dependencies = [
|
|||
"getrandom",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -8837,7 +8836,7 @@ version = "0.1.9"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
|
||||
dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -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(())
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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(());
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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())) };
|
||||
|
|
|
@ -139,7 +139,7 @@ impl CustomElementRegistry {
|
|||
fn check_prototype(
|
||||
&self,
|
||||
constructor: HandleObject,
|
||||
prototype: MutableHandleValue,
|
||||
mut prototype: MutableHandleValue,
|
||||
) -> ErrorResult {
|
||||
unsafe {
|
||||
// Step 10.1
|
||||
|
@ -147,7 +147,7 @@ impl CustomElementRegistry {
|
|||
*GlobalScope::get_cx(),
|
||||
constructor,
|
||||
c"prototype".as_ptr(),
|
||||
prototype,
|
||||
prototype.reborrow(),
|
||||
) {
|
||||
return Err(Error::JSFailed);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ use js::jsapi::{
|
|||
NewUCRegExpObject, ObjectIsDate, RegExpFlag_Unicode, RegExpFlags,
|
||||
};
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::jsapi_wrapped::{CheckRegExpSyntax, ExecuteRegExpNoStatics, ObjectIsRegExp};
|
||||
use js::rust::wrappers::{CheckRegExpSyntax, ExecuteRegExpNoStatics, ObjectIsRegExp};
|
||||
use js::rust::{HandleObject, MutableHandleObject};
|
||||
use net_traits::blob_url_store::get_blob_origin;
|
||||
use net_traits::filemanager_thread::FileManagerThreadMsg;
|
||||
|
@ -3010,7 +3010,7 @@ fn check_js_regex_syntax(cx: SafeJSContext, pattern: &str) -> bool {
|
|||
RegExpFlags {
|
||||
flags_: RegExpFlag_Unicode,
|
||||
},
|
||||
&mut exception.handle_mut(),
|
||||
exception.handle_mut(),
|
||||
);
|
||||
|
||||
if !valid {
|
||||
|
@ -3063,7 +3063,7 @@ fn matches_js_regex(cx: SafeJSContext, regex_obj: HandleObject, value: &str) ->
|
|||
value.len(),
|
||||
&mut index,
|
||||
true,
|
||||
&mut rval.handle_mut(),
|
||||
rval.handle_mut(),
|
||||
);
|
||||
|
||||
if ok {
|
||||
|
|
|
@ -1216,14 +1216,21 @@ impl WebGL2RenderingContextMethods<crate::DomTypeHolder> for WebGL2RenderingCont
|
|||
);
|
||||
handle_potential_webgl_error!(
|
||||
self.base,
|
||||
self.get_specific_fb_attachment_param(cx, &fb, target, attachment, pname, rval),
|
||||
self.get_specific_fb_attachment_param(
|
||||
cx,
|
||||
&fb,
|
||||
target,
|
||||
attachment,
|
||||
pname,
|
||||
rval.reborrow()
|
||||
),
|
||||
rval.set(NullValue())
|
||||
)
|
||||
} else {
|
||||
// The default framebuffer is bound to the target
|
||||
handle_potential_webgl_error!(
|
||||
self.base,
|
||||
self.get_default_fb_attachment_param(attachment, pname, rval),
|
||||
self.get_default_fb_attachment_param(attachment, pname, rval.reborrow()),
|
||||
rval.set(NullValue())
|
||||
)
|
||||
}
|
||||
|
|
|
@ -3552,7 +3552,7 @@ impl WebGLRenderingContextMethods<crate::DomTypeHolder> for WebGLRenderingContex
|
|||
constants::VERTEX_ATTRIB_ARRAY_STRIDE => retval.set(Int32Value(data.stride as i32)),
|
||||
constants::VERTEX_ATTRIB_ARRAY_BUFFER_BINDING => unsafe {
|
||||
if let Some(buffer) = data.buffer() {
|
||||
buffer.to_jsval(*cx, retval);
|
||||
buffer.to_jsval(*cx, retval.reborrow());
|
||||
} else {
|
||||
retval.set(NullValue());
|
||||
}
|
||||
|
|
|
@ -1441,7 +1441,12 @@ impl XMLHttpRequest {
|
|||
let json_text = decode_to_utf16_with_bom_removal(&bytes, UTF_8);
|
||||
// Step 5
|
||||
unsafe {
|
||||
if !JS_ParseJSON(*cx, json_text.as_ptr(), json_text.len() as u32, rval) {
|
||||
if !JS_ParseJSON(
|
||||
*cx,
|
||||
json_text.as_ptr(),
|
||||
json_text.len() as u32,
|
||||
rval.reborrow(),
|
||||
) {
|
||||
JS_ClearPendingException(*cx);
|
||||
return rval.set(NullValue());
|
||||
}
|
||||
|
|
|
@ -27,8 +27,7 @@ use js::jsapi::{
|
|||
ThrowOnModuleEvaluationFailure, Value,
|
||||
};
|
||||
use js::jsval::{JSVal, PrivateValue, UndefinedValue};
|
||||
use js::rust::jsapi_wrapped::JS_GetPendingException;
|
||||
use js::rust::wrappers::JS_SetPendingException;
|
||||
use js::rust::wrappers::{JS_GetPendingException, JS_SetPendingException};
|
||||
use js::rust::{
|
||||
CompileOptionsWrapper, Handle, HandleObject as RustHandleObject, HandleValue, IntoHandle,
|
||||
MutableHandleObject as RustMutableHandleObject, transform_str_to_source_text,
|
||||
|
@ -488,7 +487,7 @@ impl ModuleTree {
|
|||
warn!("fail to compile module script of {}", url);
|
||||
|
||||
rooted!(in(*cx) let mut exception = UndefinedValue());
|
||||
assert!(JS_GetPendingException(*cx, &mut exception.handle_mut()));
|
||||
assert!(JS_GetPendingException(*cx, exception.handle_mut()));
|
||||
JS_ClearPendingException(*cx);
|
||||
|
||||
return Err(RethrowError(RootedTraceableBox::from_box(Heap::boxed(
|
||||
|
@ -531,7 +530,7 @@ impl ModuleTree {
|
|||
warn!("fail to link & instantiate module");
|
||||
|
||||
rooted!(in(*cx) let mut exception = UndefinedValue());
|
||||
assert!(JS_GetPendingException(*cx, &mut exception.handle_mut()));
|
||||
assert!(JS_GetPendingException(*cx, exception.handle_mut()));
|
||||
JS_ClearPendingException(*cx);
|
||||
|
||||
Err(RethrowError(RootedTraceableBox::from_box(Heap::boxed(
|
||||
|
@ -577,7 +576,7 @@ impl ModuleTree {
|
|||
warn!("fail to evaluate module");
|
||||
|
||||
rooted!(in(*cx) let mut exception = UndefinedValue());
|
||||
assert!(JS_GetPendingException(*cx, &mut exception.handle_mut()));
|
||||
assert!(JS_GetPendingException(*cx, exception.handle_mut()));
|
||||
JS_ClearPendingException(*cx);
|
||||
|
||||
Err(RethrowError(RootedTraceableBox::from_box(Heap::boxed(
|
||||
|
|
|
@ -6394,13 +6394,13 @@ let cx = SafeJSContext::from_ptr(cx);
|
|||
{maybeCrossOriginGet}
|
||||
|
||||
let proxy_lt = Handle::from_raw(proxy);
|
||||
let vp_lt = MutableHandle::from_raw(vp);
|
||||
let mut vp_lt = MutableHandle::from_raw(vp);
|
||||
let id_lt = Handle::from_raw(id);
|
||||
let receiver_lt = Handle::from_raw(receiver);
|
||||
|
||||
{getIndexedOrExpando}
|
||||
let mut found = false;
|
||||
if !get_property_on_prototype(*cx, proxy_lt, receiver_lt, id_lt, &mut found, vp_lt) {{
|
||||
if !get_property_on_prototype(*cx, proxy_lt, receiver_lt, id_lt, &mut found, vp_lt.reborrow()) {{
|
||||
return false;
|
||||
}}
|
||||
|
||||
|
@ -7285,7 +7285,7 @@ impl{self.generic} Clone for {self.makeClassName(self.dictionary)}{self.genericS
|
|||
memberInserts = [memberInsert(m) for m in self.memberInfo]
|
||||
|
||||
if d.parent:
|
||||
memberInserts = [CGGeneric("self.parent.to_jsobject(cx, obj);\n")] + memberInserts
|
||||
memberInserts = [CGGeneric("self.parent.to_jsobject(cx, obj.reborrow());\n")] + memberInserts
|
||||
|
||||
selfName = self.makeClassName(d)
|
||||
if self.membersNeedTracing():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue