mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Mark promise creation methods with CanGc (#33928)
* Add CanGc annotations to promise constructor. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Propagate CanGc arguments for Promise::new_in_current_realm. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix out-of-order entries. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Propagate CanGc from Promise::new. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Suppress clippy warning. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
edc304854f
commit
575e885529
50 changed files with 422 additions and 221 deletions
|
@ -86,16 +86,16 @@ impl Drop for Promise {
|
|||
}
|
||||
|
||||
impl Promise {
|
||||
pub fn new(global: &GlobalScope) -> Rc<Promise> {
|
||||
pub fn new(global: &GlobalScope, can_gc: CanGc) -> Rc<Promise> {
|
||||
let realm = enter_realm(global);
|
||||
let comp = InRealm::Entered(&realm);
|
||||
Promise::new_in_current_realm(comp)
|
||||
Promise::new_in_current_realm(comp, can_gc)
|
||||
}
|
||||
|
||||
pub fn new_in_current_realm(_comp: InRealm) -> Rc<Promise> {
|
||||
pub fn new_in_current_realm(_comp: InRealm, can_gc: CanGc) -> Rc<Promise> {
|
||||
let cx = GlobalScope::get_cx();
|
||||
rooted!(in(*cx) let mut obj = ptr::null_mut::<JSObject>());
|
||||
Promise::create_js_promise(cx, obj.handle_mut());
|
||||
Promise::create_js_promise(cx, obj.handle_mut(), can_gc);
|
||||
Promise::new_with_js_promise(obj.handle(), cx)
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,9 @@ impl Promise {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
fn create_js_promise(cx: SafeJSContext, mut obj: MutableHandleObject) {
|
||||
// The apparently-unused CanGc parameter reflects the fact that the JS API calls
|
||||
// like JS_NewFunction can trigger a GC.
|
||||
fn create_js_promise(cx: SafeJSContext, mut obj: MutableHandleObject, _can_gc: CanGc) {
|
||||
unsafe {
|
||||
let do_nothing_func = JS_NewFunction(
|
||||
*cx,
|
||||
|
@ -253,18 +255,25 @@ impl Promise {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn append_native_handler(&self, handler: &PromiseNativeHandler, _comp: InRealm) {
|
||||
pub fn append_native_handler(
|
||||
&self,
|
||||
handler: &PromiseNativeHandler,
|
||||
_comp: InRealm,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
let _ais = AutoEntryScript::new(&handler.global());
|
||||
let cx = GlobalScope::get_cx();
|
||||
rooted!(in(*cx) let resolve_func =
|
||||
create_native_handler_function(*cx,
|
||||
handler.reflector().get_jsobject(),
|
||||
NativeHandlerTask::Resolve));
|
||||
NativeHandlerTask::Resolve,
|
||||
can_gc));
|
||||
|
||||
rooted!(in(*cx) let reject_func =
|
||||
create_native_handler_function(*cx,
|
||||
handler.reflector().get_jsobject(),
|
||||
NativeHandlerTask::Reject));
|
||||
NativeHandlerTask::Reject,
|
||||
can_gc));
|
||||
|
||||
unsafe {
|
||||
let ok = AddPromiseReactions(
|
||||
|
@ -335,10 +344,13 @@ unsafe extern "C" fn native_handler_callback(
|
|||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
// The apparently-unused CanGc argument reflects the fact that the JS API calls
|
||||
// like NewFunctionWithReserved can trigger a GC.
|
||||
fn create_native_handler_function(
|
||||
cx: *mut JSContext,
|
||||
holder: HandleObject,
|
||||
task: NativeHandlerTask,
|
||||
_can_gc: CanGc,
|
||||
) -> *mut JSObject {
|
||||
unsafe {
|
||||
let func = NewFunctionWithReserved(cx, Some(native_handler_callback), 1, 0, ptr::null());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue