Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefine globals, not just shadow #43

Merged
merged 3 commits into from Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/execjs/support/jsc_runner.js
Expand Up @@ -2,6 +2,7 @@
}, function(program) {
var output;
try {
delete this.console;
result = program();
if (typeof result == 'undefined' && result !== null) {
print('["ok"]');
Expand Down
13 changes: 12 additions & 1 deletion lib/execjs/support/node_runner.js
@@ -1,10 +1,20 @@
(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);
};
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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someday we could move Nodes execution over to vm.Script. We'd have full control over what globals were exposed to the v8 context. vm.Script also has nice support for timeouts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is blocking us to change this right now? The version of node that support vm.Script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version of node that support vm.Script?

It is well supported, but that change would be a substantial refactoring.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks.

this.process = __process__;
if (typeof result == 'undefined' && result !== null) {
print('["ok"]');
} else {
Expand All @@ -15,6 +25,7 @@
}
}
} catch (err) {
this.process = __process__;
print(JSON.stringify(['err', '' + err, err.stack]));
}
});
17 changes: 17 additions & 0 deletions test/test_execjs.rb
Expand Up @@ -237,14 +237,24 @@ 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'")
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
Expand All @@ -254,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
Expand Down