fix Promise.prototype.finally to correctly propagate onFinally errors#1725
Merged
Conversation
There was a problem hiding this comment.
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.finallyto wrap theonFinallyinvocation in a new promise so its rejection propagates. - Add unit tests for
Promise.finallycovering 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Promise.prototype.finallyto match the TC39 reference polyfill: wraponFinally()in a new Promise so errors are propagated instead of silently swallowed.Promise.finallyto propagate errors through finally blocks.