2017-01-20 19:44:56 +01:00
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
2017-10-17 17:27:27 +02:00
|
|
|
|
2017-01-20 19:44:56 +01:00
|
|
|
const vm = require('vm');
|
|
|
|
|
2017-10-17 17:27:27 +02:00
|
|
|
// https://github.com/nodejs/node/issues/10223
|
2017-01-20 19:44:56 +01:00
|
|
|
const ctx = vm.createContext();
|
2017-10-17 17:27:27 +02:00
|
|
|
|
|
|
|
// Define x with writable = false.
|
2017-01-20 19:44:56 +01:00
|
|
|
vm.runInContext('Object.defineProperty(this, "x", { value: 42 })', ctx);
|
2017-10-17 17:27:27 +02:00
|
|
|
assert.strictEqual(ctx.x, 42);
|
2017-01-20 19:44:56 +01:00
|
|
|
assert.strictEqual(vm.runInContext('x', ctx), 42);
|
2017-10-17 17:27:27 +02:00
|
|
|
|
2017-01-20 19:44:56 +01:00
|
|
|
vm.runInContext('x = 0', ctx); // Does not throw but x...
|
|
|
|
assert.strictEqual(vm.runInContext('x', ctx), 42); // ...should be unaltered.
|
2017-10-17 17:27:27 +02:00
|
|
|
|
2017-01-20 19:44:56 +01:00
|
|
|
assert.throws(() => vm.runInContext('"use strict"; x = 0', ctx),
|
|
|
|
/Cannot assign to read only property 'x'/);
|
|
|
|
assert.strictEqual(vm.runInContext('x', ctx), 42);
|