Exception: Rhino::JSError
Instance Method Summary collapse
-
#backtrace ⇒ Object
The backtrace is constructed using #javascript_backtrace + the Ruby part.
-
#cause ⇒ Object
Returns the (nested) cause of this error if any, most likely a #Rhino::JS::JavaScriptException instance.
-
#initialize(native) ⇒ JSError
constructor
A new instance of JSError.
- #inspect ⇒ Object
-
#javascript_backtrace(keep_elements = false) ⇒ Object
Returns the JavaScript back-trace part for this error (the script stack).
-
#message ⇒ Object
Returns the error message, in case of a native JavaScript value, will return that value converted to a String.
-
#unwrap ⇒ Object
Attempts to unwrap the (native) JavaScript/Java exception.
-
#value(unwrap = false) ⇒ Object
Return the thown (native) JavaScript value.
Constructor Details
#initialize(native) ⇒ JSError
Returns a new instance of JSError.
5 6 7 8 9 10 11 12 |
# File 'lib/rhino/error.rb', line 5 def initialize(native) @native = native # NativeException wrapping a Java Throwable if ( value = self.value(true) ) != nil super value.is_a?(Exception) ? "#{value.class.name}: #{value.}" : value else super cause ? cause.details : @native end end |
Instance Method Details
#backtrace ⇒ Object
The backtrace is constructed using #javascript_backtrace + the Ruby part.
60 61 62 63 64 65 66 |
# File 'lib/rhino/error.rb', line 60 def backtrace if js_backtrace = javascript_backtrace js_backtrace.push(*super) else super end end |
#cause ⇒ Object
Returns the (nested) cause of this error if any, most likely a #Rhino::JS::JavaScriptException instance.
26 27 28 29 30 31 32 33 |
# File 'lib/rhino/error.rb', line 26 def cause return @cause if defined?(@cause) if @native.respond_to?(:cause) && @native.cause @native.cause else @native.is_a?(JS::RhinoException) ? @native : nil end end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/rhino/error.rb', line 14 def inspect "#<#{self.class.name}: #{}>" end |
#javascript_backtrace(keep_elements = false) ⇒ Object
Returns the JavaScript back-trace part for this error (the script stack).
69 70 71 72 73 74 75 76 77 |
# File 'lib/rhino/error.rb', line 69 def javascript_backtrace(keep_elements = false) if cause.is_a?(JS::RhinoException) cause.getScriptStack.map do |element| # ScriptStackElement[] keep_elements ? element : element.to_s end else nil end end |
#message ⇒ Object
Returns the error message, in case of a native JavaScript value, will return that value converted to a String.
20 21 22 |
# File 'lib/rhino/error.rb', line 20 def super.to_s # since 1.9.x message is expected to allways be a string end |
#unwrap ⇒ Object
Attempts to unwrap the (native) JavaScript/Java exception.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rhino/error.rb', line 36 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 |
#value(unwrap = false) ⇒ Object
Return the thown (native) JavaScript value.
52 53 54 55 56 57 |
# File 'lib/rhino/error.rb', line 52 def value(unwrap = false) return @value if defined?(@value) && ! unwrap @value = get_value unless defined?(@value) return @value.unwrap if unwrap && @value.respond_to?(:unwrap) @value end |