### Home Classes Methods

### In Files

- lib/v8/version.rb
- lib/v8/stack.rb
- lib/v8/weak.rb
- lib/v8/error.rb
- ext/v8/rr.cc
- ext/v8/handles.cc
- ext/v8/trycatch.cc
- ext/v8/locker.cc

### Namespace

- MODULE V8::C
- MODULE V8::Weak
- CLASS V8::Access
- CLASS V8::Array
- CLASS V8::Conversion
- CLASS V8::Error
- CLASS V8::Function
- CLASS V8::Object
- CLASS V8::StackFrame
- CLASS V8::StackTrace

### Methods

- ::Error

### Files

- Makefile

### Class/Module Index

Quicksearch

- V8
- V8::Access
- V8::Access::Indices
- V8::Access::Invocation
- V8::Access::Invocation::Aritize
- V8::Access::Invocation::Method
- V8::Access::Invocation::Proc
- V8::Access::Invocation::UnboundMethod
- V8::Access::Names
- V8::Array
- V8::C
- V8::Conversion
- V8::Conversion::Accessor
- V8::Conversion::Array
- V8::Conversion::Class
- V8::Conversion::Code
- V8::Conversion::Code::InvocationHandler
- V8::Conversion::Constructor
- V8::Conversion::Constructor::Args
- V8::Conversion::Fixnum
- V8::Conversion::Fundamental
- V8::Conversion::Get
- V8::Conversion::Hash
- V8::Conversion::IGet
- V8::Conversion::ISet
- V8::Conversion::Identity
- V8::Conversion::Method
- V8::Conversion::Method::MethodCache
- V8::Conversion::NativeDate
- V8::Conversion::NativeObject
- V8::Conversion::NativeString
- V8::Conversion::Object
- V8::Conversion::Primitive
- V8::Conversion::Proc
- V8::Conversion::Reference
- V8::Conversion::Set
- V8::Conversion::String
- V8::Conversion::Symbol
- V8::Conversion::Time
- V8::Error
- V8::Error::Protect
- V8::Error::Try
- V8::Function
- V8::Object
- V8::StackFrame
- V8::StackTrace
- V8::Weak
- V8::Weak::Cell
- V8::Weak::Cell::Storage
- V8::Weak::Ref
- V8::Weak::WeakValueMap
- Object
- UnboundMethod

No matching classes.

# V8

### Constants

VERSION

### Public Class Methods

Error(trycatch) click to toggle source

Convert the result of a triggered JavaScript try/catch block into a V8::Error

This is a bit of a yak-shave because JavaScript let's you throw all kinds of things. We do our best to make sure that the message property of the resulting V8::Error is as helpful as possible, and that it contains as much source location information as we can put onto it.

For example:

    throw 4
    throw 'four'
    throw {number: 4}

are all valid cases, none of which actually reference an exception object with a stack trace and a message. only with something like:

    throw new Error('fail!')

do you get the a proper stacktrace and a message property. However a lot of times JavaScript library authors are lazy and do this:

    throw {message: 'foo', otherMetadata: 'bar'}

It's common enough so we do the courtesy of having the resulting V8::Error have as its message in ruby land the 'message' property of the value object

To further complicate things, SyntaxErrors do not have a JavaScript stack (even if they occur during js execution). This can make debugging a nightmare so we copy in the source location of the syntax error into the message of the resulting V8::Error

@param [V8::C::TryCatch] native trycatch object that has been triggered @return [V8::Error] the error generated by this try/catch

    # File lib/v8/error.rb, line 140
    def self.Error(trycatch)
      exception = trycatch.Exception()

      value = exception.to_ruby
      cause = nil
      message = trycatch.Message()
      javascript_backtrace = V8::StackTrace.new(message.GetStackTrace()) if message

      message = if !exception.kind_of?(V8::C::Value)
        exception.to_s==""?"Script Timed Out":exception.to_s
      elsif exception.IsNativeError()
        if cause = exception.GetHiddenValue("rr::Cause")
          cause = cause.Value()
        end
        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

[Validate]

Generated with the Darkfish Rdoc Generator 2.