aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/script/dom/bindings/callback.rs22
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py2
-rw-r--r--components/script/dom/bindings/import.rs2
-rw-r--r--components/script/dom/underlyingsourcecontainer.rs11
4 files changed, 31 insertions, 6 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,
diff --git a/components/script/dom/underlyingsourcecontainer.rs b/components/script/dom/underlyingsourcecontainer.rs
index a6d6d750ce1..8c6387c924a 100644
--- a/components/script/dom/underlyingsourcecontainer.rs
+++ b/components/script/dom/underlyingsourcecontainer.rs
@@ -16,6 +16,8 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
use crate::dom::readablestreamdefaultcontroller::ReadableStreamDefaultController;
use crate::js::conversions::ToJSValConvertible;
+use js::jsapi::JSObject;
+use std::ptr;
/// <https://streams.spec.whatwg.org/#underlying-source-api>
/// The `Js` variant corresponds to
@@ -85,11 +87,18 @@ impl UnderlyingSourceContainer {
}
/// <https://streams.spec.whatwg.org/#dom-underlyingsource-pull>
+ #[allow(unsafe_code)]
pub fn call_pull_algorithm(&self, controller: Controller) -> Option<Rc<Promise>> {
if let UnderlyingSourceType::Js(source) = &self.underlying_source_type {
let global = self.global();
let promise = if let Some(pull) = &source.pull {
- pull.Call_(&*self, controller, ExceptionHandling::Report)
+ let cx = GlobalScope::get_cx();
+ rooted!(in(*cx) let mut this_object = ptr::null_mut::<JSObject>());
+ unsafe {
+ source.to_jsobject(*cx, this_object.handle_mut());
+ }
+ let this_handle = this_object.handle();
+ pull.Call_(&this_handle, controller, ExceptionHandling::Report)
.expect("Pull algorithm call failed")
} else {
let promise = Promise::new(&*global);