Skip to content

fix Promise.prototype.finally to correctly propagate onFinally errors#1725

Merged
Perryvw merged 2 commits into
TypeScriptToLua:masterfrom
pilaoda:fix/promise-finally
May 31, 2026
Merged

fix Promise.prototype.finally to correctly propagate onFinally errors#1725
Perryvw merged 2 commits into
TypeScriptToLua:masterfrom
pilaoda:fix/promise-finally

Conversation

@pilaoda
Copy link
Copy Markdown
Contributor

@pilaoda pilaoda commented May 28, 2026

Summary

  • Rewrite Promise.prototype.finally to match the TC39 reference polyfill: wrap onFinally() in a new Promise so errors are propagated instead of silently swallowed.
  • This also fixes async try/catch/finally re-throw, since the async transformation relies on Promise.finally to propagate errors through finally blocks.

Copilot AI review requested due to automatic review settings May 28, 2026 13:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes Promise.finally to conform to the ES spec: when the onFinally callback throws or returns a rejected promise, the resulting error now overrides the original fulfillment value or rejection reason. Also handles non-function arguments by delegating to .then.

Changes:

  • Reimplement Promise.prototype.finally to wrap the onFinally invocation in a new promise so its rejection propagates.
  • Add unit tests for Promise.finally covering throws and rejected-promise returns over both fulfilled and rejected chains.
  • Add async/await tests covering re-throwing in catch and overriding behavior of finally (throw and return).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/lualib/Promise.ts Rewrites finally to use the TC39 polyfill pattern so onFinally errors override the original outcome.
test/unit/builtins/promise.spec.ts Adds tests verifying that throws / rejected returns from finally override prior value or reason.
test/unit/builtins/async-await.spec.ts Adds async/await tests exercising re-throws and finally overriding catch results.

@Perryvw Perryvw merged commit bc88c58 into TypeScriptToLua:master May 31, 2026
5 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.

3 participants