NativeStackTrace.hx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package haxe;
  2. import haxe.CallStack.StackItem;
  3. private typedef NativeTrace = Array<python.Tuple.Tuple4<String, Int, String, String>>;
  4. /**
  5. Do not use manually.
  6. **/
  7. @:dox(hide)
  8. @:noCompletion
  9. class NativeStackTrace {
  10. @:ifFeature('haxe.NativeStackTrace.exceptionStack')
  11. static public inline function saveStack(exception:Any):Void {
  12. }
  13. static public inline function callStack():NativeTrace {
  14. var infos = python.lib.Traceback.extract_stack();
  15. infos.pop();
  16. infos.reverse();
  17. return infos;
  18. }
  19. static public function exceptionStack():NativeTrace {
  20. var exc = python.lib.Sys.exc_info();
  21. if (exc._3 != null) {
  22. var infos = python.lib.Traceback.extract_tb(exc._3);
  23. infos.reverse();
  24. return infos;
  25. } else {
  26. return [];
  27. }
  28. }
  29. static public function toHaxe(native:NativeTrace, skip:Int = 0):Array<StackItem> {
  30. var stack = [];
  31. for(i in 0...native.length) {
  32. if(skip > i) {
  33. continue;
  34. }
  35. var elem = native[i];
  36. stack.push(FilePos(Method(null, elem._3), elem._1, elem._2));
  37. }
  38. return stack;
  39. }
  40. }