mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -548,16 +548,12 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
|
|||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-customelementregistry-get>
|
||||
#[allow(unsafe_code)]
|
||||
fn Get(&self, cx: JSContext, name: DOMString) -> JSVal {
|
||||
fn Get(&self, cx: JSContext, name: DOMString, mut retval: MutableHandleValue) {
|
||||
match self.definitions.borrow().get(&LocalName::from(&*name)) {
|
||||
Some(definition) => unsafe {
|
||||
rooted!(in(*cx) let mut constructor = UndefinedValue());
|
||||
definition
|
||||
.constructor
|
||||
.to_jsval(*cx, constructor.handle_mut());
|
||||
constructor.get()
|
||||
definition.constructor.to_jsval(*cx, retval);
|
||||
},
|
||||
None => UndefinedValue(),
|
||||
None => retval.set(UndefinedValue()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -994,7 +990,13 @@ impl CustomElementReaction {
|
|||
.iter()
|
||||
.map(|arg| unsafe { HandleValue::from_raw(arg.handle()) })
|
||||
.collect();
|
||||
let _ = callback.Call_(element, arguments, ExceptionHandling::Report);
|
||||
rooted!(in(*GlobalScope::get_cx()) let mut value: JSVal);
|
||||
let _ = callback.Call_(
|
||||
element,
|
||||
arguments,
|
||||
value.handle_mut(),
|
||||
ExceptionHandling::Report,
|
||||
);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue