Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

runInThisContext fails to run within the context of the caller; it instead runs in root context

View code.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
var vm = process.binding('evals').Script;
var ctx = vm.createContext({vm:vm});
 
Object.foo = 1;
 
console.log('Object.foo ', Object.foo);
console.log('this Object.foo ', vm.runInThisContext("Object.foo"));
 
console.log('new Object.foo ', vm.runInNewContext(
'Object.foo=2; Object.foo', {vm:vm}));
console.log('new this Object.foo ',vm.runInNewContext(
'Object.foo=2; vm.runInThisContext("Object.foo")', {vm:vm}));
 
vm.runInContext('Object.foo = 2', ctx);
console.log('ctx Object.foo ', vm.runInContext(
'Object.foo', ctx));
console.log('ctx this Object.foo ', vm.runInContext(
'vm.runInThisContext("Object.foo")', ctx));
View code.js
1 2 3 4 5 6
Object.foo 1
this Object.foo 1
new Object.foo 2
new this Object.foo 1
ctx Object.foo 2
ctx this Object.foo 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.