public
Description: Johnson wraps JavaScript in a loving Ruby embrace.
Homepage: http://github.com/jbarnette/johnson/wikis
Clone URL: git://github.com/jbarnette/johnson.git
making more shit work
tenderlove (author)
Fri May 30 16:50:00 -0700 2008
commit  e6e9ac78c9aee246329f6bc90b19c58c49a2f538
tree    26c1852e99f90ad428f37959d652f8a48c7440fa
parent  dc2a8331070fe0cb318d359ee5d439859d957604
...
3
4
5
6
 
7
8
9
10
 
11
12
13
...
15
16
17
18
 
19
20
21
...
23
24
25
26
 
27
28
29
30
 
31
32
33
34
 
35
36
37
 
 
38
39
40
...
43
44
45
46
 
47
48
49
...
3
4
5
 
6
7
8
9
 
10
11
12
13
...
15
16
17
 
18
19
20
21
...
23
24
25
 
26
27
28
29
 
30
31
32
33
 
34
35
 
 
36
37
38
39
40
...
43
44
45
 
46
47
48
49
0
@@ -3,11 +3,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), "/../helper"))
0
 module Johnson
0
   class PreludeTest < Johnson::TestCase
0
     def setup
0
-      @context = Johnson::Context.new
0
+      @runtime = Johnson::Runtime.new
0
     end
0
     
0
     def test_symbols_are_interned
0
-      assert(@context.evaluate("Johnson.symbolize('foo') === Johnson.symbolize('foo')"))
0
+      assert(@runtime.evaluate("Johnson.symbolize('foo') === Johnson.symbolize('foo')"))
0
     end
0
     
0
     def test_strings_had_a_to_symbol_method
0
@@ -15,7 +15,7 @@ module Johnson
0
     end
0
     
0
     def test_string_to_symbol_is_not_enumerable
0
-      assert(!@context.evaluate(<<-END))
0
+      assert(!@runtime.evaluate(<<-END))
0
         var flag = false;
0
         for (x in "foo") { if (x == 'toSymbol') flag = true }
0
         flag
0
@@ -23,18 +23,18 @@ module Johnson
0
     end
0
     
0
     def test_symbol_to_string
0
-      assert_equal("monkey", @context.evaluate("Johnson.symbolize('monkey').toString()"))
0
+      assert_equal("monkey", @runtime.evaluate("Johnson.symbolize('monkey').toString()"))
0
     end
0
 
0
     def test_symbol_inspect
0
-      assert_equal(":monkey", @context.evaluate("Johnson.symbolize('monkey').inspect()"))
0
+      assert_equal(":monkey", @runtime.evaluate("Johnson.symbolize('monkey').inspect()"))
0
     end
0
     
0
     def test_all_of_ruby_is_available
0
-      assert_raise(Johnson::Error) { @context.evaluate("Ruby.Set.new()") }
0
+      assert_raise(Johnson::Error) { @runtime.evaluate("Ruby.Set.new()") }
0
       
0
-      @context.evaluate("Ruby.require('set')")
0
-      assert_kind_of(Set, @context.evaluate("Ruby.Set.new()"))
0
+      @runtime.evaluate("Ruby.require('set')")
0
+      assert_kind_of(Set, @runtime.evaluate("Ruby.Set.new()"))
0
     end
0
     
0
     def test_require_an_existing_js_file_without_extension
0
@@ -43,7 +43,7 @@ module Johnson
0
     
0
     def test_require_returns_false_the_second_time_around
0
       assert_js("Johnson.require('johnson/template')")
0
-      assert(!@context.evaluate("Johnson.require('johnson/template')"))
0
+      assert(!@runtime.evaluate("Johnson.require('johnson/template')"))
0
     end
0
     
0
     def test_missing_requires_throw_LoadError
...
4
5
6
7
 
8
9
10
11
 
12
13
14
15
16
17
 
 
 
 
18
19
20
...
4
5
6
 
7
8
9
10
 
