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

44 lines
899 B
Ruby

module Rhino
class JSError < StandardError
def initialize(native)
@native = native # NativeException wrapping a Java Throwable
end
def message
cause ? cause.details : @native.to_s
end
def to_s
super
end
# most likely a Rhino::JS::JavaScriptException
def cause
@native.respond_to?(:cause) ? @native.cause : nil
end
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
def javascript_backtrace
cause.is_a?(JS::RhinoException) ? cause.getScriptStackTrace : nil
end
end
end