diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-04-03 18:56:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-03 18:56:11 +0800 |
commit | a4007418683f55fec52b8085bac5e4d545b70a0e (patch) | |
tree | 833cdd70afa6df9c31391f01b270581a0242db79 | |
parent | 59a4e56bc81ce96b3ee81ad4f068cfc7d89a4790 (diff) | |
download | tracifyjs-a4007418683f55fec52b8085bac5e4d545b70a0e.tar.gz tracifyjs-a4007418683f55fec52b8085bac5e4d545b70a0e.zip |
workaround Node.js bugs (#1775)
Wrap test code in IIFE before passing to `vm`
fixes #1768
fixes #1771
-rw-r--r-- | test/sandbox.js | 8 |
1 files 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) { |