11
12
13
 
 
 
 
14
15
16
17
18
19
20
0
@@ -4,17 +4,17 @@ module Johnson
0
   module SpiderMonkey
0
     class ContextTest < Johnson::TestCase
0
       def setup
0
-        @context = Johnson::Context.new(Johnson::SpiderMonkey::Context)
0
+        @runtime = Johnson::Runtime.new(Johnson::SpiderMonkey::Runtime)
0
       end
0
       
0
       def test_wraps_global_unfuckedly
0
-        assert_same(@context.global, @context.evaluate("this"))
0
+        assert_same(@runtime.global, @runtime.evaluate("this"))
0
       end
0
       
0
-      def test_provides_basic_context_interface
0
-        assert(@context.respond_to?(:evaluate))
0
-        assert(@context.respond_to?(:[]))
0
-        assert(@context.respond_to?(:[]=))
0
+      def test_provides_basic_runtime_interface
0
+        assert(@runtime.respond_to?(:evaluate))
0
+        assert(@runtime.respond_to?(:[]))
0
+        assert(@runtime.respond_to?(:[]=))
0
       end
0
     end
0
   end
...
58
59
60
61
 
62
63
64
...
66
67
68
69
 
70
71
72
73
74
 
75
76
 
77
78
79
...
81
82
83
84
 
85
86
 
87
88
89
...
92
93
94
95
96
 
 
97
98
 
99
100
101
102
103
 
104
105
106
107
108
109
110
 
 
111
112
113
114
115
 
 
116
117
118
119
120
 
 
121
122
123
124
125
 
 
126
127
128
129
 
130
131
132
133
134
 
135
136
137
138
139
140
141
 
142
143
144
145
146
 
147
148
149
150
151
152
 
153
154
155
156
157
158
 
159
160
161
162
163
 
164
165
166
167
168
 
169
170
171
172
173
 
174
175
176
177
178
179
 
 
180
181
182
183
184
 
 
185
186
187
188
189
190
 
 
191
192
193
 
194
195
196
197
198
 
199
200
201
202
203
 
204
205
206
...
221
222
223
224
 
225
226
227
228
 
229
230
231
232
 
233
234
235
...
58
59
60
 
61
62
63
64
...
66
67
68
 
69
70
71
72
73
 
74
75
 
76
77
78
79
...
81
82
83
 
84
85
 
86
87
88
89
...
92
93
94
 
 
95
96
97
 
98
99
100
101
102
 
103
104
105
106
107
108
 
 
109
110
111
112
113
 
 
114
115
116
117
118
 
 
119
120
121
122
123
 
 
124
125
126
127
128
 
129
130
131
132
133
 
134
135
136
137
138
139
140
 
141
142
143
144
145
 
146
147
148
149
150
151
 
152
153
154
155
156
157
 
158
159
160
161
162
 
163
164
165
166
167
 
168
169
170
171
172
 
173
174
175
176
177
 
 
178
179
180
181
182
 
 
183
184
185
186
187
188
 
 
189
190
191
192
 
193
194
195
196
197
 
198
199
200
201
202
 
203
204
205
206
...
221
222
223
 
224
225
226
227
 
228
229
230
231
 
232
233
234
235
0
@@ -58,7 +58,7 @@ module Johnson
0
       end
0
 
0
       def setup
0
-        @context = Johnson::Context.new(Johnson::SpiderMonkey::Context)
0
+        @runtime = Johnson::Runtime.new(Johnson::SpiderMonkey::Runtime)
0
       end
0
 
0
       def test_find_constants
0
@@ -66,14 +66,14 @@ module Johnson
0
       end
0
 
0
       def test_proxies_get_reused
0
-        @context["foo"] = @context["bar"] = Foo.new
0
+        @runtime["foo"] = @runtime["bar"] = Foo.new
0
         assert_js_equal(true, "foo === bar")
0
       end
0
 
0
       def test_attributes_get_added_to_ruby
0
-        foo = @context["foo"] = Foo.new
0
+        foo = @runtime["foo"] = Foo.new
0
         assert !foo.respond_to?(:johnson)
