workaround Node.js bugs (#1775)
Wrap test code in IIFE before passing to `vm` fixes #1768 fixes #1771
This commit is contained in:
@@ -12,7 +12,6 @@ var FUNC_TOSTRING = [
|
|||||||
' return "[Function: __func_" + i + "__]";',
|
' return "[Function: __func_" + i + "__]";',
|
||||||
" }",
|
" }",
|
||||||
"}();",
|
"}();",
|
||||||
""
|
|
||||||
].join("\n");
|
].join("\n");
|
||||||
exports.run_code = function(code) {
|
exports.run_code = function(code) {
|
||||||
var stdout = "";
|
var stdout = "";
|
||||||
@@ -21,7 +20,12 @@ exports.run_code = function(code) {
|
|||||||
stdout += chunk;
|
stdout += chunk;
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
new vm.Script(FUNC_TOSTRING + code).runInNewContext({
|
vm.runInNewContext([
|
||||||
|
"!function() {",
|
||||||
|
FUNC_TOSTRING,
|
||||||
|
code,
|
||||||
|
"}();",
|
||||||
|
].join("\n"), {
|
||||||
console: {
|
console: {
|
||||||
log: function() {
|
log: function() {
|
||||||
return console.log.apply(console, [].map.call(arguments, function(arg) {
|
return console.log.apply(console, [].map.call(arguments, function(arg) {
|
||||||
|
|||||||
Reference in New Issue
Block a user