Add a simple API to reject promises with DOM error values.

This commit is contained in:
Josh Matthews 2016-09-06 19:58:26 -04:00
parent ae81ab3972
commit 27d44c8d10
5 changed files with 35 additions and 2 deletions

View file

@ -14,7 +14,7 @@
use dom::bindings::callback::CallbackContainer;
use dom::bindings::codegen::Bindings::PromiseBinding::AnyCallback;
use dom::bindings::conversions::root_from_object;
use dom::bindings::error::Fallible;
use dom::bindings::error::{Error, Fallible};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::MutHeapJSVal;
use dom::bindings::reflector::{Reflectable, MutReflectable, Reflector};
@ -156,6 +156,15 @@ impl Promise {
self.maybe_reject(cx, v.handle());
}
#[allow(unsafe_code)]
pub fn maybe_reject_error(&self, cx: *mut JSContext, error: Error) {
rooted!(in(cx) let mut v = UndefinedValue());
unsafe {
error.maybe_to_jsval(cx, self.global().r(), v.handle_mut());
}
self.maybe_reject(cx, v.handle());
}
#[allow(unrooted_must_root, unsafe_code)]
pub fn maybe_reject(&self,
cx: *mut JSContext,