jbarnette-johnson 1.0.0.200806240111

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. data/CHANGELOG +5 -0
  2. data/MANIFEST +385 -0
  3. data/MINGW32.mk +124 -0
  4. data/README.rdoc +51 -0
  5. data/Rakefile +166 -0
  6. data/bin/johnson +107 -0
  7. data/cross-compile.txt +38 -0
  8. data/ext/spidermonkey/context.c +122 -0
  9. data/ext/spidermonkey/context.h +19 -0
  10. data/ext/spidermonkey/conversions.c +286 -0
  11. data/ext/spidermonkey/conversions.h +18 -0
  12. data/ext/spidermonkey/debugger.c +208 -0
  13. data/ext/spidermonkey/debugger.h +9 -0
  14. data/ext/spidermonkey/extconf.rb +25 -0
  15. data/ext/spidermonkey/extensions.c +37 -0
  16. data/ext/spidermonkey/extensions.h +12 -0
  17. data/ext/spidermonkey/global.c +40 -0
  18. data/ext/spidermonkey/global.h +11 -0
  19. data/ext/spidermonkey/idhash.c +16 -0
  20. data/ext/spidermonkey/idhash.h +8 -0
  21. data/ext/spidermonkey/immutable_node.c.erb +522 -0
  22. data/ext/spidermonkey/immutable_node.h +22 -0
  23. data/ext/spidermonkey/jroot.h +187 -0
  24. data/ext/spidermonkey/js_land_proxy.c +609 -0
  25. data/ext/spidermonkey/js_land_proxy.h +20 -0
  26. data/ext/spidermonkey/ruby_land_proxy.c +537 -0
  27. data/ext/spidermonkey/ruby_land_proxy.h +17 -0
  28. data/ext/spidermonkey/runtime.c +304 -0
  29. data/ext/spidermonkey/runtime.h +25 -0
  30. data/ext/spidermonkey/spidermonkey.c +20 -0
  31. data/ext/spidermonkey/spidermonkey.h +29 -0
  32. data/js/johnson/browser.js +9 -0
  33. data/js/johnson/browser/env.js +687 -0
  34. data/js/johnson/browser/jquery.js +3444 -0
  35. data/js/johnson/browser/xmlsax.js +1564 -0
  36. data/js/johnson/browser/xmlw3cdom.js +4189 -0
  37. data/js/johnson/cli.js +30 -0
  38. data/js/johnson/prelude.js +80 -0
  39. data/js/johnson/template.js +29 -0
  40. data/lib/hoe.rb +748 -0
  41. data/lib/johnson.rb +46 -0
  42. data/lib/johnson/cli.rb +7 -0
  43. data/lib/johnson/cli/options.rb +56 -0
  44. data/lib/johnson/error.rb +4 -0
  45. data/lib/johnson/nodes.rb +7 -0
  46. data/lib/johnson/nodes/binary_node.rb +64 -0
  47. data/lib/johnson/nodes/for.rb +14 -0
  48. data/lib/johnson/nodes/for_in.rb +12 -0
  49. data/lib/johnson/nodes/function.rb +13 -0
  50. data/lib/johnson/nodes/list.rb +27 -0
  51. data/lib/johnson/nodes/node.rb +68 -0
  52. data/lib/johnson/nodes/ternary_node.rb +20 -0
  53. data/lib/johnson/parser.rb +21 -0
  54. data/lib/johnson/parser/syntax_error.rb +13 -0
  55. data/lib/johnson/runtime.rb +55 -0
  56. data/lib/johnson/spidermonkey/context.rb +10 -0
  57. data/lib/johnson/spidermonkey/debugger.rb +67 -0
  58. data/lib/johnson/spidermonkey/immutable_node.rb +280 -0
  59. data/lib/johnson/spidermonkey/js_land_proxy.rb +62 -0
  60. data/lib/johnson/spidermonkey/mutable_tree_visitor.rb +233 -0
  61. data/lib/johnson/spidermonkey/ruby_land_proxy.rb +52 -0
  62. data/lib/johnson/spidermonkey/runtime.rb +94 -0
  63. data/lib/johnson/version.rb +4 -0
  64. data/lib/johnson/visitable.rb +16 -0
  65. data/lib/johnson/visitors.rb +4 -0
  66. data/lib/johnson/visitors/dot_visitor.rb +167 -0
  67. data/lib/johnson/visitors/ecma_visitor.rb +315 -0
  68. data/lib/johnson/visitors/enumerating_visitor.rb +115 -0
  69. data/lib/johnson/visitors/sexp_visitor.rb +172 -0
  70. data/lib/rails/init.rb +37 -0
  71. data/test/assets/index.html +38 -0
  72. data/test/assets/jquery_test.html +186 -0
  73. data/test/helper.rb +58 -0
  74. data/test/johnson/browser_test.rb +38 -0
  75. data/test/johnson/conversions/array_test.rb +32 -0
  76. data/test/johnson/conversions/boolean_test.rb +17 -0
  77. data/test/johnson/conversions/callable_test.rb +34 -0
  78. data/test/johnson/conversions/file_test.rb +15 -0
  79. data/test/johnson/conversions/nil_test.rb +20 -0
  80. data/test/johnson/conversions/number_test.rb +34 -0
  81. data/test/johnson/conversions/regexp_test.rb +24 -0
  82. data/test/johnson/conversions/string_test.rb +26 -0
  83. data/test/johnson/conversions/struct_test.rb +15 -0
  84. data/test/johnson/conversions/symbol_test.rb +19 -0
  85. data/test/johnson/conversions/thread_test.rb +24 -0
  86. data/test/johnson/error_test.rb +9 -0
  87. data/test/johnson/extensions_test.rb +56 -0
  88. data/test/johnson/nodes/array_literal_test.rb +57 -0
  89. data/test/johnson/nodes/array_node_test.rb +26 -0
  90. data/test/johnson/nodes/binary_node_test.rb +61 -0
  91. data/test/johnson/nodes/bracket_access_test.rb +16 -0
  92. data/test/johnson/nodes/delete_test.rb +11 -0
  93. data/test/johnson/nodes/do_while_test.rb +12 -0
  94. data/test/johnson/nodes/dot_accessor_test.rb +15 -0
  95. data/test/johnson/nodes/export_test.rb +9 -0
  96. data/test/johnson/nodes/for_test.rb +54 -0
  97. data/test/johnson/nodes/function_test.rb +71 -0
  98. data/test/johnson/nodes/if_test.rb +41 -0
  99. data/test/johnson/nodes/import_test.rb +13 -0
  100. data/test/johnson/nodes/label_test.rb +19 -0
  101. data/test/johnson/nodes/object_literal_test.rb +110 -0
  102. data/test/johnson/nodes/return_test.rb +16 -0
  103. data/test/johnson/nodes/semi_test.rb +8 -0
  104. data/test/johnson/nodes/switch_test.rb +55 -0
  105. data/test/johnson/nodes/ternary_test.rb +25 -0
  106. data/test/johnson/nodes/throw_test.rb +9 -0
  107. data/test/johnson/nodes/try_node_test.rb +59 -0
  108. data/test/johnson/nodes/typeof_test.rb +11 -0
  109. data/test/johnson/nodes/unary_node_test.rb +23 -0
  110. data/test/johnson/nodes/void_test.rb +11 -0
  111. data/test/johnson/nodes/while_test.rb +26 -0
  112. data/test/johnson/nodes/with_test.rb +10 -0
  113. data/test/johnson/prelude_test.rb +56 -0
  114. data/test/johnson/runtime_test.rb +46 -0
  115. data/test/johnson/spidermonkey/context_test.rb +21 -0
  116. data/test/johnson/spidermonkey/immutable_node_test.rb +34 -0
  117. data/test/johnson/spidermonkey/js_land_proxy_test.rb +236 -0
  118. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +225 -0
  119. data/test/johnson/spidermonkey/runtime_test.rb +17 -0
  120. data/test/johnson/version_test.rb +13 -0
  121. data/test/johnson/visitors/dot_visitor_test.rb +39 -0
  122. data/test/johnson/visitors/enumerating_visitor_test.rb +12 -0
  123. data/test/johnson_test.rb +16 -0
  124. data/test/jquery_units/test.js +27 -0
  125. data/test/jquery_units/test_helper.js +197 -0
  126. data/test/jquery_units/units/ajax.js +795 -0
  127. data/test/jquery_units/units/core.js +1563 -0
  128. data/test/jquery_units/units/event.js +299 -0
  129. data/test/jquery_units/units/fx.js +427 -0
  130. data/test/jquery_units/units/offset.js +112 -0
  131. data/test/jquery_units/units/selector.js +224 -0
  132. data/test/jspec/helper.js +7 -0
  133. data/test/jspec/jspec.js +192 -0
  134. data/test/jspec/simple_spec.js +68 -0
  135. data/test/parser_test.rb +276 -0
  136. data/todo/.keep +0 -0
  137. metadata +501 -0
