mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
bindings: Support non-object this values for callbacks. (#35427)
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
cf3ad2de77
commit
cb3ecd4417
3 changed files with 24 additions and 22 deletions
|
@ -7,7 +7,6 @@
|
|||
use std::default::Default;
|
||||
use std::ffi::CString;
|
||||
use std::mem::drop;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
|
||||
use js::jsapi::{
|
||||
|
@ -15,7 +14,7 @@ use js::jsapi::{
|
|||
};
|
||||
use js::jsval::{JSVal, ObjectValue, UndefinedValue};
|
||||
use js::rust::wrappers::{JS_GetProperty, JS_WrapObject};
|
||||
use js::rust::{MutableHandleObject, Runtime};
|
||||
use js::rust::{MutableHandleValue, Runtime};
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::WindowMethods;
|
||||
use crate::dom::bindings::error::{report_pending_exception, Error, Fallible};
|
||||
|
@ -208,19 +207,22 @@ impl CallbackInterface {
|
|||
pub(crate) use script_bindings::callback::ThisReflector;
|
||||
|
||||
/// Wraps the reflector for `p` into the realm of `cx`.
|
||||
pub(crate) fn wrap_call_this_object<T: ThisReflector>(
|
||||
pub(crate) fn wrap_call_this_value<T: ThisReflector>(
|
||||
cx: JSContext,
|
||||
p: &T,
|
||||
mut rval: MutableHandleObject,
|
||||
) {
|
||||
rval.set(p.jsobject());
|
||||
assert!(!rval.get().is_null());
|
||||
mut rval: MutableHandleValue,
|
||||
) -> bool {
|
||||
rooted!(in(*cx) let mut obj = p.jsobject());
|
||||
assert!(!obj.is_null());
|
||||
|
||||
unsafe {
|
||||
if !JS_WrapObject(*cx, rval) {
|
||||
rval.set(ptr::null_mut());
|
||||
if !JS_WrapObject(*cx, obj.handle_mut()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
rval.set(ObjectValue(*obj));
|
||||
true
|
||||
}
|
||||
|
||||
/// A class that performs whatever setup we need to safely make a call while
|
||||
|
|
|
@ -14,11 +14,11 @@ pub(crate) mod base {
|
|||
};
|
||||
pub(crate) use js::jsval::{JSVal, NullValue, ObjectOrNullValue, ObjectValue, UndefinedValue};
|
||||
pub(crate) use js::panic::maybe_resume_unwind;
|
||||
pub(crate) use js::rust::wrappers::{JS_CallFunctionValue, JS_WrapValue};
|
||||
pub(crate) use js::rust::wrappers::{Call, JS_WrapValue};
|
||||
pub(crate) use js::rust::{HandleObject, HandleValue, MutableHandleObject, MutableHandleValue};
|
||||
|
||||
pub(crate) use crate::dom::bindings::callback::{
|
||||
wrap_call_this_object, CallSetup, CallbackContainer, CallbackFunction, CallbackInterface,
|
||||
wrap_call_this_value, CallSetup, CallbackContainer, CallbackFunction, CallbackInterface,
|
||||
CallbackObject, ExceptionHandling, ThisReflector,
|
||||
};
|
||||
pub(crate) use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue