mirror of
https://github.com/servo/servo.git
synced 2025-07-16 20:03:39 +01:00
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:
parent
3b41a16fcf
commit
64b401696a
2 changed files with 6 additions and 7 deletions
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue