Wrap test code in IIFE before passing to `vm`
fixes #1768
fixes #1771
' return "[Function: __func_" + i + "__]";',
" }",
"}();",
- ""
].join("\n");
exports.run_code = function(code) {
var stdout = "";
stdout += chunk;
};
try {
- new vm.Script(FUNC_TOSTRING + code).runInNewContext({
+ vm.runInNewContext([
+ "!function() {",
+ FUNC_TOSTRING,
+ code,
+ "}();",
+ ].join("\n"), {
console: {
log: function() {
return console.log.apply(console, [].map.call(arguments, function(arg) {