module V8

Constants

VERSION

Public Class Methods

Error(trycatch) click to toggle source
# File lib/v8/error.rb, line 106
def self.Error(trycatch)
  exception = trycatch.Exception()
  value = exception.to_ruby
  cause = nil
  javascript_backtrace = V8::StackTrace.new(trycatch.Message().GetStackTrace())
  message = if !exception.kind_of?(V8::C::Value)
    exception.to_s
  elsif exception.IsNativeError()
    if cause = exception.GetHiddenValue("rr::Cause")
      cause = cause.Value()
    end
    # SyntaxErrors do not have a JavaScript stack (even if they occur during js execution).
    # To caputre where the error occured, we need to put it in the message
    if value['constructor'] == V8::Context.current['SyntaxError']
      info = trycatch.Message()
      resource_name = info.GetScriptResourceName().to_ruby
      "#{value['message']} at #{resource_name}:#{info.GetLineNumber()}:#{info.GetStartColumn() + 1}"
    else
      exception.Get("message").to_ruby
    end
  elsif exception.IsObject()
    value['message'] || value.to_s
  else
    value.to_s
  end
  V8::Error.new(message, value, javascript_backtrace, cause)
end