Skip to content

Object.getOwnPropertyDescriptor operator in VM uses [[Get]] instead of [[GetOwnProperty]] #17481

Closed
@TimothyGu

Description

@TimothyGu
  • Version: master
  • Platform: all
  • Subsystem: vm

Very similar to #17480, except the issue now is with Object.getOwnPropertyDescriptor rather than in operator.

const globals = {};
const handlers = {};
const realHandlers = Reflect.ownKeys(Reflect).reduce((handlers, p) => {
  handlers[p] = (t, ...args) => {
    // Avoid printing the Receiver argument, which can lead to an infinite loop.
    console.log(p, ...(p === 'get' || p === 'set' ? args.slice(0, -1) : args));
    return Reflect[p](t, ...args);
  };
  return handlers;
}, {});
const proxy = vm.createContext(new Proxy(globals, handlers));

// Indirection needed to mitigate against #17465
// https://github.com/nodejs/node/issues/17465
const globalProxy = vm.runInContext('this', proxy);
for (const k of Reflect.ownKeys(globalProxy)) {
  Object.defineProperty(globals, k, Object.getOwnPropertyDescriptor(globalProxy, k));
}
Object.assign(handlers, realHandlers);

Object.getOwnPropertyDescriptor(proxy, "a")
  // prints "getOwnPropertyDescriptor a"
  // returns undefined

vm.runInContext('Object.getOwnPropertyDescriptor(this, "a")', proxy);
  // prints "get Object"
  // prints "getOwnPropertyDescriptor a"
  // prints "get a"
  // prints "get a"
  // returns { value: undefined,
  //           writable: true,
  //           enumerable: false,
  //           configurable: true } (because of https://github.com/nodejs/node/issues/17465)

Metadata

Metadata

Assignees

No one assigned

    Labels

    v8 engineIssues and PRs related to the V8 dependency.vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions