aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-04-03 18:56:11 +0800
committerGitHub <noreply@github.com>2017-04-03 18:56:11 +0800
commita4007418683f55fec52b8085bac5e4d545b70a0e (patch)
tree833cdd70afa6df9c31391f01b270581a0242db79
parent59a4e56bc81ce96b3ee81ad4f068cfc7d89a4790 (diff)
downloadtracifyjs-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.js8
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) {