Use task! to reject promises

This commit is contained in:
Anthony Ramine 2017-09-18 10:41:16 +02:00
parent ad41ce7a6f
commit 851d40b204

View file

@ -123,18 +123,14 @@ impl TrustedPromise {
/// A task which will reject the promise. /// A task which will reject the promise.
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn reject_task(self, error: Error) -> impl Send + Task { pub fn reject_task(self, error: Error) -> impl Send + Task {
struct RejectPromise(TrustedPromise, Error); let this = self;
impl Task for RejectPromise { task!(reject_promise: move || {
fn run(self: Box<Self>) { debug!("Rejecting promise.");
debug!("Rejecting promise."); let this = this.root();
let this = *self; let cx = this.global().get_cx();
let promise = this.0.root(); let _ac = JSAutoCompartment::new(cx, this.reflector().get_jsobject().get());
let cx = promise.global().get_cx(); this.reject_error(cx, error);
let _ac = JSAutoCompartment::new(cx, promise.reflector().get_jsobject().get()); })
promise.reject_error(cx, this.1);
}
}
RejectPromise(self, error)
} }
/// A task which will resolve the promise. /// A task which will resolve the promise.