From 6c7d9f4818a010f32ca5cfc6bc10c8962fd5202e Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 11 Dec 2014 10:29:12 -0800 Subject: [PATCH] Test compile anonymous and named functions --- test/test_execjs.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test_execjs.rb b/test/test_execjs.rb index fa4ef02..957b7b2 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -160,13 +160,20 @@ class TestExecJS < Test end end - def test_compile + def test_compile_anonymous_function context = ExecJS.compile("foo = function() { return \"bar\"; }") assert_equal "bar", context.exec("return foo()") assert_equal "bar", context.eval("foo()") assert_equal "bar", context.call("foo") 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 assert_equal true, ExecJS.eval("this === (function() {return this})()") assert_equal true, ExecJS.exec("return this === (function() {return this})()")