Skip to content

Proxy [[Construct]] forwarding doesn't honor newTarget.prototype (subclassing) #3877

@proggeramlug

Description

@proggeramlug

Follow-up to #3656 (PR #3875). After Proxy apply/construct trap dispatch landed, three built-ins/Proxy/construct cases remain:

  • construct/trap-is-missing-target-is-proxy.js
  • construct/trap-is-null-target-is-proxy.js
  • construct/trap-is-undefined-target-is-proxy.js

Cause

A [[Construct]] forwarded through a trap-less proxy chain to a class / bound-constructor / builtin (Array) does not honor newTarget.prototype when allocating the instance. forward_construct constructs from the target function but ignores the threaded newTarget, so instanceof newTarget, inherited getters from class X extends …, and Array subclassing fail.

Repro

class Foo { constructor(a){ this.arg = a; } }
class Bar extends Foo { get isBar(){ return true; } }
var FooProxy = new Proxy(new Proxy(Foo, {}), { construct: null });
var bar = Reflect.construct(FooProxy, [2], Bar);
// expected: bar instanceof Bar, bar.arg === 2, bar.isBar

Scope

Honor an explicit newTarget in the forwarded [[Construct]] path: allocate the instance with newTarget.prototype and run the target constructor against it (OrdinaryCreateFromConstructor semantics), including builtin subclassing (extends Array). Orthogonal to the proxy trap machinery itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions