From a4007418683f55fec52b8085bac5e4d545b70a0e Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 3 Apr 2017 18:56:11 +0800 Subject: [PATCH] workaround Node.js bugs (#1775) Wrap test code in IIFE before passing to `vm` fixes #1768 fixes #1771 --- test/sandbox.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/sandbox.js b/test/sandbox.js index 396a6e2c..ea3a60a5 100644 --- a/test/sandbox.js +++ b/test/sandbox.js @@ -12,7 +12,6 @@ var FUNC_TOSTRING = [ ' return "[Function: __func_" + i + "__]";', " }", "}();", - "" ].join("\n"); exports.run_code = function(code) { var stdout = ""; @@ -21,7 +20,12 @@ exports.run_code = function(code) { 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) { -- 2.34.1