mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Fix rhino errors
This commit is contained in:
parent
bb8810fdd1
commit
ed5acddc40
1 changed files with 15 additions and 14 deletions
|
@ -10,7 +10,7 @@ module ExecJS
|
||||||
fix_memory_limit! @rhino_context
|
fix_memory_limit! @rhino_context
|
||||||
@rhino_context.eval(source)
|
@rhino_context.eval(source)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
reraise_error(e)
|
raise wrap_error(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec(source, options = {})
|
def exec(source, options = {})
|
||||||
|
@ -28,13 +28,13 @@ module ExecJS
|
||||||
unbox @rhino_context.eval("(#{source})")
|
unbox @rhino_context.eval("(#{source})")
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
reraise_error(e)
|
raise wrap_error(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(properties, *args)
|
def call(properties, *args)
|
||||||
unbox @rhino_context.eval(properties).call(*args)
|
unbox @rhino_context.eval(properties).call(*args)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
reraise_error(e)
|
raise wrap_error(e)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unbox(value)
|
def unbox(value)
|
||||||
|
@ -58,17 +58,18 @@ module ExecJS
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def reraise_error(e)
|
def wrap_error(e)
|
||||||
case e
|
return e unless e.is_a?(::Rhino::JSError)
|
||||||
when ::Rhino::JSError
|
|
||||||
if e.message == "syntax error"
|
error_class = e.message == "syntax error" ? RuntimeError : ProgramError
|
||||||
raise RuntimeError, e.message
|
|
||||||
else
|
stack = e.backtrace
|
||||||
raise ProgramError, e.message
|
stack = stack.map { |line| line.sub(" at ", "").sub("<eval>", "(execjs)").strip }
|
||||||
end
|
stack.unshift("(execjs):1") if e.javascript_backtrace.empty?
|
||||||
else
|
|
||||||
raise e
|
error = error_class.new(e.value.to_s)
|
||||||
end
|
error.set_backtrace(stack)
|
||||||
|
error
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in a new issue