1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00

Remove process and other node globals from this

This commit is contained in:
Joshua Peek 2016-06-05 16:03:21 -07:00
parent af43a575f8
commit b0be19c73d
No known key found for this signature in database
GPG key ID: 2852ABCC729F67DA
2 changed files with 24 additions and 0 deletions

View file

@ -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]));
}
});

View file

@ -239,16 +239,22 @@ class TestExecJS < Test
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 @@ class TestExecJS < Test
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