• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2require('../common');
3const assert = require('assert');
4
5const vm = require('vm');
6
7// https://github.com/nodejs/node/issues/10223
8const ctx = vm.createContext();
9
10// Define x with writable = false.
11vm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx);
12assert.strictEqual(ctx.x, 42);
13assert.strictEqual(vm.runInContext('x', ctx), 42);
14
15vm.runInContext('x = 0', ctx);                      // Does not throw but x...
16assert.strictEqual(vm.runInContext('x', ctx), 42);  // ...should be unaltered.
17
18assert.throws(() => vm.runInContext('"use strict"; x = 0', ctx),
19              /Cannot assign to read only property 'x'/);
20assert.strictEqual(vm.runInContext('x', ctx), 42);
21