Skip to content

VM context object silently fails on Object.defineProperty #5679

Closed
@kriskowal

Description

@kriskowal
  • Version: problem exists in 0.12.9 and later, does not exist in 0.10.36
  • Platform: Darwin XXXX 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
  • Subsystem: vm

The following script creates a VM context and runs a script that adds a property to that context, redefines that property as immutable, attempts to assign to that property, logs the error if there is one, then logs the value and property descriptor.

Expected behavior (exhibited in Node.js v0.10.36):

Cannot assign to read only property 'x' of #<Object>
20
{ value: 20,
  writable: false,
  enumerable: false,
  configurable: false }

Actual behavior (exhibited in Node.js v4.3.1, v5.8.0):

Cannot assign to read only property 'x' of #<Object>
30
{ value: 30,
  writable: true,
  enumerable: true,
  configurable: true }
var vm = require('vm');

var script = '(' + function () {
    'use strict';
    global.x = 10;
    Object.defineProperty(global, 'x', {
        writable: false,
        enumerable: false,
        configurable: false,
        value: 20
    });
    try {
        x = 30;
    } catch (e) {
        console.error(e);
    }
    console.log(x); // should be 20
    console.log(Object.getOwnPropertyDescriptor(global, 'x'));
} + ')()';

var global = {};
global.console = console;
global.global = global;

var context = vm.createContext(global);
vm.runInContext(script, context);

cc @erights

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