jbarnette / johnson

Johnson wraps JavaScript in a loving Ruby embrace.

This URL has Read+Write access

johnson / lib / johnson.rb
100644 56 lines (43 sloc) 1.421 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "generator"
require "johnson/version"
 
# the command-line option parser and support libs
require "johnson/cli"
 
# the native SpiderMonkey extension
require "johnson/spidermonkey"
 
# visitable module and visitors
require "johnson/visitable"
require "johnson/visitors"
 
# parse tree nodes
require "johnson/nodes"
 
# the SpiderMonkey bits written in Ruby
require "johnson/spidermonkey/runtime"
require "johnson/spidermonkey/context"
require "johnson/spidermonkey/js_land_proxy"
require "johnson/spidermonkey/ruby_land_proxy"
require "johnson/spidermonkey/mutable_tree_visitor"
require "johnson/spidermonkey/debugger"
require "johnson/spidermonkey/immutable_node"
 
# the 'public' interface
require "johnson/error"
require "johnson/runtime"
require "johnson/parser"
 
# make sure all the Johnson JavaScript libs are in the load path
$LOAD_PATH.push(File.expand_path("#{File.dirname(__FILE__)}/../js"))
 
module Johnson
  PRELUDE = IO.read(File.dirname(__FILE__) + "/../js/johnson/prelude.js")
  
  def self.evaluate(expression, vars={})
    runtime = Johnson::Runtime.new
    vars.each { |key, value| runtime[key] = value }
    
    runtime.evaluate(expression)
  end
  
  def self.parse(js, *args)
    Johnson::Parser.parse(js, *args)
  end
 
  ###
  # Create a new runtime and load all +files+. Returns a new Johnson::Runtime.
  def self.load(*files)
    rt = Johnson::Runtime.new
    rt.load(*files)
    rt
  end
end