Skip to content

vm: accessor properties get converted to data properties inside the vm #2734

Closed
@domenic

Description

@domenic

Example:

'use strict';
const vm = require('vm');

const x = {};
Object.defineProperty(x, 'prop', {
  get() { return 'foo'; }
});
const o = vm.createContext(x);

const code = 'Object.getOwnPropertyDescriptor(this, "prop")';
const res = vm.runInContext(code, o, 'test');

console.log(res);

gives

$ iojs test.js
Object {
  value: 'foo',
  writable: true,
  enumerable: false,
  configurable: false }

In 659dadd I fixed it to return the correct data descriptor. But it appears the accessor descriptor is just broken.

As far as I can tell this is a shortcoming of the V8 API. The named properties handler and the GlobalPropertyQueryCallback always returns data descriptors. This is probably because that is all that is required by Web IDL for the browser use case, where the named property handler is meant to be used for things like window.idOrName or window.forms.foo, which are always data descriptors.

I think Chrome also has this problem. Even for non-named properties, things like window.top are data descriptors. I'm asking related questions on blink-dev.

Original discovery: jsdom/jsdom#1208, where this is affecting Facebook's use in jest.

/cc @nodejs/v8

Metadata

Metadata

Assignees

No one assigned

    Labels

    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