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

ReferenceError: setTimeout is not defined #135

Open
hex0wn opened this issue Mar 29, 2019 · 3 comments
Open

ReferenceError: setTimeout is not defined #135

hex0wn opened this issue Mar 29, 2019 · 3 comments

Comments

@hex0wn
Copy link

hex0wn commented Mar 29, 2019

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

@SamSaffron
Copy link
Collaborator

SamSaffron commented Apr 1, 2019 via email

@ianks
Copy link
Contributor

ianks commented May 11, 2019

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.

@SamSaffron
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants