a zip code crypto-currency system good for red ONLY

long-stack-trace-zone.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
  10. typeof define === 'function' && define.amd ? define(factory) :
  11. (factory());
  12. }(this, (function () { 'use strict';
  13. /**
  14. * @license
  15. * Copyright Google Inc. All Rights Reserved.
  16. *
  17. * Use of this source code is governed by an MIT-style license that can be
  18. * found in the LICENSE file at https://angular.io/license
  19. */
  20. /**
  21. * @fileoverview
  22. * @suppress {globalThis}
  23. */
  24. var NEWLINE = '\n';
  25. var IGNORE_FRAMES = {};
  26. var creationTrace = '__creationTrace__';
  27. var ERROR_TAG = 'STACKTRACE TRACKING';
  28. var SEP_TAG = '__SEP_TAG__';
  29. var sepTemplate = SEP_TAG + '@[native]';
  30. var LongStackTrace = /** @class */ (function () {
  31. function LongStackTrace() {
  32. this.error = getStacktrace();
  33. this.timestamp = new Date();
  34. }
  35. return LongStackTrace;
  36. }());
  37. function getStacktraceWithUncaughtError() {
  38. return new Error(ERROR_TAG);
  39. }
  40. function getStacktraceWithCaughtError() {
  41. try {
  42. throw getStacktraceWithUncaughtError();
  43. }
  44. catch (err) {
  45. return err;
  46. }
  47. }
  48. // Some implementations of exception handling don't create a stack trace if the exception
  49. // isn't thrown, however it's faster not to actually throw the exception.
  50. var error = getStacktraceWithUncaughtError();
  51. var caughtError = getStacktraceWithCaughtError();
  52. var getStacktrace = error.stack ?
  53. getStacktraceWithUncaughtError :
  54. (caughtError.stack ? getStacktraceWithCaughtError : getStacktraceWithUncaughtError);
  55. function getFrames(error) {
  56. return error.stack ? error.stack.split(NEWLINE) : [];
  57. }
  58. function addErrorStack(lines, error) {
  59. var trace = getFrames(error);
  60. for (var i = 0; i < trace.length; i++) {
  61. var frame = trace[i];
  62. // Filter out the Frames which are part of stack capturing.
  63. if (!IGNORE_FRAMES.hasOwnProperty(frame)) {
  64. lines.push(trace[i]);
  65. }
  66. }
  67. }
  68. function renderLongStackTrace(frames, stack) {
  69. var longTrace = [stack ? stack.trim() : ''];
  70. if (frames) {
  71. var timestamp = new Date().getTime();
  72. for (var i = 0; i < frames.length; i++) {
  73. var traceFrames = frames[i];
  74. var lastTime = traceFrames.timestamp;
  75. var separator = "____________________Elapsed " + (timestamp - lastTime.getTime()) + " ms; At: " + lastTime;
  76. separator = separator.replace(/[^\w\d]/g, '_');
  77. longTrace.push(sepTemplate.replace(SEP_TAG, separator));
  78. addErrorStack(longTrace, traceFrames.error);
  79. timestamp = lastTime.getTime();
  80. }
  81. }
  82. return longTrace.join(NEWLINE);
  83. }
  84. Zone['longStackTraceZoneSpec'] = {
  85. name: 'long-stack-trace',
  86. longStackTraceLimit: 10,
  87. // add a getLongStackTrace method in spec to
  88. // handle handled reject promise error.
  89. getLongStackTrace: function (error) {
  90. if (!error) {
  91. return undefined;
  92. }
  93. var trace = error[Zone.__symbol__('currentTaskTrace')];
  94. if (!trace) {
  95. return error.stack;
  96. }
  97. return renderLongStackTrace(trace, error.stack);
  98. },
  99. onScheduleTask: function (parentZoneDelegate, currentZone, targetZone, task) {
  100. if (Error.stackTraceLimit > 0) {
  101. // if Error.stackTraceLimit is 0, means stack trace
  102. // is disabled, so we don't need to generate long stack trace
  103. // this will improve performance in some test(some test will
  104. // set stackTraceLimit to 0, https://github.com/angular/zone.js/issues/698
  105. var currentTask = Zone.currentTask;
  106. var trace = currentTask && currentTask.data && currentTask.data[creationTrace] || [];
  107. trace = [new LongStackTrace()].concat(trace);
  108. if (trace.length > this.longStackTraceLimit) {
  109. trace.length = this.longStackTraceLimit;
  110. }
  111. if (!task.data)
  112. task.data = {};
  113. task.data[creationTrace] = trace;
  114. }
  115. return parentZoneDelegate.scheduleTask(targetZone, task);
  116. },
  117. onHandleError: function (parentZoneDelegate, currentZone, targetZone, error) {
  118. if (Error.stackTraceLimit > 0) {
  119. // if Error.stackTraceLimit is 0, means stack trace
  120. // is disabled, so we don't need to generate long stack trace
  121. // this will improve performance in some test(some test will
  122. // set stackTraceLimit to 0, https://github.com/angular/zone.js/issues/698
  123. var parentTask = Zone.currentTask || error.task;
  124. if (error instanceof Error && parentTask) {
  125. var longStack = renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], error.stack);
  126. try {
  127. error.stack = error.longStack = longStack;
  128. }
  129. catch (err) {
  130. }
  131. }
  132. }
  133. return parentZoneDelegate.handleError(targetZone, error);
  134. }
  135. };
  136. function captureStackTraces(stackTraces, count) {
  137. if (count > 0) {
  138. stackTraces.push(getFrames((new LongStackTrace()).error));
  139. captureStackTraces(stackTraces, count - 1);
  140. }
  141. }
  142. function computeIgnoreFrames() {
  143. if (Error.stackTraceLimit <= 0) {
  144. return;
  145. }
  146. var frames = [];
  147. captureStackTraces(frames, 2);
  148. var frames1 = frames[0];
  149. var frames2 = frames[1];
  150. for (var i = 0; i < frames1.length; i++) {
  151. var frame1 = frames1[i];
  152. if (frame1.indexOf(ERROR_TAG) == -1) {
  153. var match = frame1.match(/^\s*at\s+/);
  154. if (match) {
  155. sepTemplate = match[0] + SEP_TAG + ' (http://localhost)';
  156. break;
  157. }
  158. }
  159. }
  160. for (var i = 0; i < frames1.length; i++) {
  161. var frame1 = frames1[i];
  162. var frame2 = frames2[i];
  163. if (frame1 === frame2) {
  164. IGNORE_FRAMES[frame1] = true;
  165. }
  166. else {
  167. break;
  168. }
  169. }
  170. }
  171. computeIgnoreFrames();
  172. })));