Commit 5207a3b
fix(vm): fix CompletionRecord semantics for Yield and Return opcodes (#4880)
## Summary
Fixes issue #2675 — Evaluate/Reevaluate the execution semantics of
`CompletionRecord`
## Root Cause
Boa's VM was previously emitting the wrong `CompletionRecord` variants
for yield and return in generator contexts:
- Yield was emitting `CompletionRecord::Return` (non-normal).
- Return was emitting `CompletionRecord::Normal`.
Both were swapped from what the ECMAScript spec requires. The generator
drive loop had its arms swapped to compensate, making the code confusing
and fragile.
## Changes
- **Sub-issue 1 — Audit**: Audited `CompletionRecord` emit/match sites
across `vm/opcode/` and `builtins/generator/`. Scope confirmed minimal —
only 2 files required changes.
- **Sub-issue 2 — Fix Yield opcode**: `Context::handle_yield` now
correctly emits `CompletionRecord::Normal` per spec §27.5.3.7.
- **Sub-issue 3 — Fix Return opcode**: `Context::handle_return` now
correctly emits `CompletionRecord::Return` per spec §14.4.
- **Sub-issue 4 — Generator drive loop**: Swapped match arms in both
`generator_resume` and `generator_resume_abrupt` so `Normal →
SuspendedYield` and `Return → Completed`.
## Testing
- [x] All existing generator tests pass.
- [x] Added 3 new regression tests covering yield, return, and
early-return scenarios.
- [x] Test262 generator suite passing with no regressions.
Co-authored-by: Nakshatra Sharma <nakshatrasharma@Nakshatras-MacBook-Air.local>1 parent 2e6d209 commit 5207a3b
2 files changed
+6
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
| 322 | + | |
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
413 | | - | |
| 413 | + | |
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
782 | 782 | | |
783 | 783 | | |
784 | 784 | | |
785 | | - | |
| 785 | + | |
786 | 786 | | |
787 | 787 | | |
788 | 788 | | |
| |||
793 | 793 | | |
794 | 794 | | |
795 | 795 | | |
796 | | - | |
| 796 | + | |
797 | 797 | | |
798 | 798 | | |
799 | 799 | | |
| |||
0 commit comments