mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Test compile anonymous and named functions
This commit is contained in:
parent
07052f23d1
commit
6c7d9f4818
1 changed files with 8 additions and 1 deletions
|
@ -160,13 +160,20 @@ class TestExecJS < Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_compile
|
def test_compile_anonymous_function
|
||||||
context = ExecJS.compile("foo = function() { return \"bar\"; }")
|
context = ExecJS.compile("foo = function() { return \"bar\"; }")
|
||||||
assert_equal "bar", context.exec("return foo()")
|
assert_equal "bar", context.exec("return foo()")
|
||||||
assert_equal "bar", context.eval("foo()")
|
assert_equal "bar", context.eval("foo()")
|
||||||
assert_equal "bar", context.call("foo")
|
assert_equal "bar", context.call("foo")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_compile_named_function
|
||||||
|
context = ExecJS.compile("function foo() { return \"bar\"; }")
|
||||||
|
assert_equal "bar", context.exec("return foo()")
|
||||||
|
assert_equal "bar", context.eval("foo()")
|
||||||
|
assert_equal "bar", context.call("foo")
|
||||||
|
end
|
||||||
|
|
||||||
def test_this_is_global_scope
|
def test_this_is_global_scope
|
||||||
assert_equal true, ExecJS.eval("this === (function() {return this})()")
|
assert_equal true, ExecJS.eval("this === (function() {return this})()")
|
||||||
assert_equal true, ExecJS.exec("return this === (function() {return this})()")
|
assert_equal true, ExecJS.exec("return this === (function() {return this})()")
|
||||||
|
|
Loading…
Reference in a new issue