You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

26 lines
644 B

'use strict';
require('../common');
const assert = require('assert');
const vm = require('vm');
const code =
'Object.defineProperty(this, "f", {\n' +
' get: function() { return x; },\n' +
' set: function(k) { x = k; },\n' +
' configurable: true,\n' +
' enumerable: true\n' +
'});\n' +
'g = f;\n' +
'f;\n';
const x = {};
const o = vm.createContext({ console: console, x: x });
const res = vm.runInContext(code, o, 'test');
assert(res);
assert.strictEqual(typeof res, 'object');
assert.strictEqual(res, x);
assert.strictEqual(o.f, res);
assert.deepStrictEqual(Object.keys(o), ['console', 'x', 'g', 'f']);