2012-08-12 21:25:48 -05:00
|
|
|
|
|
|
|
module V8
|
|
|
|
|
|
|
|
class StackTrace
|
|
|
|
include Enumerable
|
|
|
|
|
|
|
|
def initialize(native)
|
2012-08-13 10:12:14 -05:00
|
|
|
@context = V8::Context.current
|
2012-08-12 21:25:48 -05:00
|
|
|
@native = native
|
|
|
|
end
|
|
|
|
|
|
|
|
def length
|
2012-08-13 10:12:14 -05:00
|
|
|
@context.enter do
|
|
|
|
@native ? @native.GetFrameCount() : 0
|
|
|
|
end
|
2012-08-12 21:25:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def each
|
|
|
|
return unless @native
|
2012-08-13 10:12:14 -05:00
|
|
|
@context.enter do
|
|
|
|
for i in 0..length - 1
|
|
|
|
yield V8::StackFrame.new(@native.GetFrame(i), @context)
|
|
|
|
end
|
2012-08-12 21:25:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
@native ? map(&:to_s).join("\n") : ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class StackFrame
|
|
|
|
|
2012-08-13 10:12:14 -05:00
|
|
|
def initialize(native, context)
|
|
|
|
@context = context
|
2012-08-12 21:25:48 -05:00
|
|
|
@native = native
|
|
|
|
end
|
|
|
|
|
|
|
|
def script_name
|
2012-08-13 10:12:14 -05:00
|
|
|
@context.enter do
|
|
|
|
@context.to_ruby(@native.GetScriptName())
|
|
|
|
end
|
2012-08-12 21:25:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def function_name
|
2012-08-13 10:12:14 -05:00
|
|
|
@context.enter do
|
|
|
|
@context.to_ruby(@native.GetFunctionName())
|
|
|
|
end
|
2012-08-12 21:25:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def line_number
|
2012-08-13 10:12:14 -05:00
|
|
|
@context.enter do
|
|
|
|
@native.GetLineNumber()
|
|
|
|
end
|
2012-08-12 21:25:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def column
|
2012-08-13 10:12:14 -05:00
|
|
|
@context.enter do
|
|
|
|
@native.GetColumn()
|
|
|
|
end
|
2012-08-12 21:25:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def eval?
|
2012-08-13 10:12:14 -05:00
|
|
|
@context.enter do
|
|
|
|
@native.IsEval()
|
|
|
|
end
|
2012-08-12 21:25:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def constructor?
|
2012-08-13 10:12:14 -05:00
|
|
|
@context.enter do
|
|
|
|
@native.IsConstructor()
|
|
|
|
end
|
2012-08-12 21:25:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2012-08-13 10:12:14 -05:00
|
|
|
@context.enter do
|
|
|
|
"at " + if !function_name.empty?
|
|
|
|
"#{function_name} (#{script_name}:#{line_number}:#{column})"
|
|
|
|
else
|
|
|
|
"#{script_name}:#{line_number}:#{column}"
|
|
|
|
end
|
2012-08-12 21:25:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|