From af43a575f81e38f3d3b53935036423de29989803 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 5 Jun 2016 15:49:07 -0700 Subject: [PATCH 1/3] Undefine global `process` Node specific global should be normalized across environments --- lib/execjs/support/node_runner.js | 2 +- test/test_execjs.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/execjs/support/node_runner.js b/lib/execjs/support/node_runner.js index ab0c6ec..3dc4757 100644 --- a/lib/execjs/support/node_runner.js +++ b/lib/execjs/support/node_runner.js @@ -1,4 +1,4 @@ -(function(program, execJS) { execJS(program) })(function(global, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source} +(function(program, execJS) { execJS(program) })(function(global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source} }, function(program) { var output, print = function(string) { process.stdout.write('' + string); diff --git a/test/test_execjs.rb b/test/test_execjs.rb index 7fd967f..061be48 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -237,6 +237,10 @@ def test_node_global_is_undefined assert ExecJS.eval("typeof global == 'undefined'") end + def test_node_process_is_undefined + assert ExecJS.eval("typeof process == 'undefined'") + end + def test_commonjs_vars_are_undefined assert ExecJS.eval("typeof module == 'undefined'") assert ExecJS.eval("typeof exports == 'undefined'") From b0be19c73ded5f20c2c86c8e546558e09da4e2a5 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 5 Jun 2016 16:03:21 -0700 Subject: [PATCH 2/3] Remove process and other node globals from `this` --- lib/execjs/support/node_runner.js | 11 +++++++++++ test/test_execjs.rb | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/execjs/support/node_runner.js b/lib/execjs/support/node_runner.js index 3dc4757..2987d9f 100644 --- a/lib/execjs/support/node_runner.js +++ b/lib/execjs/support/node_runner.js @@ -4,7 +4,17 @@ process.stdout.write('' + string); }; try { + var __process__ = process; + delete this.process; + delete this.console; + delete this.setTimeout; + delete this.setInterval; + delete this.clearTimeout; + delete this.clearInterval; + delete this.setImmediate; + delete this.clearImmediate; result = program(); + this.process = __process__; if (typeof result == 'undefined' && result !== null) { print('["ok"]'); } else { @@ -15,6 +25,7 @@ } } } catch (err) { + this.process = __process__; print(JSON.stringify(['err', '' + err, err.stack])); } }); diff --git a/test/test_execjs.rb b/test/test_execjs.rb index 061be48..0ee411f 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -239,16 +239,22 @@ def test_node_global_is_undefined def test_node_process_is_undefined assert ExecJS.eval("typeof process == 'undefined'") + refute ExecJS.eval("'process' in this") end def test_commonjs_vars_are_undefined assert ExecJS.eval("typeof module == 'undefined'") assert ExecJS.eval("typeof exports == 'undefined'") assert ExecJS.eval("typeof require == 'undefined'") + + refute ExecJS.eval("'module' in this") + refute ExecJS.eval("'exports' in this") + refute ExecJS.eval("'require' in this") end def test_console_is_undefined assert ExecJS.eval("typeof console == 'undefined'") + refute ExecJS.eval("'console' in this") end def test_timers_are_undefined @@ -258,6 +264,13 @@ def test_timers_are_undefined assert ExecJS.eval("typeof clearInterval == 'undefined'") assert ExecJS.eval("typeof setImmediate == 'undefined'") assert ExecJS.eval("typeof clearImmediate == 'undefined'") + + refute ExecJS.eval("'setTimeout' in this") + refute ExecJS.eval("'setInterval' in this") + refute ExecJS.eval("'clearTimeout' in this") + refute ExecJS.eval("'clearInterval' in this") + refute ExecJS.eval("'setImmediate' in this") + refute ExecJS.eval("'clearImmediate' in this") end def test_compile_large_scripts From 5c6f4a9115ebc86a9607a32ac7d15f9b7e5eb47c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 5 Jun 2016 16:04:06 -0700 Subject: [PATCH 3/3] Normalize `console` in JSC --- lib/execjs/support/jsc_runner.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/execjs/support/jsc_runner.js b/lib/execjs/support/jsc_runner.js index c57a944..b7188a5 100644 --- a/lib/execjs/support/jsc_runner.js +++ b/lib/execjs/support/jsc_runner.js @@ -2,6 +2,7 @@ }, function(program) { var output; try { + delete this.console; result = program(); if (typeof result == 'undefined' && result !== null) { print('["ok"]');