data/lib/johnson.rb ADDED
@@ -0,0 +1,46 @@
1
+ require "generator"
2
+ require "johnson/version"
3
+
4
+ # the command-line option parser and support libs
5
+ require "johnson/cli"
6
+
7
+ # the native SpiderMonkey extension
8
+ require "johnson/spidermonkey"
9
+
10
+ # visitable module and visitors
11
+ require "johnson/visitable"
12
+ require "johnson/visitors"
13
+
14
+ # parse tree nodes
15
+ require "johnson/nodes"
16
+
17
+ # the SpiderMonkey bits written in Ruby
18
+ require "johnson/spidermonkey/runtime"
19
+ require "johnson/spidermonkey/context"
20
+ require "johnson/spidermonkey/js_land_proxy"
21
+ require "johnson/spidermonkey/ruby_land_proxy"
22
+ require "johnson/spidermonkey/mutable_tree_visitor"
23
+ require "johnson/spidermonkey/debugger"
24
+ require "johnson/spidermonkey/immutable_node"
25
+
26
+ # the 'public' interface
27
+ require "johnson/error"
28
+ require "johnson/runtime"
29
+ require "johnson/parser"
30
+
31
+ $LOAD_PATH.push(File.expand_path("#{File.dirname(__FILE__)}/../js"))
32
+
33
+ module Johnson
34
+ PRELUDE = IO.read(File.dirname(__FILE__) + "/../js/johnson/prelude.js")
35
+
36
+ def self.evaluate(expression, vars={})
37
+ runtime = Johnson::Runtime.new
38
+ vars.each { |key, value| runtime[key] = value }
39
+
40
+ runtime.evaluate(expression)
41
+ end
42
+
43
+ def self.parse(js, *args)
44
+ Johnson::Parser.parse(js, *args)
45
+ end
46
+ end
@@ -0,0 +1,7 @@
1
+ require "johnson/cli/options"
2
+
3
+ module Johnson #:nodoc:
4
+ module CLI #:nodoc:
5
+ JS = IO.read(File.dirname(__FILE__) + "/../../js/johnson/cli.js")
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ require "optparse"
2
+
3
+ module Johnson #:nodoc:
4
+ module CLI #:nodoc:
5
+ class Options #:nodoc:
6
+ class << self
7
+ alias_method :parse!, :new
8
+ end
9
+
10
+ attr_reader :expressions, :load_paths, :files_to_preload, :file_to_evaluate, :arguments
11
+
12
+ def initialize(*args)
13
+ argv = args.flatten
14
+ @expressions = []
15
+ @load_paths = []
16
+ @files_to_preload = []
17
+
18
+ parser = OptionParser.new do |parser|
19
+ parser.banner = "Usage: johnson [options] [file.js] [-- jsargs]"
20
+ parser.version = Johnson::VERSION
21
+
22
+ parser.on("-e [EXPRESSION]", "Evaluate [EXPRESSION] and exit") do |expression|
23
+ @expressions << expression
24
+ end
25
+
26
+ parser.on("-I [DIRECTORY]", "Specify $LOAD_PATH directories") do |dir|
27
+ @load_paths << dir
28
+ end
29
+
30
+ parser.on("-i [FILE]", "Evaluate [FILE] before interaction") do |file|
31
+ @files_to_preload << file
32
+ end
33
+
34
+ parser.on("-i [FILE]", "Evaluate [FILE] before interaction") do |file|
35
+ @files_to_preload << file
36
+ end
37
+
38
+ parser.on("-h", "-?", "--help", "Show this message") do
39
+ puts parser
40
+ exit
41
+ end
42
+
43
+ parser.on("-v", "--version", "Show Johnson's version (#{Johnson::VERSION})") do
44
+ puts Johnson::VERSION
45
+ exit
46
+ end
47
+ end
48
+
49
+ parser.parse!(argv)
50
+
51
+ @file_to_evaluate = argv.shift
52
+ @arguments = argv.dup
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ module Johnson
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'johnson/nodes/node'
2
+ require 'johnson/nodes/function'
3
+ require 'johnson/nodes/list'
4
+ require 'johnson/nodes/for'
5
+ require 'johnson/nodes/for_in'
6
+ require 'johnson/nodes/ternary_node'
7
+ require 'johnson/nodes/binary_node'
@@ -0,0 +1,64 @@
1
+ module Johnson
2
+ module Nodes
3
+ BINARY_NODES = %w{
4
+ And
5
+ DoWhile
6
+ Case
7
+ Default
8
+ While
9
+ With
10
+ In
11
+ Switch
12
+ InstanceOf
13
+ AssignExpr
14
+ BracketAccess
15
+ DotAccessor
16
+ Equal
17
+ GetterProperty
18
+ Label
19
+ GreaterThan
20
+ LessThan
21
+ GreaterThanOrEqual
22
+ LessThanOrEqual
23
+ NotEqual
24
+ OpAdd
25
+ OpAddEqual
26
+ OpBitAnd
27
+ OpBitAndEqual
28
+ OpBitOr
29
+ OpBitOrEqual
30
+ OpBitXor
31
+ OpBitXorEqual
32
+ OpDivide
33
+ OpDivideEqual
34
+ OpEqual
35
+ OpLShift
36
+ OpLShiftEqual
37
+ OpMod
38
+ OpModEqual
39
+ OpMultiply
40
+ OpMultiplyEqual
41
+ OpRShift
42
+ OpRShiftEqual
43
+ OpSubtract
44
+ OpSubtractEqual
45
+ OpURShift
46
+ OpURShiftEqual
47
+ Or
48
+ Property
49
+ SetterProperty
50
+ StrictEqual
51
+ StrictNotEqual
52
+ }
53
+
54
+ class BinaryNode < Node
55
+ alias :right :value
56
+ attr_accessor :left
57
+ def initialize(line, column, left, right)
58
+ super(line, column, right)
59
+ @left = left
60
+ end
61
+ end
62
+ BINARY_NODES.each { |bn| const_set(bn.to_sym, Class.new(BinaryNode)) }
63
+ end
64
+ end
@@ -0,0 +1,14 @@
1
+ module Johnson
2
+ module Nodes
3
+ class For < Node
4
+ alias :body :value
5
+ attr_accessor :init, :cond, :update
6
+ def initialize(line, column, init, cond, update, body)
7
+ super(line, column, body)
8
+ @init = init
9
+ @cond = cond
10
+ @update = update
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Johnson
2
+ module Nodes
3
+ class ForIn < Node
4
+ alias :body :value
5
+ attr_accessor :in_cond
6
+ def initialize(line, column, in_cond, body)
7
+ super(line, column, body)
8
+ @in_cond = in_cond
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Johnson
2
+ module Nodes
3
+ class Function < Node
4
+ alias :body :value
5
+ attr_accessor :name, :arguments
6
+ def initialize(line, column, name, arguments, body)
7
+ super(line, column, body)
8
+ @name = name
9
+ @arguments = arguments
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module Johnson
2
+ module Nodes
3
+ LIST_NODES = %w{
4
+ SourceElements
5
+ VarStatement
6
+ Comma
7
+ ObjectLiteral
8
+ ArrayLiteral
9
+ New
10
+ FunctionCall
11
+ Import
12
+ Export
13
+ }
14
+ # This is an abstract node used for nodes of list type
15
+ # see SourceElements
16
+ class List < Node
17
+ def initialize(line, column, value = [])
18
+ super
19
+ end
20
+
21
+ def <<(obj)
22
+ self.value << obj
23
+ end
24
+ end
25
+ LIST_NODES.each { |ln| const_set(ln.to_sym, Class.new(List)) }
26
+ end
27
+ end
@@ -0,0 +1,68 @@
1
+ module Johnson
2
+ module Nodes
3
+ SINGLE_NODES = %w{
4
+ BitwiseNot
5
+ Break
6
+ Continue
7
+ Delete
8
+ False
9
+ Name
10
+ Not
11
+ Null
12
+ Number
13
+ Parenthesis
14
+ PostfixIncrement
15
+ PrefixIncrement
16
+ PostfixDecrement
17
+ PrefixDecrement
18
+ Regexp
19
+ Return
20
+ String
21
+ This
22
+ Throw
23
+ True
24
+ Typeof
25
+ UnaryNegative
26
+ UnaryPositive
27
+ Void
28
+ }
29
+ class Node
30
+ include Johnson::Visitable
31
+ include Johnson::Visitors
32
+
33
+ attr_accessor :value
34
+ attr_reader :line, :column
35
+ def initialize(line, column, value)
36
+ @line = line
37
+ @column = column
38
+ @value = value
39
+ end
40
+
41
+ def to_s
42
+ to_sexp.inspect
43
+ end
44
+
45
+ alias_method :inspect, :to_s
46
+
47
+ def to_sexp
48
+ SexpVisitor.new.accept(self)
49
+ end
50
+
51
+ def to_ecma
52
+ EcmaVisitor.new.accept(self)
53
+ end
54
+
55
+ alias_method :to_js, :to_ecma
56
+
57
+ def to_dot
58
+ DotVisitor.new { |d| d.accept(self) }
59
+ end
60
+
61
+ def each(&block)
62
+ EnumeratingVisitor.new(block).accept(self)
63
+ self
64
+ end
65
+ end
66
+ SINGLE_NODES.each { |se| const_set(se.to_sym, Class.new(Node)) }
67
+ end
68
+ end
@@ -0,0 +1,20 @@
1
+ module Johnson
2
+ module Nodes
3
+ TERNARY_NODES = %w{
4
+ Ternary
5
+ If
6
+ Try
7
+ Catch
8
+ }
9
+ class TernaryNode < Node
10
+ alias :b_else :value
11
+ attr_accessor :cond, :b_then
12
+ def initialize(line, column, cond, b_then, b_else)
13
+ super(line, column, b_else)
14
+ @cond = cond
15
+ @b_then = b_then
16
+ end
17
+ end
18
+ TERNARY_NODES.each { |bn| const_set(bn.to_sym, Class.new(TernaryNode)) }
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'stringio'
2
+ require 'johnson/parser/syntax_error'
3
+
4
+ module Johnson
5
+ module Parser
6
+ class << self
7
+ def parse(js, filename = nil, linenum = nil)
8
+ tree = if js.is_a?(String)
9
+ parse_io(StringIO.new(js), filename, linenum)
10
+ else
11
+ parse_io(js, filename, linenum)
12
+ end
13
+ tree.to_mutable_tree
14
+ end
15
+
16
+ def parse_io(js, filename = nil, linenum = nil)
17
+ Johnson::SpiderMonkey::ImmutableNode.parse_io(js, filename, linenum)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Johnson
2
+ module Parser
3
+ class SyntaxError < RuntimeError
4
+ attr_accessor :message, :file_name, :line_number
5
+ def initialize(message, file_name, line_number)
6
+ super("#{message} in (#{file_name || "nil"}): #{line_number}")
7
+ @message = message
8
+ @file_name = file_name
9
+ @line_number = line_number
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,55 @@
1
+ module Johnson
2
+ class Runtime
3
+ attr_reader :delegate
4
+
5
+ def initialize(delegate=Johnson::SpiderMonkey::Runtime)
6
+ @delegate = delegate.is_a?(Class) ? delegate.new : delegate
7
+ evaluate(Johnson::PRELUDE, "Johnson::PRELUDE", 1)
8
+ global.Johnson.runtime = self
9
+ end
10
+
11
+ def [](key)
12
+ delegate[key.to_s]
13
+ end
14
+
15
+ def []=(key, value)
16
+ delegate[key.to_s] = value
17
+ end
18
+
19
+ def evaluate(expression, filename=nil, linenum=nil)
20
+ return nil if expression.nil?
21
+ delegate.evaluate(expression, filename, linenum)
22
+ end
23
+
24
+ def global
25
+ delegate.global
26
+ end
27
+
28
+ def load(file)
29
+ delegate.evaluate(IO.read(file), file, 1)
30
+ end
31
+
32
+ ###
33
+ # Compile +script+ with +filename+ and +linenum+
34
+ def compile(script, filename=nil, linenum=nil)
35
+ delegate.compile(script, filename, linenum)
36
+ end
37
+
38
+ ###
39
+ # Yield to +block+ in +filename+ at +linenum+
40
+ def break(filename, linenum, &block)
41
+ delegate.break(filename, linenum, &block)
42
+ end
43
+
44
+ def evaluate_compiled_script(script)
45
+ delegate.evaluate_compiled_script(script)
46
+ end
47
+
48
+ private
49
+ # Called by SpiderMonkey's garbage collector to determine whether or
50
+ # not it should GC
51
+ def should_sm_gc?
52
+ false
53
+ end
54
+ end
55
+ end