Skip to content

Instantly share code, notes, and snippets.

@AnnaMag
Created January 14, 2017 17:22
Show Gist options
  • Save AnnaMag/c0de1176433443afb8b6c505db756059 to your computer and use it in GitHub Desktop.
Save AnnaMag/c0de1176433443afb8b6c505db756059 to your computer and use it in GitHub Desktop.
vm test 2
'use strict';
require('../common');
var assert = require('assert');
var vm = require('vm');
const util = require('util');
const sandbox = { globalVar: 1 };
const context = vm.createContext(sandbox);
const code = `var Parent = Object.create(null);
Parent.prototype = {
sProp: 'some string value',
numProp: 2,
bProp: false
};
var x = {
a: 'foo',
b: 'foo2'
}
var object = {};
object.foo = 1;
object.bar = null;
object.baz = function() {
return "hello from baz()";
};
var child = Object.create(Parent.prototype, {
color: { writable: true, value: 'red' },
desc: {
configurable: true,
get: function () { return "get working"; },
set: function (value) { this.color = "set working"; }
}
});
`;
const codee = ` `;
const res = vm.runInContext(codee, context);
console.log(util.inspect(sandbox));
//assert.equal(typeof ctx.a, 'function');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment