Skip to content

fix(promise): set [[PromiseIsHandled]] correctly#4983

Merged
jedel1043 merged 1 commit intoboa-dev:mainfrom
ashnaaseth2325-oss:fix/promise-is-handled-pending
Mar 10, 2026
Merged

fix(promise): set [[PromiseIsHandled]] correctly#4983
jedel1043 merged 1 commit intoboa-dev:mainfrom
ashnaaseth2325-oss:fix/promise-is-handled-pending

Conversation

@ashnaaseth2325-oss
Copy link
Copy Markdown

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:

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:

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.

// 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.

…iseThen

Step 12 of the PerformPromiseThen spec (§27.2.5.4.1) requires setting
promise.[[PromiseIsHandled]] to true regardless of the promise's current
state. The flag was only being set inside the Rejected branch, leaving it
false for pending promises with attached handlers. This caused RejectPromise
to fire spurious HostPromiseRejectionTracker("reject") events even when a
.catch() handler was already registered.

Signed-off-by: ashnaaseth2325-oss <ashnaaseth2325@gmail.com>
@github-actions
Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 49,713 49,713 0
Ignored 2,262 2,262 0
Failed 988 988 0
Panics 0 0 0
Conformance 93.86% 93.86% 0.00%

Tested main commit: dc02d4f354ac278dd845f529a3331001c4ea0ede
Tested PR commit: 2c0cd6df030e07d4e2bac06101b029270ae20011
Compare commits: dc02d4f...2c0cd6d

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.36%. Comparing base (6ddc2b4) to head (2c0cd6d).
⚠️ Report is 800 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #4983       +/-   ##
===========================================
+ Coverage   47.24%   58.36%   +11.12%     
===========================================
  Files         476      556       +80     
  Lines       46892    61154    +14262     
===========================================
+ Hits        22154    35695    +13541     
- Misses      24738    25459      +721     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@jedel1043 jedel1043 added this pull request to the merge queue Mar 10, 2026
Merged via the queue into boa-dev:main with commit c3fb70b Mar 10, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants