Skip to content

Add tests for Generator.prototype.return() with yield in finally#4939

Open
taras wants to merge 1 commit intotc39:mainfrom
taras:generator-return-yield-in-finally
Open

Add tests for Generator.prototype.return() with yield in finally#4939
taras wants to merge 1 commit intotc39:mainfrom
taras:generator-return-yield-in-finally

Conversation

@taras
Copy link

@taras taras commented Feb 20, 2026

Closes #4937

These tests cover the scenario where generator.return() is called while the generator is paused in a try block, and the finally block contains a yield statement. The existing tests don't cover this path:

  • try-finally-within-try.js: finally has no yield
  • try-finally-within-finally.js: generator already paused at yield in finally

New tests:

  • try-finally-yield-triggered-by-return.js: basic yield in finally during return
  • try-finally-nested-yields-triggered-by-return.js: nested try-finally with yields
  • try-finally-yield-resume-value-during-return.js: resume value to yield in finally
  • try-finally-throw-before-yield-during-return.js: throw before yield in finally
  • try-finally-throw-after-yield-during-return.js: throw after yield in finally
  • try-finally-yield-star-during-return.js: yield* in finally during return
  • try-finally-yield-star-delegation-return.js: yield* delegation with finally
  • try-finally-return-overrides-during-return.js: return in finally overrides value

All tests validated against V8 (Node.js), SpiderMonkey (Firefox), and JavaScriptCore (Safari).

This coverage gap was discovered while fixing a bug in Sobek (grafana/sobek#115), a Go-based JavaScript runtime.

@taras taras requested a review from a team as a code owner February 20, 2026 18:46
Tighten spec assertions for completion behavior after throws in finally and for return value propagation through yield* delegation during return.
@taras taras force-pushed the generator-return-yield-in-finally branch from cfed5ef to 7cad34b Compare February 20, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing tests for yield in finally block of a generator

2 participants