Skip to content

Commit e57706f

Browse files
authored
Merge pull request #43 from josh/undef-process
Undefine globals, not just shadow
2 parents 4f2fc87 + 5c6f4a9 commit e57706f

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/execjs/support/jsc_runner.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
}, function(program) {
33
var output;
44
try {
5+
delete this.console;
56
result = program();
67
if (typeof result == 'undefined' && result !== null) {
78
print('["ok"]');

lib/execjs/support/node_runner.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
(function(program, execJS) { execJS(program) })(function(global, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
1+
(function(program, execJS) { execJS(program) })(function(global, process, module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
22
}, function(program) {
33
var output, print = function(string) {
44
process.stdout.write('' + string);
55
};
66
try {
7+
var __process__ = process;
8+
delete this.process;
9+
delete this.console;
10+
delete this.setTimeout;
11+
delete this.setInterval;
12+
delete this.clearTimeout;
13+
delete this.clearInterval;
14+
delete this.setImmediate;
15+
delete this.clearImmediate;
716
result = program();
17+
this.process = __process__;
818
if (typeof result == 'undefined' && result !== null) {
919
print('["ok"]');
1020
} else {
@@ -15,6 +25,7 @@
1525
}
1626
}
1727
} catch (err) {
28+
this.process = __process__;
1829
print(JSON.stringify(['err', '' + err, err.stack]));
1930
}
2031
});

test/test_execjs.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,24 @@ def test_node_global_is_undefined
237237
assert ExecJS.eval("typeof global == 'undefined'")
238238
end
239239

240+
def test_node_process_is_undefined
241+
assert ExecJS.eval("typeof process == 'undefined'")
242+
refute ExecJS.eval("'process' in this")
243+
end
244+
240245
def test_commonjs_vars_are_undefined
241246
assert ExecJS.eval("typeof module == 'undefined'")
242247
assert ExecJS.eval("typeof exports == 'undefined'")
243248
assert ExecJS.eval("typeof require == 'undefined'")
249+
250+
refute ExecJS.eval("'module' in this")
251+
refute ExecJS.eval("'exports' in this")
252+
refute ExecJS.eval("'require' in this")
244253
end
245254

246255
def test_console_is_undefined
247256
assert ExecJS.eval("typeof console == 'undefined'")
257+
refute ExecJS.eval("'console' in this")
248258
end
249259

250260
def test_timers_are_undefined
@@ -254,6 +264,13 @@ def test_timers_are_undefined
254264
assert ExecJS.eval("typeof clearInterval == 'undefined'")
255265
assert ExecJS.eval("typeof setImmediate == 'undefined'")
256266
assert ExecJS.eval("typeof clearImmediate == 'undefined'")
267+
268+
refute ExecJS.eval("'setTimeout' in this")
269+
refute ExecJS.eval("'setInterval' in this")
270+
refute ExecJS.eval("'clearTimeout' in this")
271+
refute ExecJS.eval("'clearInterval' in this")
272+
refute ExecJS.eval("'setImmediate' in this")
273+
refute ExecJS.eval("'clearImmediate' in this")
257274
end
258275

259276
def test_compile_large_scripts

0 commit comments

Comments
 (0)