Commit c3fb70b
ashnaaseth2325-oss
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
1 file changed
+3
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1904 | 1904 | | |
1905 | 1905 | | |
1906 | 1906 | | |
1907 | | - | |
1908 | | - | |
1909 | | - | |
1910 | 1907 | | |
1911 | 1908 | | |
1912 | 1909 | | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
1913 | 1913 | | |
1914 | 1914 | | |
1915 | 1915 | | |
| |||
0 commit comments