Skip to content

Commit c3fb70b

Browse files
author
ashnaaseth2325-oss
authored
fix(promise): set [[PromiseIsHandled]] correctly (#4983)
## Summary This PR fixes how `[[PromiseIsHandled]]` is set in `Promise::perform_promise_then`. According to the ECMAScript spec, step 12 of **PerformPromiseThen** must run unconditionally. Currently, Boa sets `handled = true` only inside the **Rejected** branch, which means pending promises with a `.catch()` attached can still be reported as unhandled later. Example of the previous placement: ```rust PromiseState::Rejected(ref reason) => { // ... promise.borrow_mut().data_mut().handled = true; } ``` Because of this, promises that register a handler while still pending may incorrectly trigger the host rejection tracker. ## Steps to Reproduce Example JavaScript: ```javascript const p = new Promise((_, reject) => { Promise.resolve().then(() => reject("oops")); }); ``` p.catch(() => {}); **Expected behavior:** -The rejection is handled, so no unhandled-rejection tracking should occur. **Actual behavior before this fix:** -The host rejection tracker may fire because [[PromiseIsHandled]] was never set while the promise was pending. ## Impact Handled rejections can be reported as **unhandled**. Hosts relying on `HostPromiseRejectionTracker` may emit incorrect warnings or test failures. This mostly affects the common case where `.catch()` is attached before the promise settles. ## Fix Move the assignment of `[[PromiseIsHandled]]` so it runs after the match block, ensuring it applies regardless of the promise state. ```rust // Step 12. Set promise.[[PromiseIsHandled]] to true. promise.borrow_mut().data_mut().handled = true; ``` This aligns the implementation with ECMAScript §27.2.5.4.1 PerformPromiseThen step 12. ## Result -`[[PromiseIsHandled]]` is now set correctly for pending, fulfilled, and rejected promises. -Handled rejections no longer trigger spurious unhandled-rejection tracking. -Behavior now matches the ECMAScript specification. Signed-off-by: ashnaaseth2325-oss <ashnaaseth2325@gmail.com>
1 parent dc02d4f commit c3fb70b

File tree

1 file changed

+3
-3
lines changed
  • core/engine/src/builtins/promise

1 file changed

+3
-3
lines changed

core/engine/src/builtins/promise/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,12 +1904,12 @@ impl Promise {
19041904
context
19051905
.job_executor()
19061906
.enqueue_job(reject_job.into(), context);
1907-
1908-
// 12. Set promise.[[PromiseIsHandled]] to true.
1909-
promise.borrow_mut().data_mut().handled = true;
19101907
}
19111908
}
19121909

1910+
// 12. Set promise.[[PromiseIsHandled]] to true.
1911+
promise.borrow_mut().data_mut().handled = true;
1912+
19131913
// 13. If resultCapability is undefined, then
19141914
// a. Return undefined.
19151915
// 14. Else,

0 commit comments

Comments
 (0)