From 30f109bf65dc5742ec4cc9b529fa2b2f5aae6824 Mon Sep 17 00:00:00 2001 From: kares Date: Wed, 30 May 2012 07:42:46 +0200 Subject: [PATCH] fn#apply error handling + include the latest specs for 6c962f7db048b7bb7903736193f73c1277a48abc --- Gemfile | 2 +- lib/rhino/rhino_ext.rb | 2 ++ spec/rhino/error_spec.rb | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 89a5beb..0b7c7ce 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,4 @@ gemspec # NOTE: some specs might be excluded @see #spec/spec_helper.rb gem 'redjs', :git => 'git://github.com/cowboyd/redjs.git', :group => :test, - :ref => "8656639e99d52b8d5414250db2e27db4bb531506" + :ref => "b212e50ad347c0d32e53f28d0d627df6b8077e68" diff --git a/lib/rhino/rhino_ext.rb b/lib/rhino/rhino_ext.rb index 158d269..ab33d6f 100644 --- a/lib/rhino/rhino_ext.rb +++ b/lib/rhino/rhino_ext.rb @@ -200,6 +200,8 @@ class Java::OrgMozillaJavascript::BaseFunction context = Rhino::JS::Context.enter; scope = current_scope(context) args = Rhino.args_to_javascript(args, scope) __call__(context, scope, Rhino.to_javascript(this), args) + rescue Rhino::JS::JavaScriptException => e + raise Rhino::JSError.new(e) ensure Rhino::JS::Context.exit end diff --git a/spec/rhino/error_spec.rb b/spec/rhino/error_spec.rb index 73c48d8..e6a19e7 100644 --- a/spec/rhino/error_spec.rb +++ b/spec/rhino/error_spec.rb @@ -127,5 +127,18 @@ describe Rhino::JSError do fail "expected to rescue" end end + + it "raises correct error from function#apply" do + begin + context = Rhino::Context.new + context.eval "function foo() { throw 'bar' }" + context['foo'].apply(nil) + rescue => e + e.should be_a Rhino::JSError + e.value.should == 'bar' + else + fail "expected to rescue" + end + end end \ No newline at end of file