Skip to content

Proxy getOwnPropertyDescriptor trap accepts an incompatible descriptor for a non-configurable property #1629

Description

@d01c2

Reproduction

const target = Object.defineProperty({}, "x", { value: 1 });

Object.getOwnPropertyDescriptor(
  new Proxy(target, { getOwnPropertyDescriptor() { return { value: 2 }; }}),
  "x"
);

Expected

A TypeError is thrown.

V8 (15.3.27):

d8> Object.getOwnPropertyDescriptor(new Proxy(target, { getOwnPropertyDescriptor() { return { value: 2 }; } }), "x");
TypeError: 'getOwnPropertyDescriptor' on proxy: trap returned descriptor for property 'x' that is incompatible with the existing property in the proxy target

Actual (QuickJS-ng)

QuickJS-ng accepts the incompatible descriptor:

qjs > Object.getOwnPropertyDescriptor(new Proxy(target, { getOwnPropertyDescriptor() { return { value: 2 }; } }), "x");
{ value: 2, writable: false, enumerable: false, configurable: false }

Spec

The target's "x" property is a non-configurable, non-writable data property whose value is 1.

The Proxy [[GetOwnProperty]] method converts and completes the descriptor returned by the getOwnPropertyDescriptor trap, then checks it using IsCompatiblePropertyDescriptor.

A non-configurable, non-writable data property cannot be reported with a different value. Since the trap reports the value as 2, the descriptor is incompatible with the target's existing property and [[GetOwnProperty]] must throw a TypeError.

Versions

  • QuickJS-ng: 0.16.0
  • V8: 15.3.27

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions