Use out parameter for generated methods returning JSVal (#34087)

* Make generated bindings that return a WebIDL `any` value use out parameters.

Returning raw JSVal values makes it easier to create GC hazards in code
that calls these methods. Accepting a MutableHandle argument instead
ensures that the values are rooted by the caller.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Update mozjs.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Fix clippy warnings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2024-11-05 03:29:08 -05:00 committed by GitHub
parent 537958a3cc
commit 25a0764a37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 763 additions and 515 deletions

View file

@ -117,13 +117,15 @@ impl Clone for DOMJSClass {
unsafe impl Sync for DOMJSClass {}
/// Returns a JSVal representing the frozen JavaScript array
pub fn to_frozen_array<T: ToJSValConvertible>(convertibles: &[T], cx: SafeJSContext) -> JSVal {
rooted!(in(*cx) let mut ports = UndefinedValue());
unsafe { convertibles.to_jsval(*cx, ports.handle_mut()) };
pub fn to_frozen_array<T: ToJSValConvertible>(
convertibles: &[T],
cx: SafeJSContext,
rval: MutableHandleValue,
) {
unsafe { convertibles.to_jsval(*cx, rval) };
rooted!(in(*cx) let obj = ports.to_object());
rooted!(in(*cx) let obj = rval.to_object());
unsafe { JS_FreezeObject(*cx, RawHandleObject::from(obj.handle())) };
*ports
}
/// Returns the ProtoOrIfaceArray for the given global object.