diff --git a/History.txt b/History.txt index a2ae735..effce26 100644 --- a/History.txt +++ b/History.txt @@ -1,6 +1,7 @@ === 1.73.3 2012-xx-xx RedJS 0.4 compatible +* allow try-catch-ing ScriptError (besides StandardError) in JS * support for yield in JS property access via the [], []= methods * refactor access implementations to classes + introduce a shared base * missing explicit require 'rhino/version' diff --git a/lib/rhino/ruby.rb b/lib/rhino/ruby.rb index e874845..689a902 100644 --- a/lib/rhino/ruby.rb +++ b/lib/rhino/ruby.rb @@ -196,7 +196,7 @@ module Rhino @callable end result = callable.call(*rb_args) - rescue StandardError => e + rescue StandardError, ScriptError => e raise Ruby.wrap_error(e) # thus `try { } catch (e)` works in JS end Rhino.to_javascript(result, scope) diff --git a/spec/rhino/redjs_spec.rb b/spec/rhino/redjs_spec.rb index 493c231..19b4d15 100644 --- a/spec/rhino/redjs_spec.rb +++ b/spec/rhino/redjs_spec.rb @@ -7,6 +7,25 @@ puts "will run JavaScript specs from RedJS #{RedJS::VERSION}" describe Rhino::Context do it_behaves_like 'RedJS::Context' + + # TODO: remove if present in RedJS + it "catched ScriptError in JS" do + klass = Class.new do + def muu(*args) + args && raise(ScriptError.new('muu')) + end + end + + error = nil + lambda { + RedJS::Context.new do |cxt| + cxt['obj'] = klass.new + error = cxt.eval('var error; try { obj.muu(); error = null } catch(e) { error = e }') + end + }.should_not raise_error + error.should_not be nil + error.should be_a ScriptError + end it "keeps objects iterable when property accessor is provided" do klass = Class.new do