Exception: Rhino::JSError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/rhino/error.rb

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ JSError

Returns a new instance of JSError.



6
7
8
9
10
# File 'lib/rhino/error.rb', line 6

def initialize(native)
  @native = native # NativeException wrapping a Java Throwable
  message = value ? value : ( cause ? cause.details : @native )
  super(message)
end

Instance Method Details

#causeObject

most likely a Rhino::JS::JavaScriptException



13
14
15
# File 'lib/rhino/error.rb', line 13

def cause
  @native.respond_to?(:cause) ? @native.cause : nil
end

#javascript_backtraceObject



43
44
45
# File 'lib/rhino/error.rb', line 43

def javascript_backtrace
  cause.is_a?(JS::RhinoException) ? cause.getScriptStackTrace : nil
end

#unwrapObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rhino/error.rb', line 28

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

#valueObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/rhino/error.rb', line 17

def value
  return @value if defined?(@value)
  if cause.respond_to?(:value) # e.g. JavaScriptException.getValue
    @value = cause.value
  elsif ( unwrap = self.unwrap ) && unwrap.respond_to?(:value)
    @value = unwrap.value
  else
    @value = nil
  end
end