lib/execjs/ruby_rhino_runtime.rb in execjs-2.2.2 vs lib/execjs/ruby_rhino_runtime.rb in execjs-2.3.0

- old
+ new

@@ -7,10 +7,12 @@ source = encode(source) @rhino_context = ::Rhino::Context.new fix_memory_limit! @rhino_context @rhino_context.eval(source) + rescue Exception => e + reraise_error(e) end def exec(source, options = {}) source = encode(source) @@ -23,26 +25,18 @@ source = encode(source) if /\S/ =~ source unbox @rhino_context.eval("(#{source})") end - rescue ::Rhino::JSError => e - if e.message =~ /^syntax error/ - raise RuntimeError, e.message - else - raise ProgramError, e.message - end + rescue Exception => e + reraise_error(e) end def call(properties, *args) unbox @rhino_context.eval(properties).call(*args) - rescue ::Rhino::JSError => e - if e.message == "syntax error" - raise RuntimeError, e.message - else - raise ProgramError, e.message - end + rescue Exception => e + reraise_error(e) end def unbox(value) case value = ::Rhino::to_ruby(value) when Java::OrgMozillaJavascript::NativeFunction @@ -59,9 +53,22 @@ end when Array value.map { |v| unbox(v) } else value + end + end + + def reraise_error(e) + case e + when ::Rhino::JSError + if e.message == "syntax error" + raise RuntimeError, e.message + else + raise ProgramError, e.message + end + else + raise e end end private # Disables bytecode compiling which limits you to 64K scripts