Skip to content

Instantly share code, notes, and snippets.

@adoyle-h adoyle-h/vm.js
Created Jun 26, 2016

Embed
What would you like to do?
var vm = require('vm');
function printError(e) {
// console.log(e instanceof Error, e, e.stack);
console.log(e instanceof Error);
}
console.log('====== Example 1 ======');
try {
vm.runInNewContext('throw new Error("nooooo")');
} catch(e) {
printError(e);
}
console.log('====== Example 2 ======');
try {
vm.runInThisContext('throw new Error("nooooo")');
} catch(e) {
printError(e);
}
console.log('====== Example 3 ======');
try {
vm.runInNewContext('throw new Error("nooooo")', {Error: Error}, {displayErrors: false});
} catch(e) {
printError(e);
}
console.log('====== Example 4 ======');
try {
var sandbox = {Error: Error};
vm.createContext(sandbox);
vm.runInContext('throw new Error("nooooo")', sandbox, {displayErrors: false});
} catch(e) {
printError(e);
}
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.