script: Correctly convert a jsval to a Promise (#36403)

Fixes an oversight of #36097, in which converting to a Promise would
fail if the value passed wasn't actually a Promise, while in binding
code we actually call `Promise::new_resolved` on the value.

Testing: There are wpt tests that should pass now

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This commit is contained in:
Gae24 2025-04-09 18:35:35 +02:00 committed by GitHub
parent 3b41a16fcf
commit 64b401696a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View file

@ -411,10 +411,12 @@ impl FromJSValConvertibleRc for Promise {
return Ok(ConversionResult::Failure("not an object".into()));
}
rooted!(in(cx) let obj = value.get().to_object());
if !IsPromiseObject(obj.handle()) {
return Ok(ConversionResult::Failure("not a promise".into()));
}
let promise = Promise::new_with_js_promise(obj.handle(), SafeJSContext::from_ptr(cx));
let cx = SafeJSContext::from_ptr(cx);
let in_realm_proof = AlreadyInRealm::assert_for_cx(cx);
let global_scope = GlobalScope::from_context(*cx, InRealm::Already(&in_realm_proof));
let promise = Promise::new_resolved(&global_scope, cx, *obj, CanGc::note());
Ok(ConversionResult::Success(promise))
}
}