MCPcopy
hub / github.com/angular/angular / patchLongStackTrace

Function patchLongStackTrace

packages/zone.js/lib/zone-spec/long-stack-trace.ts:15–203  ·  view source on GitHub ↗
(Zone: ZoneType)

Source from the content-addressed store, hash-verified

13import {ZoneType} from '../zone-impl';
14
15export function patchLongStackTrace(Zone: ZoneType): void {
16 const NEWLINE = '\n';
17 const IGNORE_FRAMES: {[k: string]: true} = {};
18 const creationTrace = '__creationTrace__';
19 const ERROR_TAG = 'STACKTRACE TRACKING';
20 const SEP_TAG = '__SEP_TAG__';
21 let sepTemplate: string = SEP_TAG + '@[native]';
22
23 class LongStackTrace {
24 error: Error = getStacktrace();
25 timestamp: Date = new Date();
26 }
27
28 function getStacktraceWithUncaughtError(): Error {
29 return new Error(ERROR_TAG);
30 }
31
32 function getStacktraceWithCaughtError(): Error {
33 try {
34 throw getStacktraceWithUncaughtError();
35 } catch (err) {
36 return err as Error;
37 }
38 }
39
40 // Some implementations of exception handling don't create a stack trace if the exception
41 // isn't thrown, however it's faster not to actually throw the exception.
42 const error = getStacktraceWithUncaughtError();
43 const caughtError = getStacktraceWithCaughtError();
44 const getStacktrace = error.stack
45 ? getStacktraceWithUncaughtError
46 : caughtError.stack
47 ? getStacktraceWithCaughtError
48 : getStacktraceWithUncaughtError;
49
50 function getFrames(error: Error): string[] {
51 return error.stack ? error.stack.split(NEWLINE) : [];
52 }
53
54 function addErrorStack(lines: string[], error: Error): void {
55 let trace: string[] = getFrames(error);
56 for (let i = 0; i < trace.length; i++) {
57 const frame = trace[i];
58 // Filter out the Frames which are part of stack capturing.
59 if (!IGNORE_FRAMES.hasOwnProperty(frame)) {
60 lines.push(trace[i]);
61 }
62 }
63 }
64
65 function renderLongStackTrace(frames: LongStackTrace[], stack?: string): string {
66 const longTrace: string[] = [stack ? stack.trim() : ''];
67
68 if (frames) {
69 let timestamp = new Date().getTime();
70 for (let i = 0; i < frames.length; i++) {
71 const traceFrames: LongStackTrace = frames[i];
72 const lastTime = traceFrames.timestamp;

Calls 8

renderLongStackTraceFunction · 0.85
stackTracesEnabledFunction · 0.85
computeIgnoreFramesFunction · 0.85
__symbol__Method · 0.80
scheduleTaskMethod · 0.65
handleErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…