aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/callback.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2024-07-15 09:41:42 -0400
committerJosh Matthews <josh@joshmatthews.net>2024-07-15 09:41:42 -0400
commitb65ba8df924db6d0f2263798c6d8810dd953b64f (patch)
tree6ce3fcf52a7e7522e5fe45fdd45feff9f8881e4d /components/script/dom/bindings/callback.rs
parent09f1360ad338fe485d8bd3ef632cf8a961673369 (diff)
downloadservo-dictionary-callback.tar.gz
servo-dictionary-callback.zip
Demonstrate using dictionary as callback this object.dictionary-callback
Diffstat (limited to 'components/script/dom/bindings/callback.rs')
-rw-r--r--components/script/dom/bindings/callback.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs
index 178c74e888f..998e48b5fbe 100644
--- a/components/script/dom/bindings/callback.rs
+++ b/components/script/dom/bindings/callback.rs
@@ -15,7 +15,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::{HandleObject, MutableHandleObject, Runtime};
use crate::dom::bindings::codegen::Bindings::WindowBinding::Window_Binding::WindowMethods;
use crate::dom::bindings::error::{report_pending_exception, Error, Fallible};
@@ -206,9 +206,25 @@ impl CallbackInterface {
}
}
+pub trait ThisReflector {
+ fn jsobject(&self) -> *mut JSObject;
+}
+
+impl <T: DomObject> ThisReflector for T {
+ fn jsobject(&self) -> *mut JSObject {
+ self.reflector().get_jsobject().get()
+ }
+}
+
+impl <'a> ThisReflector for HandleObject<'a> {
+ fn jsobject(&self) -> *mut JSObject {
+ self.get()
+ }
+}
+
/// Wraps the reflector for `p` into the realm of `cx`.
-pub fn wrap_call_this_object<T: DomObject>(cx: JSContext, p: &T, mut rval: MutableHandleObject) {
- rval.set(p.reflector().get_jsobject().get());
+pub fn wrap_call_this_object<T: ThisReflector>(cx: JSContext, p: &T, mut rval: MutableHandleObject) {
+ rval.set(p.jsobject());
assert!(!rval.get().is_null());
unsafe {