1
0
Fork 0
mirror of https://github.com/rubyjs/therubyrhino synced 2023-03-27 23:21:34 -04:00

allow try-catch-ing ScriptError (besides StandardError) in JS

This commit is contained in:
kares 2012-04-23 21:26:22 +02:00
parent 6918349af9
commit 03d30b881b
3 changed files with 21 additions and 1 deletions

View file

@ -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'

View file

@ -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)

View file

@ -8,6 +8,25 @@ 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
def [](name); name; end