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