-
Notifications
You must be signed in to change notification settings - Fork 93
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
ReferenceError: setTimeout is not defined #135
Comments
setTimeout and setInterval are not defined by v8, the platform needs to
provide them. if you want timeout you are going to have to implement in
Ruby and attach the method.
…On Fri, Mar 29, 2019 at 8:28 PM hex0wn ***@***.***> wrote:
Here is my code
require 'mini_racer'
ctx = MiniRacer::Context.new
ctx.eval('setTimeout(function(){console.log(1)}, 1000)')
The error info is
Traceback (most recent call last):
7: from 1.rb:3:in `<main>'
6: from /usr/local/rvm/gems/ruby-2.5.3/gems/mini_racer-0.2.4/lib/mini_racer.rb:176:in `eval'
5: from /usr/local/rvm/gems/ruby-2.5.3/gems/mini_racer-0.2.4/lib/mini_racer.rb:176:in `synchronize'
4: from /usr/local/rvm/gems/ruby-2.5.3/gems/mini_racer-0.2.4/lib/mini_racer.rb:178:in `block in eval'
3: from /usr/local/rvm/gems/ruby-2.5.3/gems/mini_racer-0.2.4/lib/mini_racer.rb:264:in `timeout'
2: from /usr/local/rvm/gems/ruby-2.5.3/gems/mini_racer-0.2.4/lib/mini_racer.rb:179:in `block (2 levels) in eval'
1: from /usr/local/rvm/gems/ruby-2.5.3/gems/mini_racer-0.2.4/lib/mini_racer.rb:179:in `eval_unsafe'
JavaScript at <anonymous>:1:1: ReferenceError: setTimeout is not defined (MiniRacer::RuntimeError)
I tried in CentOS Linux release 7.5.1804 and Ubuntu 16.04.5 LTS
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#135>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAUXantwBeHkJ9gPOVjGkUW1WFIAVJfks5vbdUKgaJpZM4cR61g>
.
|
I was thinking it might be useful to attach an (optional) event loop to a mini_racer context. Some libs require and event loop, so for now I just polyfill it like: // Pseudo since I'm on phone
function setTimeout(func) { func() } Obvious correctness issues there, but "It Works" ™️. There will be some complexity ensuring event loop is properly shut down and before exit, but it night be a worthwhile edition. |
Technically this is doable today I have a reasonably efficient implementation of timer thread at: https://github.com/SamSaffron/message_bus/blob/master/lib/message_bus/timer_thread.rb It would be pretty straight forward to glue it on by attaching stuff. It is a bit tricky though getting full details of the func being called out of the boundary, so you would may need some sort of weakmap or something. |
Here is my code
The error info is
I tried in
CentOS Linux release 7.5.1804
andUbuntu 16.04.5 LTS
The text was updated successfully, but these errors were encountered: