source: trip-planner-front/node_modules/zone.js/dist/zone-error.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 17.2 KB
RevLine 
[6a3a178]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,undefinedVars}
22 */
23 Zone.__load_patch('Error', function (global, Zone, api) {
24 /*
25 * This code patches Error so that:
26 * - It ignores un-needed stack frames.
27 * - It Shows the associated Zone for reach frame.
28 */
29 var zoneJsInternalStackFramesSymbol = api.symbol('zoneJsInternalStackFrames');
30 var NativeError = global[api.symbol('Error')] = global['Error'];
31 // Store the frames which should be removed from the stack frames
32 var zoneJsInternalStackFrames = {};
33 // We must find the frame where Error was created, otherwise we assume we don't understand stack
34 var zoneAwareFrame1;
35 var zoneAwareFrame2;
36 var zoneAwareFrame1WithoutNew;
37 var zoneAwareFrame2WithoutNew;
38 var zoneAwareFrame3WithoutNew;
39 global['Error'] = ZoneAwareError;
40 var stackRewrite = 'stackRewrite';
41 var zoneJsInternalStackFramesPolicy = global['__Zone_Error_BlacklistedStackFrames_policy'] ||
42 global['__Zone_Error_ZoneJsInternalStackFrames_policy'] || 'default';
43 function buildZoneFrameNames(zoneFrame) {
44 var zoneFrameName = { zoneName: zoneFrame.zone.name };
45 var result = zoneFrameName;
46 while (zoneFrame.parent) {
47 zoneFrame = zoneFrame.parent;
48 var parentZoneFrameName = { zoneName: zoneFrame.zone.name };
49 zoneFrameName.parent = parentZoneFrameName;
50 zoneFrameName = parentZoneFrameName;
51 }
52 return result;
53 }
54 function buildZoneAwareStackFrames(originalStack, zoneFrame, isZoneFrame) {
55 if (isZoneFrame === void 0) { isZoneFrame = true; }
56 var frames = originalStack.split('\n');
57 var i = 0;
58 // Find the first frame
59 while (!(frames[i] === zoneAwareFrame1 || frames[i] === zoneAwareFrame2 ||
60 frames[i] === zoneAwareFrame1WithoutNew || frames[i] === zoneAwareFrame2WithoutNew ||
61 frames[i] === zoneAwareFrame3WithoutNew) &&
62 i < frames.length) {
63 i++;
64 }
65 for (; i < frames.length && zoneFrame; i++) {
66 var frame = frames[i];
67 if (frame.trim()) {
68 switch (zoneJsInternalStackFrames[frame]) {
69 case 0 /* zoneJsInternal */:
70 frames.splice(i, 1);
71 i--;
72 break;
73 case 1 /* transition */:
74 if (zoneFrame.parent) {
75 // This is the special frame where zone changed. Print and process it accordingly
76 zoneFrame = zoneFrame.parent;
77 }
78 else {
79 zoneFrame = null;
80 }
81 frames.splice(i, 1);
82 i--;
83 break;
84 default:
85 frames[i] += isZoneFrame ? " [" + zoneFrame.zone.name + "]" :
86 " [" + zoneFrame.zoneName + "]";
87 }
88 }
89 }
90 return frames.join('\n');
91 }
92 /**
93 * This is ZoneAwareError which processes the stack frame and cleans up extra frames as well as
94 * adds zone information to it.
95 */
96 function ZoneAwareError() {
97 var _this = this;
98 // We always have to return native error otherwise the browser console will not work.
99 var error = NativeError.apply(this, arguments);
100 // Save original stack trace
101 var originalStack = error['originalStack'] = error.stack;
102 // Process the stack trace and rewrite the frames.
103 if (ZoneAwareError[stackRewrite] && originalStack) {
104 var zoneFrame = api.currentZoneFrame();
105 if (zoneJsInternalStackFramesPolicy === 'lazy') {
106 // don't handle stack trace now
107 error[api.symbol('zoneFrameNames')] = buildZoneFrameNames(zoneFrame);
108 }
109 else if (zoneJsInternalStackFramesPolicy === 'default') {
110 try {
111 error.stack = error.zoneAwareStack = buildZoneAwareStackFrames(originalStack, zoneFrame);
112 }
113 catch (e) {
114 // ignore as some browsers don't allow overriding of stack
115 }
116 }
117 }
118 if (this instanceof NativeError && this.constructor != NativeError) {
119 // We got called with a `new` operator AND we are subclass of ZoneAwareError
120 // in that case we have to copy all of our properties to `this`.
121 Object.keys(error).concat('stack', 'message').forEach(function (key) {
122 var value = error[key];
123 if (value !== undefined) {
124 try {
125 _this[key] = value;
126 }
127 catch (e) {
128 // ignore the assignment in case it is a setter and it throws.
129 }
130 }
131 });
132 return this;
133 }
134 return error;
135 }
136 // Copy the prototype so that instanceof operator works as expected
137 ZoneAwareError.prototype = NativeError.prototype;
138 ZoneAwareError[zoneJsInternalStackFramesSymbol] = zoneJsInternalStackFrames;
139 ZoneAwareError[stackRewrite] = false;
140 var zoneAwareStackSymbol = api.symbol('zoneAwareStack');
141 // try to define zoneAwareStack property when zoneJsInternal frames policy is delay
142 if (zoneJsInternalStackFramesPolicy === 'lazy') {
143 Object.defineProperty(ZoneAwareError.prototype, 'zoneAwareStack', {
144 configurable: true,
145 enumerable: true,
146 get: function () {
147 if (!this[zoneAwareStackSymbol]) {
148 this[zoneAwareStackSymbol] = buildZoneAwareStackFrames(this.originalStack, this[api.symbol('zoneFrameNames')], false);
149 }
150 return this[zoneAwareStackSymbol];
151 },
152 set: function (newStack) {
153 this.originalStack = newStack;
154 this[zoneAwareStackSymbol] = buildZoneAwareStackFrames(this.originalStack, this[api.symbol('zoneFrameNames')], false);
155 }
156 });
157 }
158 // those properties need special handling
159 var specialPropertyNames = ['stackTraceLimit', 'captureStackTrace', 'prepareStackTrace'];
160 // those properties of NativeError should be set to ZoneAwareError
161 var nativeErrorProperties = Object.keys(NativeError);
162 if (nativeErrorProperties) {
163 nativeErrorProperties.forEach(function (prop) {
164 if (specialPropertyNames.filter(function (sp) { return sp === prop; }).length === 0) {
165 Object.defineProperty(ZoneAwareError, prop, {
166 get: function () {
167 return NativeError[prop];
168 },
169 set: function (value) {
170 NativeError[prop] = value;
171 }
172 });
173 }
174 });
175 }
176 if (NativeError.hasOwnProperty('stackTraceLimit')) {
177 // Extend default stack limit as we will be removing few frames.
178 NativeError.stackTraceLimit = Math.max(NativeError.stackTraceLimit, 15);
179 // make sure that ZoneAwareError has the same property which forwards to NativeError.
180 Object.defineProperty(ZoneAwareError, 'stackTraceLimit', {
181 get: function () {
182 return NativeError.stackTraceLimit;
183 },
184 set: function (value) {
185 return NativeError.stackTraceLimit = value;
186 }
187 });
188 }
189 if (NativeError.hasOwnProperty('captureStackTrace')) {
190 Object.defineProperty(ZoneAwareError, 'captureStackTrace', {
191 // add named function here because we need to remove this
192 // stack frame when prepareStackTrace below
193 value: function zoneCaptureStackTrace(targetObject, constructorOpt) {
194 NativeError.captureStackTrace(targetObject, constructorOpt);
195 }
196 });
197 }
198 var ZONE_CAPTURESTACKTRACE = 'zoneCaptureStackTrace';
199 Object.defineProperty(ZoneAwareError, 'prepareStackTrace', {
200 get: function () {
201 return NativeError.prepareStackTrace;
202 },
203 set: function (value) {
204 if (!value || typeof value !== 'function') {
205 return NativeError.prepareStackTrace = value;
206 }
207 return NativeError.prepareStackTrace = function (error, structuredStackTrace) {
208 // remove additional stack information from ZoneAwareError.captureStackTrace
209 if (structuredStackTrace) {
210 for (var i = 0; i < structuredStackTrace.length; i++) {
211 var st = structuredStackTrace[i];
212 // remove the first function which name is zoneCaptureStackTrace
213 if (st.getFunctionName() === ZONE_CAPTURESTACKTRACE) {
214 structuredStackTrace.splice(i, 1);
215 break;
216 }
217 }
218 }
219 return value.call(this, error, structuredStackTrace);
220 };
221 }
222 });
223 if (zoneJsInternalStackFramesPolicy === 'disable') {
224 // don't need to run detectZone to populate zoneJs internal stack frames
225 return;
226 }
227 // Now we need to populate the `zoneJsInternalStackFrames` as well as find the
228 // run/runGuarded/runTask frames. This is done by creating a detect zone and then threading
229 // the execution through all of the above methods so that we can look at the stack trace and
230 // find the frames of interest.
231 var detectZone = Zone.current.fork({
232 name: 'detect',
233 onHandleError: function (parentZD, current, target, error) {
234 if (error.originalStack && Error === ZoneAwareError) {
235 var frames_1 = error.originalStack.split(/\n/);
236 var runFrame = false, runGuardedFrame = false, runTaskFrame = false;
237 while (frames_1.length) {
238 var frame = frames_1.shift();
239 // On safari it is possible to have stack frame with no line number.
240 // This check makes sure that we don't filter frames on name only (must have
241 // line number or exact equals to `ZoneAwareError`)
242 if (/:\d+:\d+/.test(frame) || frame === 'ZoneAwareError') {
243 // Get rid of the path so that we don't accidentally find function name in path.
244 // In chrome the separator is `(` and `@` in FF and safari
245 // Chrome: at Zone.run (zone.js:100)
246 // Chrome: at Zone.run (http://localhost:9876/base/build/lib/zone.js:100:24)
247 // FireFox: Zone.prototype.run@http://localhost:9876/base/build/lib/zone.js:101:24
248 // Safari: run@http://localhost:9876/base/build/lib/zone.js:101:24
249 var fnName = frame.split('(')[0].split('@')[0];
250 var frameType = 1 /* transition */;
251 if (fnName.indexOf('ZoneAwareError') !== -1) {
252 if (fnName.indexOf('new ZoneAwareError') !== -1) {
253 zoneAwareFrame1 = frame;
254 zoneAwareFrame2 = frame.replace('new ZoneAwareError', 'new Error.ZoneAwareError');
255 }
256 else {
257 zoneAwareFrame1WithoutNew = frame;
258 zoneAwareFrame2WithoutNew = frame.replace('Error.', '');
259 if (frame.indexOf('Error.ZoneAwareError') === -1) {
260 zoneAwareFrame3WithoutNew =
261 frame.replace('ZoneAwareError', 'Error.ZoneAwareError');
262 }
263 }
264 zoneJsInternalStackFrames[zoneAwareFrame2] = 0 /* zoneJsInternal */;
265 }
266 if (fnName.indexOf('runGuarded') !== -1) {
267 runGuardedFrame = true;
268 }
269 else if (fnName.indexOf('runTask') !== -1) {
270 runTaskFrame = true;
271 }
272 else if (fnName.indexOf('run') !== -1) {
273 runFrame = true;
274 }
275 else {
276 frameType = 0 /* zoneJsInternal */;
277 }
278 zoneJsInternalStackFrames[frame] = frameType;
279 // Once we find all of the frames we can stop looking.
280 if (runFrame && runGuardedFrame && runTaskFrame) {
281 ZoneAwareError[stackRewrite] = true;
282 break;
283 }
284 }
285 }
286 }
287 return false;
288 }
289 });
290 // carefully constructor a stack frame which contains all of the frames of interest which
291 // need to be detected and marked as an internal zoneJs frame.
292 var childDetectZone = detectZone.fork({
293 name: 'child',
294 onScheduleTask: function (delegate, curr, target, task) {
295 return delegate.scheduleTask(target, task);
296 },
297 onInvokeTask: function (delegate, curr, target, task, applyThis, applyArgs) {
298 return delegate.invokeTask(target, task, applyThis, applyArgs);
299 },
300 onCancelTask: function (delegate, curr, target, task) {
301 return delegate.cancelTask(target, task);
302 },
303 onInvoke: function (delegate, curr, target, callback, applyThis, applyArgs, source) {
304 return delegate.invoke(target, callback, applyThis, applyArgs, source);
305 }
306 });
307 // we need to detect all zone related frames, it will
308 // exceed default stackTraceLimit, so we set it to
309 // larger number here, and restore it after detect finish.
310 // We cast through any so we don't need to depend on nodejs typings.
311 var originalStackTraceLimit = Error.stackTraceLimit;
312 Error.stackTraceLimit = 100;
313 // we schedule event/micro/macro task, and invoke them
314 // when onSchedule, so we can get all stack traces for
315 // all kinds of tasks with one error thrown.
316 childDetectZone.run(function () {
317 childDetectZone.runGuarded(function () {
318 var fakeTransitionTo = function () { };
319 childDetectZone.scheduleEventTask(zoneJsInternalStackFramesSymbol, function () {
320 childDetectZone.scheduleMacroTask(zoneJsInternalStackFramesSymbol, function () {
321 childDetectZone.scheduleMicroTask(zoneJsInternalStackFramesSymbol, function () {
322 throw new Error();
323 }, undefined, function (t) {
324 t._transitionTo = fakeTransitionTo;
325 t.invoke();
326 });
327 childDetectZone.scheduleMicroTask(zoneJsInternalStackFramesSymbol, function () {
328 throw Error();
329 }, undefined, function (t) {
330 t._transitionTo = fakeTransitionTo;
331 t.invoke();
332 });
333 }, undefined, function (t) {
334 t._transitionTo = fakeTransitionTo;
335 t.invoke();
336 }, function () { });
337 }, undefined, function (t) {
338 t._transitionTo = fakeTransitionTo;
339 t.invoke();
340 }, function () { });
341 });
342 });
343 Error.stackTraceLimit = originalStackTraceLimit;
344 });
345})));
Note: See TracBrowser for help on using the repository browser.