0
-        @context.evaluate("foo.johnson = 'explode';")
0
+        @runtime.evaluate("foo.johnson = 'explode';")
0
         assert foo.respond_to?(:johnson)
0
         assert_equal('explode', foo.johnson)
0
         assert_js_equal('explode', 'foo.johnson')
0
@@ -81,9 +81,9 @@ module Johnson
0
       end
0
 
0
       def test_assign_function_as_attribute
0
-        foo = @context["foo"] = Foo.new
0
+        foo = @runtime["foo"] = Foo.new
0
         assert !foo.respond_to?(:johnson)
0
-        f = @context.evaluate("foo.johnson = function() { return 'explode'; }")
0
+        f = @runtime.evaluate("foo.johnson = function() { return 'explode'; }")
0
         assert foo.respond_to?(:johnson)
0
         assert_equal('explode', foo.johnson)
0
         assert_js_equal('explode', 'foo.johnson()')
0
@@ -92,115 +92,115 @@ module Johnson
0
       end
0
 
0
       def test_assign_function_as_attribute_with_this
0
-        foo = @context["foo"] = Foo.new
0
-        @context.evaluate("foo.ex_squared = function(x) { return this.x2(x); }")
0
+        foo = @runtime["foo"] = Foo.new
0
+        @runtime.evaluate("foo.ex_squared = function(x) { return this.x2(x); }")
0
         assert_equal(4, foo.ex_squared(2))
0
-        @context.evaluate("foo.ex_squared = 20;")
0
+        @runtime.evaluate("foo.ex_squared = 20;")
0
         assert_equal(20, foo.ex_squared)
0
       end
0
 
0
       def test_use_ruby_global_object
0
-        func = @context.evaluate("function(x) { return this.x2(x); }")
0
+        func = @runtime.evaluate("function(x) { return this.x2(x); }")
0
         foo  = Foo.new
0
         assert_equal(4, func.call_using(foo, 2))
0
       end
0
       
0
       def test_proxies_roundtrip
0
-        @context["foo"] = foo = Foo.new
0
-        assert_same(foo, @context.evaluate("foo"))
0
+        @runtime["foo"] = foo = Foo.new
0
+        assert_same(foo, @runtime.evaluate("foo"))
0
       end
0
       
0
       def test_proxies_classes
0
-        @context["Foo"] = Foo
0
-        assert_same(Foo, @context.evaluate("Foo"))
0
+        @runtime["Foo"] = Foo
0
+        assert_same(Foo, @runtime.evaluate("Foo"))
0
       end
0
       
0
       def test_proxies_modules
0
-        @context["AModule"] = AModule
0
-        assert_same(AModule, @context.evaluate("AModule"))
0
+        @runtime["AModule"] = AModule
0
+        assert_same(AModule, @runtime.evaluate("AModule"))
0
       end
0
       
0
       def test_proxies_hashes
0
-        @context["beatles"] = { "george" => "guitar" }
0
-        assert_equal("guitar", @context.evaluate("beatles['george']"))
0
+        @runtime["beatles"] = { "george" => "guitar" }
0
+        assert_equal("guitar", @runtime.evaluate("beatles['george']"))
0
       end
0
       
0
       def test_getter_calls_0_arity_method
0
-        @context["foo"] = Foo.new
0
+        @runtime["foo"] = Foo.new
0
         assert_js_equal(10, "foo.bar")
0
       end
0
       
0
       def test_getter_calls_indexer
0
-        @context["foo"] = indexable = Indexable.new
0
+        @runtime["foo"] = indexable = Indexable.new
0
         indexable["bar"] = 10
0
         
0
         assert_js_equal(10, "foo.bar")
0
       end
0
       
0
       def test_getter_returns_nil_for_unknown_properties
0
-        @context["foo"] = Foo.new
0
+        @runtime["foo"] = Foo.new
0
         assert_js_equal(nil, "foo.quux")
0
       end
0
 
0
       def test_setter_calls_key=
