2
0

NativeStackTrace.hx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package haxe;
  2. import haxe.CallStack.StackItem;
  3. private typedef NativeTrace = {
  4. final skip:Int;
  5. final stack:Dynamic;
  6. }
  7. /**
  8. Do not use manually.
  9. **/
  10. @:dox(hide)
  11. @:noCompletion
  12. class NativeStackTrace {
  13. @:ifFeature('haxe.NativeStackTrace.exceptionStack')
  14. static public inline function saveStack(exception:Any):Void {
  15. }
  16. static public inline function callStack():NativeTrace {
  17. return { skip:1, stack:untyped __dollar__callstack() };
  18. }
  19. static public function exceptionStack():NativeTrace {
  20. return { skip:0, stack:untyped __dollar__excstack() };
  21. }
  22. static public function toHaxe(native:NativeTrace, skip:Int = 0):Array<StackItem> {
  23. skip += native.skip;
  24. var a = new Array();
  25. var l = untyped __dollar__asize(native.stack);
  26. var i = 0;
  27. while (i < l) {
  28. var x = native.stack[l - i - 1];
  29. //skip all CFunctions until we skip required amount of hx entries
  30. if(x == null && skip > i) {
  31. skip++;
  32. }
  33. if(skip > i++) {
  34. continue;
  35. }
  36. if (x == null)
  37. a.push(CFunction);
  38. else if (untyped __dollar__typeof(x) == __dollar__tstring)
  39. a.push(Module(new String(x)));
  40. else
  41. a.push(FilePos(null, new String(untyped x[0]), untyped x[1]));
  42. }
  43. return a;
  44. }
  45. }