mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Useful APIs for resolving/rejecting from native code.
This commit is contained in:
parent
fd778b4240
commit
7ba3172ce0
1 changed files with 18 additions and 0 deletions
|
@ -78,6 +78,15 @@ impl Promise {
|
|||
Ok(Promise::new_with_js_promise(p.handle()))
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn maybe_resolve_native<T>(&self, cx: *mut JSContext, val: &T) where T: ToJSValConvertible {
|
||||
rooted!(in(cx) let mut v = UndefinedValue());
|
||||
unsafe {
|
||||
val.to_jsval(cx, m.handle_mut());
|
||||
}
|
||||
self.maybe_resolve(cx, v.handle());
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root, unsafe_code)]
|
||||
pub fn maybe_resolve(&self,
|
||||
cx: *mut JSContext,
|
||||
|
@ -89,6 +98,15 @@ impl Promise {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn maybe_reject_native<T>(&self, cx: *mut JSContext, val: &T) where T: ToJSValConvertible {
|
||||
rooted!(in(cx) let mut v = UndefinedValue());
|
||||
unsafe {
|
||||
val.to_jsval(cx, m.handle_mut());
|
||||
}
|
||||
self.maybe_reject(cx, v.handle());
|
||||
}
|
||||
|
||||
#[allow(unrooted_must_root, unsafe_code)]
|
||||
pub fn maybe_reject(&self,
|
||||
cx: *mut JSContext,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue