Sha256: d87e536e47488a70d3302618cb2c60107c10623c29f8d6fd17d59bd306303acf

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

module V8
  class Error < StandardError
    attr_reader :value
    def initialize(message, value)
      super(message)
      @value = value
    end

    module Try
      def try
        context = V8::Context.current
        V8::C::TryCatch() do |trycatch|
          result = yield
          if trycatch.HasCaught()
            V8::Error(trycatch.Exception())
          else
            result
          end
        end
      end
    end

    module Protect
      def protect
        yield
      rescue Football => e
        e.kickoff!
      rescue Exception => e
        e.extend Football
        e.kickoff!
      end
    end

    module Football
      def kickoff!
        error = V8::C::Exception::Error(message)
        error.SetHiddenValue("rr::Football", V8::C::External::New(self))
        V8::C::ThrowException(error)
      end
    end

  end

  def self.Error(exception)
    value = exception.to_ruby
    if !exception.kind_of?(V8::C::Value)
      raise V8::Error.new(exception.to_s, value)
    elsif exception.IsNativeError()
      if football = exception.GetHiddenValue("rr::Football")
        raise football.Value()
      else
        raise V8::Error.new(exception.Get("message").to_ruby, value)
      end
    else
      raise V8::Error.new(exception.ToString().to_ruby, value)
    end
  end
  const_set :JSError, Error
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
therubyracer-0.11.0beta7-x86_64-linux lib/v8/error.rb
therubyracer-0.11.0beta7-x86-linux lib/v8/error.rb
therubyracer-0.11.0beta7-x86_64-darwin-10 lib/v8/error.rb
therubyracer-0.11.0beta7 lib/v8/error.rb