diff options
Diffstat (limited to 'components/script/dom/bindings')
-rw-r--r-- | components/script/dom/bindings/callback.rs | 22 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 2 | ||||
-rw-r--r-- | components/script/dom/bindings/import.rs | 2 |
3 files changed, 21 insertions, 5 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 { diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 291ec47a0b0..bb0351a20fa 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -7212,7 +7212,7 @@ class CGCallback(CGClass): }) return [ClassMethod(method.name + '_', method.returnType, args, bodyInHeader=True, - templateArgs=["T: DomObject"], + templateArgs=["T: ThisReflector"], body=bodyWithThis, visibility='pub'), ClassMethod(method.name + '__', method.returnType, argsWithoutThis, diff --git a/components/script/dom/bindings/import.rs b/components/script/dom/bindings/import.rs index f2c6a5e2b81..6509acc2207 100644 --- a/components/script/dom/bindings/import.rs +++ b/components/script/dom/bindings/import.rs @@ -19,7 +19,7 @@ pub mod base { pub use crate::dom::bindings::callback::{ wrap_call_this_object, CallSetup, CallbackContainer, CallbackFunction, CallbackInterface, - CallbackObject, ExceptionHandling, + CallbackObject, ExceptionHandling, ThisReflector, }; pub use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{ ChannelCountMode, ChannelCountModeValues, ChannelInterpretation, |