Useful APIs for resolving/rejecting from native code.

This commit is contained in:
Josh Matthews 2016-08-12 02:35:44 -04:00
parent fd778b4240
commit 7ba3172ce0

View file

@ -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,