0
@@ -4,7 +4,7 @@ module Johnson
0
class RubyLandProxyTest < Johnson::TestCase
0
- @
context = Johnson::Context.new(Johnson::SpiderMonkey::Context)
0
+ @
runtime = Johnson::Runtime.new(Johnson::SpiderMonkey::Runtime)
0
def test_constructing_a_proxy_directly_asplodes
0
@@ -12,18 +12,18 @@ module Johnson
0
def test_objects_get_wrapped_as_proxies
0
- assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, @context.evaluate("x = {}"))
0
- assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, @context.evaluate("new Object()"))
0
+ assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, @runtime.evaluate("x = {}"))
0
+ assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, @runtime.evaluate("new Object()"))
0
def test_proxies_get_unwrapped_when_roundtripping
0
- proxy = @context.evaluate("x = {}")
0
- assert(@context.evaluate("x === y"))
0
+ proxy = @runtime.evaluate("x = {}")
0
+ assert(@runtime.evaluate("x === y"))
0
def test_array_indexable
0
- proxy = @
context.evaluate("var x = [1,2,3]; x")
0
+ proxy = @
runtime.evaluate("var x = [1,2,3]; x")
0
assert_equal(1, proxy[0])
0
assert_equal(1, proxy['0'])
0
@@ -32,7 +32,7 @@ module Johnson
0
def test_hash_indexable
0
- proxy = @
context.evaluate("var x = { 0: 1, 1: 2, 2: 3 }; x")
0
+ proxy = @
runtime.evaluate("var x = { 0: 1, 1: 2, 2: 3 }; x")
0
assert_equal(1, proxy[0])
0
assert_equal(1, proxy['0'])
0
@@ -41,49 +41,49 @@ module Johnson
0
def test_functions_get_wrapped_as_proxies
0
- f = @
context.evaluate("function() {}")
0
+ f = @
runtime.evaluate("function() {}")
0
assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, f)
0
- f = @
context.evaluate("function() {}")
0
+ f = @
runtime.evaluate("function() {}")
0
assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, f)
0
- f = @
context.evaluate("new Object()")
0
+ f = @
runtime.evaluate("new Object()")
0
assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, f)
0
def test_calling_non_functions_complains
0
- assert_raise(Johnson::Error) { @
context.evaluate("new Object()").call }
0
+ assert_raise(Johnson::Error) { @
runtime.evaluate("new Object()").call }
0
def test_functions_can_be_called
0
- f = @
context.evaluate("function() { return 42; }")
0
+ f = @
runtime.evaluate("function() { return 42; }")
0
assert_equal(42, f.call)
0
def test_functions_can_be_called_with_args
0
- f = @
context.evaluate("function(x) { return x * 2; }")
0
+ f = @
runtime.evaluate("function(x) { return x * 2; }")
0
assert_equal(84, f.call(42))
0
def test_functions_can_be_used_as_procs
0
- f = @
context.evaluate("function(x) { return x * 2; }")
0
+ f = @
runtime.evaluate("function(x) { return x * 2; }")
0
assert_equal([2, 4, 6], a.collect(&f))
0
def test_function_proxies_are_called_with_a_global_this
0
- f = @
context.evaluate("x = 42; function() { return this.x; }")
0
+ f = @
runtime.evaluate("x = 42; function() { return this.x; }")
0
assert_equal(42, f.call)
0
def test_can_be_indexed_by_string
0
- proxy = @
context.evaluate("x = { foo: 42 }")
0
+ proxy = @
runtime.evaluate("x = { foo: 42 }")
0
assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, proxy)
0
assert_equal(42, proxy["foo"])
0
@@ -97,29 +97,29 @@ module Johnson
0
def test_multilevel_indexing_works
0
- proxy = @
context.evaluate("x = { foo: { bar: 42 , baz: function() { return 42 } } }")
0
+ proxy = @
runtime.evaluate("x = { foo: { bar: 42 , baz: function() { return 42 } } }")
0
assert_equal(42, proxy["foo"]["bar"])
0
assert_equal(42, proxy["foo"]["baz"].call)
0
def test_respond_to_works
0
- proxy = @
context.evaluate("x = { foo: 42 }")
0
+ proxy = @
runtime.evaluate("x = { foo: 42 }")
0
assert(!proxy.respond_to?(:bar))
0
assert(proxy.respond_to?(:foo))
0
def test_respond_to_always_returns_true_for_assignment
0
- proxy = @
context.evaluate("x = {}")
0
+ proxy = @
runtime.evaluate("x = {}")
0
assert(proxy.respond_to?(:bar=))
0
- proxy = @
context.evaluate("x = { foo: 42 }")
0
+ proxy = @
runtime.evaluate("x = { foo: 42 }")
0
assert_equal(42, proxy.foo)
0
- proxy = @
context.evaluate("x = {}")
0
+ proxy = @
runtime.evaluate("x = {}")
0
assert_js_equal(42, "x.foo")
0
@@ -127,22 +127,22 @@ module Johnson
0
def test_method_with_no_arguments
0
- proxy = @
context.evaluate("x = { foo: function() { return 42 } }")
0
+ proxy = @
runtime.evaluate("x = { foo: function() { return 42 } }")
0
assert_equal(42, proxy.foo)
0
def test_method_with_one_argument
0
- proxy = @
context.evaluate("f = { f: function(x) { return x * 2 } }")
0
+ proxy = @
runtime.evaluate("f = { f: function(x) { return x * 2 } }")
0
assert_equal(84, proxy.f(42))
0
def test_method_with_multiple_arguments
0
- proxy = @
context.evaluate("x = { add: function(x, y) { return x + y } }")
0
+ proxy = @
runtime.evaluate("x = { add: function(x, y) { return x + y } }")
0
assert_equal(42, proxy.add(40, 2))
0
def test_supports_each_on_arrays
0
- proxy = @
context.evaluate("[1, 2, 3]")
0
+ proxy = @
runtime.evaluate("[1, 2, 3]")
0
proxy.each { |n| values << n }
0
@@ -150,7 +150,7 @@ module Johnson
0
def test_supports_each_on_things_that_arent_arrays
0
- proxy = @
context.evaluate("x = { foo: 'fooval', bar: 'barval' }; x[0] = 42; x")
0
+ proxy = @
runtime.evaluate("x = { foo: 'fooval', bar: 'barval' }; x[0] = 42; x")
0
proxy.each { |k, v| values[k] = v }
0
@@ -158,7 +158,7 @@ module Johnson
0
def test_each_passes_an_exception
0
- proxy = @
context.evaluate("x = { foo: 'fooval', bar: 'barval' }; x[0] = 42; x")
0
+ proxy = @
runtime.evaluate("x = { foo: 'fooval', bar: 'barval' }; x[0] = 42; x")
0
assert_raise(RuntimeError) do
0
@@ -171,29 +171,29 @@ module Johnson
0
- proxy = @
context.evaluate("[1, 2, 3]")
0
+ proxy = @
runtime.evaluate("[1, 2, 3]")
0
assert_kind_of(Enumerable, proxy)
0
assert_equal([2, 4, 6], proxy.collect { |n| n * 2 })
0
- proxy = @
context.evaluate("[1, 2, 3]")
0
+ proxy = @
runtime.evaluate("[1, 2, 3]")
0
assert_equal(3, proxy.length)
0
def test_length_is_aliased_as_size
0
- proxy = @
context.evaluate("[1, 2, 3]")
0
+ proxy = @
runtime.evaluate("[1, 2, 3]")
0
assert_equal(3, proxy.size)
0
def test_length_for_arrays_ignores_non_numeric_properties
0
- proxy = @
context.evaluate("x = [1, 2, 3]; x['foo'] = 'bar'; x")
0
+ proxy = @
runtime.evaluate("x = [1, 2, 3]; x['foo'] = 'bar'; x")
0
assert_equal(3, proxy.length)
0
def test_length_for_objects_includes_all_properties
0
- proxy = @
context.evaluate("x = { foo: 'foo', bar: 'bar', 0: 42 }")
0
+ proxy = @
runtime.evaluate("x = { foo: 'foo', bar: 'bar', 0: 42 }")
0
assert_equal(3, proxy.length)