Skip to content

Instantly share code, notes, and snippets.

@AnnaMag
Created January 14, 2017 17:22
Show Gist options
  • Save AnnaMag/bc5201b057e03203f57210e7c7ec278d to your computer and use it in GitHub Desktop.
Save AnnaMag/bc5201b057e03203f57210e7c7ec278d to your computer and use it in GitHub Desktop.
test vm 3
'use strict';
// Refs: https://github.com/nodejs/node/issues/2734
require('../common');
const assert = require('assert');
const vm = require('vm');
const util = require('util');
const sandbox = { globalVar: 1, v: 12 };
Object.defineProperty(sandbox, 'prop', {
get() {
return 'foo';
}
});
const descriptor = Object.getOwnPropertyDescriptor(sandbox, 'prop');
const context = vm.createContext(sandbox);
const code = 'Object.getOwnPropertyDescriptor(this, "prop");';
var result = vm.runInContext(code, context);
console.log(util.inspect(sandbox));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment