Monday, June 9th, 2008

Johnson: Wrapping JavaScript in a loving Ruby embrace, and ARAX

Category: JavaScript, Ruby

John Resig pointed us to Johnson, a project that “wraps JavaScript in a loving Ruby embrace.”

It seems to give you a JavaScript interpreter that you can pass a context into to. The simple examples are:

  1. require "johnson"
  3. Johnson.evaluate("4 + 4") # => 8
  4. Johnson.evaluate("4 + foo", :foo => 4) # => 8

John saw the following code that gives you __FILE__ as a global that stores the file name a la Perl:


  1. (function(){
  2.   this.__defineGetter__("__FILE__", function() {
  3.     return (new Error).stack.split("\n")[2].split("@")[1].split(":").slice(0,-1).join(":");
  4.   });
  5. })();

I am curious to see the itch that they guys are scratching here.

Of course, Silverlight is giving us ARAX according to John Lam. Darryl Taft reported on the news, and I quickly told him that JRuby has given us Ruby in the browser for quite some time. The latest Java plugin supports JNLP, and JRuby build a JNLP distribution for you if you want it. Silverlight is another vector for Ruby in the browser.

Ben said the following about the Silverlight version:

If this is about using Silverlight to host client-side browser scripting in Ruby, it’s definitely an appealing notion, but the problem will always be about Silverlight being a Microsoft technology.

As long as Windows/Office dominates Microsoft’s balance sheet, these cross-platform Microsoft plays always feel a bit like the story of the boy who upon encountering a rattlesnake picks it up after it promises not to hurt him, upon which the snake promptly bites. After the boy protests, the snake says: ‘You knew what I was when you picked me up.’ No matter what capabilities Silverlight may have, I think most of us in the community simply wouldn’t dream of embracing architectures dependent on Microsoft’s goodwill to support other OS vendors.

Posted by Dion Almaer at 6:05 am

3.6 rating from 22 votes


Comments feed TrackBack URI

Beyond being a fun hack, the primary itches we’re scratching with Johnson are server-side testing of JavaScript libraries and frameworks (we’re working hard on jQuery and Prototype’s test suites now) and better web crawling (we’re looking at integration with Mechanize and possibly webrat).

Johnson also exposes a mutable Ruby AST for JavaScript, allowing easy application of AOP-style advice, transforms, or tracing. We also want to make it easy to use JS 1.9+ features and dynamically degrade for less capable browsers.

On on the fun side, using bin/johnson:

js> rb js[:foo] = [1, 2, 3] # bind a Ruby array to a JS global
=> [1, 2, 3]
js> foo
=> [1, 2, 3] # a transparent proxy to the Ruby array
js> foo.collect(function(n) { return n * 2 })
=> [2, 4, 6] # the JS function acts as a Ruby proc

Comment by jbarnette — June 9, 2008

I don’t ruby is necessary for Ajax guys.

Comment by KKFC — June 9, 2008

Johnson == Awesome? Yes. Imagine the testing that can be done once these guys integrate Johnson into Mechanize — complete DOM traversal *and* JS execution via Ruby?? These guys even have a Johnson interactive “jrb” shell! …J. Barnette, A. Patterson (aka ‘tenderlove’), Y. Katz… three super smart guys right there, hats off and congrats to them for this interesting work. –‘thanks for sharing your Johnson with the rest of the world’ (gratuitous Johnson joke)

Comment by holts — June 10, 2008

Hey folks,

Please note that Silverlight is not reliant on Microsoft’s good will. The Mono project has created an implementation entirely without dependence on Microsoft IP. The Silverlight == Microsoft argument is a red herring.



Comment by cjac — August 15, 2008

firefox installer:

Comment by cjac — August 15, 2008

Leave a comment

You must be logged in to post a comment.