Make Promise::reject unsafe

This commit is contained in:
Anthony Ramine 2017-09-22 14:04:07 +02:00
parent d246c5cf20
commit d31018d444

View file

@ -166,9 +166,9 @@ impl Promise {
rooted!(in(cx) let mut v = UndefinedValue()); rooted!(in(cx) let mut v = UndefinedValue());
unsafe { unsafe {
val.to_jsval(cx, v.handle_mut()); val.to_jsval(cx, v.handle_mut());
}
self.reject(cx, v.handle()); self.reject(cx, v.handle());
} }
}
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn reject_error(&self, error: Error) { pub fn reject_error(&self, error: Error) {
@ -177,20 +177,16 @@ impl Promise {
rooted!(in(cx) let mut v = UndefinedValue()); rooted!(in(cx) let mut v = UndefinedValue());
unsafe { unsafe {
error.to_jsval(cx, &self.global(), v.handle_mut()); error.to_jsval(cx, &self.global(), v.handle_mut());
}
self.reject(cx, v.handle()); self.reject(cx, v.handle());
} }
}
#[allow(unrooted_must_root, unsafe_code)] #[allow(unrooted_must_root, unsafe_code)]
pub fn reject(&self, pub unsafe fn reject(&self, cx: *mut JSContext, value: HandleValue) {
cx: *mut JSContext,
value: HandleValue) {
unsafe {
if !RejectPromise(cx, self.promise_obj(), value) { if !RejectPromise(cx, self.promise_obj(), value) {
JS_ClearPendingException(cx); JS_ClearPendingException(cx);
} }
} }
}
#[allow(unrooted_must_root, unsafe_code)] #[allow(unrooted_must_root, unsafe_code)]
pub fn then(&self, pub fn then(&self,