mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
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:
parent
537958a3cc
commit
25a0764a37
38 changed files with 763 additions and 515 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue