Fix crash when using Reflect.construct on a mock function - #29790
Closed
robobun wants to merge 2 commits into
Closed
Fix crash when using Reflect.construct on a mock function#29790robobun wants to merge 2 commits into
robobun wants to merge 2 commits into
Claude / Claude Code Review
completed
Apr 27, 2026 in 25m 56s
Code review found 1 potential issue
Found 1 candidates, confirmed 1. See review comments for details.
Details
| Severity | Count |
|---|---|
| 🔴 Important | 0 |
| 🟡 Nit | 1 |
| 🟣 Pre-existing | 0 |
| Severity | File:Line | Issue |
|---|---|---|
| 🟡 Nit | src/bun.js/bindings/JSMockFunction.cpp:985-1003 |
Construct fallback object created after impl runs, losing this-mutations |
Annotations
Check warning on line 1003 in src/bun.js/bindings/JSMockFunction.cpp
claude / Claude Code Review
Construct fallback object created after impl runs, losing this-mutations
Nit: the fallback object is allocated *after* the implementation runs (which is invoked as a plain `[[Call]]` with `callframe->thisValue()`), so for `new (jest.fn(function(){ this.x = 42 }))()` the `this.x = 42` lands on the wrong object and the returned instance is an empty `{}` — Jest yields `{x: 42}`. Not blocking — this is still a strict improvement over the crash — but the "matching ordinary `[[Construct]]` semantics" claim doesn't hold for the constructor‑assigns‑to‑`this` pattern; a fulle
Loading