0
-        @context["foo"] = foo = Foo.new
0
+        @runtime["foo"] = foo = Foo.new
0
         assert_js_equal(42, "foo.bar = 42")
0
         assert_equal(42, foo.bar)
0
       end
0
       
0
       def test_setter_calls_indexer
0
-        @context["foo"] = indexable = Indexable.new
0
+        @runtime["foo"] = indexable = Indexable.new
0
         assert_js_equal(42, "foo.monkey = 42")
0
         assert_equal(42, indexable["monkey"])
0
       end
0
       
0
       def test_calls_attr_reader
0
-        @context["foo"] = Foo.new
0
+        @runtime["foo"] = Foo.new
0
         assert_js_equal(10, "foo.bar")
0
       end
0
       
0
       def test_calls_1_arity_method
0
-        @context["foo"] = Foo.new
0
+        @runtime["foo"] = Foo.new
0
         assert_js_equal(10, "foo.x2(5)")
0
       end
0
       
0
       def test_calls_n_arity_method
0
-        @context["foo"] = Foo.new
0
+        @runtime["foo"] = Foo.new
0
         assert_js_equal(10, "foo.add(4, 2, 2, 1, 1)")
0
       end
0
       
0
       def test_calls_class_method
0
-        @context["Foo"] = Foo
0
+        @runtime["Foo"] = Foo
0
         assert_js_equal(Foo.bar, "Foo.bar()")
0
       end
0
       
0
       def test_accesses_consts
0
-        @context["Foo"] = Foo
0
-        assert_same(Foo::Inner, @context.evaluate("Foo.Inner"))
0
+        @runtime["Foo"] = Foo
0
+        assert_same(Foo::Inner, @runtime.evaluate("Foo.Inner"))
0
       end
0
             
0
       def test_can_create_new_instances_in_js
0
-        @context["AClass"] = AClass
0
-        foo = @context.evaluate("AClass.new()")
0
+        @runtime["AClass"] = AClass
0
+        foo = @runtime.evaluate("AClass.new()")
0
         assert_kind_of(AClass, foo)
0
       end
0
       
0
       def test_class_proxies_provide_a_ctor
0
-        @context["AClass"] = AClass
0
-        foo = @context.evaluate("new AClass()")
0
+        @runtime["AClass"] = AClass
0
+        foo = @runtime.evaluate("new AClass()")
0
         assert_kind_of(AClass, foo)
0
         
0
-        bar = @context.evaluate("new AClass(1, 2, 3)")
0
+        bar = @runtime.evaluate("new AClass(1, 2, 3)")
0
         assert_equal([1, 2, 3], bar.args)
0
       end
0
       
0
       def test_dwims_blocks
0
-        @context["foo"] = Foo.new
0
+        @runtime["foo"] = Foo.new
0
         assert_js_equal(4, "foo.xform(2, function(x) { return x * 2 })")
0
       end
0
       
0
       def test_dwims_blocks_for_0_arity_methods
0
-        @context[:arr] = [1, 2, 3]
0
+        @runtime[:arr] = [1, 2, 3]
0
         assert_js_equal([2, 4, 6], "arr.collect(function(x) { return x * 2 })")
0
       end
0
       
0
@@ -221,15 +221,15 @@ module Johnson
0
       end
0
 
0
       def test_raises_string_to_ruby
0
-        assert_raise(Johnson::Error) { @context.evaluate("throw 'my string';") }
0
+        assert_raise(Johnson::Error) { @runtime.evaluate("throw 'my string';") }
0
       end
0
 
0
       def test_raises_object_to_ruby
0
-        assert_raise(Johnson::Error) { @context.evaluate("throw { bad: true };") }
0
+        assert_raise(Johnson::Error) { @runtime.evaluate("throw { bad: true };") }
0
       end
0
 
0
       def test_raises_exception_to_ruby
0
-        assert_raise(Johnson::Error) { @context.evaluate("undefinedValue();") }
0
+        assert_raise(Johnson::Error) { @runtime.evaluate("undefinedValue();") }
0
       end
0
     end
0
   end

Comments