Sha256: 60930f65a5114c499c1645470b3f73f3edb0ad8e5ee239a221d2bf0384b2a0d9

Contents?: true

Size: 1.44 KB

Versions: 22

Compression:

Stored size: 1.44 KB

Contents

module V8

  class StackTrace
    include Enumerable

    def initialize(native)
      @context = V8::Context.current
      @native = native
    end

    def length
      @context.enter do
        @native ? @native.GetFrameCount() : 0
      end
    end

    def each
      return unless @native
      @context.enter do
        for i in 0..length - 1
          yield V8::StackFrame.new(@native.GetFrame(i), @context)
        end
      end
    end

    def to_s
      @native ? map(&:to_s).join("\n") : ""
    end
  end

  class StackFrame

    def initialize(native, context)
      @context = context
      @native = native
    end

    def script_name
      @context.enter do
        @context.to_ruby(@native.GetScriptName())
      end
    end

    def function_name
      @context.enter do
        @context.to_ruby(@native.GetFunctionName())
      end
    end

    def line_number
      @context.enter do
        @native.GetLineNumber()
      end
    end

    def column
      @context.enter do
        @native.GetColumn()
      end
    end

    def eval?
      @context.enter do
        @native.IsEval()
      end
    end

    def constructor?
      @context.enter do
        @native.IsConstructor()
      end
    end

    def to_s
      @context.enter do
        "at " + if !function_name.empty?
          "#{function_name} (#{script_name}:#{line_number}:#{column})"
        else
          "#{script_name}:#{line_number}:#{column}"
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 8 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/therubyracer-0.12.2/lib/v8/stack.rb
therubyracer-0.12.3 lib/v8/stack.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/therubyracer-0.11.4/lib/v8/stack.rb
therubyracer-xcode-0.12.3 lib/v8/stack.rb
therubyracer-xcode-0.12.2 lib/v8/stack.rb
therubyracer-tmpfork-0.12.2 lib/v8/stack.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/therubyracer-0.12.2/lib/v8/stack.rb
therubyracer-0.12.2 lib/v8/stack.rb
therubyracer-0.12.1 lib/v8/stack.rb
therubyracer-discourse-0.12.0 lib/v8/stack.rb
therubyracer-0.12.0 lib/v8/stack.rb
therubyracer-0.11.4 lib/v8/stack.rb
therubyracer-0.11.3 lib/v8/stack.rb
therubyracer-0.11.2 lib/v8/stack.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/therubyracer-0.11.0/lib/v8/stack.rb
therubyracer-0.11.1 lib/v8/stack.rb
therubyracer-0.11.1beta1 lib/v8/stack.rb
therubyracer-0.11.0 lib/v8/stack.rb
therubyracer-0.11.0beta8-x86-freebsd-9 lib/v8/stack.rb
therubyracer-0.11.0beta8-x86_64-linux lib/v8/stack.rb