2011-12-09 05:28:27 -05:00
|
|
|
|
|
|
|
module Rhino
|
|
|
|
|
|
|
|
class JSError < StandardError
|
|
|
|
|
|
|
|
def initialize(native)
|
|
|
|
@native = native # NativeException wrapping a Java Throwable
|
|
|
|
end
|
|
|
|
|
2012-01-07 11:01:38 -05:00
|
|
|
def message
|
|
|
|
cause ? cause.details : @native.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2011-12-09 05:28:27 -05:00
|
|
|
# most likely a Rhino::JS::JavaScriptException
|
|
|
|
def cause
|
|
|
|
@native.respond_to?(:cause) ? @native.cause : nil
|
|
|
|
end
|
|
|
|
|
2012-01-07 11:01:38 -05:00
|
|
|
def unwrap
|
|
|
|
return @unwrap if defined?(@unwrap)
|
|
|
|
cause = self.cause
|
|
|
|
if cause && cause.is_a?(JS::WrappedException)
|
|
|
|
e = cause.getWrappedException
|
|
|
|
if e && e.is_a?(Java::OrgJrubyExceptions::RaiseException)
|
|
|
|
@unwrap = e.getException
|
|
|
|
else
|
|
|
|
@unwrap = e
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@unwrap = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-09 05:28:27 -05:00
|
|
|
def javascript_backtrace
|
|
|
|
cause.is_a?(JS::RhinoException) ? cause.getScriptStackTrace : nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|