This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
johnson.rb
72 lines (59 loc) · 2.02 KB
/
johnson.rb
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require "generator" if RUBY_VERSION =~ /1.8/
require "johnson/version"
# the command-line option parser and support libs
require "johnson/cli"
unless ENV['JOHNSON_FFI']
# the native SpiderMonkey extension
require "johnson/spidermonkey"
end
# visitable module and visitors
require "johnson/visitable"
require "johnson/visitors"
# parse tree nodes
require "johnson/nodes"
# the SpiderMonkey bits written in Ruby
unless ENV['JOHNSON_FFI']
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"
else
require "johnson/spidermonkey/ffi/ffi-spidermonkey"
require "johnson/spidermonkey/ffi/has_pointer"
require "johnson/spidermonkey/ffi/convert"
require "johnson/spidermonkey/ffi/js_gc_thing"
require "johnson/spidermonkey/ffi/js_value"
require "johnson/spidermonkey/ffi/native_global"
require "johnson/spidermonkey/ffi/js_land_proxy"
require "johnson/spidermonkey/ffi/runtime"
require "johnson/spidermonkey/ffi/context"
require "johnson/spidermonkey/ffi/ruby_land_proxy"
require "johnson/spidermonkey/ffi/immutable_node"
end
# 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