From 8deaaf16a8000eb546f0d3e15de9b358eb380dbc Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 1 Aug 2011 23:13:56 -0500 Subject: [PATCH 1/3] Fix typo --- lib/execjs/johnson_runtime.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/execjs/johnson_runtime.rb b/lib/execjs/johnson_runtime.rb index 1d3e1ff..44a9dae 100644 --- a/lib/execjs/johnson_runtime.rb +++ b/lib/execjs/johnson_runtime.rb @@ -7,7 +7,7 @@ module ExecJS end def exec(source, options = {}) - souce = source.encode('UTF-8') if source.respond_to?(:encode) + source = source.encode('UTF-8') if source.respond_to?(:encode) if /\S/ =~ source eval "(function(){#{source}})()", options @@ -15,7 +15,7 @@ module ExecJS end def eval(source, options = {}) - souce = source.encode('UTF-8') if source.respond_to?(:encode) + source = source.encode('UTF-8') if source.respond_to?(:encode) if /\S/ =~ source unbox @runtime.evaluate("(#{source})") From 6ffac452159e24ae46cef6a399ae3e5ec4630687 Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Wed, 3 Aug 2011 09:51:25 -0500 Subject: [PATCH 2/3] Fix unboxing nested functions on RubyRhino --- lib/execjs/ruby_rhino_runtime.rb | 11 +++++++++-- test/test_runtime.rb | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/execjs/ruby_rhino_runtime.rb b/lib/execjs/ruby_rhino_runtime.rb index b971bd6..e6d5f8a 100644 --- a/lib/execjs/ruby_rhino_runtime.rb +++ b/lib/execjs/ruby_rhino_runtime.rb @@ -42,14 +42,21 @@ module ExecJS end def unbox(value) - case value + case value = ::Rhino::To.ruby(value) when ::Rhino::NativeFunction nil when ::Rhino::NativeObject value.inject({}) do |vs, (k, v)| - vs[k] = unbox(v) unless v.is_a?(::Rhino::NativeFunction) + case v + when ::Rhino::NativeFunction, ::Rhino::J::Function + nil + else + vs[k] = unbox(v) + end vs end + when Array + value.map { |v| unbox(v) } else value end diff --git a/test/test_runtime.rb b/test/test_runtime.rb index 2b4f44e..313cf29 100644 --- a/test/test_runtime.rb +++ b/test/test_runtime.rb @@ -29,8 +29,10 @@ class TestRuntime < Test::Unit::TestCase assert_equal 0, @runtime.eval("0") assert_equal true, @runtime.eval("true") assert_equal [1, 2], @runtime.eval("[1, 2]") + assert_equal [1, nil], @runtime.eval("[1, function() {}]") assert_equal "hello", @runtime.eval("'hello'") assert_equal({"a"=>1,"b"=>2}, @runtime.eval("{a:1,b:2}")) + assert_equal({"a"=>true}, @runtime.eval("{a:true,b:function (){}}")) assert_equal "café", @runtime.eval("'café'") assert_equal "☃", @runtime.eval('"☃"') assert_equal "\\", @runtime.eval('"\\\\"') From 0f9a48587736f3108c0d33a95baa76e8d42b3402 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 3 Aug 2011 09:55:01 -0500 Subject: [PATCH 3/3] Fix double VERSION loading warning --- execjs.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/execjs.gemspec b/execjs.gemspec index 17f3009..2f228b5 100644 --- a/execjs.gemspec +++ b/execjs.gemspec @@ -1,4 +1,5 @@ -require File.expand_path("../lib/execjs/version.rb", __FILE__) +$:.unshift File.expand_path('..', __FILE__) +require 'execjs/version' Gem::Specification.new do |s| s.name = "execjs"