News for hackers. Stuff that matters.
Re:Snarl - A JavaScript Bridge for JRuby by bensummers on Monday November 09, 2009 @10:04AM (#930989)
Nice, but very simple. I don't think there's a way of passing a Ruby object in to the Javascript and calling methods on it, which is a shame.
Re:Snarl - A JavaScript Bridge for JRuby by jcrosby on Monday November 09, 2009 @01:36PM (#931450)
Hi Ben. This first version attacks the most efficient way to use the bridge -- keep the Ruby and JavaScript parts as self-contained as possible, crossing the bridge only when absolutely necessary. A future version will likely provide the type of feature you are describing for use in scenarios where performance is less critical.
Re:Snarl - A JavaScript Bridge for JRuby by bensummers on Monday November 09, 2009 @04:17PM (#931747)
I've been looking into the JRuby / Rhino combination to implement server-side user plugins, where you can't trust the code[1]. I don't think it'll be that slow to let JS call Ruby code.

That said, I'm now wondering whether writing them in Java and using SecurityManagers plus byte-code verification and adding of checks for running too long in loops is the way to go.

[1] And of course, because it's Javascript, it can run in the browser too. With suitable shim code, you can then debug in Firebug. IDE for free!

Re:Snarl - A JavaScript Bridge for JRuby by ilyak on Monday November 09, 2009 @10:59AM (#931111)
You can easily pass an object into Javascript:

context.put(“rubyObject”, MyRubyClass.new)

Whether you would be able to call methods on it depends on whether the Snarl author did some (trivial) code magic or not, but it's certainly doable too.

Still I have no idea why would you want javascript in ruby in the first place.

Re:Snarl - A JavaScript Bridge for JRuby by rcoder on Monday November 09, 2009 @12:35PM (#931327)
Once you have a Javascript environment, it's not a large jump to emulate a minimal DOM -- see env.js, for example: http://ejohn.org/blog/bringing-the-browser-to-the-server/

With a stub DOM and Javascript interpreter, you can pass generated output from web application views directly into your testing environment and make assertions about the resulting behavior, dynamically-generated DOM nodes, etc.

There are a number of projects similar to this one (for which, sadly, I cannot currently pull up any bookmarks) mostly intended for a similar set of tasks. Being able to bring RSpec or Cucumber to bear on a hairy JS testing job can make the process much more enjoyable.

Re:Snarl - A JavaScript Bridge for JRuby by bensummers on Monday November 09, 2009 @12:38PM (#931335)
I looked at the code. I don't think that'd work.

As for using Javascript from Ruby, it might be quite nice as a language to let your users write extensions and plugins. It's a language where the implementations all have an emphasis on sandboxing.

Re:Snarl - A JavaScript Bridge for JRuby by ilyak on Monday November 09, 2009 @01:31PM (#931436)
Why not? I mean, rhino has methodNotFound-like thing, so you certainly can.
Re:Snarl - A JavaScript Bridge for JRuby by bensummers on Monday November 09, 2009 @04:12PM (#931739)
I meant I looked at the Snarl code, and it wasn't implemented there.

But you are right, it is technically possible.