Skip to content

Fix Proxy construct trap receiving Array-constructor-mangled arguments#2670

Merged
lahma merged 1 commit into
sebastienros:mainfrom
lahma:proxy-construct-args
Jul 13, 2026
Merged

Fix Proxy construct trap receiving Array-constructor-mangled arguments#2670
lahma merged 1 commit into
sebastienros:mainfrom
lahma:proxy-construct-args

Conversation

@lahma

@lahma lahma commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

JsProxy.[[Construct]] built the trap's argumentsList with Array.Construct, i.e. JS Array(...) constructor semantics. A single numeric argument therefore hit the Array(length) path:

var p = new Proxy(function () {}, { construct: (t, args) => ({ len: args.length, first: args[0] }) });
new p(42)   // trap saw args.length === 42, args[0] === undefined; spec/V8: [42]
new p(1.5)  // threw RangeError: invalid array length; spec/V8: [1.5]

Per spec step 7 the list must be created with CreateArrayFromList — now uses ConstructFast, the same helper the [[Call]]/apply path already uses.

test262 misses this because built-ins/Proxy/construct/call-parameters.js constructs with two arguments. Cross-checked against node 24 / V8.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EsHuKuE4UihKZp5HYapDHE

@lahma
lahma enabled auto-merge (squash) July 13, 2026 12:55
@lahma
lahma force-pushed the proxy-construct-args branch from bc5088d to 44b3f37 Compare July 13, 2026 14:18
The [[Construct]] internal method built the trap's argumentsList via the
Array constructor, so a single numeric argument hit Array(length)
semantics: `new proxy(42)` handed the construct trap an empty array with
length 42 instead of [42], and `new proxy(1.5)` threw a spurious
RangeError (invalid array length). Per spec step 7
(https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-construct-argumentslist-newtarget)
the list must be created with CreateArrayFromList; use ConstructFast
like the [[Call]]/apply path already does.

test262 misses this because built-ins/Proxy/construct/call-parameters.js
constructs with two arguments. V8 (node 24) confirms the fixed behavior:
new p(42) -> args [42], new p(1.5) -> args [1.5].

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EsHuKuE4UihKZp5HYapDHE
@lahma
lahma force-pushed the proxy-construct-args branch from 44b3f37 to 1a5cc53 Compare July 13, 2026 14:30
@lahma
lahma merged commit 8d511b2 into sebastienros:main Jul 13, 2026
4 checks passed
@lahma
lahma deleted the proxy-construct-args branch July 13, 2026 14:42
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.

1 participant