From 64b401696aea71bf9ffe0aed4f87911c9a73e28c Mon Sep 17 00:00:00 2001 From: Gae24 <96017547+Gae24@users.noreply.github.com> Date: Wed, 9 Apr 2025 18:35:35 +0200 Subject: [PATCH] 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> --- components/script/dom/promise.rs | 10 ++++++---- .../meta/clipboard-apis/clipboard-item.https.html.ini | 3 --- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/components/script/dom/promise.rs b/components/script/dom/promise.rs index 1ac1aa52a45..80b62f161bc 100644 --- a/components/script/dom/promise.rs +++ b/components/script/dom/promise.rs @@ -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)) } } diff --git a/tests/wpt/meta/clipboard-apis/clipboard-item.https.html.ini b/tests/wpt/meta/clipboard-apis/clipboard-item.https.html.ini index a76ef482f19..2a5d4f9792e 100644 --- a/tests/wpt/meta/clipboard-apis/clipboard-item.https.html.ini +++ b/tests/wpt/meta/clipboard-apis/clipboard-item.https.html.ini @@ -2,9 +2,6 @@ [ClipboardItem({string, Blob}) succeeds with different types] expected: FAIL - [ClipboardItem() succeeds with empty options] - expected: FAIL - [types() returns correct values] expected: FAIL