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

Merge pull request #170 from sstephenson/event-loop

Event Loop restrictions
This commit is contained in:
Joshua Peek 2014-12-22 23:26:53 -06:00
commit 4b7d781381
3 changed files with 15 additions and 1 deletions

View file

@ -52,6 +52,11 @@ in. If you want to access the Node API, you should check another library like
[commonjs.rb](https://github.com/cowboyd/commonjs.rb) designed to provide a
consistent interface.
**Why can't I use `setTimeout`**
For similar reasons as modules, not all runtimes guarantee a full JavaScript
event loop. So `setTimeout`, `setInterval` and other timers are not defined.
# License

View file

@ -1,4 +1,4 @@
(function(program, execJS) { execJS(program) })(function(module, exports, require, console) { #{source}
(function(program, execJS) { execJS(program) })(function(module, exports, require, console, setTimeout, setInterval, clearTimeout, clearInterval, setImmediate, clearImmediate) { #{source}
}, function(program) {
var output, print = function(string) {
process.stdout.write('' + string);

View file

@ -230,6 +230,15 @@ class TestExecJS < Test
assert ExecJS.eval("typeof console == 'undefined'")
end
def test_timers_are_undefined
assert ExecJS.eval("typeof setTimeout == 'undefined'")
assert ExecJS.eval("typeof setInterval == 'undefined'")
assert ExecJS.eval("typeof clearTimeout == 'undefined'")
assert ExecJS.eval("typeof clearInterval == 'undefined'")
assert ExecJS.eval("typeof setImmediate == 'undefined'")
assert ExecJS.eval("typeof clearImmediate == 'undefined'")
end
def test_compile_large_scripts
body = "var foo = 'bar';\n" * 100_000
assert ExecJS.exec("function foo() {\n#{body}\n};\nreturn true")