Created
January 14, 2017 17:22
-
-
Save AnnaMag/c0de1176433443afb8b6c505db756059 to your computer and use it in GitHub Desktop.
vm test 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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