@!attribute [r] cause @return [Exception] the underlying error (if any) that triggered this error to be raised
@!attribute [r] #javascript_backtrace @return [V8::StackTrace] the complete JavaScript stack at the point this error was thrown
@!attribute [r] value @return [Object] the JavaScript value passed to the `throw` statement
# File lib/v8/error.rb, line 24 def initialize(message, value, javascript_backtrace, cause = nil) super(message) @value = value @cause = cause @javascript_backtrace = javascript_backtrace end
# 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
# 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
# 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
# File lib/v8/error.rb, line 55 def in_javascript? causes.last.is_a? self.class end
# File lib/v8/error.rb, line 59 def in_ruby? !in_javascript? end
# File lib/v8/error.rb, line 51 def root_cause causes.last end
keep an alias to the StandardError#backtrace method so that we can capture just ruby backtrace frames