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:
commit
4b7d781381
3 changed files with 15 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue