Exception: V8::Error
- Inherits:
-
StandardError
- Object
- StandardError
- V8::Error
- Includes:
- Enumerable
- Defined in:
- lib/v8/error.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#cause ⇒ Exception
readonly
The underlying error (if any) that triggered this error to be raised.
-
#javascript_backtrace ⇒ V8::StackTrace
readonly
The complete JavaScript stack at the point this error was thrown.
-
#value ⇒ Object
readonly
The JavaScript value passed to the ‘throw` statement.
Instance Method Summary collapse
- #backtrace(*modifiers) ⇒ Object
- #bilingual_backtrace(trace_ruby = true, trace_javascript = true) ⇒ Object
- #causes ⇒ Object
- #in_javascript? ⇒ Boolean
- #in_ruby? ⇒ Boolean
-
#initialize(message, value, javascript_backtrace, cause = nil) ⇒ Error
constructor
A new instance of Error.
- #root_cause ⇒ Object
-
#standard_error_backtrace ⇒ Object
keep an alias to the StandardError#backtrace method so that we can capture just ruby backtrace frames.
Constructor Details
#initialize(message, value, javascript_backtrace, cause = nil) ⇒ Error
Returns a new instance of Error.
24 25 26 27 28 29 |
# File 'lib/v8/error.rb', line 24 def initialize(, value, javascript_backtrace, cause = nil) super() @value = value @cause = cause @javascript_backtrace = javascript_backtrace end |
Instance Attribute Details
#cause ⇒ Exception (readonly)
Returns the underlying error (if any) that triggered this error to be raised.
14 15 16 |
# File 'lib/v8/error.rb', line 14 def cause @cause end |
#javascript_backtrace ⇒ V8::StackTrace (readonly)
Returns the complete JavaScript stack at the point this error was thrown.
18 19 20 |
# File 'lib/v8/error.rb', line 18 def javascript_backtrace @javascript_backtrace end |
#value ⇒ Object (readonly)
Returns the JavaScript value passed to the ‘throw` statement.
10 11 12 |
# File 'lib/v8/error.rb', line 10 def value @value end |
Instance Method Details
#backtrace(*modifiers) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/v8/error.rb', line 41 def backtrace(*modifiers) return unless super() trace_framework = modifiers.include?(:framework) trace_ruby = modifiers.length == 0 || modifiers.include?(:ruby) trace_javascript = modifiers.length == 0 || modifiers.include?(:javascript) bilingual_backtrace(trace_ruby, trace_javascript).tap do |trace| trace.reject! {|frame| frame =~ %r{(lib/v8/.*\.rb|ext/v8/.*\.cc)}} unless modifiers.include?(:framework) end end |
#bilingual_backtrace(trace_ruby = true, trace_javascript = true) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/v8/error.rb', line 63 def bilingual_backtrace(trace_ruby = true, trace_javascript = true) backtrace = causes.reduce(:backtrace => [], :ruby => -1, :javascript => -1) { |accumulator, cause| accumulator.tap do if trace_ruby backtrace_selector = cause.respond_to?(:standard_error_backtrace) ? :standard_error_backtrace : :backtrace ruby_frames = cause.send(backtrace_selector)[0..accumulator[:ruby]] accumulator[:backtrace].unshift *ruby_frames accumulator[:ruby] -= ruby_frames.length end if trace_javascript && cause.respond_to?(:javascript_backtrace) javascript_frames = cause.javascript_backtrace.to_a[0..accumulator[:javascript]].map(&:to_s) accumulator[:backtrace].unshift *javascript_frames accumulator[:javascript] -= javascript_frames.length end end }[:backtrace] end |
#causes ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/v8/error.rb', line 31 def causes [].tap do |causes| current = self until current.nil? do causes.push current current = current.respond_to?(:cause) ? current.cause : nil end end end |
#in_javascript? ⇒ Boolean
55 56 57 |
# File 'lib/v8/error.rb', line 55 def in_javascript? causes.last.is_a? self.class end |
#in_ruby? ⇒ Boolean
59 60 61 |
# File 'lib/v8/error.rb', line 59 def in_ruby? !in_javascript? end |
#root_cause ⇒ Object
51 52 53 |
# File 'lib/v8/error.rb', line 51 def root_cause causes.last end |
#standard_error_backtrace ⇒ Object
keep an alias to the StandardError#backtrace method so that we can capture just ruby backtrace frames
22 |
# File 'lib/v8/error.rb', line 22 alias_method :standard_error_backtrace, :backtrace |