Skip to content

Commit

Permalink
Useful APIs for resolving/rejecting from native code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Sep 22, 2016
1 parent fd778b4 commit 7ba3172
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions components/script/dom/promise.rs
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 7ba3172

Please sign in to comment.