rubyjs / therubyrhino

Embed the Mozilla Rhino Javascript interpreter into Ruby
153 stars 40 forks source link

Rhino is only JS 1.7 compatible - prevents using modern JS syntax #38

Open rob99 opened 6 years ago

rob99 commented 6 years ago

I'm putting this here for documentation as much as anything. It's not clear to me if Mozilla Rhino will ever be made ECMAscript 6 compliant or be kept up to date in general...

I've found that using therubyrhino in a rails 4.2 application on JRuby that rake assets:precompile will fail even though my javascript executes without error in the browser.

This appears to be because Mozilla Rhino is only JS 1.7 compliant, whereas my browser can execute v6.

E.g.:

jirb
irb(main):001:0> require 'rhino'
=> true
irb(main):002:0> eval_js "7 * 6"
=> 42
irb(main):003:0> eval_js "var a = 1"
=> nil
irb(main):004:0> eval_js "let a = 1"
Rhino::JSError: missing ; before statement

Not sure if the solution is to have JRuby move to another Java JS engine (are there any?) or somehow make rake assets:precompile not do syntax checking, or get Mozilla Rhino updated.

kares commented 6 years ago

unfortunately, there's very little maintenance I can afford going into Rhino. if someone lends here should definitely look into that, there's failures that might need looking into ... attempting to upgrade rhino alternatively you can give dienashorner gem a go (uses the Nashorn JS engine available in Java 8)