Skip to content

Commit b0be19c

Browse files
committed
Remove process and other node globals from this
1 parent af43a57 commit b0be19c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/execjs/support/node_runner.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,22 @@ def test_node_global_is_undefined
239239

240240
def test_node_process_is_undefined
241241
assert ExecJS.eval("typeof process == 'undefined'")
242+
refute ExecJS.eval("'process' in this")
242243
end
243244

244245
def test_commonjs_vars_are_undefined
245246
assert ExecJS.eval("typeof module == 'undefined'")
246247
assert ExecJS.eval("typeof exports == 'undefined'")
247248
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")
248253
end
249254

250255
def test_console_is_undefined
251256
assert ExecJS.eval("typeof console == 'undefined'")
257+
refute ExecJS.eval("'console' in this")
252258
end
253259

254260
def test_timers_are_undefined
@@ -258,6 +264,13 @@ def test_timers_are_undefined
258264
assert ExecJS.eval("typeof clearInterval == 'undefined'")
259265
assert ExecJS.eval("typeof setImmediate == 'undefined'")
260266
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")
261274
end
262275

263276
def test_compile_large_scripts

0 commit comments

Comments
 (0)