source: trip-planner-front/node_modules/zone.js/bundles/zone-testing-node-bundle.umd.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 220.3 KB
Line 
1'use strict';
2var __spreadArrays = (this && this.__spreadArrays) || function () {
3 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4 for (var r = Array(s), k = 0, i = 0; i < il; i++)
5 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6 r[k] = a[j];
7 return r;
8};
9/**
10 * @license Angular v12.0.0-next.0
11 * (c) 2010-2020 Google LLC. https://angular.io/
12 * License: MIT
13 */
14(function (factory) {
15 typeof define === 'function' && define.amd ? define(factory) :
16 factory();
17}((function () {
18 'use strict';
19 /**
20 * @license
21 * Copyright Google LLC All Rights Reserved.
22 *
23 * Use of this source code is governed by an MIT-style license that can be
24 * found in the LICENSE file at https://angular.io/license
25 */
26 var Zone$1 = (function (global) {
27 var performance = global['performance'];
28 function mark(name) {
29 performance && performance['mark'] && performance['mark'](name);
30 }
31 function performanceMeasure(name, label) {
32 performance && performance['measure'] && performance['measure'](name, label);
33 }
34 mark('Zone');
35 // Initialize before it's accessed below.
36 // __Zone_symbol_prefix global can be used to override the default zone
37 // symbol prefix with a custom one if needed.
38 var symbolPrefix = global['__Zone_symbol_prefix'] || '__zone_symbol__';
39 function __symbol__(name) {
40 return symbolPrefix + name;
41 }
42 var checkDuplicate = global[__symbol__('forceDuplicateZoneCheck')] === true;
43 if (global['Zone']) {
44 // if global['Zone'] already exists (maybe zone.js was already loaded or
45 // some other lib also registered a global object named Zone), we may need
46 // to throw an error, but sometimes user may not want this error.
47 // For example,
48 // we have two web pages, page1 includes zone.js, page2 doesn't.
49 // and the 1st time user load page1 and page2, everything work fine,
50 // but when user load page2 again, error occurs because global['Zone'] already exists.
51 // so we add a flag to let user choose whether to throw this error or not.
52 // By default, if existing Zone is from zone.js, we will not throw the error.
53 if (checkDuplicate || typeof global['Zone'].__symbol__ !== 'function') {
54 throw new Error('Zone already loaded.');
55 }
56 else {
57 return global['Zone'];
58 }
59 }
60 var Zone = /** @class */ (function () {
61 function Zone(parent, zoneSpec) {
62 this._parent = parent;
63 this._name = zoneSpec ? zoneSpec.name || 'unnamed' : '<root>';
64 this._properties = zoneSpec && zoneSpec.properties || {};
65 this._zoneDelegate =
66 new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec);
67 }
68 Zone.assertZonePatched = function () {
69 if (global['Promise'] !== patches['ZoneAwarePromise']) {
70 throw new Error('Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' +
71 'has been overwritten.\n' +
72 'Most likely cause is that a Promise polyfill has been loaded ' +
73 'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' +
74 'If you must load one, do so before loading zone.js.)');
75 }
76 };
77 Object.defineProperty(Zone, "root", {
78 get: function () {
79 var zone = Zone.current;
80 while (zone.parent) {
81 zone = zone.parent;
82 }
83 return zone;
84 },
85 enumerable: false,
86 configurable: true
87 });
88 Object.defineProperty(Zone, "current", {
89 get: function () {
90 return _currentZoneFrame.zone;
91 },
92 enumerable: false,
93 configurable: true
94 });
95 Object.defineProperty(Zone, "currentTask", {
96 get: function () {
97 return _currentTask;
98 },
99 enumerable: false,
100 configurable: true
101 });
102 // tslint:disable-next-line:require-internal-with-underscore
103 Zone.__load_patch = function (name, fn, ignoreDuplicate) {
104 if (ignoreDuplicate === void 0) { ignoreDuplicate = false; }
105 if (patches.hasOwnProperty(name)) {
106 // `checkDuplicate` option is defined from global variable
107 // so it works for all modules.
108 // `ignoreDuplicate` can work for the specified module
109 if (!ignoreDuplicate && checkDuplicate) {
110 throw Error('Already loaded patch: ' + name);
111 }
112 }
113 else if (!global['__Zone_disable_' + name]) {
114 var perfName = 'Zone:' + name;
115 mark(perfName);
116 patches[name] = fn(global, Zone, _api);
117 performanceMeasure(perfName, perfName);
118 }
119 };
120 Object.defineProperty(Zone.prototype, "parent", {
121 get: function () {
122 return this._parent;
123 },
124 enumerable: false,
125 configurable: true
126 });
127 Object.defineProperty(Zone.prototype, "name", {
128 get: function () {
129 return this._name;
130 },
131 enumerable: false,
132 configurable: true
133 });
134 Zone.prototype.get = function (key) {
135 var zone = this.getZoneWith(key);
136 if (zone)
137 return zone._properties[key];
138 };
139 Zone.prototype.getZoneWith = function (key) {
140 var current = this;
141 while (current) {
142 if (current._properties.hasOwnProperty(key)) {
143 return current;
144 }
145 current = current._parent;
146 }
147 return null;
148 };
149 Zone.prototype.fork = function (zoneSpec) {
150 if (!zoneSpec)
151 throw new Error('ZoneSpec required!');
152 return this._zoneDelegate.fork(this, zoneSpec);
153 };
154 Zone.prototype.wrap = function (callback, source) {
155 if (typeof callback !== 'function') {
156 throw new Error('Expecting function got: ' + callback);
157 }
158 var _callback = this._zoneDelegate.intercept(this, callback, source);
159 var zone = this;
160 return function () {
161 return zone.runGuarded(_callback, this, arguments, source);
162 };
163 };
164 Zone.prototype.run = function (callback, applyThis, applyArgs, source) {
165 _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
166 try {
167 return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
168 }
169 finally {
170 _currentZoneFrame = _currentZoneFrame.parent;
171 }
172 };
173 Zone.prototype.runGuarded = function (callback, applyThis, applyArgs, source) {
174 if (applyThis === void 0) { applyThis = null; }
175 _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
176 try {
177 try {
178 return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
179 }
180 catch (error) {
181 if (this._zoneDelegate.handleError(this, error)) {
182 throw error;
183 }
184 }
185 }
186 finally {
187 _currentZoneFrame = _currentZoneFrame.parent;
188 }
189 };
190 Zone.prototype.runTask = function (task, applyThis, applyArgs) {
191 if (task.zone != this) {
192 throw new Error('A task can only be run in the zone of creation! (Creation: ' +
193 (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
194 }
195 // https://github.com/angular/zone.js/issues/778, sometimes eventTask
196 // will run in notScheduled(canceled) state, we should not try to
197 // run such kind of task but just return
198 if (task.state === notScheduled && (task.type === eventTask || task.type === macroTask)) {
199 return;
200 }
201 var reEntryGuard = task.state != running;
202 reEntryGuard && task._transitionTo(running, scheduled);
203 task.runCount++;
204 var previousTask = _currentTask;
205 _currentTask = task;
206 _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
207 try {
208 if (task.type == macroTask && task.data && !task.data.isPeriodic) {
209 task.cancelFn = undefined;
210 }
211 try {
212 return this._zoneDelegate.invokeTask(this, task, applyThis, applyArgs);
213 }
214 catch (error) {
215 if (this._zoneDelegate.handleError(this, error)) {
216 throw error;
217 }
218 }
219 }
220 finally {
221 // if the task's state is notScheduled or unknown, then it has already been cancelled
222 // we should not reset the state to scheduled
223 if (task.state !== notScheduled && task.state !== unknown) {
224 if (task.type == eventTask || (task.data && task.data.isPeriodic)) {
225 reEntryGuard && task._transitionTo(scheduled, running);
226 }
227 else {
228 task.runCount = 0;
229 this._updateTaskCount(task, -1);
230 reEntryGuard &&
231 task._transitionTo(notScheduled, running, notScheduled);
232 }
233 }
234 _currentZoneFrame = _currentZoneFrame.parent;
235 _currentTask = previousTask;
236 }
237 };
238 Zone.prototype.scheduleTask = function (task) {
239 if (task.zone && task.zone !== this) {
240 // check if the task was rescheduled, the newZone
241 // should not be the children of the original zone
242 var newZone = this;
243 while (newZone) {
244 if (newZone === task.zone) {
245 throw Error("can not reschedule task to " + this.name + " which is descendants of the original zone " + task.zone.name);
246 }
247 newZone = newZone.parent;
248 }
249 }
250 task._transitionTo(scheduling, notScheduled);
251 var zoneDelegates = [];
252 task._zoneDelegates = zoneDelegates;
253 task._zone = this;
254 try {
255 task = this._zoneDelegate.scheduleTask(this, task);
256 }
257 catch (err) {
258 // should set task's state to unknown when scheduleTask throw error
259 // because the err may from reschedule, so the fromState maybe notScheduled
260 task._transitionTo(unknown, scheduling, notScheduled);
261 // TODO: @JiaLiPassion, should we check the result from handleError?
262 this._zoneDelegate.handleError(this, err);
263 throw err;
264 }
265 if (task._zoneDelegates === zoneDelegates) {
266 // we have to check because internally the delegate can reschedule the task.
267 this._updateTaskCount(task, 1);
268 }
269 if (task.state == scheduling) {
270 task._transitionTo(scheduled, scheduling);
271 }
272 return task;
273 };
274 Zone.prototype.scheduleMicroTask = function (source, callback, data, customSchedule) {
275 return this.scheduleTask(new ZoneTask(microTask, source, callback, data, customSchedule, undefined));
276 };
277 Zone.prototype.scheduleMacroTask = function (source, callback, data, customSchedule, customCancel) {
278 return this.scheduleTask(new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel));
279 };
280 Zone.prototype.scheduleEventTask = function (source, callback, data, customSchedule, customCancel) {
281 return this.scheduleTask(new ZoneTask(eventTask, source, callback, data, customSchedule, customCancel));
282 };
283 Zone.prototype.cancelTask = function (task) {
284 if (task.zone != this)
285 throw new Error('A task can only be cancelled in the zone of creation! (Creation: ' +
286 (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
287 task._transitionTo(canceling, scheduled, running);
288 try {
289 this._zoneDelegate.cancelTask(this, task);
290 }
291 catch (err) {
292 // if error occurs when cancelTask, transit the state to unknown
293 task._transitionTo(unknown, canceling);
294 this._zoneDelegate.handleError(this, err);
295 throw err;
296 }
297 this._updateTaskCount(task, -1);
298 task._transitionTo(notScheduled, canceling);
299 task.runCount = 0;
300 return task;
301 };
302 Zone.prototype._updateTaskCount = function (task, count) {
303 var zoneDelegates = task._zoneDelegates;
304 if (count == -1) {
305 task._zoneDelegates = null;
306 }
307 for (var i = 0; i < zoneDelegates.length; i++) {
308 zoneDelegates[i]._updateTaskCount(task.type, count);
309 }
310 };
311 return Zone;
312 }());
313 // tslint:disable-next-line:require-internal-with-underscore
314 Zone.__symbol__ = __symbol__;
315 var DELEGATE_ZS = {
316 name: '',
317 onHasTask: function (delegate, _, target, hasTaskState) { return delegate.hasTask(target, hasTaskState); },
318 onScheduleTask: function (delegate, _, target, task) { return delegate.scheduleTask(target, task); },
319 onInvokeTask: function (delegate, _, target, task, applyThis, applyArgs) { return delegate.invokeTask(target, task, applyThis, applyArgs); },
320 onCancelTask: function (delegate, _, target, task) { return delegate.cancelTask(target, task); }
321 };
322 var ZoneDelegate = /** @class */ (function () {
323 function ZoneDelegate(zone, parentDelegate, zoneSpec) {
324 this._taskCounts = { 'microTask': 0, 'macroTask': 0, 'eventTask': 0 };
325 this.zone = zone;
326 this._parentDelegate = parentDelegate;
327 this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate._forkZS);
328 this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate._forkDlgt);
329 this._forkCurrZone =
330 zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate._forkCurrZone);
331 this._interceptZS =
332 zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS);
333 this._interceptDlgt =
334 zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt);
335 this._interceptCurrZone =
336 zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate._interceptCurrZone);
337 this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate._invokeZS);
338 this._invokeDlgt =
339 zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt);
340 this._invokeCurrZone =
341 zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate._invokeCurrZone);
342 this._handleErrorZS =
343 zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS);
344 this._handleErrorDlgt =
345 zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt);
346 this._handleErrorCurrZone =
347 zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate._handleErrorCurrZone);
348 this._scheduleTaskZS =
349 zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS);
350 this._scheduleTaskDlgt = zoneSpec &&
351 (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt);
352 this._scheduleTaskCurrZone =
353 zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate._scheduleTaskCurrZone);
354 this._invokeTaskZS =
355 zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS);
356 this._invokeTaskDlgt =
357 zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt);
358 this._invokeTaskCurrZone =
359 zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate._invokeTaskCurrZone);
360 this._cancelTaskZS =
361 zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS);
362 this._cancelTaskDlgt =
363 zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt);
364 this._cancelTaskCurrZone =
365 zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate._cancelTaskCurrZone);
366 this._hasTaskZS = null;
367 this._hasTaskDlgt = null;
368 this._hasTaskDlgtOwner = null;
369 this._hasTaskCurrZone = null;
370 var zoneSpecHasTask = zoneSpec && zoneSpec.onHasTask;
371 var parentHasTask = parentDelegate && parentDelegate._hasTaskZS;
372 if (zoneSpecHasTask || parentHasTask) {
373 // If we need to report hasTask, than this ZS needs to do ref counting on tasks. In such
374 // a case all task related interceptors must go through this ZD. We can't short circuit it.
375 this._hasTaskZS = zoneSpecHasTask ? zoneSpec : DELEGATE_ZS;
376 this._hasTaskDlgt = parentDelegate;
377 this._hasTaskDlgtOwner = this;
378 this._hasTaskCurrZone = zone;
379 if (!zoneSpec.onScheduleTask) {
380 this._scheduleTaskZS = DELEGATE_ZS;
381 this._scheduleTaskDlgt = parentDelegate;
382 this._scheduleTaskCurrZone = this.zone;
383 }
384 if (!zoneSpec.onInvokeTask) {
385 this._invokeTaskZS = DELEGATE_ZS;
386 this._invokeTaskDlgt = parentDelegate;
387 this._invokeTaskCurrZone = this.zone;
388 }
389 if (!zoneSpec.onCancelTask) {
390 this._cancelTaskZS = DELEGATE_ZS;
391 this._cancelTaskDlgt = parentDelegate;
392 this._cancelTaskCurrZone = this.zone;
393 }
394 }
395 }
396 ZoneDelegate.prototype.fork = function (targetZone, zoneSpec) {
397 return this._forkZS ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) :
398 new Zone(targetZone, zoneSpec);
399 };
400 ZoneDelegate.prototype.intercept = function (targetZone, callback, source) {
401 return this._interceptZS ?
402 this._interceptZS.onIntercept(this._interceptDlgt, this._interceptCurrZone, targetZone, callback, source) :
403 callback;
404 };
405 ZoneDelegate.prototype.invoke = function (targetZone, callback, applyThis, applyArgs, source) {
406 return this._invokeZS ? this._invokeZS.onInvoke(this._invokeDlgt, this._invokeCurrZone, targetZone, callback, applyThis, applyArgs, source) :
407 callback.apply(applyThis, applyArgs);
408 };
409 ZoneDelegate.prototype.handleError = function (targetZone, error) {
410 return this._handleErrorZS ?
411 this._handleErrorZS.onHandleError(this._handleErrorDlgt, this._handleErrorCurrZone, targetZone, error) :
412 true;
413 };
414 ZoneDelegate.prototype.scheduleTask = function (targetZone, task) {
415 var returnTask = task;
416 if (this._scheduleTaskZS) {
417 if (this._hasTaskZS) {
418 returnTask._zoneDelegates.push(this._hasTaskDlgtOwner);
419 }
420 // clang-format off
421 returnTask = this._scheduleTaskZS.onScheduleTask(this._scheduleTaskDlgt, this._scheduleTaskCurrZone, targetZone, task);
422 // clang-format on
423 if (!returnTask)
424 returnTask = task;
425 }
426 else {
427 if (task.scheduleFn) {
428 task.scheduleFn(task);
429 }
430 else if (task.type == microTask) {
431 scheduleMicroTask(task);
432 }
433 else {
434 throw new Error('Task is missing scheduleFn.');
435 }
436 }
437 return returnTask;
438 };
439 ZoneDelegate.prototype.invokeTask = function (targetZone, task, applyThis, applyArgs) {
440 return this._invokeTaskZS ? this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt, this._invokeTaskCurrZone, targetZone, task, applyThis, applyArgs) :
441 task.callback.apply(applyThis, applyArgs);
442 };
443 ZoneDelegate.prototype.cancelTask = function (targetZone, task) {
444 var value;
445 if (this._cancelTaskZS) {
446 value = this._cancelTaskZS.onCancelTask(this._cancelTaskDlgt, this._cancelTaskCurrZone, targetZone, task);
447 }
448 else {
449 if (!task.cancelFn) {
450 throw Error('Task is not cancelable');
451 }
452 value = task.cancelFn(task);
453 }
454 return value;
455 };
456 ZoneDelegate.prototype.hasTask = function (targetZone, isEmpty) {
457 // hasTask should not throw error so other ZoneDelegate
458 // can still trigger hasTask callback
459 try {
460 this._hasTaskZS &&
461 this._hasTaskZS.onHasTask(this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty);
462 }
463 catch (err) {
464 this.handleError(targetZone, err);
465 }
466 };
467 // tslint:disable-next-line:require-internal-with-underscore
468 ZoneDelegate.prototype._updateTaskCount = function (type, count) {
469 var counts = this._taskCounts;
470 var prev = counts[type];
471 var next = counts[type] = prev + count;
472 if (next < 0) {
473 throw new Error('More tasks executed then were scheduled.');
474 }
475 if (prev == 0 || next == 0) {
476 var isEmpty = {
477 microTask: counts['microTask'] > 0,
478 macroTask: counts['macroTask'] > 0,
479 eventTask: counts['eventTask'] > 0,
480 change: type
481 };
482 this.hasTask(this.zone, isEmpty);
483 }
484 };
485 return ZoneDelegate;
486 }());
487 var ZoneTask = /** @class */ (function () {
488 function ZoneTask(type, source, callback, options, scheduleFn, cancelFn) {
489 // tslint:disable-next-line:require-internal-with-underscore
490 this._zone = null;
491 this.runCount = 0;
492 // tslint:disable-next-line:require-internal-with-underscore
493 this._zoneDelegates = null;
494 // tslint:disable-next-line:require-internal-with-underscore
495 this._state = 'notScheduled';
496 this.type = type;
497 this.source = source;
498 this.data = options;
499 this.scheduleFn = scheduleFn;
500 this.cancelFn = cancelFn;
501 if (!callback) {
502 throw new Error('callback is not defined');
503 }
504 this.callback = callback;
505 var self = this;
506 // TODO: @JiaLiPassion options should have interface
507 if (type === eventTask && options && options.useG) {
508 this.invoke = ZoneTask.invokeTask;
509 }
510 else {
511 this.invoke = function () {
512 return ZoneTask.invokeTask.call(global, self, this, arguments);
513 };
514 }
515 }
516 ZoneTask.invokeTask = function (task, target, args) {
517 if (!task) {
518 task = this;
519 }
520 _numberOfNestedTaskFrames++;
521 try {
522 task.runCount++;
523 return task.zone.runTask(task, target, args);
524 }
525 finally {
526 if (_numberOfNestedTaskFrames == 1) {
527 drainMicroTaskQueue();
528 }
529 _numberOfNestedTaskFrames--;
530 }
531 };
532 Object.defineProperty(ZoneTask.prototype, "zone", {
533 get: function () {
534 return this._zone;
535 },
536 enumerable: false,
537 configurable: true
538 });
539 Object.defineProperty(ZoneTask.prototype, "state", {
540 get: function () {
541 return this._state;
542 },
543 enumerable: false,
544 configurable: true
545 });
546 ZoneTask.prototype.cancelScheduleRequest = function () {
547 this._transitionTo(notScheduled, scheduling);
548 };
549 // tslint:disable-next-line:require-internal-with-underscore
550 ZoneTask.prototype._transitionTo = function (toState, fromState1, fromState2) {
551 if (this._state === fromState1 || this._state === fromState2) {
552 this._state = toState;
553 if (toState == notScheduled) {
554 this._zoneDelegates = null;
555 }
556 }
557 else {
558 throw new Error(this.type + " '" + this.source + "': can not transition to '" + toState + "', expecting state '" + fromState1 + "'" + (fromState2 ? ' or \'' + fromState2 + '\'' : '') + ", was '" + this._state + "'.");
559 }
560 };
561 ZoneTask.prototype.toString = function () {
562 if (this.data && typeof this.data.handleId !== 'undefined') {
563 return this.data.handleId.toString();
564 }
565 else {
566 return Object.prototype.toString.call(this);
567 }
568 };
569 // add toJSON method to prevent cyclic error when
570 // call JSON.stringify(zoneTask)
571 ZoneTask.prototype.toJSON = function () {
572 return {
573 type: this.type,
574 state: this.state,
575 source: this.source,
576 zone: this.zone.name,
577 runCount: this.runCount
578 };
579 };
580 return ZoneTask;
581 }());
582 //////////////////////////////////////////////////////
583 //////////////////////////////////////////////////////
584 /// MICROTASK QUEUE
585 //////////////////////////////////////////////////////
586 //////////////////////////////////////////////////////
587 var symbolSetTimeout = __symbol__('setTimeout');
588 var symbolPromise = __symbol__('Promise');
589 var symbolThen = __symbol__('then');
590 var _microTaskQueue = [];
591 var _isDrainingMicrotaskQueue = false;
592 var nativeMicroTaskQueuePromise;
593 function scheduleMicroTask(task) {
594 // if we are not running in any task, and there has not been anything scheduled
595 // we must bootstrap the initial task creation by manually scheduling the drain
596 if (_numberOfNestedTaskFrames === 0 && _microTaskQueue.length === 0) {
597 // We are not running in Task, so we need to kickstart the microtask queue.
598 if (!nativeMicroTaskQueuePromise) {
599 if (global[symbolPromise]) {
600 nativeMicroTaskQueuePromise = global[symbolPromise].resolve(0);
601 }
602 }
603 if (nativeMicroTaskQueuePromise) {
604 var nativeThen = nativeMicroTaskQueuePromise[symbolThen];
605 if (!nativeThen) {
606 // native Promise is not patchable, we need to use `then` directly
607 // issue 1078
608 nativeThen = nativeMicroTaskQueuePromise['then'];
609 }
610 nativeThen.call(nativeMicroTaskQueuePromise, drainMicroTaskQueue);
611 }
612 else {
613 global[symbolSetTimeout](drainMicroTaskQueue, 0);
614 }
615 }
616 task && _microTaskQueue.push(task);
617 }
618 function drainMicroTaskQueue() {
619 if (!_isDrainingMicrotaskQueue) {
620 _isDrainingMicrotaskQueue = true;
621 while (_microTaskQueue.length) {
622 var queue = _microTaskQueue;
623 _microTaskQueue = [];
624 for (var i = 0; i < queue.length; i++) {
625 var task = queue[i];
626 try {
627 task.zone.runTask(task, null, null);
628 }
629 catch (error) {
630 _api.onUnhandledError(error);
631 }
632 }
633 }
634 _api.microtaskDrainDone();
635 _isDrainingMicrotaskQueue = false;
636 }
637 }
638 //////////////////////////////////////////////////////
639 //////////////////////////////////////////////////////
640 /// BOOTSTRAP
641 //////////////////////////////////////////////////////
642 //////////////////////////////////////////////////////
643 var NO_ZONE = { name: 'NO ZONE' };
644 var notScheduled = 'notScheduled', scheduling = 'scheduling', scheduled = 'scheduled', running = 'running', canceling = 'canceling', unknown = 'unknown';
645 var microTask = 'microTask', macroTask = 'macroTask', eventTask = 'eventTask';
646 var patches = {};
647 var _api = {
648 symbol: __symbol__,
649 currentZoneFrame: function () { return _currentZoneFrame; },
650 onUnhandledError: noop,
651 microtaskDrainDone: noop,
652 scheduleMicroTask: scheduleMicroTask,
653 showUncaughtError: function () { return !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; },
654 patchEventTarget: function () { return []; },
655 patchOnProperties: noop,
656 patchMethod: function () { return noop; },
657 bindArguments: function () { return []; },
658 patchThen: function () { return noop; },
659 patchMacroTask: function () { return noop; },
660 patchEventPrototype: function () { return noop; },
661 isIEOrEdge: function () { return false; },
662 getGlobalObjects: function () { return undefined; },
663 ObjectDefineProperty: function () { return noop; },
664 ObjectGetOwnPropertyDescriptor: function () { return undefined; },
665 ObjectCreate: function () { return undefined; },
666 ArraySlice: function () { return []; },
667 patchClass: function () { return noop; },
668 wrapWithCurrentZone: function () { return noop; },
669 filterProperties: function () { return []; },
670 attachOriginToPatched: function () { return noop; },
671 _redefineProperty: function () { return noop; },
672 patchCallbacks: function () { return noop; }
673 };
674 var _currentZoneFrame = { parent: null, zone: new Zone(null, null) };
675 var _currentTask = null;
676 var _numberOfNestedTaskFrames = 0;
677 function noop() { }
678 performanceMeasure('Zone', 'Zone');
679 return global['Zone'] = Zone;
680 })(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
681 /**
682 * @license
683 * Copyright Google LLC All Rights Reserved.
684 *
685 * Use of this source code is governed by an MIT-style license that can be
686 * found in the LICENSE file at https://angular.io/license
687 */
688 /**
689 * Suppress closure compiler errors about unknown 'Zone' variable
690 * @fileoverview
691 * @suppress {undefinedVars,globalThis,missingRequire}
692 */
693 /// <reference types="node"/>
694 // issue #989, to reduce bundle size, use short name
695 /** Object.getOwnPropertyDescriptor */
696 var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
697 /** Object.defineProperty */
698 var ObjectDefineProperty = Object.defineProperty;
699 /** Object.getPrototypeOf */
700 var ObjectGetPrototypeOf = Object.getPrototypeOf;
701 /** Array.prototype.slice */
702 var ArraySlice = Array.prototype.slice;
703 /** addEventListener string const */
704 var ADD_EVENT_LISTENER_STR = 'addEventListener';
705 /** removeEventListener string const */
706 var REMOVE_EVENT_LISTENER_STR = 'removeEventListener';
707 /** zoneSymbol addEventListener */
708 var ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR);
709 /** zoneSymbol removeEventListener */
710 var ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR);
711 /** true string const */
712 var TRUE_STR = 'true';
713 /** false string const */
714 var FALSE_STR = 'false';
715 /** Zone symbol prefix string const. */
716 var ZONE_SYMBOL_PREFIX = Zone.__symbol__('');
717 function wrapWithCurrentZone(callback, source) {
718 return Zone.current.wrap(callback, source);
719 }
720 function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) {
721 return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel);
722 }
723 var zoneSymbol = Zone.__symbol__;
724 var isWindowExists = typeof window !== 'undefined';
725 var internalWindow = isWindowExists ? window : undefined;
726 var _global = isWindowExists && internalWindow || typeof self === 'object' && self || global;
727 var REMOVE_ATTRIBUTE = 'removeAttribute';
728 var NULL_ON_PROP_VALUE = [null];
729 function bindArguments(args, source) {
730 for (var i = args.length - 1; i >= 0; i--) {
731 if (typeof args[i] === 'function') {
732 args[i] = wrapWithCurrentZone(args[i], source + '_' + i);
733 }
734 }
735 return args;
736 }
737 function isPropertyWritable(propertyDesc) {
738 if (!propertyDesc) {
739 return true;
740 }
741 if (propertyDesc.writable === false) {
742 return false;
743 }
744 return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined');
745 }
746 var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope);
747 // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
748 // this code.
749 var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' &&
750 {}.toString.call(_global.process) === '[object process]');
751 var isBrowser = !isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']);
752 // we are in electron of nw, so we are both browser and nodejs
753 // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
754 // this code.
755 var isMix = typeof _global.process !== 'undefined' &&
756 {}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
757 !!(isWindowExists && internalWindow['HTMLElement']);
758 var zoneSymbolEventNames = {};
759 var wrapFn = function (event) {
760 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
761 // event will be undefined, so we need to use window.event
762 event = event || _global.event;
763 if (!event) {
764 return;
765 }
766 var eventNameSymbol = zoneSymbolEventNames[event.type];
767 if (!eventNameSymbol) {
768 eventNameSymbol = zoneSymbolEventNames[event.type] = zoneSymbol('ON_PROPERTY' + event.type);
769 }
770 var target = this || event.target || _global;
771 var listener = target[eventNameSymbol];
772 var result;
773 if (isBrowser && target === internalWindow && event.type === 'error') {
774 // window.onerror have different signiture
775 // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror#window.onerror
776 // and onerror callback will prevent default when callback return true
777 var errorEvent = event;
778 result = listener &&
779 listener.call(this, errorEvent.message, errorEvent.filename, errorEvent.lineno, errorEvent.colno, errorEvent.error);
780 if (result === true) {
781 event.preventDefault();
782 }
783 }
784 else {
785 result = listener && listener.apply(this, arguments);
786 if (result != undefined && !result) {
787 event.preventDefault();
788 }
789 }
790 return result;
791 };
792 function patchProperty(obj, prop, prototype) {
793 var desc = ObjectGetOwnPropertyDescriptor(obj, prop);
794 if (!desc && prototype) {
795 // when patch window object, use prototype to check prop exist or not
796 var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop);
797 if (prototypeDesc) {
798 desc = { enumerable: true, configurable: true };
799 }
800 }
801 // if the descriptor not exists or is not configurable
802 // just return
803 if (!desc || !desc.configurable) {
804 return;
805 }
806 var onPropPatchedSymbol = zoneSymbol('on' + prop + 'patched');
807 if (obj.hasOwnProperty(onPropPatchedSymbol) && obj[onPropPatchedSymbol]) {
808 return;
809 }
810 // A property descriptor cannot have getter/setter and be writable
811 // deleting the writable and value properties avoids this error:
812 //
813 // TypeError: property descriptors must not specify a value or be writable when a
814 // getter or setter has been specified
815 delete desc.writable;
816 delete desc.value;
817 var originalDescGet = desc.get;
818 var originalDescSet = desc.set;
819 // substr(2) cuz 'onclick' -> 'click', etc
820 var eventName = prop.substr(2);
821 var eventNameSymbol = zoneSymbolEventNames[eventName];
822 if (!eventNameSymbol) {
823 eventNameSymbol = zoneSymbolEventNames[eventName] = zoneSymbol('ON_PROPERTY' + eventName);
824 }
825 desc.set = function (newValue) {
826 // in some of windows's onproperty callback, this is undefined
827 // so we need to check it
828 var target = this;
829 if (!target && obj === _global) {
830 target = _global;
831 }
832 if (!target) {
833 return;
834 }
835 var previousValue = target[eventNameSymbol];
836 if (previousValue) {
837 target.removeEventListener(eventName, wrapFn);
838 }
839 // issue #978, when onload handler was added before loading zone.js
840 // we should remove it with originalDescSet
841 if (originalDescSet) {
842 originalDescSet.apply(target, NULL_ON_PROP_VALUE);
843 }
844 if (typeof newValue === 'function') {
845 target[eventNameSymbol] = newValue;
846 target.addEventListener(eventName, wrapFn, false);
847 }
848 else {
849 target[eventNameSymbol] = null;
850 }
851 };
852 // The getter would return undefined for unassigned properties but the default value of an
853 // unassigned property is null
854 desc.get = function () {
855 // in some of windows's onproperty callback, this is undefined
856 // so we need to check it
857 var target = this;
858 if (!target && obj === _global) {
859 target = _global;
860 }
861 if (!target) {
862 return null;
863 }
864 var listener = target[eventNameSymbol];
865 if (listener) {
866 return listener;
867 }
868 else if (originalDescGet) {
869 // result will be null when use inline event attribute,
870 // such as <button onclick="func();">OK</button>
871 // because the onclick function is internal raw uncompiled handler
872 // the onclick will be evaluated when first time event was triggered or
873 // the property is accessed, https://github.com/angular/zone.js/issues/525
874 // so we should use original native get to retrieve the handler
875 var value = originalDescGet && originalDescGet.call(this);
876 if (value) {
877 desc.set.call(this, value);
878 if (typeof target[REMOVE_ATTRIBUTE] === 'function') {
879 target.removeAttribute(prop);
880 }
881 return value;
882 }
883 }
884 return null;
885 };
886 ObjectDefineProperty(obj, prop, desc);
887 obj[onPropPatchedSymbol] = true;
888 }
889 function patchOnProperties(obj, properties, prototype) {
890 if (properties) {
891 for (var i = 0; i < properties.length; i++) {
892 patchProperty(obj, 'on' + properties[i], prototype);
893 }
894 }
895 else {
896 var onProperties = [];
897 for (var prop in obj) {
898 if (prop.substr(0, 2) == 'on') {
899 onProperties.push(prop);
900 }
901 }
902 for (var j = 0; j < onProperties.length; j++) {
903 patchProperty(obj, onProperties[j], prototype);
904 }
905 }
906 }
907 var originalInstanceKey = zoneSymbol('originalInstance');
908 function copySymbolProperties(src, dest) {
909 if (typeof Object.getOwnPropertySymbols !== 'function') {
910 return;
911 }
912 var symbols = Object.getOwnPropertySymbols(src);
913 symbols.forEach(function (symbol) {
914 var desc = Object.getOwnPropertyDescriptor(src, symbol);
915 Object.defineProperty(dest, symbol, {
916 get: function () {
917 return src[symbol];
918 },
919 set: function (value) {
920 if (desc && (!desc.writable || typeof desc.set !== 'function')) {
921 // if src[symbol] is not writable or not have a setter, just return
922 return;
923 }
924 src[symbol] = value;
925 },
926 enumerable: desc ? desc.enumerable : true,
927 configurable: desc ? desc.configurable : true
928 });
929 });
930 }
931 var shouldCopySymbolProperties = false;
932 function setShouldCopySymbolProperties(flag) {
933 shouldCopySymbolProperties = flag;
934 }
935 function patchMethod(target, name, patchFn) {
936 var proto = target;
937 while (proto && !proto.hasOwnProperty(name)) {
938 proto = ObjectGetPrototypeOf(proto);
939 }
940 if (!proto && target[name]) {
941 // somehow we did not find it, but we can see it. This happens on IE for Window properties.
942 proto = target;
943 }
944 var delegateName = zoneSymbol(name);
945 var delegate = null;
946 if (proto && (!(delegate = proto[delegateName]) || !proto.hasOwnProperty(delegateName))) {
947 delegate = proto[delegateName] = proto[name];
948 // check whether proto[name] is writable
949 // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
950 var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
951 if (isPropertyWritable(desc)) {
952 var patchDelegate_1 = patchFn(delegate, delegateName, name);
953 proto[name] = function () {
954 return patchDelegate_1(this, arguments);
955 };
956 attachOriginToPatched(proto[name], delegate);
957 if (shouldCopySymbolProperties) {
958 copySymbolProperties(delegate, proto[name]);
959 }
960 }
961 }
962 return delegate;
963 }
964 // TODO: @JiaLiPassion, support cancel task later if necessary
965 function patchMacroTask(obj, funcName, metaCreator) {
966 var setNative = null;
967 function scheduleTask(task) {
968 var data = task.data;
969 data.args[data.cbIdx] = function () {
970 task.invoke.apply(this, arguments);
971 };
972 setNative.apply(data.target, data.args);
973 return task;
974 }
975 setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
976 var meta = metaCreator(self, args);
977 if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
978 return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask);
979 }
980 else {
981 // cause an error by calling it directly.
982 return delegate.apply(self, args);
983 }
984 }; });
985 }
986 function patchMicroTask(obj, funcName, metaCreator) {
987 var setNative = null;
988 function scheduleTask(task) {
989 var data = task.data;
990 data.args[data.cbIdx] = function () {
991 task.invoke.apply(this, arguments);
992 };
993 setNative.apply(data.target, data.args);
994 return task;
995 }
996 setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
997 var meta = metaCreator(self, args);
998 if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
999 return Zone.current.scheduleMicroTask(meta.name, args[meta.cbIdx], meta, scheduleTask);
1000 }
1001 else {
1002 // cause an error by calling it directly.
1003 return delegate.apply(self, args);
1004 }
1005 }; });
1006 }
1007 function attachOriginToPatched(patched, original) {
1008 patched[zoneSymbol('OriginalDelegate')] = original;
1009 }
1010 /**
1011 * @license
1012 * Copyright Google LLC All Rights Reserved.
1013 *
1014 * Use of this source code is governed by an MIT-style license that can be
1015 * found in the LICENSE file at https://angular.io/license
1016 */
1017 Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) {
1018 var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
1019 var ObjectDefineProperty = Object.defineProperty;
1020 function readableObjectToString(obj) {
1021 if (obj && obj.toString === Object.prototype.toString) {
1022 var className = obj.constructor && obj.constructor.name;
1023 return (className ? className : '') + ': ' + JSON.stringify(obj);
1024 }
1025 return obj ? obj.toString() : Object.prototype.toString.call(obj);
1026 }
1027 var __symbol__ = api.symbol;
1028 var _uncaughtPromiseErrors = [];
1029 var isDisableWrappingUncaughtPromiseRejection = global[__symbol__('DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION')] === true;
1030 var symbolPromise = __symbol__('Promise');
1031 var symbolThen = __symbol__('then');
1032 var creationTrace = '__creationTrace__';
1033 api.onUnhandledError = function (e) {
1034 if (api.showUncaughtError()) {
1035 var rejection = e && e.rejection;
1036 if (rejection) {
1037 console.error('Unhandled Promise rejection:', rejection instanceof Error ? rejection.message : rejection, '; Zone:', e.zone.name, '; Task:', e.task && e.task.source, '; Value:', rejection, rejection instanceof Error ? rejection.stack : undefined);
1038 }
1039 else {
1040 console.error(e);
1041 }
1042 }
1043 };
1044 api.microtaskDrainDone = function () {
1045 var _loop_1 = function () {
1046 var uncaughtPromiseError = _uncaughtPromiseErrors.shift();
1047 try {
1048 uncaughtPromiseError.zone.runGuarded(function () {
1049 if (uncaughtPromiseError.throwOriginal) {
1050 throw uncaughtPromiseError.rejection;
1051 }
1052 throw uncaughtPromiseError;
1053 });
1054 }
1055 catch (error) {
1056 handleUnhandledRejection(error);
1057 }
1058 };
1059 while (_uncaughtPromiseErrors.length) {
1060 _loop_1();
1061 }
1062 };
1063 var UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__('unhandledPromiseRejectionHandler');
1064 function handleUnhandledRejection(e) {
1065 api.onUnhandledError(e);
1066 try {
1067 var handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL];
1068 if (typeof handler === 'function') {
1069 handler.call(this, e);
1070 }
1071 }
1072 catch (err) {
1073 }
1074 }
1075 function isThenable(value) {
1076 return value && value.then;
1077 }
1078 function forwardResolution(value) {
1079 return value;
1080 }
1081 function forwardRejection(rejection) {
1082 return ZoneAwarePromise.reject(rejection);
1083 }
1084 var symbolState = __symbol__('state');
1085 var symbolValue = __symbol__('value');
1086 var symbolFinally = __symbol__('finally');
1087 var symbolParentPromiseValue = __symbol__('parentPromiseValue');
1088 var symbolParentPromiseState = __symbol__('parentPromiseState');
1089 var source = 'Promise.then';
1090 var UNRESOLVED = null;
1091 var RESOLVED = true;
1092 var REJECTED = false;
1093 var REJECTED_NO_CATCH = 0;
1094 function makeResolver(promise, state) {
1095 return function (v) {
1096 try {
1097 resolvePromise(promise, state, v);
1098 }
1099 catch (err) {
1100 resolvePromise(promise, false, err);
1101 }
1102 // Do not return value or you will break the Promise spec.
1103 };
1104 }
1105 var once = function () {
1106 var wasCalled = false;
1107 return function wrapper(wrappedFunction) {
1108 return function () {
1109 if (wasCalled) {
1110 return;
1111 }
1112 wasCalled = true;
1113 wrappedFunction.apply(null, arguments);
1114 };
1115 };
1116 };
1117 var TYPE_ERROR = 'Promise resolved with itself';
1118 var CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace');
1119 // Promise Resolution
1120 function resolvePromise(promise, state, value) {
1121 var onceWrapper = once();
1122 if (promise === value) {
1123 throw new TypeError(TYPE_ERROR);
1124 }
1125 if (promise[symbolState] === UNRESOLVED) {
1126 // should only get value.then once based on promise spec.
1127 var then = null;
1128 try {
1129 if (typeof value === 'object' || typeof value === 'function') {
1130 then = value && value.then;
1131 }
1132 }
1133 catch (err) {
1134 onceWrapper(function () {
1135 resolvePromise(promise, false, err);
1136 })();
1137 return promise;
1138 }
1139 // if (value instanceof ZoneAwarePromise) {
1140 if (state !== REJECTED && value instanceof ZoneAwarePromise &&
1141 value.hasOwnProperty(symbolState) && value.hasOwnProperty(symbolValue) &&
1142 value[symbolState] !== UNRESOLVED) {
1143 clearRejectedNoCatch(value);
1144 resolvePromise(promise, value[symbolState], value[symbolValue]);
1145 }
1146 else if (state !== REJECTED && typeof then === 'function') {
1147 try {
1148 then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)));
1149 }
1150 catch (err) {
1151 onceWrapper(function () {
1152 resolvePromise(promise, false, err);
1153 })();
1154 }
1155 }
1156 else {
1157 promise[symbolState] = state;
1158 var queue = promise[symbolValue];
1159 promise[symbolValue] = value;
1160 if (promise[symbolFinally] === symbolFinally) {
1161 // the promise is generated by Promise.prototype.finally
1162 if (state === RESOLVED) {
1163 // the state is resolved, should ignore the value
1164 // and use parent promise value
1165 promise[symbolState] = promise[symbolParentPromiseState];
1166 promise[symbolValue] = promise[symbolParentPromiseValue];
1167 }
1168 }
1169 // record task information in value when error occurs, so we can
1170 // do some additional work such as render longStackTrace
1171 if (state === REJECTED && value instanceof Error) {
1172 // check if longStackTraceZone is here
1173 var trace = Zone.currentTask && Zone.currentTask.data &&
1174 Zone.currentTask.data[creationTrace];
1175 if (trace) {
1176 // only keep the long stack trace into error when in longStackTraceZone
1177 ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace });
1178 }
1179 }
1180 for (var i = 0; i < queue.length;) {
1181 scheduleResolveOrReject(promise, queue[i++], queue[i++], queue[i++], queue[i++]);
1182 }
1183 if (queue.length == 0 && state == REJECTED) {
1184 promise[symbolState] = REJECTED_NO_CATCH;
1185 var uncaughtPromiseError = value;
1186 try {
1187 // Here we throws a new Error to print more readable error log
1188 // and if the value is not an error, zone.js builds an `Error`
1189 // Object here to attach the stack information.
1190 throw new Error('Uncaught (in promise): ' + readableObjectToString(value) +
1191 (value && value.stack ? '\n' + value.stack : ''));
1192 }
1193 catch (err) {
1194 uncaughtPromiseError = err;
1195 }
1196 if (isDisableWrappingUncaughtPromiseRejection) {
1197 // If disable wrapping uncaught promise reject
1198 // use the value instead of wrapping it.
1199 uncaughtPromiseError.throwOriginal = true;
1200 }
1201 uncaughtPromiseError.rejection = value;
1202 uncaughtPromiseError.promise = promise;
1203 uncaughtPromiseError.zone = Zone.current;
1204 uncaughtPromiseError.task = Zone.currentTask;
1205 _uncaughtPromiseErrors.push(uncaughtPromiseError);
1206 api.scheduleMicroTask(); // to make sure that it is running
1207 }
1208 }
1209 }
1210 // Resolving an already resolved promise is a noop.
1211 return promise;
1212 }
1213 var REJECTION_HANDLED_HANDLER = __symbol__('rejectionHandledHandler');
1214 function clearRejectedNoCatch(promise) {
1215 if (promise[symbolState] === REJECTED_NO_CATCH) {
1216 // if the promise is rejected no catch status
1217 // and queue.length > 0, means there is a error handler
1218 // here to handle the rejected promise, we should trigger
1219 // windows.rejectionhandled eventHandler or nodejs rejectionHandled
1220 // eventHandler
1221 try {
1222 var handler = Zone[REJECTION_HANDLED_HANDLER];
1223 if (handler && typeof handler === 'function') {
1224 handler.call(this, { rejection: promise[symbolValue], promise: promise });
1225 }
1226 }
1227 catch (err) {
1228 }
1229 promise[symbolState] = REJECTED;
1230 for (var i = 0; i < _uncaughtPromiseErrors.length; i++) {
1231 if (promise === _uncaughtPromiseErrors[i].promise) {
1232 _uncaughtPromiseErrors.splice(i, 1);
1233 }
1234 }
1235 }
1236 }
1237 function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) {
1238 clearRejectedNoCatch(promise);
1239 var promiseState = promise[symbolState];
1240 var delegate = promiseState ?
1241 (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution :
1242 (typeof onRejected === 'function') ? onRejected : forwardRejection;
1243 zone.scheduleMicroTask(source, function () {
1244 try {
1245 var parentPromiseValue = promise[symbolValue];
1246 var isFinallyPromise = !!chainPromise && symbolFinally === chainPromise[symbolFinally];
1247 if (isFinallyPromise) {
1248 // if the promise is generated from finally call, keep parent promise's state and value
1249 chainPromise[symbolParentPromiseValue] = parentPromiseValue;
1250 chainPromise[symbolParentPromiseState] = promiseState;
1251 }
1252 // should not pass value to finally callback
1253 var value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ?
1254 [] :
1255 [parentPromiseValue]);
1256 resolvePromise(chainPromise, true, value);
1257 }
1258 catch (error) {
1259 // if error occurs, should always return this error
1260 resolvePromise(chainPromise, false, error);
1261 }
1262 }, chainPromise);
1263 }
1264 var ZONE_AWARE_PROMISE_TO_STRING = 'function ZoneAwarePromise() { [native code] }';
1265 var noop = function () { };
1266 var ZoneAwarePromise = /** @class */ (function () {
1267 function ZoneAwarePromise(executor) {
1268 var promise = this;
1269 if (!(promise instanceof ZoneAwarePromise)) {
1270 throw new Error('Must be an instanceof Promise.');
1271 }
1272 promise[symbolState] = UNRESOLVED;
1273 promise[symbolValue] = []; // queue;
1274 try {
1275 executor && executor(makeResolver(promise, RESOLVED), makeResolver(promise, REJECTED));
1276 }
1277 catch (error) {
1278 resolvePromise(promise, false, error);
1279 }
1280 }
1281 ZoneAwarePromise.toString = function () {
1282 return ZONE_AWARE_PROMISE_TO_STRING;
1283 };
1284 ZoneAwarePromise.resolve = function (value) {
1285 return resolvePromise(new this(null), RESOLVED, value);
1286 };
1287 ZoneAwarePromise.reject = function (error) {
1288 return resolvePromise(new this(null), REJECTED, error);
1289 };
1290 ZoneAwarePromise.race = function (values) {
1291 var resolve;
1292 var reject;
1293 var promise = new this(function (res, rej) {
1294 resolve = res;
1295 reject = rej;
1296 });
1297 function onResolve(value) {
1298 resolve(value);
1299 }
1300 function onReject(error) {
1301 reject(error);
1302 }
1303 for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
1304 var value = values_1[_i];
1305 if (!isThenable(value)) {
1306 value = this.resolve(value);
1307 }
1308 value.then(onResolve, onReject);
1309 }
1310 return promise;
1311 };
1312 ZoneAwarePromise.all = function (values) {
1313 return ZoneAwarePromise.allWithCallback(values);
1314 };
1315 ZoneAwarePromise.allSettled = function (values) {
1316 var P = this && this.prototype instanceof ZoneAwarePromise ? this : ZoneAwarePromise;
1317 return P.allWithCallback(values, {
1318 thenCallback: function (value) { return ({ status: 'fulfilled', value: value }); },
1319 errorCallback: function (err) { return ({ status: 'rejected', reason: err }); }
1320 });
1321 };
1322 ZoneAwarePromise.allWithCallback = function (values, callback) {
1323 var resolve;
1324 var reject;
1325 var promise = new this(function (res, rej) {
1326 resolve = res;
1327 reject = rej;
1328 });
1329 // Start at 2 to prevent prematurely resolving if .then is called immediately.
1330 var unresolvedCount = 2;
1331 var valueIndex = 0;
1332 var resolvedValues = [];
1333 var _loop_2 = function (value) {
1334 if (!isThenable(value)) {
1335 value = this_1.resolve(value);
1336 }
1337 var curValueIndex = valueIndex;
1338 try {
1339 value.then(function (value) {
1340 resolvedValues[curValueIndex] = callback ? callback.thenCallback(value) : value;
1341 unresolvedCount--;
1342 if (unresolvedCount === 0) {
1343 resolve(resolvedValues);
1344 }
1345 }, function (err) {
1346 if (!callback) {
1347 reject(err);
1348 }
1349 else {
1350 resolvedValues[curValueIndex] = callback.errorCallback(err);
1351 unresolvedCount--;
1352 if (unresolvedCount === 0) {
1353 resolve(resolvedValues);
1354 }
1355 }
1356 });
1357 }
1358 catch (thenErr) {
1359 reject(thenErr);
1360 }
1361 unresolvedCount++;
1362 valueIndex++;
1363 };
1364 var this_1 = this;
1365 for (var _i = 0, values_2 = values; _i < values_2.length; _i++) {
1366 var value = values_2[_i];
1367 _loop_2(value);
1368 }
1369 // Make the unresolvedCount zero-based again.
1370 unresolvedCount -= 2;
1371 if (unresolvedCount === 0) {
1372 resolve(resolvedValues);
1373 }
1374 return promise;
1375 };
1376 Object.defineProperty(ZoneAwarePromise.prototype, Symbol.toStringTag, {
1377 get: function () {
1378 return 'Promise';
1379 },
1380 enumerable: false,
1381 configurable: true
1382 });
1383 Object.defineProperty(ZoneAwarePromise.prototype, Symbol.species, {
1384 get: function () {
1385 return ZoneAwarePromise;
1386 },
1387 enumerable: false,
1388 configurable: true
1389 });
1390 ZoneAwarePromise.prototype.then = function (onFulfilled, onRejected) {
1391 var C = this.constructor[Symbol.species];
1392 if (!C || typeof C !== 'function') {
1393 C = this.constructor || ZoneAwarePromise;
1394 }
1395 var chainPromise = new C(noop);
1396 var zone = Zone.current;
1397 if (this[symbolState] == UNRESOLVED) {
1398 this[symbolValue].push(zone, chainPromise, onFulfilled, onRejected);
1399 }
1400 else {
1401 scheduleResolveOrReject(this, zone, chainPromise, onFulfilled, onRejected);
1402 }
1403 return chainPromise;
1404 };
1405 ZoneAwarePromise.prototype.catch = function (onRejected) {
1406 return this.then(null, onRejected);
1407 };
1408 ZoneAwarePromise.prototype.finally = function (onFinally) {
1409 var C = this.constructor[Symbol.species];
1410 if (!C || typeof C !== 'function') {
1411 C = ZoneAwarePromise;
1412 }
1413 var chainPromise = new C(noop);
1414 chainPromise[symbolFinally] = symbolFinally;
1415 var zone = Zone.current;
1416 if (this[symbolState] == UNRESOLVED) {
1417 this[symbolValue].push(zone, chainPromise, onFinally, onFinally);
1418 }
1419 else {
1420 scheduleResolveOrReject(this, zone, chainPromise, onFinally, onFinally);
1421 }
1422 return chainPromise;
1423 };
1424 return ZoneAwarePromise;
1425 }());
1426 // Protect against aggressive optimizers dropping seemingly unused properties.
1427 // E.g. Closure Compiler in advanced mode.
1428 ZoneAwarePromise['resolve'] = ZoneAwarePromise.resolve;
1429 ZoneAwarePromise['reject'] = ZoneAwarePromise.reject;
1430 ZoneAwarePromise['race'] = ZoneAwarePromise.race;
1431 ZoneAwarePromise['all'] = ZoneAwarePromise.all;
1432 var NativePromise = global[symbolPromise] = global['Promise'];
1433 global['Promise'] = ZoneAwarePromise;
1434 var symbolThenPatched = __symbol__('thenPatched');
1435 function patchThen(Ctor) {
1436 var proto = Ctor.prototype;
1437 var prop = ObjectGetOwnPropertyDescriptor(proto, 'then');
1438 if (prop && (prop.writable === false || !prop.configurable)) {
1439 // check Ctor.prototype.then propertyDescriptor is writable or not
1440 // in meteor env, writable is false, we should ignore such case
1441 return;
1442 }
1443 var originalThen = proto.then;
1444 // Keep a reference to the original method.
1445 proto[symbolThen] = originalThen;
1446 Ctor.prototype.then = function (onResolve, onReject) {
1447 var _this = this;
1448 var wrapped = new ZoneAwarePromise(function (resolve, reject) {
1449 originalThen.call(_this, resolve, reject);
1450 });
1451 return wrapped.then(onResolve, onReject);
1452 };
1453 Ctor[symbolThenPatched] = true;
1454 }
1455 api.patchThen = patchThen;
1456 function zoneify(fn) {
1457 return function (self, args) {
1458 var resultPromise = fn.apply(self, args);
1459 if (resultPromise instanceof ZoneAwarePromise) {
1460 return resultPromise;
1461 }
1462 var ctor = resultPromise.constructor;
1463 if (!ctor[symbolThenPatched]) {
1464 patchThen(ctor);
1465 }
1466 return resultPromise;
1467 };
1468 }
1469 if (NativePromise) {
1470 patchThen(NativePromise);
1471 patchMethod(global, 'fetch', function (delegate) { return zoneify(delegate); });
1472 }
1473 // This is not part of public API, but it is useful for tests, so we expose it.
1474 Promise[Zone.__symbol__('uncaughtPromiseErrors')] = _uncaughtPromiseErrors;
1475 return ZoneAwarePromise;
1476 });
1477 /**
1478 * @license
1479 * Copyright Google LLC All Rights Reserved.
1480 *
1481 * Use of this source code is governed by an MIT-style license that can be
1482 * found in the LICENSE file at https://angular.io/license
1483 */
1484 // override Function.prototype.toString to make zone.js patched function
1485 // look like native function
1486 Zone.__load_patch('toString', function (global) {
1487 // patch Func.prototype.toString to let them look like native
1488 var originalFunctionToString = Function.prototype.toString;
1489 var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate');
1490 var PROMISE_SYMBOL = zoneSymbol('Promise');
1491 var ERROR_SYMBOL = zoneSymbol('Error');
1492 var newFunctionToString = function toString() {
1493 if (typeof this === 'function') {
1494 var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL];
1495 if (originalDelegate) {
1496 if (typeof originalDelegate === 'function') {
1497 return originalFunctionToString.call(originalDelegate);
1498 }
1499 else {
1500 return Object.prototype.toString.call(originalDelegate);
1501 }
1502 }
1503 if (this === Promise) {
1504 var nativePromise = global[PROMISE_SYMBOL];
1505 if (nativePromise) {
1506 return originalFunctionToString.call(nativePromise);
1507 }
1508 }
1509 if (this === Error) {
1510 var nativeError = global[ERROR_SYMBOL];
1511 if (nativeError) {
1512 return originalFunctionToString.call(nativeError);
1513 }
1514 }
1515 }
1516 return originalFunctionToString.call(this);
1517 };
1518 newFunctionToString[ORIGINAL_DELEGATE_SYMBOL] = originalFunctionToString;
1519 Function.prototype.toString = newFunctionToString;
1520 // patch Object.prototype.toString to let them look like native
1521 var originalObjectToString = Object.prototype.toString;
1522 var PROMISE_OBJECT_TO_STRING = '[object Promise]';
1523 Object.prototype.toString = function () {
1524 if (typeof Promise === 'function' && this instanceof Promise) {
1525 return PROMISE_OBJECT_TO_STRING;
1526 }
1527 return originalObjectToString.call(this);
1528 };
1529 });
1530 /**
1531 * @license
1532 * Copyright Google LLC All Rights Reserved.
1533 *
1534 * Use of this source code is governed by an MIT-style license that can be
1535 * found in the LICENSE file at https://angular.io/license
1536 */
1537 Zone.__load_patch('node_util', function (global, Zone, api) {
1538 api.patchOnProperties = patchOnProperties;
1539 api.patchMethod = patchMethod;
1540 api.bindArguments = bindArguments;
1541 api.patchMacroTask = patchMacroTask;
1542 setShouldCopySymbolProperties(true);
1543 });
1544 /**
1545 * @license
1546 * Copyright Google LLC All Rights Reserved.
1547 *
1548 * Use of this source code is governed by an MIT-style license that can be
1549 * found in the LICENSE file at https://angular.io/license
1550 */
1551 var passiveSupported = false;
1552 if (typeof window !== 'undefined') {
1553 try {
1554 var options = Object.defineProperty({}, 'passive', {
1555 get: function () {
1556 passiveSupported = true;
1557 }
1558 });
1559 window.addEventListener('test', options, options);
1560 window.removeEventListener('test', options, options);
1561 }
1562 catch (err) {
1563 passiveSupported = false;
1564 }
1565 }
1566 // an identifier to tell ZoneTask do not create a new invoke closure
1567 var OPTIMIZED_ZONE_EVENT_TASK_DATA = {
1568 useG: true
1569 };
1570 var zoneSymbolEventNames$1 = {};
1571 var globalSources = {};
1572 var EVENT_NAME_SYMBOL_REGX = new RegExp('^' + ZONE_SYMBOL_PREFIX + '(\\w+)(true|false)$');
1573 var IMMEDIATE_PROPAGATION_SYMBOL = zoneSymbol('propagationStopped');
1574 function prepareEventNames(eventName, eventNameToString) {
1575 var falseEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + FALSE_STR;
1576 var trueEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + TRUE_STR;
1577 var symbol = ZONE_SYMBOL_PREFIX + falseEventName;
1578 var symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
1579 zoneSymbolEventNames$1[eventName] = {};
1580 zoneSymbolEventNames$1[eventName][FALSE_STR] = symbol;
1581 zoneSymbolEventNames$1[eventName][TRUE_STR] = symbolCapture;
1582 }
1583 function patchEventTarget(_global, apis, patchOptions) {
1584 var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR;
1585 var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR;
1586 var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners';
1587 var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners';
1588 var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER);
1589 var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':';
1590 var PREPEND_EVENT_LISTENER = 'prependListener';
1591 var PREPEND_EVENT_LISTENER_SOURCE = '.' + PREPEND_EVENT_LISTENER + ':';
1592 var invokeTask = function (task, target, event) {
1593 // for better performance, check isRemoved which is set
1594 // by removeEventListener
1595 if (task.isRemoved) {
1596 return;
1597 }
1598 var delegate = task.callback;
1599 if (typeof delegate === 'object' && delegate.handleEvent) {
1600 // create the bind version of handleEvent when invoke
1601 task.callback = function (event) { return delegate.handleEvent(event); };
1602 task.originalDelegate = delegate;
1603 }
1604 // invoke static task.invoke
1605 task.invoke(task, target, [event]);
1606 var options = task.options;
1607 if (options && typeof options === 'object' && options.once) {
1608 // if options.once is true, after invoke once remove listener here
1609 // only browser need to do this, nodejs eventEmitter will cal removeListener
1610 // inside EventEmitter.once
1611 var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback;
1612 target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options);
1613 }
1614 };
1615 // global shared zoneAwareCallback to handle all event callback with capture = false
1616 var globalZoneAwareCallback = function (event) {
1617 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
1618 // event will be undefined, so we need to use window.event
1619 event = event || _global.event;
1620 if (!event) {
1621 return;
1622 }
1623 // event.target is needed for Samsung TV and SourceBuffer
1624 // || global is needed https://github.com/angular/zone.js/issues/190
1625 var target = this || event.target || _global;
1626 var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]];
1627 if (tasks) {
1628 // invoke all tasks which attached to current target with given event.type and capture = false
1629 // for performance concern, if task.length === 1, just invoke
1630 if (tasks.length === 1) {
1631 invokeTask(tasks[0], target, event);
1632 }
1633 else {
1634 // https://github.com/angular/zone.js/issues/836
1635 // copy the tasks array before invoke, to avoid
1636 // the callback will remove itself or other listener
1637 var copyTasks = tasks.slice();
1638 for (var i = 0; i < copyTasks.length; i++) {
1639 if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
1640 break;
1641 }
1642 invokeTask(copyTasks[i], target, event);
1643 }
1644 }
1645 }
1646 };
1647 // global shared zoneAwareCallback to handle all event callback with capture = true
1648 var globalZoneAwareCaptureCallback = function (event) {
1649 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
1650 // event will be undefined, so we need to use window.event
1651 event = event || _global.event;
1652 if (!event) {
1653 return;
1654 }
1655 // event.target is needed for Samsung TV and SourceBuffer
1656 // || global is needed https://github.com/angular/zone.js/issues/190
1657 var target = this || event.target || _global;
1658 var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]];
1659 if (tasks) {
1660 // invoke all tasks which attached to current target with given event.type and capture = false
1661 // for performance concern, if task.length === 1, just invoke
1662 if (tasks.length === 1) {
1663 invokeTask(tasks[0], target, event);
1664 }
1665 else {
1666 // https://github.com/angular/zone.js/issues/836
1667 // copy the tasks array before invoke, to avoid
1668 // the callback will remove itself or other listener
1669 var copyTasks = tasks.slice();
1670 for (var i = 0; i < copyTasks.length; i++) {
1671 if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
1672 break;
1673 }
1674 invokeTask(copyTasks[i], target, event);
1675 }
1676 }
1677 }
1678 };
1679 function patchEventTargetMethods(obj, patchOptions) {
1680 if (!obj) {
1681 return false;
1682 }
1683 var useGlobalCallback = true;
1684 if (patchOptions && patchOptions.useG !== undefined) {
1685 useGlobalCallback = patchOptions.useG;
1686 }
1687 var validateHandler = patchOptions && patchOptions.vh;
1688 var checkDuplicate = true;
1689 if (patchOptions && patchOptions.chkDup !== undefined) {
1690 checkDuplicate = patchOptions.chkDup;
1691 }
1692 var returnTarget = false;
1693 if (patchOptions && patchOptions.rt !== undefined) {
1694 returnTarget = patchOptions.rt;
1695 }
1696 var proto = obj;
1697 while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) {
1698 proto = ObjectGetPrototypeOf(proto);
1699 }
1700 if (!proto && obj[ADD_EVENT_LISTENER]) {
1701 // somehow we did not find it, but we can see it. This happens on IE for Window properties.
1702 proto = obj;
1703 }
1704 if (!proto) {
1705 return false;
1706 }
1707 if (proto[zoneSymbolAddEventListener]) {
1708 return false;
1709 }
1710 var eventNameToString = patchOptions && patchOptions.eventNameToString;
1711 // a shared global taskData to pass data for scheduleEventTask
1712 // so we do not need to create a new object just for pass some data
1713 var taskData = {};
1714 var nativeAddEventListener = proto[zoneSymbolAddEventListener] = proto[ADD_EVENT_LISTENER];
1715 var nativeRemoveEventListener = proto[zoneSymbol(REMOVE_EVENT_LISTENER)] =
1716 proto[REMOVE_EVENT_LISTENER];
1717 var nativeListeners = proto[zoneSymbol(LISTENERS_EVENT_LISTENER)] =
1718 proto[LISTENERS_EVENT_LISTENER];
1719 var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] =
1720 proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER];
1721 var nativePrependEventListener;
1722 if (patchOptions && patchOptions.prepend) {
1723 nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] =
1724 proto[patchOptions.prepend];
1725 }
1726 /**
1727 * This util function will build an option object with passive option
1728 * to handle all possible input from the user.
1729 */
1730 function buildEventListenerOptions(options, passive) {
1731 if (!passiveSupported && typeof options === 'object' && options) {
1732 // doesn't support passive but user want to pass an object as options.
1733 // this will not work on some old browser, so we just pass a boolean
1734 // as useCapture parameter
1735 return !!options.capture;
1736 }
1737 if (!passiveSupported || !passive) {
1738 return options;
1739 }
1740 if (typeof options === 'boolean') {
1741 return { capture: options, passive: true };
1742 }
1743 if (!options) {
1744 return { passive: true };
1745 }
1746 if (typeof options === 'object' && options.passive !== false) {
1747 return Object.assign(Object.assign({}, options), { passive: true });
1748 }
1749 return options;
1750 }
1751 var customScheduleGlobal = function (task) {
1752 // if there is already a task for the eventName + capture,
1753 // just return, because we use the shared globalZoneAwareCallback here.
1754 if (taskData.isExisting) {
1755 return;
1756 }
1757 return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options);
1758 };
1759 var customCancelGlobal = function (task) {
1760 // if task is not marked as isRemoved, this call is directly
1761 // from Zone.prototype.cancelTask, we should remove the task
1762 // from tasksList of target first
1763 if (!task.isRemoved) {
1764 var symbolEventNames = zoneSymbolEventNames$1[task.eventName];
1765 var symbolEventName = void 0;
1766 if (symbolEventNames) {
1767 symbolEventName = symbolEventNames[task.capture ? TRUE_STR : FALSE_STR];
1768 }
1769 var existingTasks = symbolEventName && task.target[symbolEventName];
1770 if (existingTasks) {
1771 for (var i = 0; i < existingTasks.length; i++) {
1772 var existingTask = existingTasks[i];
1773 if (existingTask === task) {
1774 existingTasks.splice(i, 1);
1775 // set isRemoved to data for faster invokeTask check
1776 task.isRemoved = true;
1777 if (existingTasks.length === 0) {
1778 // all tasks for the eventName + capture have gone,
1779 // remove globalZoneAwareCallback and remove the task cache from target
1780 task.allRemoved = true;
1781 task.target[symbolEventName] = null;
1782 }
1783 break;
1784 }
1785 }
1786 }
1787 }
1788 // if all tasks for the eventName + capture have gone,
1789 // we will really remove the global event callback,
1790 // if not, return
1791 if (!task.allRemoved) {
1792 return;
1793 }
1794 return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options);
1795 };
1796 var customScheduleNonGlobal = function (task) {
1797 return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
1798 };
1799 var customSchedulePrepend = function (task) {
1800 return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
1801 };
1802 var customCancelNonGlobal = function (task) {
1803 return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options);
1804 };
1805 var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal;
1806 var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal;
1807 var compareTaskCallbackVsDelegate = function (task, delegate) {
1808 var typeOfDelegate = typeof delegate;
1809 return (typeOfDelegate === 'function' && task.callback === delegate) ||
1810 (typeOfDelegate === 'object' && task.originalDelegate === delegate);
1811 };
1812 var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate;
1813 var unpatchedEvents = Zone[zoneSymbol('UNPATCHED_EVENTS')];
1814 var passiveEvents = _global[zoneSymbol('PASSIVE_EVENTS')];
1815 var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) {
1816 if (returnTarget === void 0) { returnTarget = false; }
1817 if (prepend === void 0) { prepend = false; }
1818 return function () {
1819 var target = this || _global;
1820 var eventName = arguments[0];
1821 if (patchOptions && patchOptions.transferEventName) {
1822 eventName = patchOptions.transferEventName(eventName);
1823 }
1824 var delegate = arguments[1];
1825 if (!delegate) {
1826 return nativeListener.apply(this, arguments);
1827 }
1828 if (isNode && eventName === 'uncaughtException') {
1829 // don't patch uncaughtException of nodejs to prevent endless loop
1830 return nativeListener.apply(this, arguments);
1831 }
1832 // don't create the bind delegate function for handleEvent
1833 // case here to improve addEventListener performance
1834 // we will create the bind delegate when invoke
1835 var isHandleEvent = false;
1836 if (typeof delegate !== 'function') {
1837 if (!delegate.handleEvent) {
1838 return nativeListener.apply(this, arguments);
1839 }
1840 isHandleEvent = true;
1841 }
1842 if (validateHandler && !validateHandler(nativeListener, delegate, target, arguments)) {
1843 return;
1844 }
1845 var passive = passiveSupported && !!passiveEvents && passiveEvents.indexOf(eventName) !== -1;
1846 var options = buildEventListenerOptions(arguments[2], passive);
1847 if (unpatchedEvents) {
1848 // check upatched list
1849 for (var i = 0; i < unpatchedEvents.length; i++) {
1850 if (eventName === unpatchedEvents[i]) {
1851 if (passive) {
1852 return nativeListener.call(target, eventName, delegate, options);
1853 }
1854 else {
1855 return nativeListener.apply(this, arguments);
1856 }
1857 }
1858 }
1859 }
1860 var capture = !options ? false : typeof options === 'boolean' ? true : options.capture;
1861 var once = options && typeof options === 'object' ? options.once : false;
1862 var zone = Zone.current;
1863 var symbolEventNames = zoneSymbolEventNames$1[eventName];
1864 if (!symbolEventNames) {
1865 prepareEventNames(eventName, eventNameToString);
1866 symbolEventNames = zoneSymbolEventNames$1[eventName];
1867 }
1868 var symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
1869 var existingTasks = target[symbolEventName];
1870 var isExisting = false;
1871 if (existingTasks) {
1872 // already have task registered
1873 isExisting = true;
1874 if (checkDuplicate) {
1875 for (var i = 0; i < existingTasks.length; i++) {
1876 if (compare(existingTasks[i], delegate)) {
1877 // same callback, same capture, same event name, just return
1878 return;
1879 }
1880 }
1881 }
1882 }
1883 else {
1884 existingTasks = target[symbolEventName] = [];
1885 }
1886 var source;
1887 var constructorName = target.constructor['name'];
1888 var targetSource = globalSources[constructorName];
1889 if (targetSource) {
1890 source = targetSource[eventName];
1891 }
1892 if (!source) {
1893 source = constructorName + addSource +
1894 (eventNameToString ? eventNameToString(eventName) : eventName);
1895 }
1896 // do not create a new object as task.data to pass those things
1897 // just use the global shared one
1898 taskData.options = options;
1899 if (once) {
1900 // if addEventListener with once options, we don't pass it to
1901 // native addEventListener, instead we keep the once setting
1902 // and handle ourselves.
1903 taskData.options.once = false;
1904 }
1905 taskData.target = target;
1906 taskData.capture = capture;
1907 taskData.eventName = eventName;
1908 taskData.isExisting = isExisting;
1909 var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : undefined;
1910 // keep taskData into data to allow onScheduleEventTask to access the task information
1911 if (data) {
1912 data.taskData = taskData;
1913 }
1914 var task = zone.scheduleEventTask(source, delegate, data, customScheduleFn, customCancelFn);
1915 // should clear taskData.target to avoid memory leak
1916 // issue, https://github.com/angular/angular/issues/20442
1917 taskData.target = null;
1918 // need to clear up taskData because it is a global object
1919 if (data) {
1920 data.taskData = null;
1921 }
1922 // have to save those information to task in case
1923 // application may call task.zone.cancelTask() directly
1924 if (once) {
1925 options.once = true;
1926 }
1927 if (!(!passiveSupported && typeof task.options === 'boolean')) {
1928 // if not support passive, and we pass an option object
1929 // to addEventListener, we should save the options to task
1930 task.options = options;
1931 }
1932 task.target = target;
1933 task.capture = capture;
1934 task.eventName = eventName;
1935 if (isHandleEvent) {
1936 // save original delegate for compare to check duplicate
1937 task.originalDelegate = delegate;
1938 }
1939 if (!prepend) {
1940 existingTasks.push(task);
1941 }
1942 else {
1943 existingTasks.unshift(task);
1944 }
1945 if (returnTarget) {
1946 return target;
1947 }
1948 };
1949 };
1950 proto[ADD_EVENT_LISTENER] = makeAddListener(nativeAddEventListener, ADD_EVENT_LISTENER_SOURCE, customSchedule, customCancel, returnTarget);
1951 if (nativePrependEventListener) {
1952 proto[PREPEND_EVENT_LISTENER] = makeAddListener(nativePrependEventListener, PREPEND_EVENT_LISTENER_SOURCE, customSchedulePrepend, customCancel, returnTarget, true);
1953 }
1954 proto[REMOVE_EVENT_LISTENER] = function () {
1955 var target = this || _global;
1956 var eventName = arguments[0];
1957 if (patchOptions && patchOptions.transferEventName) {
1958 eventName = patchOptions.transferEventName(eventName);
1959 }
1960 var options = arguments[2];
1961 var capture = !options ? false : typeof options === 'boolean' ? true : options.capture;
1962 var delegate = arguments[1];
1963 if (!delegate) {
1964 return nativeRemoveEventListener.apply(this, arguments);
1965 }
1966 if (validateHandler &&
1967 !validateHandler(nativeRemoveEventListener, delegate, target, arguments)) {
1968 return;
1969 }
1970 var symbolEventNames = zoneSymbolEventNames$1[eventName];
1971 var symbolEventName;
1972 if (symbolEventNames) {
1973 symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
1974 }
1975 var existingTasks = symbolEventName && target[symbolEventName];
1976 if (existingTasks) {
1977 for (var i = 0; i < existingTasks.length; i++) {
1978 var existingTask = existingTasks[i];
1979 if (compare(existingTask, delegate)) {
1980 existingTasks.splice(i, 1);
1981 // set isRemoved to data for faster invokeTask check
1982 existingTask.isRemoved = true;
1983 if (existingTasks.length === 0) {
1984 // all tasks for the eventName + capture have gone,
1985 // remove globalZoneAwareCallback and remove the task cache from target
1986 existingTask.allRemoved = true;
1987 target[symbolEventName] = null;
1988 // in the target, we have an event listener which is added by on_property
1989 // such as target.onclick = function() {}, so we need to clear this internal
1990 // property too if all delegates all removed
1991 if (typeof eventName === 'string') {
1992 var onPropertySymbol = ZONE_SYMBOL_PREFIX + 'ON_PROPERTY' + eventName;
1993 target[onPropertySymbol] = null;
1994 }
1995 }
1996 existingTask.zone.cancelTask(existingTask);
1997 if (returnTarget) {
1998 return target;
1999 }
2000 return;
2001 }
2002 }
2003 }
2004 // issue 930, didn't find the event name or callback
2005 // from zone kept existingTasks, the callback maybe
2006 // added outside of zone, we need to call native removeEventListener
2007 // to try to remove it.
2008 return nativeRemoveEventListener.apply(this, arguments);
2009 };
2010 proto[LISTENERS_EVENT_LISTENER] = function () {
2011 var target = this || _global;
2012 var eventName = arguments[0];
2013 if (patchOptions && patchOptions.transferEventName) {
2014 eventName = patchOptions.transferEventName(eventName);
2015 }
2016 var listeners = [];
2017 var tasks = findEventTasks(target, eventNameToString ? eventNameToString(eventName) : eventName);
2018 for (var i = 0; i < tasks.length; i++) {
2019 var task = tasks[i];
2020 var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2021 listeners.push(delegate);
2022 }
2023 return listeners;
2024 };
2025 proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER] = function () {
2026 var target = this || _global;
2027 var eventName = arguments[0];
2028 if (!eventName) {
2029 var keys = Object.keys(target);
2030 for (var i = 0; i < keys.length; i++) {
2031 var prop = keys[i];
2032 var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
2033 var evtName = match && match[1];
2034 // in nodejs EventEmitter, removeListener event is
2035 // used for monitoring the removeListener call,
2036 // so just keep removeListener eventListener until
2037 // all other eventListeners are removed
2038 if (evtName && evtName !== 'removeListener') {
2039 this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName);
2040 }
2041 }
2042 // remove removeListener listener finally
2043 this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener');
2044 }
2045 else {
2046 if (patchOptions && patchOptions.transferEventName) {
2047 eventName = patchOptions.transferEventName(eventName);
2048 }
2049 var symbolEventNames = zoneSymbolEventNames$1[eventName];
2050 if (symbolEventNames) {
2051 var symbolEventName = symbolEventNames[FALSE_STR];
2052 var symbolCaptureEventName = symbolEventNames[TRUE_STR];
2053 var tasks = target[symbolEventName];
2054 var captureTasks = target[symbolCaptureEventName];
2055 if (tasks) {
2056 var removeTasks = tasks.slice();
2057 for (var i = 0; i < removeTasks.length; i++) {
2058 var task = removeTasks[i];
2059 var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2060 this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
2061 }
2062 }
2063 if (captureTasks) {
2064 var removeTasks = captureTasks.slice();
2065 for (var i = 0; i < removeTasks.length; i++) {
2066 var task = removeTasks[i];
2067 var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2068 this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
2069 }
2070 }
2071 }
2072 }
2073 if (returnTarget) {
2074 return this;
2075 }
2076 };
2077 // for native toString patch
2078 attachOriginToPatched(proto[ADD_EVENT_LISTENER], nativeAddEventListener);
2079 attachOriginToPatched(proto[REMOVE_EVENT_LISTENER], nativeRemoveEventListener);
2080 if (nativeRemoveAllListeners) {
2081 attachOriginToPatched(proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER], nativeRemoveAllListeners);
2082 }
2083 if (nativeListeners) {
2084 attachOriginToPatched(proto[LISTENERS_EVENT_LISTENER], nativeListeners);
2085 }
2086 return true;
2087 }
2088 var results = [];
2089 for (var i = 0; i < apis.length; i++) {
2090 results[i] = patchEventTargetMethods(apis[i], patchOptions);
2091 }
2092 return results;
2093 }
2094 function findEventTasks(target, eventName) {
2095 if (!eventName) {
2096 var foundTasks = [];
2097 for (var prop in target) {
2098 var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
2099 var evtName = match && match[1];
2100 if (evtName && (!eventName || evtName === eventName)) {
2101 var tasks = target[prop];
2102 if (tasks) {
2103 for (var i = 0; i < tasks.length; i++) {
2104 foundTasks.push(tasks[i]);
2105 }
2106 }
2107 }
2108 }
2109 return foundTasks;
2110 }
2111 var symbolEventName = zoneSymbolEventNames$1[eventName];
2112 if (!symbolEventName) {
2113 prepareEventNames(eventName);
2114 symbolEventName = zoneSymbolEventNames$1[eventName];
2115 }
2116 var captureFalseTasks = target[symbolEventName[FALSE_STR]];
2117 var captureTrueTasks = target[symbolEventName[TRUE_STR]];
2118 if (!captureFalseTasks) {
2119 return captureTrueTasks ? captureTrueTasks.slice() : [];
2120 }
2121 else {
2122 return captureTrueTasks ? captureFalseTasks.concat(captureTrueTasks) :
2123 captureFalseTasks.slice();
2124 }
2125 }
2126 /**
2127 * @license
2128 * Copyright Google LLC All Rights Reserved.
2129 *
2130 * Use of this source code is governed by an MIT-style license that can be
2131 * found in the LICENSE file at https://angular.io/license
2132 */
2133 Zone.__load_patch('EventEmitter', function (global) {
2134 // For EventEmitter
2135 var EE_ADD_LISTENER = 'addListener';
2136 var EE_PREPEND_LISTENER = 'prependListener';
2137 var EE_REMOVE_LISTENER = 'removeListener';
2138 var EE_REMOVE_ALL_LISTENER = 'removeAllListeners';
2139 var EE_LISTENERS = 'listeners';
2140 var EE_ON = 'on';
2141 var EE_OFF = 'off';
2142 var compareTaskCallbackVsDelegate = function (task, delegate) {
2143 // same callback, same capture, same event name, just return
2144 return task.callback === delegate || task.callback.listener === delegate;
2145 };
2146 var eventNameToString = function (eventName) {
2147 if (typeof eventName === 'string') {
2148 return eventName;
2149 }
2150 if (!eventName) {
2151 return '';
2152 }
2153 return eventName.toString().replace('(', '_').replace(')', '_');
2154 };
2155 function patchEventEmitterMethods(obj) {
2156 var result = patchEventTarget(global, [obj], {
2157 useG: false,
2158 add: EE_ADD_LISTENER,
2159 rm: EE_REMOVE_LISTENER,
2160 prepend: EE_PREPEND_LISTENER,
2161 rmAll: EE_REMOVE_ALL_LISTENER,
2162 listeners: EE_LISTENERS,
2163 chkDup: false,
2164 rt: true,
2165 diff: compareTaskCallbackVsDelegate,
2166 eventNameToString: eventNameToString
2167 });
2168 if (result && result[0]) {
2169 obj[EE_ON] = obj[EE_ADD_LISTENER];
2170 obj[EE_OFF] = obj[EE_REMOVE_LISTENER];
2171 }
2172 }
2173 // EventEmitter
2174 var events;
2175 try {
2176 events = require('events');
2177 }
2178 catch (err) {
2179 }
2180 if (events && events.EventEmitter) {
2181 patchEventEmitterMethods(events.EventEmitter.prototype);
2182 }
2183 });
2184 /**
2185 * @license
2186 * Copyright Google LLC All Rights Reserved.
2187 *
2188 * Use of this source code is governed by an MIT-style license that can be
2189 * found in the LICENSE file at https://angular.io/license
2190 */
2191 Zone.__load_patch('fs', function () {
2192 var fs;
2193 try {
2194 fs = require('fs');
2195 }
2196 catch (err) {
2197 }
2198 // watch, watchFile, unwatchFile has been patched
2199 // because EventEmitter has been patched
2200 var TO_PATCH_MACROTASK_METHODS = [
2201 'access', 'appendFile', 'chmod', 'chown', 'close', 'exists', 'fchmod',
2202 'fchown', 'fdatasync', 'fstat', 'fsync', 'ftruncate', 'futimes', 'lchmod',
2203 'lchown', 'link', 'lstat', 'mkdir', 'mkdtemp', 'open', 'read',
2204 'readdir', 'readFile', 'readlink', 'realpath', 'rename', 'rmdir', 'stat',
2205 'symlink', 'truncate', 'unlink', 'utimes', 'write', 'writeFile',
2206 ];
2207 if (fs) {
2208 TO_PATCH_MACROTASK_METHODS.filter(function (name) { return !!fs[name] && typeof fs[name] === 'function'; })
2209 .forEach(function (name) {
2210 patchMacroTask(fs, name, function (self, args) {
2211 return {
2212 name: 'fs.' + name,
2213 args: args,
2214 cbIdx: args.length > 0 ? args.length - 1 : -1,
2215 target: self
2216 };
2217 });
2218 });
2219 }
2220 });
2221 /**
2222 * @license
2223 * Copyright Google LLC All Rights Reserved.
2224 *
2225 * Use of this source code is governed by an MIT-style license that can be
2226 * found in the LICENSE file at https://angular.io/license
2227 */
2228 var taskSymbol = zoneSymbol('zoneTask');
2229 function patchTimer(window, setName, cancelName, nameSuffix) {
2230 var setNative = null;
2231 var clearNative = null;
2232 setName += nameSuffix;
2233 cancelName += nameSuffix;
2234 var tasksByHandleId = {};
2235 function scheduleTask(task) {
2236 var data = task.data;
2237 data.args[0] = function () {
2238 return task.invoke.apply(this, arguments);
2239 };
2240 data.handleId = setNative.apply(window, data.args);
2241 return task;
2242 }
2243 function clearTask(task) {
2244 return clearNative.call(window, task.data.handleId);
2245 }
2246 setNative =
2247 patchMethod(window, setName, function (delegate) { return function (self, args) {
2248 if (typeof args[0] === 'function') {
2249 var options_1 = {
2250 isPeriodic: nameSuffix === 'Interval',
2251 delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 :
2252 undefined,
2253 args: args
2254 };
2255 var callback_1 = args[0];
2256 args[0] = function timer() {
2257 try {
2258 return callback_1.apply(this, arguments);
2259 }
2260 finally {
2261 // issue-934, task will be cancelled
2262 // even it is a periodic task such as
2263 // setInterval
2264 // https://github.com/angular/angular/issues/40387
2265 // Cleanup tasksByHandleId should be handled before scheduleTask
2266 // Since some zoneSpec may intercept and doesn't trigger
2267 // scheduleFn(scheduleTask) provided here.
2268 if (!(options_1.isPeriodic)) {
2269 if (typeof options_1.handleId === 'number') {
2270 // in non-nodejs env, we remove timerId
2271 // from local cache
2272 delete tasksByHandleId[options_1.handleId];
2273 }
2274 else if (options_1.handleId) {
2275 // Node returns complex objects as handleIds
2276 // we remove task reference from timer object
2277 options_1.handleId[taskSymbol] = null;
2278 }
2279 }
2280 }
2281 };
2282 var task = scheduleMacroTaskWithCurrentZone(setName, args[0], options_1, scheduleTask, clearTask);
2283 if (!task) {
2284 return task;
2285 }
2286 // Node.js must additionally support the ref and unref functions.
2287 var handle = task.data.handleId;
2288 if (typeof handle === 'number') {
2289 // for non nodejs env, we save handleId: task
2290 // mapping in local cache for clearTimeout
2291 tasksByHandleId[handle] = task;
2292 }
2293 else if (handle) {
2294 // for nodejs env, we save task
2295 // reference in timerId Object for clearTimeout
2296 handle[taskSymbol] = task;
2297 }
2298 // check whether handle is null, because some polyfill or browser
2299 // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame
2300 if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' &&
2301 typeof handle.unref === 'function') {
2302 task.ref = handle.ref.bind(handle);
2303 task.unref = handle.unref.bind(handle);
2304 }
2305 if (typeof handle === 'number' || handle) {
2306 return handle;
2307 }
2308 return task;
2309 }
2310 else {
2311 // cause an error by calling it directly.
2312 return delegate.apply(window, args);
2313 }
2314 }; });
2315 clearNative =
2316 patchMethod(window, cancelName, function (delegate) { return function (self, args) {
2317 var id = args[0];
2318 var task;
2319 if (typeof id === 'number') {
2320 // non nodejs env.
2321 task = tasksByHandleId[id];
2322 }
2323 else {
2324 // nodejs env.
2325 task = id && id[taskSymbol];
2326 // other environments.
2327 if (!task) {
2328 task = id;
2329 }
2330 }
2331 if (task && typeof task.type === 'string') {
2332 if (task.state !== 'notScheduled' &&
2333 (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) {
2334 if (typeof id === 'number') {
2335 delete tasksByHandleId[id];
2336 }
2337 else if (id) {
2338 id[taskSymbol] = null;
2339 }
2340 // Do not cancel already canceled functions
2341 task.zone.cancelTask(task);
2342 }
2343 }
2344 else {
2345 // cause an error by calling it directly.
2346 delegate.apply(window, args);
2347 }
2348 }; });
2349 }
2350 /**
2351 * @license
2352 * Copyright Google LLC All Rights Reserved.
2353 *
2354 * Use of this source code is governed by an MIT-style license that can be
2355 * found in the LICENSE file at https://angular.io/license
2356 */
2357 var set = 'set';
2358 var clear = 'clear';
2359 Zone.__load_patch('node_timers', function (global, Zone) {
2360 // Timers
2361 var globalUseTimeoutFromTimer = false;
2362 try {
2363 var timers = require('timers');
2364 var globalEqualTimersTimeout = global.setTimeout === timers.setTimeout;
2365 if (!globalEqualTimersTimeout && !isMix) {
2366 // 1. if isMix, then we are in mix environment such as Electron
2367 // we should only patch timers.setTimeout because global.setTimeout
2368 // have been patched
2369 // 2. if global.setTimeout not equal timers.setTimeout, check
2370 // whether global.setTimeout use timers.setTimeout or not
2371 var originSetTimeout_1 = timers.setTimeout;
2372 timers.setTimeout = function () {
2373 globalUseTimeoutFromTimer = true;
2374 return originSetTimeout_1.apply(this, arguments);
2375 };
2376 var detectTimeout = global.setTimeout(function () { }, 100);
2377 clearTimeout(detectTimeout);
2378 timers.setTimeout = originSetTimeout_1;
2379 }
2380 patchTimer(timers, set, clear, 'Timeout');
2381 patchTimer(timers, set, clear, 'Interval');
2382 patchTimer(timers, set, clear, 'Immediate');
2383 }
2384 catch (error) {
2385 // timers module not exists, for example, when we using nativeScript
2386 // timers is not available
2387 }
2388 if (isMix) {
2389 // if we are in mix environment, such as Electron,
2390 // the global.setTimeout has already been patched,
2391 // so we just patch timers.setTimeout
2392 return;
2393 }
2394 if (!globalUseTimeoutFromTimer) {
2395 // 1. global setTimeout equals timers setTimeout
2396 // 2. or global don't use timers setTimeout(maybe some other library patch setTimeout)
2397 // 3. or load timers module error happens, we should patch global setTimeout
2398 patchTimer(global, set, clear, 'Timeout');
2399 patchTimer(global, set, clear, 'Interval');
2400 patchTimer(global, set, clear, 'Immediate');
2401 }
2402 else {
2403 // global use timers setTimeout, but not equals
2404 // this happens when use nodejs v0.10.x, global setTimeout will
2405 // use a lazy load version of timers setTimeout
2406 // we should not double patch timer's setTimeout
2407 // so we only store the __symbol__ for consistency
2408 global[Zone.__symbol__('setTimeout')] = global.setTimeout;
2409 global[Zone.__symbol__('setInterval')] = global.setInterval;
2410 global[Zone.__symbol__('setImmediate')] = global.setImmediate;
2411 }
2412 });
2413 // patch process related methods
2414 Zone.__load_patch('nextTick', function () {
2415 // patch nextTick as microTask
2416 patchMicroTask(process, 'nextTick', function (self, args) {
2417 return {
2418 name: 'process.nextTick',
2419 args: args,
2420 cbIdx: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1,
2421 target: process
2422 };
2423 });
2424 });
2425 Zone.__load_patch('handleUnhandledPromiseRejection', function (global, Zone, api) {
2426 Zone[api.symbol('unhandledPromiseRejectionHandler')] =
2427 findProcessPromiseRejectionHandler('unhandledRejection');
2428 Zone[api.symbol('rejectionHandledHandler')] =
2429 findProcessPromiseRejectionHandler('rejectionHandled');
2430 // handle unhandled promise rejection
2431 function findProcessPromiseRejectionHandler(evtName) {
2432 return function (e) {
2433 var eventTasks = findEventTasks(process, evtName);
2434 eventTasks.forEach(function (eventTask) {
2435 // process has added unhandledrejection event listener
2436 // trigger the event listener
2437 if (evtName === 'unhandledRejection') {
2438 eventTask.invoke(e.rejection, e.promise);
2439 }
2440 else if (evtName === 'rejectionHandled') {
2441 eventTask.invoke(e.promise);
2442 }
2443 });
2444 };
2445 }
2446 });
2447 // Crypto
2448 Zone.__load_patch('crypto', function () {
2449 var crypto;
2450 try {
2451 crypto = require('crypto');
2452 }
2453 catch (err) {
2454 }
2455 // use the generic patchMacroTask to patch crypto
2456 if (crypto) {
2457 var methodNames = ['randomBytes', 'pbkdf2'];
2458 methodNames.forEach(function (name) {
2459 patchMacroTask(crypto, name, function (self, args) {
2460 return {
2461 name: 'crypto.' + name,
2462 args: args,
2463 cbIdx: (args.length > 0 && typeof args[args.length - 1] === 'function') ?
2464 args.length - 1 :
2465 -1,
2466 target: crypto
2467 };
2468 });
2469 });
2470 }
2471 });
2472 Zone.__load_patch('console', function (global, Zone) {
2473 var consoleMethods = ['dir', 'log', 'info', 'error', 'warn', 'assert', 'debug', 'timeEnd', 'trace'];
2474 consoleMethods.forEach(function (m) {
2475 var originalMethod = console[Zone.__symbol__(m)] = console[m];
2476 if (originalMethod) {
2477 console[m] = function () {
2478 var args = ArraySlice.call(arguments);
2479 if (Zone.current === Zone.root) {
2480 return originalMethod.apply(this, args);
2481 }
2482 else {
2483 return Zone.root.run(originalMethod, this, args);
2484 }
2485 };
2486 }
2487 });
2488 });
2489 /**
2490 * @license
2491 * Copyright Google LLC All Rights Reserved.
2492 *
2493 * Use of this source code is governed by an MIT-style license that can be
2494 * found in the LICENSE file at https://angular.io/license
2495 */
2496 /**
2497 * @fileoverview
2498 * @suppress {globalThis}
2499 */
2500 var NEWLINE = '\n';
2501 var IGNORE_FRAMES = {};
2502 var creationTrace = '__creationTrace__';
2503 var ERROR_TAG = 'STACKTRACE TRACKING';
2504 var SEP_TAG = '__SEP_TAG__';
2505 var sepTemplate = SEP_TAG + '@[native]';
2506 var LongStackTrace = /** @class */ (function () {
2507 function LongStackTrace() {
2508 this.error = getStacktrace();
2509 this.timestamp = new Date();
2510 }
2511 return LongStackTrace;
2512 }());
2513 function getStacktraceWithUncaughtError() {
2514 return new Error(ERROR_TAG);
2515 }
2516 function getStacktraceWithCaughtError() {
2517 try {
2518 throw getStacktraceWithUncaughtError();
2519 }
2520 catch (err) {
2521 return err;
2522 }
2523 }
2524 // Some implementations of exception handling don't create a stack trace if the exception
2525 // isn't thrown, however it's faster not to actually throw the exception.
2526 var error = getStacktraceWithUncaughtError();
2527 var caughtError = getStacktraceWithCaughtError();
2528 var getStacktrace = error.stack ?
2529 getStacktraceWithUncaughtError :
2530 (caughtError.stack ? getStacktraceWithCaughtError : getStacktraceWithUncaughtError);
2531 function getFrames(error) {
2532 return error.stack ? error.stack.split(NEWLINE) : [];
2533 }
2534 function addErrorStack(lines, error) {
2535 var trace = getFrames(error);
2536 for (var i = 0; i < trace.length; i++) {
2537 var frame = trace[i];
2538 // Filter out the Frames which are part of stack capturing.
2539 if (!IGNORE_FRAMES.hasOwnProperty(frame)) {
2540 lines.push(trace[i]);
2541 }
2542 }
2543 }
2544 function renderLongStackTrace(frames, stack) {
2545 var longTrace = [stack ? stack.trim() : ''];
2546 if (frames) {
2547 var timestamp = new Date().getTime();
2548 for (var i = 0; i < frames.length; i++) {
2549 var traceFrames = frames[i];
2550 var lastTime = traceFrames.timestamp;
2551 var separator = "____________________Elapsed " + (timestamp - lastTime.getTime()) + " ms; At: " + lastTime;
2552 separator = separator.replace(/[^\w\d]/g, '_');
2553 longTrace.push(sepTemplate.replace(SEP_TAG, separator));
2554 addErrorStack(longTrace, traceFrames.error);
2555 timestamp = lastTime.getTime();
2556 }
2557 }
2558 return longTrace.join(NEWLINE);
2559 }
2560 // if Error.stackTraceLimit is 0, means stack trace
2561 // is disabled, so we don't need to generate long stack trace
2562 // this will improve performance in some test(some test will
2563 // set stackTraceLimit to 0, https://github.com/angular/zone.js/issues/698
2564 function stackTracesEnabled() {
2565 // Cast through any since this property only exists on Error in the nodejs
2566 // typings.
2567 return Error.stackTraceLimit > 0;
2568 }
2569 Zone['longStackTraceZoneSpec'] = {
2570 name: 'long-stack-trace',
2571 longStackTraceLimit: 10,
2572 // add a getLongStackTrace method in spec to
2573 // handle handled reject promise error.
2574 getLongStackTrace: function (error) {
2575 if (!error) {
2576 return undefined;
2577 }
2578 var trace = error[Zone.__symbol__('currentTaskTrace')];
2579 if (!trace) {
2580 return error.stack;
2581 }
2582 return renderLongStackTrace(trace, error.stack);
2583 },
2584 onScheduleTask: function (parentZoneDelegate, currentZone, targetZone, task) {
2585 if (stackTracesEnabled()) {
2586 var currentTask = Zone.currentTask;
2587 var trace = currentTask && currentTask.data && currentTask.data[creationTrace] || [];
2588 trace = [new LongStackTrace()].concat(trace);
2589 if (trace.length > this.longStackTraceLimit) {
2590 trace.length = this.longStackTraceLimit;
2591 }
2592 if (!task.data)
2593 task.data = {};
2594 if (task.type === 'eventTask') {
2595 // Fix issue https://github.com/angular/zone.js/issues/1195,
2596 // For event task of browser, by default, all task will share a
2597 // singleton instance of data object, we should create a new one here
2598 // The cast to `any` is required to workaround a closure bug which wrongly applies
2599 // URL sanitization rules to .data access.
2600 task.data = Object.assign({}, task.data);
2601 }
2602 task.data[creationTrace] = trace;
2603 }
2604 return parentZoneDelegate.scheduleTask(targetZone, task);
2605 },
2606 onHandleError: function (parentZoneDelegate, currentZone, targetZone, error) {
2607 if (stackTracesEnabled()) {
2608 var parentTask = Zone.currentTask || error.task;
2609 if (error instanceof Error && parentTask) {
2610 var longStack = renderLongStackTrace(parentTask.data && parentTask.data[creationTrace], error.stack);
2611 try {
2612 error.stack = error.longStack = longStack;
2613 }
2614 catch (err) {
2615 }
2616 }
2617 }
2618 return parentZoneDelegate.handleError(targetZone, error);
2619 }
2620 };
2621 function captureStackTraces(stackTraces, count) {
2622 if (count > 0) {
2623 stackTraces.push(getFrames((new LongStackTrace()).error));
2624 captureStackTraces(stackTraces, count - 1);
2625 }
2626 }
2627 function computeIgnoreFrames() {
2628 if (!stackTracesEnabled()) {
2629 return;
2630 }
2631 var frames = [];
2632 captureStackTraces(frames, 2);
2633 var frames1 = frames[0];
2634 var frames2 = frames[1];
2635 for (var i = 0; i < frames1.length; i++) {
2636 var frame1 = frames1[i];
2637 if (frame1.indexOf(ERROR_TAG) == -1) {
2638 var match = frame1.match(/^\s*at\s+/);
2639 if (match) {
2640 sepTemplate = match[0] + SEP_TAG + ' (http://localhost)';
2641 break;
2642 }
2643 }
2644 }
2645 for (var i = 0; i < frames1.length; i++) {
2646 var frame1 = frames1[i];
2647 var frame2 = frames2[i];
2648 if (frame1 === frame2) {
2649 IGNORE_FRAMES[frame1] = true;
2650 }
2651 else {
2652 break;
2653 }
2654 }
2655 }
2656 computeIgnoreFrames();
2657 /**
2658 * @license
2659 * Copyright Google LLC All Rights Reserved.
2660 *
2661 * Use of this source code is governed by an MIT-style license that can be
2662 * found in the LICENSE file at https://angular.io/license
2663 */
2664 var ProxyZoneSpec = /** @class */ (function () {
2665 function ProxyZoneSpec(defaultSpecDelegate) {
2666 if (defaultSpecDelegate === void 0) { defaultSpecDelegate = null; }
2667 this.defaultSpecDelegate = defaultSpecDelegate;
2668 this.name = 'ProxyZone';
2669 this._delegateSpec = null;
2670 this.properties = { 'ProxyZoneSpec': this };
2671 this.propertyKeys = null;
2672 this.lastTaskState = null;
2673 this.isNeedToTriggerHasTask = false;
2674 this.tasks = [];
2675 this.setDelegate(defaultSpecDelegate);
2676 }
2677 ProxyZoneSpec.get = function () {
2678 return Zone.current.get('ProxyZoneSpec');
2679 };
2680 ProxyZoneSpec.isLoaded = function () {
2681 return ProxyZoneSpec.get() instanceof ProxyZoneSpec;
2682 };
2683 ProxyZoneSpec.assertPresent = function () {
2684 if (!ProxyZoneSpec.isLoaded()) {
2685 throw new Error("Expected to be running in 'ProxyZone', but it was not found.");
2686 }
2687 return ProxyZoneSpec.get();
2688 };
2689 ProxyZoneSpec.prototype.setDelegate = function (delegateSpec) {
2690 var _this = this;
2691 var isNewDelegate = this._delegateSpec !== delegateSpec;
2692 this._delegateSpec = delegateSpec;
2693 this.propertyKeys && this.propertyKeys.forEach(function (key) { return delete _this.properties[key]; });
2694 this.propertyKeys = null;
2695 if (delegateSpec && delegateSpec.properties) {
2696 this.propertyKeys = Object.keys(delegateSpec.properties);
2697 this.propertyKeys.forEach(function (k) { return _this.properties[k] = delegateSpec.properties[k]; });
2698 }
2699 // if a new delegateSpec was set, check if we need to trigger hasTask
2700 if (isNewDelegate && this.lastTaskState &&
2701 (this.lastTaskState.macroTask || this.lastTaskState.microTask)) {
2702 this.isNeedToTriggerHasTask = true;
2703 }
2704 };
2705 ProxyZoneSpec.prototype.getDelegate = function () {
2706 return this._delegateSpec;
2707 };
2708 ProxyZoneSpec.prototype.resetDelegate = function () {
2709 var delegateSpec = this.getDelegate();
2710 this.setDelegate(this.defaultSpecDelegate);
2711 };
2712 ProxyZoneSpec.prototype.tryTriggerHasTask = function (parentZoneDelegate, currentZone, targetZone) {
2713 if (this.isNeedToTriggerHasTask && this.lastTaskState) {
2714 // last delegateSpec has microTask or macroTask
2715 // should call onHasTask in current delegateSpec
2716 this.isNeedToTriggerHasTask = false;
2717 this.onHasTask(parentZoneDelegate, currentZone, targetZone, this.lastTaskState);
2718 }
2719 };
2720 ProxyZoneSpec.prototype.removeFromTasks = function (task) {
2721 if (!this.tasks) {
2722 return;
2723 }
2724 for (var i = 0; i < this.tasks.length; i++) {
2725 if (this.tasks[i] === task) {
2726 this.tasks.splice(i, 1);
2727 return;
2728 }
2729 }
2730 };
2731 ProxyZoneSpec.prototype.getAndClearPendingTasksInfo = function () {
2732 if (this.tasks.length === 0) {
2733 return '';
2734 }
2735 var taskInfo = this.tasks.map(function (task) {
2736 var dataInfo = task.data &&
2737 Object.keys(task.data)
2738 .map(function (key) {
2739 return key + ':' + task.data[key];
2740 })
2741 .join(',');
2742 return "type: " + task.type + ", source: " + task.source + ", args: {" + dataInfo + "}";
2743 });
2744 var pendingTasksInfo = '--Pending async tasks are: [' + taskInfo + ']';
2745 // clear tasks
2746 this.tasks = [];
2747 return pendingTasksInfo;
2748 };
2749 ProxyZoneSpec.prototype.onFork = function (parentZoneDelegate, currentZone, targetZone, zoneSpec) {
2750 if (this._delegateSpec && this._delegateSpec.onFork) {
2751 return this._delegateSpec.onFork(parentZoneDelegate, currentZone, targetZone, zoneSpec);
2752 }
2753 else {
2754 return parentZoneDelegate.fork(targetZone, zoneSpec);
2755 }
2756 };
2757 ProxyZoneSpec.prototype.onIntercept = function (parentZoneDelegate, currentZone, targetZone, delegate, source) {
2758 if (this._delegateSpec && this._delegateSpec.onIntercept) {
2759 return this._delegateSpec.onIntercept(parentZoneDelegate, currentZone, targetZone, delegate, source);
2760 }
2761 else {
2762 return parentZoneDelegate.intercept(targetZone, delegate, source);
2763 }
2764 };
2765 ProxyZoneSpec.prototype.onInvoke = function (parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source) {
2766 this.tryTriggerHasTask(parentZoneDelegate, currentZone, targetZone);
2767 if (this._delegateSpec && this._delegateSpec.onInvoke) {
2768 return this._delegateSpec.onInvoke(parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source);
2769 }
2770 else {
2771 return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source);
2772 }
2773 };
2774 ProxyZoneSpec.prototype.onHandleError = function (parentZoneDelegate, currentZone, targetZone, error) {
2775 if (this._delegateSpec && this._delegateSpec.onHandleError) {
2776 return this._delegateSpec.onHandleError(parentZoneDelegate, currentZone, targetZone, error);
2777 }
2778 else {
2779 return parentZoneDelegate.handleError(targetZone, error);
2780 }
2781 };
2782 ProxyZoneSpec.prototype.onScheduleTask = function (parentZoneDelegate, currentZone, targetZone, task) {
2783 if (task.type !== 'eventTask') {
2784 this.tasks.push(task);
2785 }
2786 if (this._delegateSpec && this._delegateSpec.onScheduleTask) {
2787 return this._delegateSpec.onScheduleTask(parentZoneDelegate, currentZone, targetZone, task);
2788 }
2789 else {
2790 return parentZoneDelegate.scheduleTask(targetZone, task);
2791 }
2792 };
2793 ProxyZoneSpec.prototype.onInvokeTask = function (parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs) {
2794 if (task.type !== 'eventTask') {
2795 this.removeFromTasks(task);
2796 }
2797 this.tryTriggerHasTask(parentZoneDelegate, currentZone, targetZone);
2798 if (this._delegateSpec && this._delegateSpec.onInvokeTask) {
2799 return this._delegateSpec.onInvokeTask(parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs);
2800 }
2801 else {
2802 return parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs);
2803 }
2804 };
2805 ProxyZoneSpec.prototype.onCancelTask = function (parentZoneDelegate, currentZone, targetZone, task) {
2806 if (task.type !== 'eventTask') {
2807 this.removeFromTasks(task);
2808 }
2809 this.tryTriggerHasTask(parentZoneDelegate, currentZone, targetZone);
2810 if (this._delegateSpec && this._delegateSpec.onCancelTask) {
2811 return this._delegateSpec.onCancelTask(parentZoneDelegate, currentZone, targetZone, task);
2812 }
2813 else {
2814 return parentZoneDelegate.cancelTask(targetZone, task);
2815 }
2816 };
2817 ProxyZoneSpec.prototype.onHasTask = function (delegate, current, target, hasTaskState) {
2818 this.lastTaskState = hasTaskState;
2819 if (this._delegateSpec && this._delegateSpec.onHasTask) {
2820 this._delegateSpec.onHasTask(delegate, current, target, hasTaskState);
2821 }
2822 else {
2823 delegate.hasTask(target, hasTaskState);
2824 }
2825 };
2826 return ProxyZoneSpec;
2827 }());
2828 // Export the class so that new instances can be created with proper
2829 // constructor params.
2830 Zone['ProxyZoneSpec'] = ProxyZoneSpec;
2831 /**
2832 * @license
2833 * Copyright Google LLC All Rights Reserved.
2834 *
2835 * Use of this source code is governed by an MIT-style license that can be
2836 * found in the LICENSE file at https://angular.io/license
2837 */
2838 var SyncTestZoneSpec = /** @class */ (function () {
2839 function SyncTestZoneSpec(namePrefix) {
2840 this.runZone = Zone.current;
2841 this.name = 'syncTestZone for ' + namePrefix;
2842 }
2843 SyncTestZoneSpec.prototype.onScheduleTask = function (delegate, current, target, task) {
2844 switch (task.type) {
2845 case 'microTask':
2846 case 'macroTask':
2847 throw new Error("Cannot call " + task.source + " from within a sync test.");
2848 case 'eventTask':
2849 task = delegate.scheduleTask(target, task);
2850 break;
2851 }
2852 return task;
2853 };
2854 return SyncTestZoneSpec;
2855 }());
2856 // Export the class so that new instances can be created with proper
2857 // constructor params.
2858 Zone['SyncTestZoneSpec'] = SyncTestZoneSpec;
2859 /**
2860 * @license
2861 * Copyright Google LLC All Rights Reserved.
2862 *
2863 * Use of this source code is governed by an MIT-style license that can be
2864 * found in the LICENSE file at https://angular.io/license
2865 */
2866 Zone.__load_patch('jasmine', function (global, Zone, api) {
2867 var __extends = function (d, b) {
2868 for (var p in b)
2869 if (b.hasOwnProperty(p))
2870 d[p] = b[p];
2871 function __() {
2872 this.constructor = d;
2873 }
2874 d.prototype = b === null ? Object.create(b) : ((__.prototype = b.prototype), new __());
2875 };
2876 // Patch jasmine's describe/it/beforeEach/afterEach functions so test code always runs
2877 // in a testZone (ProxyZone). (See: angular/zone.js#91 & angular/angular#10503)
2878 if (!Zone)
2879 throw new Error('Missing: zone.js');
2880 if (typeof jest !== 'undefined') {
2881 // return if jasmine is a light implementation inside jest
2882 // in this case, we are running inside jest not jasmine
2883 return;
2884 }
2885 if (typeof jasmine == 'undefined' || jasmine['__zone_patch__']) {
2886 return;
2887 }
2888 jasmine['__zone_patch__'] = true;
2889 var SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
2890 var ProxyZoneSpec = Zone['ProxyZoneSpec'];
2891 if (!SyncTestZoneSpec)
2892 throw new Error('Missing: SyncTestZoneSpec');
2893 if (!ProxyZoneSpec)
2894 throw new Error('Missing: ProxyZoneSpec');
2895 var ambientZone = Zone.current;
2896 // Create a synchronous-only zone in which to run `describe` blocks in order to raise an
2897 // error if any asynchronous operations are attempted inside of a `describe` but outside of
2898 // a `beforeEach` or `it`.
2899 var syncZone = ambientZone.fork(new SyncTestZoneSpec('jasmine.describe'));
2900 var symbol = Zone.__symbol__;
2901 // whether patch jasmine clock when in fakeAsync
2902 var disablePatchingJasmineClock = global[symbol('fakeAsyncDisablePatchingClock')] === true;
2903 // the original variable name fakeAsyncPatchLock is not accurate, so the name will be
2904 // fakeAsyncAutoFakeAsyncWhenClockPatched and if this enablePatchingJasmineClock is false, we also
2905 // automatically disable the auto jump into fakeAsync feature
2906 var enableAutoFakeAsyncWhenClockPatched = !disablePatchingJasmineClock &&
2907 ((global[symbol('fakeAsyncPatchLock')] === true) ||
2908 (global[symbol('fakeAsyncAutoFakeAsyncWhenClockPatched')] === true));
2909 var ignoreUnhandledRejection = global[symbol('ignoreUnhandledRejection')] === true;
2910 if (!ignoreUnhandledRejection) {
2911 var globalErrors_1 = jasmine.GlobalErrors;
2912 if (globalErrors_1 && !jasmine[symbol('GlobalErrors')]) {
2913 jasmine[symbol('GlobalErrors')] = globalErrors_1;
2914 jasmine.GlobalErrors = function () {
2915 var instance = new globalErrors_1();
2916 var originalInstall = instance.install;
2917 if (originalInstall && !instance[symbol('install')]) {
2918 instance[symbol('install')] = originalInstall;
2919 instance.install = function () {
2920 var originalHandlers = process.listeners('unhandledRejection');
2921 var r = originalInstall.apply(this, arguments);
2922 process.removeAllListeners('unhandledRejection');
2923 if (originalHandlers) {
2924 originalHandlers.forEach(function (h) { return process.on('unhandledRejection', h); });
2925 }
2926 return r;
2927 };
2928 }
2929 return instance;
2930 };
2931 }
2932 }
2933 // Monkey patch all of the jasmine DSL so that each function runs in appropriate zone.
2934 var jasmineEnv = jasmine.getEnv();
2935 ['describe', 'xdescribe', 'fdescribe'].forEach(function (methodName) {
2936 var originalJasmineFn = jasmineEnv[methodName];
2937 jasmineEnv[methodName] = function (description, specDefinitions) {
2938 return originalJasmineFn.call(this, description, wrapDescribeInZone(specDefinitions));
2939 };
2940 });
2941 ['it', 'xit', 'fit'].forEach(function (methodName) {
2942 var originalJasmineFn = jasmineEnv[methodName];
2943 jasmineEnv[symbol(methodName)] = originalJasmineFn;
2944 jasmineEnv[methodName] = function (description, specDefinitions, timeout) {
2945 arguments[1] = wrapTestInZone(specDefinitions);
2946 return originalJasmineFn.apply(this, arguments);
2947 };
2948 });
2949 ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach(function (methodName) {
2950 var originalJasmineFn = jasmineEnv[methodName];
2951 jasmineEnv[symbol(methodName)] = originalJasmineFn;
2952 jasmineEnv[methodName] = function (specDefinitions, timeout) {
2953 arguments[0] = wrapTestInZone(specDefinitions);
2954 return originalJasmineFn.apply(this, arguments);
2955 };
2956 });
2957 if (!disablePatchingJasmineClock) {
2958 // need to patch jasmine.clock().mockDate and jasmine.clock().tick() so
2959 // they can work properly in FakeAsyncTest
2960 var originalClockFn_1 = (jasmine[symbol('clock')] = jasmine['clock']);
2961 jasmine['clock'] = function () {
2962 var clock = originalClockFn_1.apply(this, arguments);
2963 if (!clock[symbol('patched')]) {
2964 clock[symbol('patched')] = symbol('patched');
2965 var originalTick_1 = (clock[symbol('tick')] = clock.tick);
2966 clock.tick = function () {
2967 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
2968 if (fakeAsyncZoneSpec) {
2969 return fakeAsyncZoneSpec.tick.apply(fakeAsyncZoneSpec, arguments);
2970 }
2971 return originalTick_1.apply(this, arguments);
2972 };
2973 var originalMockDate_1 = (clock[symbol('mockDate')] = clock.mockDate);
2974 clock.mockDate = function () {
2975 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
2976 if (fakeAsyncZoneSpec) {
2977 var dateTime = arguments.length > 0 ? arguments[0] : new Date();
2978 return fakeAsyncZoneSpec.setFakeBaseSystemTime.apply(fakeAsyncZoneSpec, dateTime && typeof dateTime.getTime === 'function' ? [dateTime.getTime()] :
2979 arguments);
2980 }
2981 return originalMockDate_1.apply(this, arguments);
2982 };
2983 // for auto go into fakeAsync feature, we need the flag to enable it
2984 if (enableAutoFakeAsyncWhenClockPatched) {
2985 ['install', 'uninstall'].forEach(function (methodName) {
2986 var originalClockFn = (clock[symbol(methodName)] = clock[methodName]);
2987 clock[methodName] = function () {
2988 var FakeAsyncTestZoneSpec = Zone['FakeAsyncTestZoneSpec'];
2989 if (FakeAsyncTestZoneSpec) {
2990 jasmine[symbol('clockInstalled')] = 'install' === methodName;
2991 return;
2992 }
2993 return originalClockFn.apply(this, arguments);
2994 };
2995 });
2996 }
2997 }
2998 return clock;
2999 };
3000 }
3001 // monkey patch createSpyObj to make properties enumerable to true
3002 if (!jasmine[Zone.__symbol__('createSpyObj')]) {
3003 var originalCreateSpyObj_1 = jasmine.createSpyObj;
3004 jasmine[Zone.__symbol__('createSpyObj')] = originalCreateSpyObj_1;
3005 jasmine.createSpyObj = function () {
3006 var args = Array.prototype.slice.call(arguments);
3007 var propertyNames = args.length >= 3 ? args[2] : null;
3008 var spyObj;
3009 if (propertyNames) {
3010 var defineProperty_1 = Object.defineProperty;
3011 Object.defineProperty = function (obj, p, attributes) {
3012 return defineProperty_1.call(this, obj, p, Object.assign(Object.assign({}, attributes), { configurable: true, enumerable: true }));
3013 };
3014 try {
3015 spyObj = originalCreateSpyObj_1.apply(this, args);
3016 }
3017 finally {
3018 Object.defineProperty = defineProperty_1;
3019 }
3020 }
3021 else {
3022 spyObj = originalCreateSpyObj_1.apply(this, args);
3023 }
3024 return spyObj;
3025 };
3026 }
3027 /**
3028 * Gets a function wrapping the body of a Jasmine `describe` block to execute in a
3029 * synchronous-only zone.
3030 */
3031 function wrapDescribeInZone(describeBody) {
3032 return function () {
3033 return syncZone.run(describeBody, this, arguments);
3034 };
3035 }
3036 function runInTestZone(testBody, applyThis, queueRunner, done) {
3037 var isClockInstalled = !!jasmine[symbol('clockInstalled')];
3038 var testProxyZoneSpec = queueRunner.testProxyZoneSpec;
3039 var testProxyZone = queueRunner.testProxyZone;
3040 if (isClockInstalled && enableAutoFakeAsyncWhenClockPatched) {
3041 // auto run a fakeAsync
3042 var fakeAsyncModule = Zone[Zone.__symbol__('fakeAsyncTest')];
3043 if (fakeAsyncModule && typeof fakeAsyncModule.fakeAsync === 'function') {
3044 testBody = fakeAsyncModule.fakeAsync(testBody);
3045 }
3046 }
3047 if (done) {
3048 return testProxyZone.run(testBody, applyThis, [done]);
3049 }
3050 else {
3051 return testProxyZone.run(testBody, applyThis);
3052 }
3053 }
3054 /**
3055 * Gets a function wrapping the body of a Jasmine `it/beforeEach/afterEach` block to
3056 * execute in a ProxyZone zone.
3057 * This will run in `testProxyZone`. The `testProxyZone` will be reset by the `ZoneQueueRunner`
3058 */
3059 function wrapTestInZone(testBody) {
3060 // The `done` callback is only passed through if the function expects at least one argument.
3061 // Note we have to make a function with correct number of arguments, otherwise jasmine will
3062 // think that all functions are sync or async.
3063 return (testBody && (testBody.length ? function (done) {
3064 return runInTestZone(testBody, this, this.queueRunner, done);
3065 } : function () {
3066 return runInTestZone(testBody, this, this.queueRunner);
3067 }));
3068 }
3069 var QueueRunner = jasmine.QueueRunner;
3070 jasmine.QueueRunner = (function (_super) {
3071 __extends(ZoneQueueRunner, _super);
3072 function ZoneQueueRunner(attrs) {
3073 var _this = this;
3074 if (attrs.onComplete) {
3075 attrs.onComplete = (function (fn) { return function () {
3076 // All functions are done, clear the test zone.
3077 _this.testProxyZone = null;
3078 _this.testProxyZoneSpec = null;
3079 ambientZone.scheduleMicroTask('jasmine.onComplete', fn);
3080 }; })(attrs.onComplete);
3081 }
3082 var nativeSetTimeout = global[Zone.__symbol__('setTimeout')];
3083 var nativeClearTimeout = global[Zone.__symbol__('clearTimeout')];
3084 if (nativeSetTimeout) {
3085 // should run setTimeout inside jasmine outside of zone
3086 attrs.timeout = {
3087 setTimeout: nativeSetTimeout ? nativeSetTimeout : global.setTimeout,
3088 clearTimeout: nativeClearTimeout ? nativeClearTimeout : global.clearTimeout
3089 };
3090 }
3091 // create a userContext to hold the queueRunner itself
3092 // so we can access the testProxy in it/xit/beforeEach ...
3093 if (jasmine.UserContext) {
3094 if (!attrs.userContext) {
3095 attrs.userContext = new jasmine.UserContext();
3096 }
3097 attrs.userContext.queueRunner = this;
3098 }
3099 else {
3100 if (!attrs.userContext) {
3101 attrs.userContext = {};
3102 }
3103 attrs.userContext.queueRunner = this;
3104 }
3105 // patch attrs.onException
3106 var onException = attrs.onException;
3107 attrs.onException = function (error) {
3108 if (error &&
3109 error.message ===
3110 'Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.') {
3111 // jasmine timeout, we can make the error message more
3112 // reasonable to tell what tasks are pending
3113 var proxyZoneSpec = this && this.testProxyZoneSpec;
3114 if (proxyZoneSpec) {
3115 var pendingTasksInfo = proxyZoneSpec.getAndClearPendingTasksInfo();
3116 try {
3117 // try catch here in case error.message is not writable
3118 error.message += pendingTasksInfo;
3119 }
3120 catch (err) {
3121 }
3122 }
3123 }
3124 if (onException) {
3125 onException.call(this, error);
3126 }
3127 };
3128 _super.call(this, attrs);
3129 }
3130 ZoneQueueRunner.prototype.execute = function () {
3131 var _this = this;
3132 var zone = Zone.current;
3133 var isChildOfAmbientZone = false;
3134 while (zone) {
3135 if (zone === ambientZone) {
3136 isChildOfAmbientZone = true;
3137 break;
3138 }
3139 zone = zone.parent;
3140 }
3141 if (!isChildOfAmbientZone)
3142 throw new Error('Unexpected Zone: ' + Zone.current.name);
3143 // This is the zone which will be used for running individual tests.
3144 // It will be a proxy zone, so that the tests function can retroactively install
3145 // different zones.
3146 // Example:
3147 // - In beforeEach() do childZone = Zone.current.fork(...);
3148 // - In it() try to do fakeAsync(). The issue is that because the beforeEach forked the
3149 // zone outside of fakeAsync it will be able to escape the fakeAsync rules.
3150 // - Because ProxyZone is parent fo `childZone` fakeAsync can retroactively add
3151 // fakeAsync behavior to the childZone.
3152 this.testProxyZoneSpec = new ProxyZoneSpec();
3153 this.testProxyZone = ambientZone.fork(this.testProxyZoneSpec);
3154 if (!Zone.currentTask) {
3155 // if we are not running in a task then if someone would register a
3156 // element.addEventListener and then calling element.click() the
3157 // addEventListener callback would think that it is the top most task and would
3158 // drain the microtask queue on element.click() which would be incorrect.
3159 // For this reason we always force a task when running jasmine tests.
3160 Zone.current.scheduleMicroTask('jasmine.execute().forceTask', function () { return QueueRunner.prototype.execute.call(_this); });
3161 }
3162 else {
3163 _super.prototype.execute.call(this);
3164 }
3165 };
3166 return ZoneQueueRunner;
3167 })(QueueRunner);
3168 });
3169 /**
3170 * @license
3171 * Copyright Google LLC All Rights Reserved.
3172 *
3173 * Use of this source code is governed by an MIT-style license that can be
3174 * found in the LICENSE file at https://angular.io/license
3175 */
3176 Zone.__load_patch('jest', function (context, Zone, api) {
3177 if (typeof jest === 'undefined' || jest['__zone_patch__']) {
3178 return;
3179 }
3180 jest['__zone_patch__'] = true;
3181 var ProxyZoneSpec = Zone['ProxyZoneSpec'];
3182 var SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
3183 if (!ProxyZoneSpec) {
3184 throw new Error('Missing ProxyZoneSpec');
3185 }
3186 var rootZone = Zone.current;
3187 var syncZone = rootZone.fork(new SyncTestZoneSpec('jest.describe'));
3188 var proxyZoneSpec = new ProxyZoneSpec();
3189 var proxyZone = rootZone.fork(proxyZoneSpec);
3190 function wrapDescribeFactoryInZone(originalJestFn) {
3191 return function () {
3192 var tableArgs = [];
3193 for (var _i = 0; _i < arguments.length; _i++) {
3194 tableArgs[_i] = arguments[_i];
3195 }
3196 var originalDescribeFn = originalJestFn.apply(this, tableArgs);
3197 return function () {
3198 var args = [];
3199 for (var _i = 0; _i < arguments.length; _i++) {
3200 args[_i] = arguments[_i];
3201 }
3202 args[1] = wrapDescribeInZone(args[1]);
3203 return originalDescribeFn.apply(this, args);
3204 };
3205 };
3206 }
3207 function wrapTestFactoryInZone(originalJestFn) {
3208 return function () {
3209 var tableArgs = [];
3210 for (var _i = 0; _i < arguments.length; _i++) {
3211 tableArgs[_i] = arguments[_i];
3212 }
3213 return function () {
3214 var args = [];
3215 for (var _i = 0; _i < arguments.length; _i++) {
3216 args[_i] = arguments[_i];
3217 }
3218 args[1] = wrapTestInZone(args[1]);
3219 return originalJestFn.apply(this, tableArgs).apply(this, args);
3220 };
3221 };
3222 }
3223 /**
3224 * Gets a function wrapping the body of a jest `describe` block to execute in a
3225 * synchronous-only zone.
3226 */
3227 function wrapDescribeInZone(describeBody) {
3228 return function () {
3229 var args = [];
3230 for (var _i = 0; _i < arguments.length; _i++) {
3231 args[_i] = arguments[_i];
3232 }
3233 return syncZone.run(describeBody, this, args);
3234 };
3235 }
3236 /**
3237 * Gets a function wrapping the body of a jest `it/beforeEach/afterEach` block to
3238 * execute in a ProxyZone zone.
3239 * This will run in the `proxyZone`.
3240 */
3241 function wrapTestInZone(testBody, isTestFunc) {
3242 if (isTestFunc === void 0) { isTestFunc = false; }
3243 if (typeof testBody !== 'function') {
3244 return testBody;
3245 }
3246 var wrappedFunc = function () {
3247 if (Zone[api.symbol('useFakeTimersCalled')] === true && testBody &&
3248 !testBody.isFakeAsync) {
3249 // jest.useFakeTimers is called, run into fakeAsyncTest automatically.
3250 var fakeAsyncModule = Zone[Zone.__symbol__('fakeAsyncTest')];
3251 if (fakeAsyncModule && typeof fakeAsyncModule.fakeAsync === 'function') {
3252 testBody = fakeAsyncModule.fakeAsync(testBody);
3253 }
3254 }
3255 proxyZoneSpec.isTestFunc = isTestFunc;
3256 return proxyZone.run(testBody, null, arguments);
3257 };
3258 // Update the length of wrappedFunc to be the same as the length of the testBody
3259 // So jest core can handle whether the test function has `done()` or not correctly
3260 Object.defineProperty(wrappedFunc, 'length', { configurable: true, writable: true, enumerable: false });
3261 wrappedFunc.length = testBody.length;
3262 return wrappedFunc;
3263 }
3264 ['describe', 'xdescribe', 'fdescribe'].forEach(function (methodName) {
3265 var originalJestFn = context[methodName];
3266 if (context[Zone.__symbol__(methodName)]) {
3267 return;
3268 }
3269 context[Zone.__symbol__(methodName)] = originalJestFn;
3270 context[methodName] = function () {
3271 var args = [];
3272 for (var _i = 0; _i < arguments.length; _i++) {
3273 args[_i] = arguments[_i];
3274 }
3275 args[1] = wrapDescribeInZone(args[1]);
3276 return originalJestFn.apply(this, args);
3277 };
3278 context[methodName].each = wrapDescribeFactoryInZone(originalJestFn.each);
3279 });
3280 context.describe.only = context.fdescribe;
3281 context.describe.skip = context.xdescribe;
3282 ['it', 'xit', 'fit', 'test', 'xtest'].forEach(function (methodName) {
3283 var originalJestFn = context[methodName];
3284 if (context[Zone.__symbol__(methodName)]) {
3285 return;
3286 }
3287 context[Zone.__symbol__(methodName)] = originalJestFn;
3288 context[methodName] = function () {
3289 var args = [];
3290 for (var _i = 0; _i < arguments.length; _i++) {
3291 args[_i] = arguments[_i];
3292 }
3293 args[1] = wrapTestInZone(args[1], true);
3294 return originalJestFn.apply(this, args);
3295 };
3296 context[methodName].each = wrapTestFactoryInZone(originalJestFn.each);
3297 context[methodName].todo = originalJestFn.todo;
3298 });
3299 context.it.only = context.fit;
3300 context.it.skip = context.xit;
3301 context.test.only = context.fit;
3302 context.test.skip = context.xit;
3303 ['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach(function (methodName) {
3304 var originalJestFn = context[methodName];
3305 if (context[Zone.__symbol__(methodName)]) {
3306 return;
3307 }
3308 context[Zone.__symbol__(methodName)] = originalJestFn;
3309 context[methodName] = function () {
3310 var args = [];
3311 for (var _i = 0; _i < arguments.length; _i++) {
3312 args[_i] = arguments[_i];
3313 }
3314 args[0] = wrapTestInZone(args[0]);
3315 return originalJestFn.apply(this, args);
3316 };
3317 });
3318 Zone.patchJestObject = function patchJestObject(Timer, isModern) {
3319 if (isModern === void 0) { isModern = false; }
3320 // check whether currently the test is inside fakeAsync()
3321 function isPatchingFakeTimer() {
3322 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3323 return !!fakeAsyncZoneSpec;
3324 }
3325 // check whether the current function is inside `test/it` or other methods
3326 // such as `describe/beforeEach`
3327 function isInTestFunc() {
3328 var proxyZoneSpec = Zone.current.get('ProxyZoneSpec');
3329 return proxyZoneSpec && proxyZoneSpec.isTestFunc;
3330 }
3331 if (Timer[api.symbol('fakeTimers')]) {
3332 return;
3333 }
3334 Timer[api.symbol('fakeTimers')] = true;
3335 // patch jest fakeTimer internal method to make sure no console.warn print out
3336 api.patchMethod(Timer, '_checkFakeTimers', function (delegate) {
3337 return function (self, args) {
3338 if (isPatchingFakeTimer()) {
3339 return true;
3340 }
3341 else {
3342 return delegate.apply(self, args);
3343 }
3344 };
3345 });
3346 // patch useFakeTimers(), set useFakeTimersCalled flag, and make test auto run into fakeAsync
3347 api.patchMethod(Timer, 'useFakeTimers', function (delegate) {
3348 return function (self, args) {
3349 Zone[api.symbol('useFakeTimersCalled')] = true;
3350 if (isModern || isInTestFunc()) {
3351 return delegate.apply(self, args);
3352 }
3353 return self;
3354 };
3355 });
3356 // patch useRealTimers(), unset useFakeTimers flag
3357 api.patchMethod(Timer, 'useRealTimers', function (delegate) {
3358 return function (self, args) {
3359 Zone[api.symbol('useFakeTimersCalled')] = false;
3360 if (isModern || isInTestFunc()) {
3361 return delegate.apply(self, args);
3362 }
3363 return self;
3364 };
3365 });
3366 // patch setSystemTime(), call setCurrentRealTime() in the fakeAsyncTest
3367 api.patchMethod(Timer, 'setSystemTime', function (delegate) {
3368 return function (self, args) {
3369 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3370 if (fakeAsyncZoneSpec && isPatchingFakeTimer()) {
3371 fakeAsyncZoneSpec.setFakeBaseSystemTime(args[0]);
3372 }
3373 else {
3374 return delegate.apply(self, args);
3375 }
3376 };
3377 });
3378 // patch getSystemTime(), call getCurrentRealTime() in the fakeAsyncTest
3379 api.patchMethod(Timer, 'getRealSystemTime', function (delegate) {
3380 return function (self, args) {
3381 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3382 if (fakeAsyncZoneSpec && isPatchingFakeTimer()) {
3383 return fakeAsyncZoneSpec.getRealSystemTime();
3384 }
3385 else {
3386 return delegate.apply(self, args);
3387 }
3388 };
3389 });
3390 // patch runAllTicks(), run all microTasks inside fakeAsync
3391 api.patchMethod(Timer, 'runAllTicks', function (delegate) {
3392 return function (self, args) {
3393 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3394 if (fakeAsyncZoneSpec) {
3395 fakeAsyncZoneSpec.flushMicrotasks();
3396 }
3397 else {
3398 return delegate.apply(self, args);
3399 }
3400 };
3401 });
3402 // patch runAllTimers(), run all macroTasks inside fakeAsync
3403 api.patchMethod(Timer, 'runAllTimers', function (delegate) {
3404 return function (self, args) {
3405 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3406 if (fakeAsyncZoneSpec) {
3407 fakeAsyncZoneSpec.flush(100, true);
3408 }
3409 else {
3410 return delegate.apply(self, args);
3411 }
3412 };
3413 });
3414 // patch advanceTimersByTime(), call tick() in the fakeAsyncTest
3415 api.patchMethod(Timer, 'advanceTimersByTime', function (delegate) {
3416 return function (self, args) {
3417 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3418 if (fakeAsyncZoneSpec) {
3419 fakeAsyncZoneSpec.tick(args[0]);
3420 }
3421 else {
3422 return delegate.apply(self, args);
3423 }
3424 };
3425 });
3426 // patch runOnlyPendingTimers(), call flushOnlyPendingTimers() in the fakeAsyncTest
3427 api.patchMethod(Timer, 'runOnlyPendingTimers', function (delegate) {
3428 return function (self, args) {
3429 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3430 if (fakeAsyncZoneSpec) {
3431 fakeAsyncZoneSpec.flushOnlyPendingTimers();
3432 }
3433 else {
3434 return delegate.apply(self, args);
3435 }
3436 };
3437 });
3438 // patch advanceTimersToNextTimer(), call tickToNext() in the fakeAsyncTest
3439 api.patchMethod(Timer, 'advanceTimersToNextTimer', function (delegate) {
3440 return function (self, args) {
3441 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3442 if (fakeAsyncZoneSpec) {
3443 fakeAsyncZoneSpec.tickToNext(args[0]);
3444 }
3445 else {
3446 return delegate.apply(self, args);
3447 }
3448 };
3449 });
3450 // patch clearAllTimers(), call removeAllTimers() in the fakeAsyncTest
3451 api.patchMethod(Timer, 'clearAllTimers', function (delegate) {
3452 return function (self, args) {
3453 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3454 if (fakeAsyncZoneSpec) {
3455 fakeAsyncZoneSpec.removeAllTimers();
3456 }
3457 else {
3458 return delegate.apply(self, args);
3459 }
3460 };
3461 });
3462 // patch getTimerCount(), call getTimerCount() in the fakeAsyncTest
3463 api.patchMethod(Timer, 'getTimerCount', function (delegate) {
3464 return function (self, args) {
3465 var fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3466 if (fakeAsyncZoneSpec) {
3467 return fakeAsyncZoneSpec.getTimerCount();
3468 }
3469 else {
3470 return delegate.apply(self, args);
3471 }
3472 };
3473 });
3474 };
3475 });
3476 /**
3477 * @license
3478 * Copyright Google LLC All Rights Reserved.
3479 *
3480 * Use of this source code is governed by an MIT-style license that can be
3481 * found in the LICENSE file at https://angular.io/license
3482 */
3483 Zone.__load_patch('mocha', function (global, Zone) {
3484 var Mocha = global.Mocha;
3485 if (typeof Mocha === 'undefined') {
3486 // return if Mocha is not available, because now zone-testing
3487 // will load mocha patch with jasmine/jest patch
3488 return;
3489 }
3490 if (typeof Zone === 'undefined') {
3491 throw new Error('Missing Zone.js');
3492 }
3493 var ProxyZoneSpec = Zone['ProxyZoneSpec'];
3494 var SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
3495 if (!ProxyZoneSpec) {
3496 throw new Error('Missing ProxyZoneSpec');
3497 }
3498 if (Mocha['__zone_patch__']) {
3499 throw new Error('"Mocha" has already been patched with "Zone".');
3500 }
3501 Mocha['__zone_patch__'] = true;
3502 var rootZone = Zone.current;
3503 var syncZone = rootZone.fork(new SyncTestZoneSpec('Mocha.describe'));
3504 var testZone = null;
3505 var suiteZone = rootZone.fork(new ProxyZoneSpec());
3506 var mochaOriginal = {
3507 after: Mocha.after,
3508 afterEach: Mocha.afterEach,
3509 before: Mocha.before,
3510 beforeEach: Mocha.beforeEach,
3511 describe: Mocha.describe,
3512 it: Mocha.it
3513 };
3514 function modifyArguments(args, syncTest, asyncTest) {
3515 var _loop_3 = function (i) {
3516 var arg = args[i];
3517 if (typeof arg === 'function') {
3518 // The `done` callback is only passed through if the function expects at
3519 // least one argument.
3520 // Note we have to make a function with correct number of arguments,
3521 // otherwise mocha will
3522 // think that all functions are sync or async.
3523 args[i] = (arg.length === 0) ? syncTest(arg) : asyncTest(arg);
3524 // Mocha uses toString to view the test body in the result list, make sure we return the
3525 // correct function body
3526 args[i].toString = function () {
3527 return arg.toString();
3528 };
3529 }
3530 };
3531 for (var i = 0; i < args.length; i++) {
3532 _loop_3(i);
3533 }
3534 return args;
3535 }
3536 function wrapDescribeInZone(args) {
3537 var syncTest = function (fn) {
3538 return function () {
3539 return syncZone.run(fn, this, arguments);
3540 };
3541 };
3542 return modifyArguments(args, syncTest);
3543 }
3544 function wrapTestInZone(args) {
3545 var asyncTest = function (fn) {
3546 return function (done) {
3547 return testZone.run(fn, this, [done]);
3548 };
3549 };
3550 var syncTest = function (fn) {
3551 return function () {
3552 return testZone.run(fn, this);
3553 };
3554 };
3555 return modifyArguments(args, syncTest, asyncTest);
3556 }
3557 function wrapSuiteInZone(args) {
3558 var asyncTest = function (fn) {
3559 return function (done) {
3560 return suiteZone.run(fn, this, [done]);
3561 };
3562 };
3563 var syncTest = function (fn) {
3564 return function () {
3565 return suiteZone.run(fn, this);
3566 };
3567 };
3568 return modifyArguments(args, syncTest, asyncTest);
3569 }
3570 global.describe = global.suite = Mocha.describe = function () {
3571 return mochaOriginal.describe.apply(this, wrapDescribeInZone(arguments));
3572 };
3573 global.xdescribe = global.suite.skip = Mocha.describe.skip = function () {
3574 return mochaOriginal.describe.skip.apply(this, wrapDescribeInZone(arguments));
3575 };
3576 global.describe.only = global.suite.only = Mocha.describe.only = function () {
3577 return mochaOriginal.describe.only.apply(this, wrapDescribeInZone(arguments));
3578 };
3579 global.it = global.specify = global.test = Mocha.it = function () {
3580 return mochaOriginal.it.apply(this, wrapTestInZone(arguments));
3581 };
3582 global.xit = global.xspecify = Mocha.it.skip = function () {
3583 return mochaOriginal.it.skip.apply(this, wrapTestInZone(arguments));
3584 };
3585 global.it.only = global.test.only = Mocha.it.only = function () {
3586 return mochaOriginal.it.only.apply(this, wrapTestInZone(arguments));
3587 };
3588 global.after = global.suiteTeardown = Mocha.after = function () {
3589 return mochaOriginal.after.apply(this, wrapSuiteInZone(arguments));
3590 };
3591 global.afterEach = global.teardown = Mocha.afterEach = function () {
3592 return mochaOriginal.afterEach.apply(this, wrapTestInZone(arguments));
3593 };
3594 global.before = global.suiteSetup = Mocha.before = function () {
3595 return mochaOriginal.before.apply(this, wrapSuiteInZone(arguments));
3596 };
3597 global.beforeEach = global.setup = Mocha.beforeEach = function () {
3598 return mochaOriginal.beforeEach.apply(this, wrapTestInZone(arguments));
3599 };
3600 (function (originalRunTest, originalRun) {
3601 Mocha.Runner.prototype.runTest = function (fn) {
3602 var _this = this;
3603 Zone.current.scheduleMicroTask('mocha.forceTask', function () {
3604 originalRunTest.call(_this, fn);
3605 });
3606 };
3607 Mocha.Runner.prototype.run = function (fn) {
3608 this.on('test', function (e) {
3609 testZone = rootZone.fork(new ProxyZoneSpec());
3610 });
3611 this.on('fail', function (test, err) {
3612 var proxyZoneSpec = testZone && testZone.get('ProxyZoneSpec');
3613 if (proxyZoneSpec && err) {
3614 try {
3615 // try catch here in case err.message is not writable
3616 err.message += proxyZoneSpec.getAndClearPendingTasksInfo();
3617 }
3618 catch (error) {
3619 }
3620 }
3621 });
3622 return originalRun.call(this, fn);
3623 };
3624 })(Mocha.Runner.prototype.runTest, Mocha.Runner.prototype.run);
3625 });
3626 /**
3627 * @license
3628 * Copyright Google LLC All Rights Reserved.
3629 *
3630 * Use of this source code is governed by an MIT-style license that can be
3631 * found in the LICENSE file at https://angular.io/license
3632 */
3633 (function (_global) {
3634 var AsyncTestZoneSpec = /** @class */ (function () {
3635 function AsyncTestZoneSpec(finishCallback, failCallback, namePrefix) {
3636 this.finishCallback = finishCallback;
3637 this.failCallback = failCallback;
3638 this._pendingMicroTasks = false;
3639 this._pendingMacroTasks = false;
3640 this._alreadyErrored = false;
3641 this._isSync = false;
3642 this.runZone = Zone.current;
3643 this.unresolvedChainedPromiseCount = 0;
3644 this.supportWaitUnresolvedChainedPromise = false;
3645 this.name = 'asyncTestZone for ' + namePrefix;
3646 this.properties = { 'AsyncTestZoneSpec': this };
3647 this.supportWaitUnresolvedChainedPromise =
3648 _global[Zone.__symbol__('supportWaitUnResolvedChainedPromise')] === true;
3649 }
3650 AsyncTestZoneSpec.prototype.isUnresolvedChainedPromisePending = function () {
3651 return this.unresolvedChainedPromiseCount > 0;
3652 };
3653 AsyncTestZoneSpec.prototype._finishCallbackIfDone = function () {
3654 var _this = this;
3655 if (!(this._pendingMicroTasks || this._pendingMacroTasks ||
3656 (this.supportWaitUnresolvedChainedPromise && this.isUnresolvedChainedPromisePending()))) {
3657 // We do this because we would like to catch unhandled rejected promises.
3658 this.runZone.run(function () {
3659 setTimeout(function () {
3660 if (!_this._alreadyErrored && !(_this._pendingMicroTasks || _this._pendingMacroTasks)) {
3661 _this.finishCallback();
3662 }
3663 }, 0);
3664 });
3665 }
3666 };
3667 AsyncTestZoneSpec.prototype.patchPromiseForTest = function () {
3668 if (!this.supportWaitUnresolvedChainedPromise) {
3669 return;
3670 }
3671 var patchPromiseForTest = Promise[Zone.__symbol__('patchPromiseForTest')];
3672 if (patchPromiseForTest) {
3673 patchPromiseForTest();
3674 }
3675 };
3676 AsyncTestZoneSpec.prototype.unPatchPromiseForTest = function () {
3677 if (!this.supportWaitUnresolvedChainedPromise) {
3678 return;
3679 }
3680 var unPatchPromiseForTest = Promise[Zone.__symbol__('unPatchPromiseForTest')];
3681 if (unPatchPromiseForTest) {
3682 unPatchPromiseForTest();
3683 }
3684 };
3685 AsyncTestZoneSpec.prototype.onScheduleTask = function (delegate, current, target, task) {
3686 if (task.type !== 'eventTask') {
3687 this._isSync = false;
3688 }
3689 if (task.type === 'microTask' && task.data && task.data instanceof Promise) {
3690 // check whether the promise is a chained promise
3691 if (task.data[AsyncTestZoneSpec.symbolParentUnresolved] === true) {
3692 // chained promise is being scheduled
3693 this.unresolvedChainedPromiseCount--;
3694 }
3695 }
3696 return delegate.scheduleTask(target, task);
3697 };
3698 AsyncTestZoneSpec.prototype.onInvokeTask = function (delegate, current, target, task, applyThis, applyArgs) {
3699 if (task.type !== 'eventTask') {
3700 this._isSync = false;
3701 }
3702 return delegate.invokeTask(target, task, applyThis, applyArgs);
3703 };
3704 AsyncTestZoneSpec.prototype.onCancelTask = function (delegate, current, target, task) {
3705 if (task.type !== 'eventTask') {
3706 this._isSync = false;
3707 }
3708 return delegate.cancelTask(target, task);
3709 };
3710 // Note - we need to use onInvoke at the moment to call finish when a test is
3711 // fully synchronous. TODO(juliemr): remove this when the logic for
3712 // onHasTask changes and it calls whenever the task queues are dirty.
3713 // updated by(JiaLiPassion), only call finish callback when no task
3714 // was scheduled/invoked/canceled.
3715 AsyncTestZoneSpec.prototype.onInvoke = function (parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source) {
3716 try {
3717 this._isSync = true;
3718 return parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source);
3719 }
3720 finally {
3721 var afterTaskCounts = parentZoneDelegate._taskCounts;
3722 if (this._isSync) {
3723 this._finishCallbackIfDone();
3724 }
3725 }
3726 };
3727 AsyncTestZoneSpec.prototype.onHandleError = function (parentZoneDelegate, currentZone, targetZone, error) {
3728 // Let the parent try to handle the error.
3729 var result = parentZoneDelegate.handleError(targetZone, error);
3730 if (result) {
3731 this.failCallback(error);
3732 this._alreadyErrored = true;
3733 }
3734 return false;
3735 };
3736 AsyncTestZoneSpec.prototype.onHasTask = function (delegate, current, target, hasTaskState) {
3737 delegate.hasTask(target, hasTaskState);
3738 if (hasTaskState.change == 'microTask') {
3739 this._pendingMicroTasks = hasTaskState.microTask;
3740 this._finishCallbackIfDone();
3741 }
3742 else if (hasTaskState.change == 'macroTask') {
3743 this._pendingMacroTasks = hasTaskState.macroTask;
3744 this._finishCallbackIfDone();
3745 }
3746 };
3747 return AsyncTestZoneSpec;
3748 }());
3749 AsyncTestZoneSpec.symbolParentUnresolved = Zone.__symbol__('parentUnresolved');
3750 // Export the class so that new instances can be created with proper
3751 // constructor params.
3752 Zone['AsyncTestZoneSpec'] = AsyncTestZoneSpec;
3753 })(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
3754 Zone.__load_patch('asynctest', function (global, Zone, api) {
3755 /**
3756 * Wraps a test function in an asynchronous test zone. The test will automatically
3757 * complete when all asynchronous calls within this zone are done.
3758 */
3759 Zone[api.symbol('asyncTest')] = function asyncTest(fn) {
3760 // If we're running using the Jasmine test framework, adapt to call the 'done'
3761 // function when asynchronous activity is finished.
3762 if (global.jasmine) {
3763 // Not using an arrow function to preserve context passed from call site
3764 return function (done) {
3765 if (!done) {
3766 // if we run beforeEach in @angular/core/testing/testing_internal then we get no done
3767 // fake it here and assume sync.
3768 done = function () { };
3769 done.fail = function (e) {
3770 throw e;
3771 };
3772 }
3773 runInTestZone(fn, this, done, function (err) {
3774 if (typeof err === 'string') {
3775 return done.fail(new Error(err));
3776 }
3777 else {
3778 done.fail(err);
3779 }
3780 });
3781 };
3782 }
3783 // Otherwise, return a promise which will resolve when asynchronous activity
3784 // is finished. This will be correctly consumed by the Mocha framework with
3785 // it('...', async(myFn)); or can be used in a custom framework.
3786 // Not using an arrow function to preserve context passed from call site
3787 return function () {
3788 var _this = this;
3789 return new Promise(function (finishCallback, failCallback) {
3790 runInTestZone(fn, _this, finishCallback, failCallback);
3791 });
3792 };
3793 };
3794 function runInTestZone(fn, context, finishCallback, failCallback) {
3795 var currentZone = Zone.current;
3796 var AsyncTestZoneSpec = Zone['AsyncTestZoneSpec'];
3797 if (AsyncTestZoneSpec === undefined) {
3798 throw new Error('AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' +
3799 'Please make sure that your environment includes zone.js/dist/async-test.js');
3800 }
3801 var ProxyZoneSpec = Zone['ProxyZoneSpec'];
3802 if (!ProxyZoneSpec) {
3803 throw new Error('ProxyZoneSpec is needed for the async() test helper but could not be found. ' +
3804 'Please make sure that your environment includes zone.js/dist/proxy.js');
3805 }
3806 var proxyZoneSpec = ProxyZoneSpec.get();
3807 ProxyZoneSpec.assertPresent();
3808 // We need to create the AsyncTestZoneSpec outside the ProxyZone.
3809 // If we do it in ProxyZone then we will get to infinite recursion.
3810 var proxyZone = Zone.current.getZoneWith('ProxyZoneSpec');
3811 var previousDelegate = proxyZoneSpec.getDelegate();
3812 proxyZone.parent.run(function () {
3813 var testZoneSpec = new AsyncTestZoneSpec(function () {
3814 // Need to restore the original zone.
3815 if (proxyZoneSpec.getDelegate() == testZoneSpec) {
3816 // Only reset the zone spec if it's
3817 // sill this one. Otherwise, assume
3818 // it's OK.
3819 proxyZoneSpec.setDelegate(previousDelegate);
3820 }
3821 testZoneSpec.unPatchPromiseForTest();
3822 currentZone.run(function () {
3823 finishCallback();
3824 });
3825 }, function (error) {
3826 // Need to restore the original zone.
3827 if (proxyZoneSpec.getDelegate() == testZoneSpec) {
3828 // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
3829 proxyZoneSpec.setDelegate(previousDelegate);
3830 }
3831 testZoneSpec.unPatchPromiseForTest();
3832 currentZone.run(function () {
3833 failCallback(error);
3834 });
3835 }, 'test');
3836 proxyZoneSpec.setDelegate(testZoneSpec);
3837 testZoneSpec.patchPromiseForTest();
3838 });
3839 return Zone.current.runGuarded(fn, context);
3840 }
3841 });
3842 /**
3843 * @license
3844 * Copyright Google LLC All Rights Reserved.
3845 *
3846 * Use of this source code is governed by an MIT-style license that can be
3847 * found in the LICENSE file at https://angular.io/license
3848 */
3849 (function (global) {
3850 var OriginalDate = global.Date;
3851 // Since when we compile this file to `es2015`, and if we define
3852 // this `FakeDate` as `class FakeDate`, and then set `FakeDate.prototype`
3853 // there will be an error which is `Cannot assign to read only property 'prototype'`
3854 // so we need to use function implementation here.
3855 function FakeDate() {
3856 if (arguments.length === 0) {
3857 var d = new OriginalDate();
3858 d.setTime(FakeDate.now());
3859 return d;
3860 }
3861 else {
3862 var args = Array.prototype.slice.call(arguments);
3863 return new (OriginalDate.bind.apply(OriginalDate, __spreadArrays([void 0], args)))();
3864 }
3865 }
3866 FakeDate.now = function () {
3867 var fakeAsyncTestZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
3868 if (fakeAsyncTestZoneSpec) {
3869 return fakeAsyncTestZoneSpec.getFakeSystemTime();
3870 }
3871 return OriginalDate.now.apply(this, arguments);
3872 };
3873 FakeDate.UTC = OriginalDate.UTC;
3874 FakeDate.parse = OriginalDate.parse;
3875 // keep a reference for zone patched timer function
3876 var timers = {
3877 setTimeout: global.setTimeout,
3878 setInterval: global.setInterval,
3879 clearTimeout: global.clearTimeout,
3880 clearInterval: global.clearInterval
3881 };
3882 var Scheduler = /** @class */ (function () {
3883 function Scheduler() {
3884 // Scheduler queue with the tuple of end time and callback function - sorted by end time.
3885 this._schedulerQueue = [];
3886 // Current simulated time in millis.
3887 this._currentTickTime = 0;
3888 // Current fake system base time in millis.
3889 this._currentFakeBaseSystemTime = OriginalDate.now();
3890 // track requeuePeriodicTimer
3891 this._currentTickRequeuePeriodicEntries = [];
3892 }
3893 Scheduler.prototype.getCurrentTickTime = function () {
3894 return this._currentTickTime;
3895 };
3896 Scheduler.prototype.getFakeSystemTime = function () {
3897 return this._currentFakeBaseSystemTime + this._currentTickTime;
3898 };
3899 Scheduler.prototype.setFakeBaseSystemTime = function (fakeBaseSystemTime) {
3900 this._currentFakeBaseSystemTime = fakeBaseSystemTime;
3901 };
3902 Scheduler.prototype.getRealSystemTime = function () {
3903 return OriginalDate.now();
3904 };
3905 Scheduler.prototype.scheduleFunction = function (cb, delay, options) {
3906 options = Object.assign({
3907 args: [],
3908 isPeriodic: false,
3909 isRequestAnimationFrame: false,
3910 id: -1,
3911 isRequeuePeriodic: false
3912 }, options);
3913 var currentId = options.id < 0 ? Scheduler.nextId++ : options.id;
3914 var endTime = this._currentTickTime + delay;
3915 // Insert so that scheduler queue remains sorted by end time.
3916 var newEntry = {
3917 endTime: endTime,
3918 id: currentId,
3919 func: cb,
3920 args: options.args,
3921 delay: delay,
3922 isPeriodic: options.isPeriodic,
3923 isRequestAnimationFrame: options.isRequestAnimationFrame
3924 };
3925 if (options.isRequeuePeriodic) {
3926 this._currentTickRequeuePeriodicEntries.push(newEntry);
3927 }
3928 var i = 0;
3929 for (; i < this._schedulerQueue.length; i++) {
3930 var currentEntry = this._schedulerQueue[i];
3931 if (newEntry.endTime < currentEntry.endTime) {
3932 break;
3933 }
3934 }
3935 this._schedulerQueue.splice(i, 0, newEntry);
3936 return currentId;
3937 };
3938 Scheduler.prototype.removeScheduledFunctionWithId = function (id) {
3939 for (var i = 0; i < this._schedulerQueue.length; i++) {
3940 if (this._schedulerQueue[i].id == id) {
3941 this._schedulerQueue.splice(i, 1);
3942 break;
3943 }
3944 }
3945 };
3946 Scheduler.prototype.removeAll = function () {
3947 this._schedulerQueue = [];
3948 };
3949 Scheduler.prototype.getTimerCount = function () {
3950 return this._schedulerQueue.length;
3951 };
3952 Scheduler.prototype.tickToNext = function (step, doTick, tickOptions) {
3953 if (step === void 0) { step = 1; }
3954 if (this._schedulerQueue.length < step) {
3955 return;
3956 }
3957 // Find the last task currently queued in the scheduler queue and tick
3958 // till that time.
3959 var startTime = this._currentTickTime;
3960 var targetTask = this._schedulerQueue[step - 1];
3961 this.tick(targetTask.endTime - startTime, doTick, tickOptions);
3962 };
3963 Scheduler.prototype.tick = function (millis, doTick, tickOptions) {
3964 if (millis === void 0) { millis = 0; }
3965 var finalTime = this._currentTickTime + millis;
3966 var lastCurrentTime = 0;
3967 tickOptions = Object.assign({ processNewMacroTasksSynchronously: true }, tickOptions);
3968 // we need to copy the schedulerQueue so nested timeout
3969 // will not be wrongly called in the current tick
3970 // https://github.com/angular/angular/issues/33799
3971 var schedulerQueue = tickOptions.processNewMacroTasksSynchronously ?
3972 this._schedulerQueue :
3973 this._schedulerQueue.slice();
3974 if (schedulerQueue.length === 0 && doTick) {
3975 doTick(millis);
3976 return;
3977 }
3978 while (schedulerQueue.length > 0) {
3979 // clear requeueEntries before each loop
3980 this._currentTickRequeuePeriodicEntries = [];
3981 var current = schedulerQueue[0];
3982 if (finalTime < current.endTime) {
3983 // Done processing the queue since it's sorted by endTime.
3984 break;
3985 }
3986 else {
3987 // Time to run scheduled function. Remove it from the head of queue.
3988 var current_1 = schedulerQueue.shift();
3989 if (!tickOptions.processNewMacroTasksSynchronously) {
3990 var idx = this._schedulerQueue.indexOf(current_1);
3991 if (idx >= 0) {
3992 this._schedulerQueue.splice(idx, 1);
3993 }
3994 }
3995 lastCurrentTime = this._currentTickTime;
3996 this._currentTickTime = current_1.endTime;
3997 if (doTick) {
3998 doTick(this._currentTickTime - lastCurrentTime);
3999 }
4000 var retval = current_1.func.apply(global, current_1.isRequestAnimationFrame ? [this._currentTickTime] : current_1.args);
4001 if (!retval) {
4002 // Uncaught exception in the current scheduled function. Stop processing the queue.
4003 break;
4004 }
4005 // check is there any requeue periodic entry is added in
4006 // current loop, if there is, we need to add to current loop
4007 if (!tickOptions.processNewMacroTasksSynchronously) {
4008 this._currentTickRequeuePeriodicEntries.forEach(function (newEntry) {
4009 var i = 0;
4010 for (; i < schedulerQueue.length; i++) {
4011 var currentEntry = schedulerQueue[i];
4012 if (newEntry.endTime < currentEntry.endTime) {
4013 break;
4014 }
4015 }
4016 schedulerQueue.splice(i, 0, newEntry);
4017 });
4018 }
4019 }
4020 }
4021 lastCurrentTime = this._currentTickTime;
4022 this._currentTickTime = finalTime;
4023 if (doTick) {
4024 doTick(this._currentTickTime - lastCurrentTime);
4025 }
4026 };
4027 Scheduler.prototype.flushOnlyPendingTimers = function (doTick) {
4028 if (this._schedulerQueue.length === 0) {
4029 return 0;
4030 }
4031 // Find the last task currently queued in the scheduler queue and tick
4032 // till that time.
4033 var startTime = this._currentTickTime;
4034 var lastTask = this._schedulerQueue[this._schedulerQueue.length - 1];
4035 this.tick(lastTask.endTime - startTime, doTick, { processNewMacroTasksSynchronously: false });
4036 return this._currentTickTime - startTime;
4037 };
4038 Scheduler.prototype.flush = function (limit, flushPeriodic, doTick) {
4039 if (limit === void 0) { limit = 20; }
4040 if (flushPeriodic === void 0) { flushPeriodic = false; }
4041 if (flushPeriodic) {
4042 return this.flushPeriodic(doTick);
4043 }
4044 else {
4045 return this.flushNonPeriodic(limit, doTick);
4046 }
4047 };
4048 Scheduler.prototype.flushPeriodic = function (doTick) {
4049 if (this._schedulerQueue.length === 0) {
4050 return 0;
4051 }
4052 // Find the last task currently queued in the scheduler queue and tick
4053 // till that time.
4054 var startTime = this._currentTickTime;
4055 var lastTask = this._schedulerQueue[this._schedulerQueue.length - 1];
4056 this.tick(lastTask.endTime - startTime, doTick);
4057 return this._currentTickTime - startTime;
4058 };
4059 Scheduler.prototype.flushNonPeriodic = function (limit, doTick) {
4060 var startTime = this._currentTickTime;
4061 var lastCurrentTime = 0;
4062 var count = 0;
4063 while (this._schedulerQueue.length > 0) {
4064 count++;
4065 if (count > limit) {
4066 throw new Error('flush failed after reaching the limit of ' + limit +
4067 ' tasks. Does your code use a polling timeout?');
4068 }
4069 // flush only non-periodic timers.
4070 // If the only remaining tasks are periodic(or requestAnimationFrame), finish flushing.
4071 if (this._schedulerQueue.filter(function (task) { return !task.isPeriodic && !task.isRequestAnimationFrame; })
4072 .length === 0) {
4073 break;
4074 }
4075 var current = this._schedulerQueue.shift();
4076 lastCurrentTime = this._currentTickTime;
4077 this._currentTickTime = current.endTime;
4078 if (doTick) {
4079 // Update any secondary schedulers like Jasmine mock Date.
4080 doTick(this._currentTickTime - lastCurrentTime);
4081 }
4082 var retval = current.func.apply(global, current.args);
4083 if (!retval) {
4084 // Uncaught exception in the current scheduled function. Stop processing the queue.
4085 break;
4086 }
4087 }
4088 return this._currentTickTime - startTime;
4089 };
4090 return Scheduler;
4091 }());
4092 // Next scheduler id.
4093 Scheduler.nextId = 1;
4094 var FakeAsyncTestZoneSpec = /** @class */ (function () {
4095 function FakeAsyncTestZoneSpec(namePrefix, trackPendingRequestAnimationFrame, macroTaskOptions) {
4096 if (trackPendingRequestAnimationFrame === void 0) { trackPendingRequestAnimationFrame = false; }
4097 this.trackPendingRequestAnimationFrame = trackPendingRequestAnimationFrame;
4098 this.macroTaskOptions = macroTaskOptions;
4099 this._scheduler = new Scheduler();
4100 this._microtasks = [];
4101 this._lastError = null;
4102 this._uncaughtPromiseErrors = Promise[Zone.__symbol__('uncaughtPromiseErrors')];
4103 this.pendingPeriodicTimers = [];
4104 this.pendingTimers = [];
4105 this.patchDateLocked = false;
4106 this.properties = { 'FakeAsyncTestZoneSpec': this };
4107 this.name = 'fakeAsyncTestZone for ' + namePrefix;
4108 // in case user can't access the construction of FakeAsyncTestSpec
4109 // user can also define macroTaskOptions by define a global variable.
4110 if (!this.macroTaskOptions) {
4111 this.macroTaskOptions = global[Zone.__symbol__('FakeAsyncTestMacroTask')];
4112 }
4113 }
4114 FakeAsyncTestZoneSpec.assertInZone = function () {
4115 if (Zone.current.get('FakeAsyncTestZoneSpec') == null) {
4116 throw new Error('The code should be running in the fakeAsync zone to call this function');
4117 }
4118 };
4119 FakeAsyncTestZoneSpec.prototype._fnAndFlush = function (fn, completers) {
4120 var _this = this;
4121 return function () {
4122 var args = [];
4123 for (var _i = 0; _i < arguments.length; _i++) {
4124 args[_i] = arguments[_i];
4125 }
4126 fn.apply(global, args);
4127 if (_this._lastError === null) { // Success
4128 if (completers.onSuccess != null) {
4129 completers.onSuccess.apply(global);
4130 }
4131 // Flush microtasks only on success.
4132 _this.flushMicrotasks();
4133 }
4134 else { // Failure
4135 if (completers.onError != null) {
4136 completers.onError.apply(global);
4137 }
4138 }
4139 // Return true if there were no errors, false otherwise.
4140 return _this._lastError === null;
4141 };
4142 };
4143 FakeAsyncTestZoneSpec._removeTimer = function (timers, id) {
4144 var index = timers.indexOf(id);
4145 if (index > -1) {
4146 timers.splice(index, 1);
4147 }
4148 };
4149 FakeAsyncTestZoneSpec.prototype._dequeueTimer = function (id) {
4150 var _this = this;
4151 return function () {
4152 FakeAsyncTestZoneSpec._removeTimer(_this.pendingTimers, id);
4153 };
4154 };
4155 FakeAsyncTestZoneSpec.prototype._requeuePeriodicTimer = function (fn, interval, args, id) {
4156 var _this = this;
4157 return function () {
4158 // Requeue the timer callback if it's not been canceled.
4159 if (_this.pendingPeriodicTimers.indexOf(id) !== -1) {
4160 _this._scheduler.scheduleFunction(fn, interval, { args: args, isPeriodic: true, id: id, isRequeuePeriodic: true });
4161 }
4162 };
4163 };
4164 FakeAsyncTestZoneSpec.prototype._dequeuePeriodicTimer = function (id) {
4165 var _this = this;
4166 return function () {
4167 FakeAsyncTestZoneSpec._removeTimer(_this.pendingPeriodicTimers, id);
4168 };
4169 };
4170 FakeAsyncTestZoneSpec.prototype._setTimeout = function (fn, delay, args, isTimer) {
4171 if (isTimer === void 0) { isTimer = true; }
4172 var removeTimerFn = this._dequeueTimer(Scheduler.nextId);
4173 // Queue the callback and dequeue the timer on success and error.
4174 var cb = this._fnAndFlush(fn, { onSuccess: removeTimerFn, onError: removeTimerFn });
4175 var id = this._scheduler.scheduleFunction(cb, delay, { args: args, isRequestAnimationFrame: !isTimer });
4176 if (isTimer) {
4177 this.pendingTimers.push(id);
4178 }
4179 return id;
4180 };
4181 FakeAsyncTestZoneSpec.prototype._clearTimeout = function (id) {
4182 FakeAsyncTestZoneSpec._removeTimer(this.pendingTimers, id);
4183 this._scheduler.removeScheduledFunctionWithId(id);
4184 };
4185 FakeAsyncTestZoneSpec.prototype._setInterval = function (fn, interval, args) {
4186 var id = Scheduler.nextId;
4187 var completers = { onSuccess: null, onError: this._dequeuePeriodicTimer(id) };
4188 var cb = this._fnAndFlush(fn, completers);
4189 // Use the callback created above to requeue on success.
4190 completers.onSuccess = this._requeuePeriodicTimer(cb, interval, args, id);
4191 // Queue the callback and dequeue the periodic timer only on error.
4192 this._scheduler.scheduleFunction(cb, interval, { args: args, isPeriodic: true });
4193 this.pendingPeriodicTimers.push(id);
4194 return id;
4195 };
4196 FakeAsyncTestZoneSpec.prototype._clearInterval = function (id) {
4197 FakeAsyncTestZoneSpec._removeTimer(this.pendingPeriodicTimers, id);
4198 this._scheduler.removeScheduledFunctionWithId(id);
4199 };
4200 FakeAsyncTestZoneSpec.prototype._resetLastErrorAndThrow = function () {
4201 var error = this._lastError || this._uncaughtPromiseErrors[0];
4202 this._uncaughtPromiseErrors.length = 0;
4203 this._lastError = null;
4204 throw error;
4205 };
4206 FakeAsyncTestZoneSpec.prototype.getCurrentTickTime = function () {
4207 return this._scheduler.getCurrentTickTime();
4208 };
4209 FakeAsyncTestZoneSpec.prototype.getFakeSystemTime = function () {
4210 return this._scheduler.getFakeSystemTime();
4211 };
4212 FakeAsyncTestZoneSpec.prototype.setFakeBaseSystemTime = function (realTime) {
4213 this._scheduler.setFakeBaseSystemTime(realTime);
4214 };
4215 FakeAsyncTestZoneSpec.prototype.getRealSystemTime = function () {
4216 return this._scheduler.getRealSystemTime();
4217 };
4218 FakeAsyncTestZoneSpec.patchDate = function () {
4219 if (!!global[Zone.__symbol__('disableDatePatching')]) {
4220 // we don't want to patch global Date
4221 // because in some case, global Date
4222 // is already being patched, we need to provide
4223 // an option to let user still use their
4224 // own version of Date.
4225 return;
4226 }
4227 if (global['Date'] === FakeDate) {
4228 // already patched
4229 return;
4230 }
4231 global['Date'] = FakeDate;
4232 FakeDate.prototype = OriginalDate.prototype;
4233 // try check and reset timers
4234 // because jasmine.clock().install() may
4235 // have replaced the global timer
4236 FakeAsyncTestZoneSpec.checkTimerPatch();
4237 };
4238 FakeAsyncTestZoneSpec.resetDate = function () {
4239 if (global['Date'] === FakeDate) {
4240 global['Date'] = OriginalDate;
4241 }
4242 };
4243 FakeAsyncTestZoneSpec.checkTimerPatch = function () {
4244 if (global.setTimeout !== timers.setTimeout) {
4245 global.setTimeout = timers.setTimeout;
4246 global.clearTimeout = timers.clearTimeout;
4247 }
4248 if (global.setInterval !== timers.setInterval) {
4249 global.setInterval = timers.setInterval;
4250 global.clearInterval = timers.clearInterval;
4251 }
4252 };
4253 FakeAsyncTestZoneSpec.prototype.lockDatePatch = function () {
4254 this.patchDateLocked = true;
4255 FakeAsyncTestZoneSpec.patchDate();
4256 };
4257 FakeAsyncTestZoneSpec.prototype.unlockDatePatch = function () {
4258 this.patchDateLocked = false;
4259 FakeAsyncTestZoneSpec.resetDate();
4260 };
4261 FakeAsyncTestZoneSpec.prototype.tickToNext = function (steps, doTick, tickOptions) {
4262 if (steps === void 0) { steps = 1; }
4263 if (tickOptions === void 0) { tickOptions = { processNewMacroTasksSynchronously: true }; }
4264 if (steps <= 0) {
4265 return;
4266 }
4267 FakeAsyncTestZoneSpec.assertInZone();
4268 this.flushMicrotasks();
4269 this._scheduler.tickToNext(steps, doTick, tickOptions);
4270 if (this._lastError !== null) {
4271 this._resetLastErrorAndThrow();
4272 }
4273 };
4274 FakeAsyncTestZoneSpec.prototype.tick = function (millis, doTick, tickOptions) {
4275 if (millis === void 0) { millis = 0; }
4276 if (tickOptions === void 0) { tickOptions = { processNewMacroTasksSynchronously: true }; }
4277 FakeAsyncTestZoneSpec.assertInZone();
4278 this.flushMicrotasks();
4279 this._scheduler.tick(millis, doTick, tickOptions);
4280 if (this._lastError !== null) {
4281 this._resetLastErrorAndThrow();
4282 }
4283 };
4284 FakeAsyncTestZoneSpec.prototype.flushMicrotasks = function () {
4285 var _this = this;
4286 FakeAsyncTestZoneSpec.assertInZone();
4287 var flushErrors = function () {
4288 if (_this._lastError !== null || _this._uncaughtPromiseErrors.length) {
4289 // If there is an error stop processing the microtask queue and rethrow the error.
4290 _this._resetLastErrorAndThrow();
4291 }
4292 };
4293 while (this._microtasks.length > 0) {
4294 var microtask = this._microtasks.shift();
4295 microtask.func.apply(microtask.target, microtask.args);
4296 }
4297 flushErrors();
4298 };
4299 FakeAsyncTestZoneSpec.prototype.flush = function (limit, flushPeriodic, doTick) {
4300 FakeAsyncTestZoneSpec.assertInZone();
4301 this.flushMicrotasks();
4302 var elapsed = this._scheduler.flush(limit, flushPeriodic, doTick);
4303 if (this._lastError !== null) {
4304 this._resetLastErrorAndThrow();
4305 }
4306 return elapsed;
4307 };
4308 FakeAsyncTestZoneSpec.prototype.flushOnlyPendingTimers = function (doTick) {
4309 FakeAsyncTestZoneSpec.assertInZone();
4310 this.flushMicrotasks();
4311 var elapsed = this._scheduler.flushOnlyPendingTimers(doTick);
4312 if (this._lastError !== null) {
4313 this._resetLastErrorAndThrow();
4314 }
4315 return elapsed;
4316 };
4317 FakeAsyncTestZoneSpec.prototype.removeAllTimers = function () {
4318 FakeAsyncTestZoneSpec.assertInZone();
4319 this._scheduler.removeAll();
4320 this.pendingPeriodicTimers = [];
4321 this.pendingTimers = [];
4322 };
4323 FakeAsyncTestZoneSpec.prototype.getTimerCount = function () {
4324 return this._scheduler.getTimerCount() + this._microtasks.length;
4325 };
4326 FakeAsyncTestZoneSpec.prototype.onScheduleTask = function (delegate, current, target, task) {
4327 switch (task.type) {
4328 case 'microTask':
4329 var args = task.data && task.data.args;
4330 // should pass additional arguments to callback if have any
4331 // currently we know process.nextTick will have such additional
4332 // arguments
4333 var additionalArgs = void 0;
4334 if (args) {
4335 var callbackIndex = task.data.cbIdx;
4336 if (typeof args.length === 'number' && args.length > callbackIndex + 1) {
4337 additionalArgs = Array.prototype.slice.call(args, callbackIndex + 1);
4338 }
4339 }
4340 this._microtasks.push({
4341 func: task.invoke,
4342 args: additionalArgs,
4343 target: task.data && task.data.target
4344 });
4345 break;
4346 case 'macroTask':
4347 switch (task.source) {
4348 case 'setTimeout':
4349 task.data['handleId'] = this._setTimeout(task.invoke, task.data['delay'], Array.prototype.slice.call(task.data['args'], 2));
4350 break;
4351 case 'setImmediate':
4352 task.data['handleId'] = this._setTimeout(task.invoke, 0, Array.prototype.slice.call(task.data['args'], 1));
4353 break;
4354 case 'setInterval':
4355 task.data['handleId'] = this._setInterval(task.invoke, task.data['delay'], Array.prototype.slice.call(task.data['args'], 2));
4356 break;
4357 case 'XMLHttpRequest.send':
4358 throw new Error('Cannot make XHRs from within a fake async test. Request URL: ' +
4359 task.data['url']);
4360 case 'requestAnimationFrame':
4361 case 'webkitRequestAnimationFrame':
4362 case 'mozRequestAnimationFrame':
4363 // Simulate a requestAnimationFrame by using a setTimeout with 16 ms.
4364 // (60 frames per second)
4365 task.data['handleId'] = this._setTimeout(task.invoke, 16, task.data['args'], this.trackPendingRequestAnimationFrame);
4366 break;
4367 default:
4368 // user can define which macroTask they want to support by passing
4369 // macroTaskOptions
4370 var macroTaskOption = this.findMacroTaskOption(task);
4371 if (macroTaskOption) {
4372 var args_1 = task.data && task.data['args'];
4373 var delay = args_1 && args_1.length > 1 ? args_1[1] : 0;
4374 var callbackArgs = macroTaskOption.callbackArgs ? macroTaskOption.callbackArgs : args_1;
4375 if (!!macroTaskOption.isPeriodic) {
4376 // periodic macroTask, use setInterval to simulate
4377 task.data['handleId'] = this._setInterval(task.invoke, delay, callbackArgs);
4378 task.data.isPeriodic = true;
4379 }
4380 else {
4381 // not periodic, use setTimeout to simulate
4382 task.data['handleId'] = this._setTimeout(task.invoke, delay, callbackArgs);
4383 }
4384 break;
4385 }
4386 throw new Error('Unknown macroTask scheduled in fake async test: ' + task.source);
4387 }
4388 break;
4389 case 'eventTask':
4390 task = delegate.scheduleTask(target, task);
4391 break;
4392 }
4393 return task;
4394 };
4395 FakeAsyncTestZoneSpec.prototype.onCancelTask = function (delegate, current, target, task) {
4396 switch (task.source) {
4397 case 'setTimeout':
4398 case 'requestAnimationFrame':
4399 case 'webkitRequestAnimationFrame':
4400 case 'mozRequestAnimationFrame':
4401 return this._clearTimeout(task.data['handleId']);
4402 case 'setInterval':
4403 return this._clearInterval(task.data['handleId']);
4404 default:
4405 // user can define which macroTask they want to support by passing
4406 // macroTaskOptions
4407 var macroTaskOption = this.findMacroTaskOption(task);
4408 if (macroTaskOption) {
4409 var handleId = task.data['handleId'];
4410 return macroTaskOption.isPeriodic ? this._clearInterval(handleId) :
4411 this._clearTimeout(handleId);
4412 }
4413 return delegate.cancelTask(target, task);
4414 }
4415 };
4416 FakeAsyncTestZoneSpec.prototype.onInvoke = function (delegate, current, target, callback, applyThis, applyArgs, source) {
4417 try {
4418 FakeAsyncTestZoneSpec.patchDate();
4419 return delegate.invoke(target, callback, applyThis, applyArgs, source);
4420 }
4421 finally {
4422 if (!this.patchDateLocked) {
4423 FakeAsyncTestZoneSpec.resetDate();
4424 }
4425 }
4426 };
4427 FakeAsyncTestZoneSpec.prototype.findMacroTaskOption = function (task) {
4428 if (!this.macroTaskOptions) {
4429 return null;
4430 }
4431 for (var i = 0; i < this.macroTaskOptions.length; i++) {
4432 var macroTaskOption = this.macroTaskOptions[i];
4433 if (macroTaskOption.source === task.source) {
4434 return macroTaskOption;
4435 }
4436 }
4437 return null;
4438 };
4439 FakeAsyncTestZoneSpec.prototype.onHandleError = function (parentZoneDelegate, currentZone, targetZone, error) {
4440 this._lastError = error;
4441 return false; // Don't propagate error to parent zone.
4442 };
4443 return FakeAsyncTestZoneSpec;
4444 }());
4445 // Export the class so that new instances can be created with proper
4446 // constructor params.
4447 Zone['FakeAsyncTestZoneSpec'] = FakeAsyncTestZoneSpec;
4448 })(typeof window === 'object' && window || typeof self === 'object' && self || global);
4449 Zone.__load_patch('fakeasync', function (global, Zone, api) {
4450 var FakeAsyncTestZoneSpec = Zone && Zone['FakeAsyncTestZoneSpec'];
4451 function getProxyZoneSpec() {
4452 return Zone && Zone['ProxyZoneSpec'];
4453 }
4454 var _fakeAsyncTestZoneSpec = null;
4455 /**
4456 * Clears out the shared fake async zone for a test.
4457 * To be called in a global `beforeEach`.
4458 *
4459 * @experimental
4460 */
4461 function resetFakeAsyncZone() {
4462 if (_fakeAsyncTestZoneSpec) {
4463 _fakeAsyncTestZoneSpec.unlockDatePatch();
4464 }
4465 _fakeAsyncTestZoneSpec = null;
4466 // in node.js testing we may not have ProxyZoneSpec in which case there is nothing to reset.
4467 getProxyZoneSpec() && getProxyZoneSpec().assertPresent().resetDelegate();
4468 }
4469 /**
4470 * Wraps a function to be executed in the fakeAsync zone:
4471 * - microtasks are manually executed by calling `flushMicrotasks()`,
4472 * - timers are synchronous, `tick()` simulates the asynchronous passage of time.
4473 *
4474 * If there are any pending timers at the end of the function, an exception will be thrown.
4475 *
4476 * Can be used to wrap inject() calls.
4477 *
4478 * ## Example
4479 *
4480 * {@example core/testing/ts/fake_async.ts region='basic'}
4481 *
4482 * @param fn
4483 * @returns The function wrapped to be executed in the fakeAsync zone
4484 *
4485 * @experimental
4486 */
4487 function fakeAsync(fn) {
4488 // Not using an arrow function to preserve context passed from call site
4489 var fakeAsyncFn = function () {
4490 var args = [];
4491 for (var _i = 0; _i < arguments.length; _i++) {
4492 args[_i] = arguments[_i];
4493 }
4494 var ProxyZoneSpec = getProxyZoneSpec();
4495 if (!ProxyZoneSpec) {
4496 throw new Error('ProxyZoneSpec is needed for the async() test helper but could not be found. ' +
4497 'Please make sure that your environment includes zone.js/dist/proxy.js');
4498 }
4499 var proxyZoneSpec = ProxyZoneSpec.assertPresent();
4500 if (Zone.current.get('FakeAsyncTestZoneSpec')) {
4501 throw new Error('fakeAsync() calls can not be nested');
4502 }
4503 try {
4504 // in case jasmine.clock init a fakeAsyncTestZoneSpec
4505 if (!_fakeAsyncTestZoneSpec) {
4506 if (proxyZoneSpec.getDelegate() instanceof FakeAsyncTestZoneSpec) {
4507 throw new Error('fakeAsync() calls can not be nested');
4508 }
4509 _fakeAsyncTestZoneSpec = new FakeAsyncTestZoneSpec();
4510 }
4511 var res = void 0;
4512 var lastProxyZoneSpec = proxyZoneSpec.getDelegate();
4513 proxyZoneSpec.setDelegate(_fakeAsyncTestZoneSpec);
4514 _fakeAsyncTestZoneSpec.lockDatePatch();
4515 try {
4516 res = fn.apply(this, args);
4517 flushMicrotasks();
4518 }
4519 finally {
4520 proxyZoneSpec.setDelegate(lastProxyZoneSpec);
4521 }
4522 if (_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length > 0) {
4523 throw new Error(_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length + " " +
4524 "periodic timer(s) still in the queue.");
4525 }
4526 if (_fakeAsyncTestZoneSpec.pendingTimers.length > 0) {
4527 throw new Error(_fakeAsyncTestZoneSpec.pendingTimers.length + " timer(s) still in the queue.");
4528 }
4529 return res;
4530 }
4531 finally {
4532 resetFakeAsyncZone();
4533 }
4534 };
4535 fakeAsyncFn.isFakeAsync = true;
4536 return fakeAsyncFn;
4537 }
4538 function _getFakeAsyncZoneSpec() {
4539 if (_fakeAsyncTestZoneSpec == null) {
4540 _fakeAsyncTestZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec');
4541 if (_fakeAsyncTestZoneSpec == null) {
4542 throw new Error('The code should be running in the fakeAsync zone to call this function');
4543 }
4544 }
4545 return _fakeAsyncTestZoneSpec;
4546 }
4547 /**
4548 * Simulates the asynchronous passage of time for the timers in the fakeAsync zone.
4549 *
4550 * The microtasks queue is drained at the very start of this function and after any timer callback
4551 * has been executed.
4552 *
4553 * ## Example
4554 *
4555 * {@example core/testing/ts/fake_async.ts region='basic'}
4556 *
4557 * @experimental
4558 */
4559 function tick(millis, ignoreNestedTimeout) {
4560 if (millis === void 0) { millis = 0; }
4561 if (ignoreNestedTimeout === void 0) { ignoreNestedTimeout = false; }
4562 _getFakeAsyncZoneSpec().tick(millis, null, ignoreNestedTimeout);
4563 }
4564 /**
4565 * Simulates the asynchronous passage of time for the timers in the fakeAsync zone by
4566 * draining the macrotask queue until it is empty. The returned value is the milliseconds
4567 * of time that would have been elapsed.
4568 *
4569 * @param maxTurns
4570 * @returns The simulated time elapsed, in millis.
4571 *
4572 * @experimental
4573 */
4574 function flush(maxTurns) {
4575 return _getFakeAsyncZoneSpec().flush(maxTurns);
4576 }
4577 /**
4578 * Discard all remaining periodic tasks.
4579 *
4580 * @experimental
4581 */
4582 function discardPeriodicTasks() {
4583 var zoneSpec = _getFakeAsyncZoneSpec();
4584 var pendingTimers = zoneSpec.pendingPeriodicTimers;
4585 zoneSpec.pendingPeriodicTimers.length = 0;
4586 }
4587 /**
4588 * Flush any pending microtasks.
4589 *
4590 * @experimental
4591 */
4592 function flushMicrotasks() {
4593 _getFakeAsyncZoneSpec().flushMicrotasks();
4594 }
4595 Zone[api.symbol('fakeAsyncTest')] =
4596 { resetFakeAsyncZone: resetFakeAsyncZone, flushMicrotasks: flushMicrotasks, discardPeriodicTasks: discardPeriodicTasks, tick: tick, flush: flush, fakeAsync: fakeAsync };
4597 }, true);
4598 /**
4599 * @license
4600 * Copyright Google LLC All Rights Reserved.
4601 *
4602 * Use of this source code is governed by an MIT-style license that can be
4603 * found in the LICENSE file at https://angular.io/license
4604 */
4605 /**
4606 * Promise for async/fakeAsync zoneSpec test
4607 * can support async operation which not supported by zone.js
4608 * such as
4609 * it ('test jsonp in AsyncZone', async() => {
4610 * new Promise(res => {
4611 * jsonp(url, (data) => {
4612 * // success callback
4613 * res(data);
4614 * });
4615 * }).then((jsonpResult) => {
4616 * // get jsonp result.
4617 *
4618 * // user will expect AsyncZoneSpec wait for
4619 * // then, but because jsonp is not zone aware
4620 * // AsyncZone will finish before then is called.
4621 * });
4622 * });
4623 */
4624 Zone.__load_patch('promisefortest', function (global, Zone, api) {
4625 var symbolState = api.symbol('state');
4626 var UNRESOLVED = null;
4627 var symbolParentUnresolved = api.symbol('parentUnresolved');
4628 // patch Promise.prototype.then to keep an internal
4629 // number for tracking unresolved chained promise
4630 // we will decrease this number when the parent promise
4631 // being resolved/rejected and chained promise was
4632 // scheduled as a microTask.
4633 // so we can know such kind of chained promise still
4634 // not resolved in AsyncTestZone
4635 Promise[api.symbol('patchPromiseForTest')] = function patchPromiseForTest() {
4636 var oriThen = Promise[Zone.__symbol__('ZonePromiseThen')];
4637 if (oriThen) {
4638 return;
4639 }
4640 oriThen = Promise[Zone.__symbol__('ZonePromiseThen')] = Promise.prototype.then;
4641 Promise.prototype.then = function () {
4642 var chained = oriThen.apply(this, arguments);
4643 if (this[symbolState] === UNRESOLVED) {
4644 // parent promise is unresolved.
4645 var asyncTestZoneSpec = Zone.current.get('AsyncTestZoneSpec');
4646 if (asyncTestZoneSpec) {
4647 asyncTestZoneSpec.unresolvedChainedPromiseCount++;
4648 chained[symbolParentUnresolved] = true;
4649 }
4650 }
4651 return chained;
4652 };
4653 };
4654 Promise[api.symbol('unPatchPromiseForTest')] = function unpatchPromiseForTest() {
4655 // restore origin then
4656 var oriThen = Promise[Zone.__symbol__('ZonePromiseThen')];
4657 if (oriThen) {
4658 Promise.prototype.then = oriThen;
4659 Promise[Zone.__symbol__('ZonePromiseThen')] = undefined;
4660 }
4661 };
4662 });
4663})));
Note: See TracBrowser for help on using the repository browser.