Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var vm = require('vm')
var sandbox = {externalArray: [], externalArryConstructor: Array}
vm.createContext(sandbox)
console.log(vm.runInContext('externalArryConstructor == Array', sandbox))
console.log(vm.runInContext('externalArray.constructor == Array', sandbox))
console.log(sandbox.externalArray.constructor == Array)
console.log(vm.runInContext('externalArray.__proto__ == [].__proto__', sandbox))
console.log(sandbox.externalArray.__proto__ == [].__proto__)
vm.runInContext('externalArray.__proto__.externalMethod = true', sandbox)
vm.runInContext('Array.prototype.internalMethod = true', sandbox)
console.log('Interal externalMethod:', vm.runInContext('[].externalMethod', sandbox))
console.log('Interal internalMethod:', vm.runInContext('[].internalMethod', sandbox))
console.log('External externalMethod', [].externalMethod)
console.log('External internalMethod', [].internalMethod)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.