aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/script/dom/promise.rs23
-rw-r--r--components/script/dom/testbinding.rs1
-rw-r--r--components/script_bindings/codegen/Bindings.conf2
-rw-r--r--components/script_bindings/webidls/TestBinding.webidl1
4 files changed, 25 insertions, 2 deletions
diff --git a/components/script/dom/promise.rs b/components/script/dom/promise.rs
index d7c309a7ded..dd09b1df3a1 100644
--- a/components/script/dom/promise.rs
+++ b/components/script/dom/promise.rs
@@ -15,7 +15,7 @@ use std::ptr;
use std::rc::Rc;
use dom_struct::dom_struct;
-use js::conversions::ToJSValConvertible;
+use js::conversions::{ConversionResult, FromJSValConvertibleRc, ToJSValConvertible};
use js::jsapi::{
AddRawValueRoot, CallArgs, GetFunctionNativeReserved, Heap, JS_ClearPendingException,
JS_GetFunctionObject, JS_NewFunction, JSAutoRealm, JSContext, JSObject,
@@ -405,3 +405,24 @@ impl PromiseHelpers<crate::DomTypeHolder> for Promise {
Promise::new_resolved(global, cx, value, CanGc::note())
}
}
+
+impl FromJSValConvertibleRc for Promise {
+ #[allow(unsafe_code)]
+ unsafe fn from_jsval(
+ cx: *mut JSContext,
+ value: HandleValue,
+ ) -> Result<ConversionResult<Rc<Promise>>, ()> {
+ if value.get().is_null() {
+ return Ok(ConversionResult::Failure("null not allowed".into()));
+ }
+ if !value.get().is_object() {
+ return Ok(ConversionResult::Failure("not an object".into()));
+ }
+ rooted!(in(cx) let obj = value.get().to_object());
+ if !IsPromiseObject(obj.handle()) {
+ return Ok(ConversionResult::Failure("not a promise".into()));
+ }
+ let promise = Promise::new_with_js_promise(obj.handle(), SafeJSContext::from_ptr(cx));
+ Ok(ConversionResult::Success(promise))
+ }
+}
diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs
index d03196de940..4095ba1319a 100644
--- a/components/script/dom/testbinding.rs
+++ b/components/script/dom/testbinding.rs
@@ -910,6 +910,7 @@ impl TestBindingMethods<crate::DomTypeHolder> for TestBinding {
fn FuncControlledMethodDisabled(&self) {}
fn FuncControlledMethodEnabled(&self) {}
+ fn PassRecordPromise(&self, _: Record<DOMString, Rc<Promise>>) {}
fn PassRecord(&self, _: Record<DOMString, i32>) {}
fn PassRecordWithUSVStringKey(&self, _: Record<USVString, i32>) {}
fn PassRecordWithByteStringKey(&self, _: Record<ByteString, i32>) {}
diff --git a/components/script_bindings/codegen/Bindings.conf b/components/script_bindings/codegen/Bindings.conf
index 4fa998a84c3..d5b1dc5c281 100644
--- a/components/script_bindings/codegen/Bindings.conf
+++ b/components/script_bindings/codegen/Bindings.conf
@@ -490,7 +490,7 @@ DOMInterfaces = {
'Promise': {
'spiderMonkeyInterface': True,
- 'additionalTraits': ["crate::dom::promise::PromiseHelpers<Self>"]
+ 'additionalTraits': ["crate::dom::promise::PromiseHelpers<Self>", "js::conversions::FromJSValConvertibleRc"]
},
'Range': {
diff --git a/components/script_bindings/webidls/TestBinding.webidl b/components/script_bindings/webidls/TestBinding.webidl
index 88f1b4d51f7..92d95e4fe73 100644
--- a/components/script_bindings/webidls/TestBinding.webidl
+++ b/components/script_bindings/webidls/TestBinding.webidl
@@ -479,6 +479,7 @@ interface TestBinding {
sequence<sequence<long>> returnSequenceSequence();
undefined passUnionSequenceSequence((long or sequence<sequence<long>>) seq);
+ undefined passRecordPromise(record<DOMString, Promise<undefined>> arg);
undefined passRecord(record<DOMString, long> arg);
undefined passRecordWithUSVStringKey(record<USVString, long> arg);
undefined passRecordWithByteStringKey(record<ByteString, long> arg);