From 70d4477e0532f79b6d9cacb610cce6bb1d0819a0 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 27 Apr 2018 07:40:34 +0800 Subject: [PATCH] workaround `vm` context issue in `node-chakracore` (#3106) --- test/compress/collapse_vars.js | 4 ++-- test/sandbox.js | 28 +++++++++++----------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index d1060563..950ebd07 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -3751,7 +3751,7 @@ issue_2506: { function f0(bar) { function f1(Infinity_2) { function f13(NaN) { - if (false <= NaN & f0 >> 1 >= 0) { + if (false <= NaN & this >> 1 >= 0) { c++; } } @@ -3767,7 +3767,7 @@ issue_2506: { function f0(bar) { (function(Infinity_2) { (function(NaN) { - if (false <= 0/0 & f0 >> 1 >= 0) + if (false <= 0/0 & this >> 1 >= 0) c++; })(0, c++); })(); diff --git a/test/sandbox.js b/test/sandbox.js index 426ac1fc..ecf95d31 100644 --- a/test/sandbox.js +++ b/test/sandbox.js @@ -2,24 +2,18 @@ var semver = require("semver"); var vm = require("vm"); function createContext() { - var context = Object.create(null); - Object.defineProperty(context, "console", { - value: function() { - var con = Object.create(null); - Object.defineProperty(con, "log", { - value: function(msg) { - if (arguments.length == 1 && typeof msg == "string") { - return console.log("%s", msg); - } - return console.log.apply(console, [].map.call(arguments, function(arg) { - return safe_log(arg, 3); - })); + return vm.createContext(Object.defineProperty({}, "console", { + value: { + log: function(msg) { + if (arguments.length == 1 && typeof msg == "string") { + return console.log("%s", msg); } - }); - return con; - }() - }); - return vm.createContext(context); + return console.log.apply(console, [].map.call(arguments, function(arg) { + return safe_log(arg, 3); + })); + } + } + })); } function safe_log(arg, level) { -- 2.34.1