stack.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. module V8
  2. class StackTrace
  3. include Enumerable
  4. def initialize(to, native)
  5. @to = to
  6. @native = native
  7. end
  8. def length
  9. @native.GetFrameCount()
  10. end
  11. def each
  12. for i in 0..length - 1
  13. yield V8::StackFrame.new(@to, @native.GetFrame(i))
  14. end
  15. end
  16. def to_s
  17. map {|f|"at #{f}"}.join("\n")
  18. end
  19. end
  20. class StackFrame
  21. def initialize(portal, native)
  22. @to = portal
  23. @native = native
  24. end
  25. def script_name
  26. @to.rb(@native.GetScriptName())
  27. end
  28. def function_name
  29. @to.rb(@native.GetFunctionName())
  30. end
  31. def line_number
  32. @native.GetLineNumber()
  33. end
  34. def column
  35. @native.GetColumn()
  36. end
  37. def eval?
  38. @native.IsEval()
  39. end
  40. def constructor?
  41. @native.IsConstructor()
  42. end
  43. def to_s
  44. if @native.GetFunctionName()
  45. "#{function_name} (#{script_name}:#{line_number}:#{column})"
  46. else
  47. "#{script_name}:#{line_number}:#{column}"
  48. end
  49. end
  50. end
  51. end