Skip to content

Object.defineProperty on the global object does not handle 'writable' properly in vm context #10223

Closed
@i8-pi

Description

@i8-pi
  • Version: v6.9.2
  • Platform: Linux 4.8.12-3-ARCH SMP PREEMPT x86_64 GNU/Linux
  • Subsystem: vm

When running in a vm context, calling Object.defineProperty on the global object does not handle writable properly

'use strict';
const vm = require('vm');
const g = {console: console};
vm.createContext(g);
vm.runInContext(`
'use strict';
Object.defineProperty(this, 'dummy', {value: 'zxcv', 'writable': false});
console.log(Object.getOwnPropertyDescriptor(this, 'dummy'));
try {
    dummy = 'osef';
} catch(e) {
    console.log(e);
}
console.log(dummy);
`, g);

Output

{ value: 'zxcv',
  writable: true,
  enumerable: true,
  configurable: true }
TypeError: Cannot assign to read only property 'dummy' of object '#<Object>'
    at evalmachine.<anonymous>:7:11
    at ContextifyScript.Script.runInContext (vm.js:35:29)
    at Object.exports.runInContext (vm.js:67:17)
    at Object.<anonymous> (/home/i8-pi/src/zxcv.js:5:4)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
osef

Expected behaviour is that the property descriptor for dummy to have writable, enumerable and configurable == false. Omitting writable from the defineProperty call behaves in the same way as specifying it to be false. Also, assigning to dummy then actually changes the property value, even though the assignment throws an exception

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