source: trip-planner-front/node_modules/zone.js/bundles/zone-mix.umd.js@ 571e0df

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

initial commit

  • Property mode set to 100644
File size: 152.6 KB
Line 
1'use strict';
2/**
3 * @license Angular v12.0.0-next.0
4 * (c) 2010-2020 Google LLC. https://angular.io/
5 * License: MIT
6 */
7(function (factory) {
8 typeof define === 'function' && define.amd ? define(factory) :
9 factory();
10}((function () {
11 'use strict';
12 /**
13 * @license
14 * Copyright Google LLC All Rights Reserved.
15 *
16 * Use of this source code is governed by an MIT-style license that can be
17 * found in the LICENSE file at https://angular.io/license
18 */
19 var Zone$1 = (function (global) {
20 var performance = global['performance'];
21 function mark(name) {
22 performance && performance['mark'] && performance['mark'](name);
23 }
24 function performanceMeasure(name, label) {
25 performance && performance['measure'] && performance['measure'](name, label);
26 }
27 mark('Zone');
28 // Initialize before it's accessed below.
29 // __Zone_symbol_prefix global can be used to override the default zone
30 // symbol prefix with a custom one if needed.
31 var symbolPrefix = global['__Zone_symbol_prefix'] || '__zone_symbol__';
32 function __symbol__(name) {
33 return symbolPrefix + name;
34 }
35 var checkDuplicate = global[__symbol__('forceDuplicateZoneCheck')] === true;
36 if (global['Zone']) {
37 // if global['Zone'] already exists (maybe zone.js was already loaded or
38 // some other lib also registered a global object named Zone), we may need
39 // to throw an error, but sometimes user may not want this error.
40 // For example,
41 // we have two web pages, page1 includes zone.js, page2 doesn't.
42 // and the 1st time user load page1 and page2, everything work fine,
43 // but when user load page2 again, error occurs because global['Zone'] already exists.
44 // so we add a flag to let user choose whether to throw this error or not.
45 // By default, if existing Zone is from zone.js, we will not throw the error.
46 if (checkDuplicate || typeof global['Zone'].__symbol__ !== 'function') {
47 throw new Error('Zone already loaded.');
48 }
49 else {
50 return global['Zone'];
51 }
52 }
53 var Zone = /** @class */ (function () {
54 function Zone(parent, zoneSpec) {
55 this._parent = parent;
56 this._name = zoneSpec ? zoneSpec.name || 'unnamed' : '<root>';
57 this._properties = zoneSpec && zoneSpec.properties || {};
58 this._zoneDelegate =
59 new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec);
60 }
61 Zone.assertZonePatched = function () {
62 if (global['Promise'] !== patches['ZoneAwarePromise']) {
63 throw new Error('Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' +
64 'has been overwritten.\n' +
65 'Most likely cause is that a Promise polyfill has been loaded ' +
66 'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' +
67 'If you must load one, do so before loading zone.js.)');
68 }
69 };
70 Object.defineProperty(Zone, "root", {
71 get: function () {
72 var zone = Zone.current;
73 while (zone.parent) {
74 zone = zone.parent;
75 }
76 return zone;
77 },
78 enumerable: false,
79 configurable: true
80 });
81 Object.defineProperty(Zone, "current", {
82 get: function () {
83 return _currentZoneFrame.zone;
84 },
85 enumerable: false,
86 configurable: true
87 });
88 Object.defineProperty(Zone, "currentTask", {
89 get: function () {
90 return _currentTask;
91 },
92 enumerable: false,
93 configurable: true
94 });
95 // tslint:disable-next-line:require-internal-with-underscore
96 Zone.__load_patch = function (name, fn, ignoreDuplicate) {
97 if (ignoreDuplicate === void 0) { ignoreDuplicate = false; }
98 if (patches.hasOwnProperty(name)) {
99 // `checkDuplicate` option is defined from global variable
100 // so it works for all modules.
101 // `ignoreDuplicate` can work for the specified module
102 if (!ignoreDuplicate && checkDuplicate) {
103 throw Error('Already loaded patch: ' + name);
104 }
105 }
106 else if (!global['__Zone_disable_' + name]) {
107 var perfName = 'Zone:' + name;
108 mark(perfName);
109 patches[name] = fn(global, Zone, _api);
110 performanceMeasure(perfName, perfName);
111 }
112 };
113 Object.defineProperty(Zone.prototype, "parent", {
114 get: function () {
115 return this._parent;
116 },
117 enumerable: false,
118 configurable: true
119 });
120 Object.defineProperty(Zone.prototype, "name", {
121 get: function () {
122 return this._name;
123 },
124 enumerable: false,
125 configurable: true
126 });
127 Zone.prototype.get = function (key) {
128 var zone = this.getZoneWith(key);
129 if (zone)
130 return zone._properties[key];
131 };
132 Zone.prototype.getZoneWith = function (key) {
133 var current = this;
134 while (current) {
135 if (current._properties.hasOwnProperty(key)) {
136 return current;
137 }
138 current = current._parent;
139 }
140 return null;
141 };
142 Zone.prototype.fork = function (zoneSpec) {
143 if (!zoneSpec)
144 throw new Error('ZoneSpec required!');
145 return this._zoneDelegate.fork(this, zoneSpec);
146 };
147 Zone.prototype.wrap = function (callback, source) {
148 if (typeof callback !== 'function') {
149 throw new Error('Expecting function got: ' + callback);
150 }
151 var _callback = this._zoneDelegate.intercept(this, callback, source);
152 var zone = this;
153 return function () {
154 return zone.runGuarded(_callback, this, arguments, source);
155 };
156 };
157 Zone.prototype.run = function (callback, applyThis, applyArgs, source) {
158 _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
159 try {
160 return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
161 }
162 finally {
163 _currentZoneFrame = _currentZoneFrame.parent;
164 }
165 };
166 Zone.prototype.runGuarded = function (callback, applyThis, applyArgs, source) {
167 if (applyThis === void 0) { applyThis = null; }
168 _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
169 try {
170 try {
171 return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
172 }
173 catch (error) {
174 if (this._zoneDelegate.handleError(this, error)) {
175 throw error;
176 }
177 }
178 }
179 finally {
180 _currentZoneFrame = _currentZoneFrame.parent;
181 }
182 };
183 Zone.prototype.runTask = function (task, applyThis, applyArgs) {
184 if (task.zone != this) {
185 throw new Error('A task can only be run in the zone of creation! (Creation: ' +
186 (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
187 }
188 // https://github.com/angular/zone.js/issues/778, sometimes eventTask
189 // will run in notScheduled(canceled) state, we should not try to
190 // run such kind of task but just return
191 if (task.state === notScheduled && (task.type === eventTask || task.type === macroTask)) {
192 return;
193 }
194 var reEntryGuard = task.state != running;
195 reEntryGuard && task._transitionTo(running, scheduled);
196 task.runCount++;
197 var previousTask = _currentTask;
198 _currentTask = task;
199 _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
200 try {
201 if (task.type == macroTask && task.data && !task.data.isPeriodic) {
202 task.cancelFn = undefined;
203 }
204 try {
205 return this._zoneDelegate.invokeTask(this, task, applyThis, applyArgs);
206 }
207 catch (error) {
208 if (this._zoneDelegate.handleError(this, error)) {
209 throw error;
210 }
211 }
212 }
213 finally {
214 // if the task's state is notScheduled or unknown, then it has already been cancelled
215 // we should not reset the state to scheduled
216 if (task.state !== notScheduled && task.state !== unknown) {
217 if (task.type == eventTask || (task.data && task.data.isPeriodic)) {
218 reEntryGuard && task._transitionTo(scheduled, running);
219 }
220 else {
221 task.runCount = 0;
222 this._updateTaskCount(task, -1);
223 reEntryGuard &&
224 task._transitionTo(notScheduled, running, notScheduled);
225 }
226 }
227 _currentZoneFrame = _currentZoneFrame.parent;
228 _currentTask = previousTask;
229 }
230 };
231 Zone.prototype.scheduleTask = function (task) {
232 if (task.zone && task.zone !== this) {
233 // check if the task was rescheduled, the newZone
234 // should not be the children of the original zone
235 var newZone = this;
236 while (newZone) {
237 if (newZone === task.zone) {
238 throw Error("can not reschedule task to " + this.name + " which is descendants of the original zone " + task.zone.name);
239 }
240 newZone = newZone.parent;
241 }
242 }
243 task._transitionTo(scheduling, notScheduled);
244 var zoneDelegates = [];
245 task._zoneDelegates = zoneDelegates;
246 task._zone = this;
247 try {
248 task = this._zoneDelegate.scheduleTask(this, task);
249 }
250 catch (err) {
251 // should set task's state to unknown when scheduleTask throw error
252 // because the err may from reschedule, so the fromState maybe notScheduled
253 task._transitionTo(unknown, scheduling, notScheduled);
254 // TODO: @JiaLiPassion, should we check the result from handleError?
255 this._zoneDelegate.handleError(this, err);
256 throw err;
257 }
258 if (task._zoneDelegates === zoneDelegates) {
259 // we have to check because internally the delegate can reschedule the task.
260 this._updateTaskCount(task, 1);
261 }
262 if (task.state == scheduling) {
263 task._transitionTo(scheduled, scheduling);
264 }
265 return task;
266 };
267 Zone.prototype.scheduleMicroTask = function (source, callback, data, customSchedule) {
268 return this.scheduleTask(new ZoneTask(microTask, source, callback, data, customSchedule, undefined));
269 };
270 Zone.prototype.scheduleMacroTask = function (source, callback, data, customSchedule, customCancel) {
271 return this.scheduleTask(new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel));
272 };
273 Zone.prototype.scheduleEventTask = function (source, callback, data, customSchedule, customCancel) {
274 return this.scheduleTask(new ZoneTask(eventTask, source, callback, data, customSchedule, customCancel));
275 };
276 Zone.prototype.cancelTask = function (task) {
277 if (task.zone != this)
278 throw new Error('A task can only be cancelled in the zone of creation! (Creation: ' +
279 (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
280 task._transitionTo(canceling, scheduled, running);
281 try {
282 this._zoneDelegate.cancelTask(this, task);
283 }
284 catch (err) {
285 // if error occurs when cancelTask, transit the state to unknown
286 task._transitionTo(unknown, canceling);
287 this._zoneDelegate.handleError(this, err);
288 throw err;
289 }
290 this._updateTaskCount(task, -1);
291 task._transitionTo(notScheduled, canceling);
292 task.runCount = 0;
293 return task;
294 };
295 Zone.prototype._updateTaskCount = function (task, count) {
296 var zoneDelegates = task._zoneDelegates;
297 if (count == -1) {
298 task._zoneDelegates = null;
299 }
300 for (var i = 0; i < zoneDelegates.length; i++) {
301 zoneDelegates[i]._updateTaskCount(task.type, count);
302 }
303 };
304 return Zone;
305 }());
306 // tslint:disable-next-line:require-internal-with-underscore
307 Zone.__symbol__ = __symbol__;
308 var DELEGATE_ZS = {
309 name: '',
310 onHasTask: function (delegate, _, target, hasTaskState) { return delegate.hasTask(target, hasTaskState); },
311 onScheduleTask: function (delegate, _, target, task) { return delegate.scheduleTask(target, task); },
312 onInvokeTask: function (delegate, _, target, task, applyThis, applyArgs) { return delegate.invokeTask(target, task, applyThis, applyArgs); },
313 onCancelTask: function (delegate, _, target, task) { return delegate.cancelTask(target, task); }
314 };
315 var ZoneDelegate = /** @class */ (function () {
316 function ZoneDelegate(zone, parentDelegate, zoneSpec) {
317 this._taskCounts = { 'microTask': 0, 'macroTask': 0, 'eventTask': 0 };
318 this.zone = zone;
319 this._parentDelegate = parentDelegate;
320 this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate._forkZS);
321 this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate._forkDlgt);
322 this._forkCurrZone =
323 zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate._forkCurrZone);
324 this._interceptZS =
325 zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS);
326 this._interceptDlgt =
327 zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt);
328 this._interceptCurrZone =
329 zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate._interceptCurrZone);
330 this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate._invokeZS);
331 this._invokeDlgt =
332 zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt);
333 this._invokeCurrZone =
334 zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate._invokeCurrZone);
335 this._handleErrorZS =
336 zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS);
337 this._handleErrorDlgt =
338 zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt);
339 this._handleErrorCurrZone =
340 zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate._handleErrorCurrZone);
341 this._scheduleTaskZS =
342 zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS);
343 this._scheduleTaskDlgt = zoneSpec &&
344 (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt);
345 this._scheduleTaskCurrZone =
346 zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate._scheduleTaskCurrZone);
347 this._invokeTaskZS =
348 zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS);
349 this._invokeTaskDlgt =
350 zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt);
351 this._invokeTaskCurrZone =
352 zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate._invokeTaskCurrZone);
353 this._cancelTaskZS =
354 zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS);
355 this._cancelTaskDlgt =
356 zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt);
357 this._cancelTaskCurrZone =
358 zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate._cancelTaskCurrZone);
359 this._hasTaskZS = null;
360 this._hasTaskDlgt = null;
361 this._hasTaskDlgtOwner = null;
362 this._hasTaskCurrZone = null;
363 var zoneSpecHasTask = zoneSpec && zoneSpec.onHasTask;
364 var parentHasTask = parentDelegate && parentDelegate._hasTaskZS;
365 if (zoneSpecHasTask || parentHasTask) {
366 // If we need to report hasTask, than this ZS needs to do ref counting on tasks. In such
367 // a case all task related interceptors must go through this ZD. We can't short circuit it.
368 this._hasTaskZS = zoneSpecHasTask ? zoneSpec : DELEGATE_ZS;
369 this._hasTaskDlgt = parentDelegate;
370 this._hasTaskDlgtOwner = this;
371 this._hasTaskCurrZone = zone;
372 if (!zoneSpec.onScheduleTask) {
373 this._scheduleTaskZS = DELEGATE_ZS;
374 this._scheduleTaskDlgt = parentDelegate;
375 this._scheduleTaskCurrZone = this.zone;
376 }
377 if (!zoneSpec.onInvokeTask) {
378 this._invokeTaskZS = DELEGATE_ZS;
379 this._invokeTaskDlgt = parentDelegate;
380 this._invokeTaskCurrZone = this.zone;
381 }
382 if (!zoneSpec.onCancelTask) {
383 this._cancelTaskZS = DELEGATE_ZS;
384 this._cancelTaskDlgt = parentDelegate;
385 this._cancelTaskCurrZone = this.zone;
386 }
387 }
388 }
389 ZoneDelegate.prototype.fork = function (targetZone, zoneSpec) {
390 return this._forkZS ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) :
391 new Zone(targetZone, zoneSpec);
392 };
393 ZoneDelegate.prototype.intercept = function (targetZone, callback, source) {
394 return this._interceptZS ?
395 this._interceptZS.onIntercept(this._interceptDlgt, this._interceptCurrZone, targetZone, callback, source) :
396 callback;
397 };
398 ZoneDelegate.prototype.invoke = function (targetZone, callback, applyThis, applyArgs, source) {
399 return this._invokeZS ? this._invokeZS.onInvoke(this._invokeDlgt, this._invokeCurrZone, targetZone, callback, applyThis, applyArgs, source) :
400 callback.apply(applyThis, applyArgs);
401 };
402 ZoneDelegate.prototype.handleError = function (targetZone, error) {
403 return this._handleErrorZS ?
404 this._handleErrorZS.onHandleError(this._handleErrorDlgt, this._handleErrorCurrZone, targetZone, error) :
405 true;
406 };
407 ZoneDelegate.prototype.scheduleTask = function (targetZone, task) {
408 var returnTask = task;
409 if (this._scheduleTaskZS) {
410 if (this._hasTaskZS) {
411 returnTask._zoneDelegates.push(this._hasTaskDlgtOwner);
412 }
413 // clang-format off
414 returnTask = this._scheduleTaskZS.onScheduleTask(this._scheduleTaskDlgt, this._scheduleTaskCurrZone, targetZone, task);
415 // clang-format on
416 if (!returnTask)
417 returnTask = task;
418 }
419 else {
420 if (task.scheduleFn) {
421 task.scheduleFn(task);
422 }
423 else if (task.type == microTask) {
424 scheduleMicroTask(task);
425 }
426 else {
427 throw new Error('Task is missing scheduleFn.');
428 }
429 }
430 return returnTask;
431 };
432 ZoneDelegate.prototype.invokeTask = function (targetZone, task, applyThis, applyArgs) {
433 return this._invokeTaskZS ? this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt, this._invokeTaskCurrZone, targetZone, task, applyThis, applyArgs) :
434 task.callback.apply(applyThis, applyArgs);
435 };
436 ZoneDelegate.prototype.cancelTask = function (targetZone, task) {
437 var value;
438 if (this._cancelTaskZS) {
439 value = this._cancelTaskZS.onCancelTask(this._cancelTaskDlgt, this._cancelTaskCurrZone, targetZone, task);
440 }
441 else {
442 if (!task.cancelFn) {
443 throw Error('Task is not cancelable');
444 }
445 value = task.cancelFn(task);
446 }
447 return value;
448 };
449 ZoneDelegate.prototype.hasTask = function (targetZone, isEmpty) {
450 // hasTask should not throw error so other ZoneDelegate
451 // can still trigger hasTask callback
452 try {
453 this._hasTaskZS &&
454 this._hasTaskZS.onHasTask(this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty);
455 }
456 catch (err) {
457 this.handleError(targetZone, err);
458 }
459 };
460 // tslint:disable-next-line:require-internal-with-underscore
461 ZoneDelegate.prototype._updateTaskCount = function (type, count) {
462 var counts = this._taskCounts;
463 var prev = counts[type];
464 var next = counts[type] = prev + count;
465 if (next < 0) {
466 throw new Error('More tasks executed then were scheduled.');
467 }
468 if (prev == 0 || next == 0) {
469 var isEmpty = {
470 microTask: counts['microTask'] > 0,
471 macroTask: counts['macroTask'] > 0,
472 eventTask: counts['eventTask'] > 0,
473 change: type
474 };
475 this.hasTask(this.zone, isEmpty);
476 }
477 };
478 return ZoneDelegate;
479 }());
480 var ZoneTask = /** @class */ (function () {
481 function ZoneTask(type, source, callback, options, scheduleFn, cancelFn) {
482 // tslint:disable-next-line:require-internal-with-underscore
483 this._zone = null;
484 this.runCount = 0;
485 // tslint:disable-next-line:require-internal-with-underscore
486 this._zoneDelegates = null;
487 // tslint:disable-next-line:require-internal-with-underscore
488 this._state = 'notScheduled';
489 this.type = type;
490 this.source = source;
491 this.data = options;
492 this.scheduleFn = scheduleFn;
493 this.cancelFn = cancelFn;
494 if (!callback) {
495 throw new Error('callback is not defined');
496 }
497 this.callback = callback;
498 var self = this;
499 // TODO: @JiaLiPassion options should have interface
500 if (type === eventTask && options && options.useG) {
501 this.invoke = ZoneTask.invokeTask;
502 }
503 else {
504 this.invoke = function () {
505 return ZoneTask.invokeTask.call(global, self, this, arguments);
506 };
507 }
508 }
509 ZoneTask.invokeTask = function (task, target, args) {
510 if (!task) {
511 task = this;
512 }
513 _numberOfNestedTaskFrames++;
514 try {
515 task.runCount++;
516 return task.zone.runTask(task, target, args);
517 }
518 finally {
519 if (_numberOfNestedTaskFrames == 1) {
520 drainMicroTaskQueue();
521 }
522 _numberOfNestedTaskFrames--;
523 }
524 };
525 Object.defineProperty(ZoneTask.prototype, "zone", {
526 get: function () {
527 return this._zone;
528 },
529 enumerable: false,
530 configurable: true
531 });
532 Object.defineProperty(ZoneTask.prototype, "state", {
533 get: function () {
534 return this._state;
535 },
536 enumerable: false,
537 configurable: true
538 });
539 ZoneTask.prototype.cancelScheduleRequest = function () {
540 this._transitionTo(notScheduled, scheduling);
541 };
542 // tslint:disable-next-line:require-internal-with-underscore
543 ZoneTask.prototype._transitionTo = function (toState, fromState1, fromState2) {
544 if (this._state === fromState1 || this._state === fromState2) {
545 this._state = toState;
546 if (toState == notScheduled) {
547 this._zoneDelegates = null;
548 }
549 }
550 else {
551 throw new Error(this.type + " '" + this.source + "': can not transition to '" + toState + "', expecting state '" + fromState1 + "'" + (fromState2 ? ' or \'' + fromState2 + '\'' : '') + ", was '" + this._state + "'.");
552 }
553 };
554 ZoneTask.prototype.toString = function () {
555 if (this.data && typeof this.data.handleId !== 'undefined') {
556 return this.data.handleId.toString();
557 }
558 else {
559 return Object.prototype.toString.call(this);
560 }
561 };
562 // add toJSON method to prevent cyclic error when
563 // call JSON.stringify(zoneTask)
564 ZoneTask.prototype.toJSON = function () {
565 return {
566 type: this.type,
567 state: this.state,
568 source: this.source,
569 zone: this.zone.name,
570 runCount: this.runCount
571 };
572 };
573 return ZoneTask;
574 }());
575 //////////////////////////////////////////////////////
576 //////////////////////////////////////////////////////
577 /// MICROTASK QUEUE
578 //////////////////////////////////////////////////////
579 //////////////////////////////////////////////////////
580 var symbolSetTimeout = __symbol__('setTimeout');
581 var symbolPromise = __symbol__('Promise');
582 var symbolThen = __symbol__('then');
583 var _microTaskQueue = [];
584 var _isDrainingMicrotaskQueue = false;
585 var nativeMicroTaskQueuePromise;
586 function scheduleMicroTask(task) {
587 // if we are not running in any task, and there has not been anything scheduled
588 // we must bootstrap the initial task creation by manually scheduling the drain
589 if (_numberOfNestedTaskFrames === 0 && _microTaskQueue.length === 0) {
590 // We are not running in Task, so we need to kickstart the microtask queue.
591 if (!nativeMicroTaskQueuePromise) {
592 if (global[symbolPromise]) {
593 nativeMicroTaskQueuePromise = global[symbolPromise].resolve(0);
594 }
595 }
596 if (nativeMicroTaskQueuePromise) {
597 var nativeThen = nativeMicroTaskQueuePromise[symbolThen];
598 if (!nativeThen) {
599 // native Promise is not patchable, we need to use `then` directly
600 // issue 1078
601 nativeThen = nativeMicroTaskQueuePromise['then'];
602 }
603 nativeThen.call(nativeMicroTaskQueuePromise, drainMicroTaskQueue);
604 }
605 else {
606 global[symbolSetTimeout](drainMicroTaskQueue, 0);
607 }
608 }
609 task && _microTaskQueue.push(task);
610 }
611 function drainMicroTaskQueue() {
612 if (!_isDrainingMicrotaskQueue) {
613 _isDrainingMicrotaskQueue = true;
614 while (_microTaskQueue.length) {
615 var queue = _microTaskQueue;
616 _microTaskQueue = [];
617 for (var i = 0; i < queue.length; i++) {
618 var task = queue[i];
619 try {
620 task.zone.runTask(task, null, null);
621 }
622 catch (error) {
623 _api.onUnhandledError(error);
624 }
625 }
626 }
627 _api.microtaskDrainDone();
628 _isDrainingMicrotaskQueue = false;
629 }
630 }
631 //////////////////////////////////////////////////////
632 //////////////////////////////////////////////////////
633 /// BOOTSTRAP
634 //////////////////////////////////////////////////////
635 //////////////////////////////////////////////////////
636 var NO_ZONE = { name: 'NO ZONE' };
637 var notScheduled = 'notScheduled', scheduling = 'scheduling', scheduled = 'scheduled', running = 'running', canceling = 'canceling', unknown = 'unknown';
638 var microTask = 'microTask', macroTask = 'macroTask', eventTask = 'eventTask';
639 var patches = {};
640 var _api = {
641 symbol: __symbol__,
642 currentZoneFrame: function () { return _currentZoneFrame; },
643 onUnhandledError: noop,
644 microtaskDrainDone: noop,
645 scheduleMicroTask: scheduleMicroTask,
646 showUncaughtError: function () { return !Zone[__symbol__('ignoreConsoleErrorUncaughtError')]; },
647 patchEventTarget: function () { return []; },
648 patchOnProperties: noop,
649 patchMethod: function () { return noop; },
650 bindArguments: function () { return []; },
651 patchThen: function () { return noop; },
652 patchMacroTask: function () { return noop; },
653 patchEventPrototype: function () { return noop; },
654 isIEOrEdge: function () { return false; },
655 getGlobalObjects: function () { return undefined; },
656 ObjectDefineProperty: function () { return noop; },
657 ObjectGetOwnPropertyDescriptor: function () { return undefined; },
658 ObjectCreate: function () { return undefined; },
659 ArraySlice: function () { return []; },
660 patchClass: function () { return noop; },
661 wrapWithCurrentZone: function () { return noop; },
662 filterProperties: function () { return []; },
663 attachOriginToPatched: function () { return noop; },
664 _redefineProperty: function () { return noop; },
665 patchCallbacks: function () { return noop; }
666 };
667 var _currentZoneFrame = { parent: null, zone: new Zone(null, null) };
668 var _currentTask = null;
669 var _numberOfNestedTaskFrames = 0;
670 function noop() { }
671 performanceMeasure('Zone', 'Zone');
672 return global['Zone'] = Zone;
673 })(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
674 /**
675 * @license
676 * Copyright Google LLC All Rights Reserved.
677 *
678 * Use of this source code is governed by an MIT-style license that can be
679 * found in the LICENSE file at https://angular.io/license
680 */
681 /**
682 * Suppress closure compiler errors about unknown 'Zone' variable
683 * @fileoverview
684 * @suppress {undefinedVars,globalThis,missingRequire}
685 */
686 /// <reference types="node"/>
687 // issue #989, to reduce bundle size, use short name
688 /** Object.getOwnPropertyDescriptor */
689 var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
690 /** Object.defineProperty */
691 var ObjectDefineProperty = Object.defineProperty;
692 /** Object.getPrototypeOf */
693 var ObjectGetPrototypeOf = Object.getPrototypeOf;
694 /** Object.create */
695 var ObjectCreate = Object.create;
696 /** Array.prototype.slice */
697 var ArraySlice = Array.prototype.slice;
698 /** addEventListener string const */
699 var ADD_EVENT_LISTENER_STR = 'addEventListener';
700 /** removeEventListener string const */
701 var REMOVE_EVENT_LISTENER_STR = 'removeEventListener';
702 /** zoneSymbol addEventListener */
703 var ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR);
704 /** zoneSymbol removeEventListener */
705 var ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR);
706 /** true string const */
707 var TRUE_STR = 'true';
708 /** false string const */
709 var FALSE_STR = 'false';
710 /** Zone symbol prefix string const. */
711 var ZONE_SYMBOL_PREFIX = Zone.__symbol__('');
712 function wrapWithCurrentZone(callback, source) {
713 return Zone.current.wrap(callback, source);
714 }
715 function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) {
716 return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel);
717 }
718 var zoneSymbol = Zone.__symbol__;
719 var isWindowExists = typeof window !== 'undefined';
720 var internalWindow = isWindowExists ? window : undefined;
721 var _global = isWindowExists && internalWindow || typeof self === 'object' && self || global;
722 var REMOVE_ATTRIBUTE = 'removeAttribute';
723 var NULL_ON_PROP_VALUE = [null];
724 function bindArguments(args, source) {
725 for (var i = args.length - 1; i >= 0; i--) {
726 if (typeof args[i] === 'function') {
727 args[i] = wrapWithCurrentZone(args[i], source + '_' + i);
728 }
729 }
730 return args;
731 }
732 function patchPrototype(prototype, fnNames) {
733 var source = prototype.constructor['name'];
734 var _loop_1 = function (i) {
735 var name_1 = fnNames[i];
736 var delegate = prototype[name_1];
737 if (delegate) {
738 var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, name_1);
739 if (!isPropertyWritable(prototypeDesc)) {
740 return "continue";
741 }
742 prototype[name_1] = (function (delegate) {
743 var patched = function () {
744 return delegate.apply(this, bindArguments(arguments, source + '.' + name_1));
745 };
746 attachOriginToPatched(patched, delegate);
747 return patched;
748 })(delegate);
749 }
750 };
751 for (var i = 0; i < fnNames.length; i++) {
752 _loop_1(i);
753 }
754 }
755 function isPropertyWritable(propertyDesc) {
756 if (!propertyDesc) {
757 return true;
758 }
759 if (propertyDesc.writable === false) {
760 return false;
761 }
762 return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined');
763 }
764 var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope);
765 // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
766 // this code.
767 var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' &&
768 {}.toString.call(_global.process) === '[object process]');
769 var isBrowser = !isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']);
770 // we are in electron of nw, so we are both browser and nodejs
771 // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
772 // this code.
773 var isMix = typeof _global.process !== 'undefined' &&
774 {}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
775 !!(isWindowExists && internalWindow['HTMLElement']);
776 var zoneSymbolEventNames = {};
777 var wrapFn = function (event) {
778 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
779 // event will be undefined, so we need to use window.event
780 event = event || _global.event;
781 if (!event) {
782 return;
783 }
784 var eventNameSymbol = zoneSymbolEventNames[event.type];
785 if (!eventNameSymbol) {
786 eventNameSymbol = zoneSymbolEventNames[event.type] = zoneSymbol('ON_PROPERTY' + event.type);
787 }
788 var target = this || event.target || _global;
789 var listener = target[eventNameSymbol];
790 var result;
791 if (isBrowser && target === internalWindow && event.type === 'error') {
792 // window.onerror have different signiture
793 // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror#window.onerror
794 // and onerror callback will prevent default when callback return true
795 var errorEvent = event;
796 result = listener &&
797 listener.call(this, errorEvent.message, errorEvent.filename, errorEvent.lineno, errorEvent.colno, errorEvent.error);
798 if (result === true) {
799 event.preventDefault();
800 }
801 }
802 else {
803 result = listener && listener.apply(this, arguments);
804 if (result != undefined && !result) {
805 event.preventDefault();
806 }
807 }
808 return result;
809 };
810 function patchProperty(obj, prop, prototype) {
811 var desc = ObjectGetOwnPropertyDescriptor(obj, prop);
812 if (!desc && prototype) {
813 // when patch window object, use prototype to check prop exist or not
814 var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop);
815 if (prototypeDesc) {
816 desc = { enumerable: true, configurable: true };
817 }
818 }
819 // if the descriptor not exists or is not configurable
820 // just return
821 if (!desc || !desc.configurable) {
822 return;
823 }
824 var onPropPatchedSymbol = zoneSymbol('on' + prop + 'patched');
825 if (obj.hasOwnProperty(onPropPatchedSymbol) && obj[onPropPatchedSymbol]) {
826 return;
827 }
828 // A property descriptor cannot have getter/setter and be writable
829 // deleting the writable and value properties avoids this error:
830 //
831 // TypeError: property descriptors must not specify a value or be writable when a
832 // getter or setter has been specified
833 delete desc.writable;
834 delete desc.value;
835 var originalDescGet = desc.get;
836 var originalDescSet = desc.set;
837 // substr(2) cuz 'onclick' -> 'click', etc
838 var eventName = prop.substr(2);
839 var eventNameSymbol = zoneSymbolEventNames[eventName];
840 if (!eventNameSymbol) {
841 eventNameSymbol = zoneSymbolEventNames[eventName] = zoneSymbol('ON_PROPERTY' + eventName);
842 }
843 desc.set = function (newValue) {
844 // in some of windows's onproperty callback, this is undefined
845 // so we need to check it
846 var target = this;
847 if (!target && obj === _global) {
848 target = _global;
849 }
850 if (!target) {
851 return;
852 }
853 var previousValue = target[eventNameSymbol];
854 if (previousValue) {
855 target.removeEventListener(eventName, wrapFn);
856 }
857 // issue #978, when onload handler was added before loading zone.js
858 // we should remove it with originalDescSet
859 if (originalDescSet) {
860 originalDescSet.apply(target, NULL_ON_PROP_VALUE);
861 }
862 if (typeof newValue === 'function') {
863 target[eventNameSymbol] = newValue;
864 target.addEventListener(eventName, wrapFn, false);
865 }
866 else {
867 target[eventNameSymbol] = null;
868 }
869 };
870 // The getter would return undefined for unassigned properties but the default value of an
871 // unassigned property is null
872 desc.get = function () {
873 // in some of windows's onproperty callback, this is undefined
874 // so we need to check it
875 var target = this;
876 if (!target && obj === _global) {
877 target = _global;
878 }
879 if (!target) {
880 return null;
881 }
882 var listener = target[eventNameSymbol];
883 if (listener) {
884 return listener;
885 }
886 else if (originalDescGet) {
887 // result will be null when use inline event attribute,
888 // such as <button onclick="func();">OK</button>
889 // because the onclick function is internal raw uncompiled handler
890 // the onclick will be evaluated when first time event was triggered or
891 // the property is accessed, https://github.com/angular/zone.js/issues/525
892 // so we should use original native get to retrieve the handler
893 var value = originalDescGet && originalDescGet.call(this);
894 if (value) {
895 desc.set.call(this, value);
896 if (typeof target[REMOVE_ATTRIBUTE] === 'function') {
897 target.removeAttribute(prop);
898 }
899 return value;
900 }
901 }
902 return null;
903 };
904 ObjectDefineProperty(obj, prop, desc);
905 obj[onPropPatchedSymbol] = true;
906 }
907 function patchOnProperties(obj, properties, prototype) {
908 if (properties) {
909 for (var i = 0; i < properties.length; i++) {
910 patchProperty(obj, 'on' + properties[i], prototype);
911 }
912 }
913 else {
914 var onProperties = [];
915 for (var prop in obj) {
916 if (prop.substr(0, 2) == 'on') {
917 onProperties.push(prop);
918 }
919 }
920 for (var j = 0; j < onProperties.length; j++) {
921 patchProperty(obj, onProperties[j], prototype);
922 }
923 }
924 }
925 var originalInstanceKey = zoneSymbol('originalInstance');
926 // wrap some native API on `window`
927 function patchClass(className) {
928 var OriginalClass = _global[className];
929 if (!OriginalClass)
930 return;
931 // keep original class in global
932 _global[zoneSymbol(className)] = OriginalClass;
933 _global[className] = function () {
934 var a = bindArguments(arguments, className);
935 switch (a.length) {
936 case 0:
937 this[originalInstanceKey] = new OriginalClass();
938 break;
939 case 1:
940 this[originalInstanceKey] = new OriginalClass(a[0]);
941 break;
942 case 2:
943 this[originalInstanceKey] = new OriginalClass(a[0], a[1]);
944 break;
945 case 3:
946 this[originalInstanceKey] = new OriginalClass(a[0], a[1], a[2]);
947 break;
948 case 4:
949 this[originalInstanceKey] = new OriginalClass(a[0], a[1], a[2], a[3]);
950 break;
951 default:
952 throw new Error('Arg list too long.');
953 }
954 };
955 // attach original delegate to patched function
956 attachOriginToPatched(_global[className], OriginalClass);
957 var instance = new OriginalClass(function () { });
958 var prop;
959 for (prop in instance) {
960 // https://bugs.webkit.org/show_bug.cgi?id=44721
961 if (className === 'XMLHttpRequest' && prop === 'responseBlob')
962 continue;
963 (function (prop) {
964 if (typeof instance[prop] === 'function') {
965 _global[className].prototype[prop] = function () {
966 return this[originalInstanceKey][prop].apply(this[originalInstanceKey], arguments);
967 };
968 }
969 else {
970 ObjectDefineProperty(_global[className].prototype, prop, {
971 set: function (fn) {
972 if (typeof fn === 'function') {
973 this[originalInstanceKey][prop] = wrapWithCurrentZone(fn, className + '.' + prop);
974 // keep callback in wrapped function so we can
975 // use it in Function.prototype.toString to return
976 // the native one.
977 attachOriginToPatched(this[originalInstanceKey][prop], fn);
978 }
979 else {
980 this[originalInstanceKey][prop] = fn;
981 }
982 },
983 get: function () {
984 return this[originalInstanceKey][prop];
985 }
986 });
987 }
988 }(prop));
989 }
990 for (prop in OriginalClass) {
991 if (prop !== 'prototype' && OriginalClass.hasOwnProperty(prop)) {
992 _global[className][prop] = OriginalClass[prop];
993 }
994 }
995 }
996 function copySymbolProperties(src, dest) {
997 if (typeof Object.getOwnPropertySymbols !== 'function') {
998 return;
999 }
1000 var symbols = Object.getOwnPropertySymbols(src);
1001 symbols.forEach(function (symbol) {
1002 var desc = Object.getOwnPropertyDescriptor(src, symbol);
1003 Object.defineProperty(dest, symbol, {
1004 get: function () {
1005 return src[symbol];
1006 },
1007 set: function (value) {
1008 if (desc && (!desc.writable || typeof desc.set !== 'function')) {
1009 // if src[symbol] is not writable or not have a setter, just return
1010 return;
1011 }
1012 src[symbol] = value;
1013 },
1014 enumerable: desc ? desc.enumerable : true,
1015 configurable: desc ? desc.configurable : true
1016 });
1017 });
1018 }
1019 var shouldCopySymbolProperties = false;
1020 function setShouldCopySymbolProperties(flag) {
1021 shouldCopySymbolProperties = flag;
1022 }
1023 function patchMethod(target, name, patchFn) {
1024 var proto = target;
1025 while (proto && !proto.hasOwnProperty(name)) {
1026 proto = ObjectGetPrototypeOf(proto);
1027 }
1028 if (!proto && target[name]) {
1029 // somehow we did not find it, but we can see it. This happens on IE for Window properties.
1030 proto = target;
1031 }
1032 var delegateName = zoneSymbol(name);
1033 var delegate = null;
1034 if (proto && (!(delegate = proto[delegateName]) || !proto.hasOwnProperty(delegateName))) {
1035 delegate = proto[delegateName] = proto[name];
1036 // check whether proto[name] is writable
1037 // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
1038 var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
1039 if (isPropertyWritable(desc)) {
1040 var patchDelegate_1 = patchFn(delegate, delegateName, name);
1041 proto[name] = function () {
1042 return patchDelegate_1(this, arguments);
1043 };
1044 attachOriginToPatched(proto[name], delegate);
1045 if (shouldCopySymbolProperties) {
1046 copySymbolProperties(delegate, proto[name]);
1047 }
1048 }
1049 }
1050 return delegate;
1051 }
1052 // TODO: @JiaLiPassion, support cancel task later if necessary
1053 function patchMacroTask(obj, funcName, metaCreator) {
1054 var setNative = null;
1055 function scheduleTask(task) {
1056 var data = task.data;
1057 data.args[data.cbIdx] = function () {
1058 task.invoke.apply(this, arguments);
1059 };
1060 setNative.apply(data.target, data.args);
1061 return task;
1062 }
1063 setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
1064 var meta = metaCreator(self, args);
1065 if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
1066 return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask);
1067 }
1068 else {
1069 // cause an error by calling it directly.
1070 return delegate.apply(self, args);
1071 }
1072 }; });
1073 }
1074 function patchMicroTask(obj, funcName, metaCreator) {
1075 var setNative = null;
1076 function scheduleTask(task) {
1077 var data = task.data;
1078 data.args[data.cbIdx] = function () {
1079 task.invoke.apply(this, arguments);
1080 };
1081 setNative.apply(data.target, data.args);
1082 return task;
1083 }
1084 setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
1085 var meta = metaCreator(self, args);
1086 if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
1087 return Zone.current.scheduleMicroTask(meta.name, args[meta.cbIdx], meta, scheduleTask);
1088 }
1089 else {
1090 // cause an error by calling it directly.
1091 return delegate.apply(self, args);
1092 }
1093 }; });
1094 }
1095 function attachOriginToPatched(patched, original) {
1096 patched[zoneSymbol('OriginalDelegate')] = original;
1097 }
1098 var isDetectedIEOrEdge = false;
1099 var ieOrEdge = false;
1100 function isIE() {
1101 try {
1102 var ua = internalWindow.navigator.userAgent;
1103 if (ua.indexOf('MSIE ') !== -1 || ua.indexOf('Trident/') !== -1) {
1104 return true;
1105 }
1106 }
1107 catch (error) {
1108 }
1109 return false;
1110 }
1111 function isIEOrEdge() {
1112 if (isDetectedIEOrEdge) {
1113 return ieOrEdge;
1114 }
1115 isDetectedIEOrEdge = true;
1116 try {
1117 var ua = internalWindow.navigator.userAgent;
1118 if (ua.indexOf('MSIE ') !== -1 || ua.indexOf('Trident/') !== -1 || ua.indexOf('Edge/') !== -1) {
1119 ieOrEdge = true;
1120 }
1121 }
1122 catch (error) {
1123 }
1124 return ieOrEdge;
1125 }
1126 /**
1127 * @license
1128 * Copyright Google LLC All Rights Reserved.
1129 *
1130 * Use of this source code is governed by an MIT-style license that can be
1131 * found in the LICENSE file at https://angular.io/license
1132 */
1133 Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) {
1134 var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
1135 var ObjectDefineProperty = Object.defineProperty;
1136 function readableObjectToString(obj) {
1137 if (obj && obj.toString === Object.prototype.toString) {
1138 var className = obj.constructor && obj.constructor.name;
1139 return (className ? className : '') + ': ' + JSON.stringify(obj);
1140 }
1141 return obj ? obj.toString() : Object.prototype.toString.call(obj);
1142 }
1143 var __symbol__ = api.symbol;
1144 var _uncaughtPromiseErrors = [];
1145 var isDisableWrappingUncaughtPromiseRejection = global[__symbol__('DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION')] === true;
1146 var symbolPromise = __symbol__('Promise');
1147 var symbolThen = __symbol__('then');
1148 var creationTrace = '__creationTrace__';
1149 api.onUnhandledError = function (e) {
1150 if (api.showUncaughtError()) {
1151 var rejection = e && e.rejection;
1152 if (rejection) {
1153 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);
1154 }
1155 else {
1156 console.error(e);
1157 }
1158 }
1159 };
1160 api.microtaskDrainDone = function () {
1161 var _loop_2 = function () {
1162 var uncaughtPromiseError = _uncaughtPromiseErrors.shift();
1163 try {
1164 uncaughtPromiseError.zone.runGuarded(function () {
1165 if (uncaughtPromiseError.throwOriginal) {
1166 throw uncaughtPromiseError.rejection;
1167 }
1168 throw uncaughtPromiseError;
1169 });
1170 }
1171 catch (error) {
1172 handleUnhandledRejection(error);
1173 }
1174 };
1175 while (_uncaughtPromiseErrors.length) {
1176 _loop_2();
1177 }
1178 };
1179 var UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__('unhandledPromiseRejectionHandler');
1180 function handleUnhandledRejection(e) {
1181 api.onUnhandledError(e);
1182 try {
1183 var handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL];
1184 if (typeof handler === 'function') {
1185 handler.call(this, e);
1186 }
1187 }
1188 catch (err) {
1189 }
1190 }
1191 function isThenable(value) {
1192 return value && value.then;
1193 }
1194 function forwardResolution(value) {
1195 return value;
1196 }
1197 function forwardRejection(rejection) {
1198 return ZoneAwarePromise.reject(rejection);
1199 }
1200 var symbolState = __symbol__('state');
1201 var symbolValue = __symbol__('value');
1202 var symbolFinally = __symbol__('finally');
1203 var symbolParentPromiseValue = __symbol__('parentPromiseValue');
1204 var symbolParentPromiseState = __symbol__('parentPromiseState');
1205 var source = 'Promise.then';
1206 var UNRESOLVED = null;
1207 var RESOLVED = true;
1208 var REJECTED = false;
1209 var REJECTED_NO_CATCH = 0;
1210 function makeResolver(promise, state) {
1211 return function (v) {
1212 try {
1213 resolvePromise(promise, state, v);
1214 }
1215 catch (err) {
1216 resolvePromise(promise, false, err);
1217 }
1218 // Do not return value or you will break the Promise spec.
1219 };
1220 }
1221 var once = function () {
1222 var wasCalled = false;
1223 return function wrapper(wrappedFunction) {
1224 return function () {
1225 if (wasCalled) {
1226 return;
1227 }
1228 wasCalled = true;
1229 wrappedFunction.apply(null, arguments);
1230 };
1231 };
1232 };
1233 var TYPE_ERROR = 'Promise resolved with itself';
1234 var CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace');
1235 // Promise Resolution
1236 function resolvePromise(promise, state, value) {
1237 var onceWrapper = once();
1238 if (promise === value) {
1239 throw new TypeError(TYPE_ERROR);
1240 }
1241 if (promise[symbolState] === UNRESOLVED) {
1242 // should only get value.then once based on promise spec.
1243 var then = null;
1244 try {
1245 if (typeof value === 'object' || typeof value === 'function') {
1246 then = value && value.then;
1247 }
1248 }
1249 catch (err) {
1250 onceWrapper(function () {
1251 resolvePromise(promise, false, err);
1252 })();
1253 return promise;
1254 }
1255 // if (value instanceof ZoneAwarePromise) {
1256 if (state !== REJECTED && value instanceof ZoneAwarePromise &&
1257 value.hasOwnProperty(symbolState) && value.hasOwnProperty(symbolValue) &&
1258 value[symbolState] !== UNRESOLVED) {
1259 clearRejectedNoCatch(value);
1260 resolvePromise(promise, value[symbolState], value[symbolValue]);
1261 }
1262 else if (state !== REJECTED && typeof then === 'function') {
1263 try {
1264 then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)));
1265 }
1266 catch (err) {
1267 onceWrapper(function () {
1268 resolvePromise(promise, false, err);
1269 })();
1270 }
1271 }
1272 else {
1273 promise[symbolState] = state;
1274 var queue = promise[symbolValue];
1275 promise[symbolValue] = value;
1276 if (promise[symbolFinally] === symbolFinally) {
1277 // the promise is generated by Promise.prototype.finally
1278 if (state === RESOLVED) {
1279 // the state is resolved, should ignore the value
1280 // and use parent promise value
1281 promise[symbolState] = promise[symbolParentPromiseState];
1282 promise[symbolValue] = promise[symbolParentPromiseValue];
1283 }
1284 }
1285 // record task information in value when error occurs, so we can
1286 // do some additional work such as render longStackTrace
1287 if (state === REJECTED && value instanceof Error) {
1288 // check if longStackTraceZone is here
1289 var trace = Zone.currentTask && Zone.currentTask.data &&
1290 Zone.currentTask.data[creationTrace];
1291 if (trace) {
1292 // only keep the long stack trace into error when in longStackTraceZone
1293 ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace });
1294 }
1295 }
1296 for (var i = 0; i < queue.length;) {
1297 scheduleResolveOrReject(promise, queue[i++], queue[i++], queue[i++], queue[i++]);
1298 }
1299 if (queue.length == 0 && state == REJECTED) {
1300 promise[symbolState] = REJECTED_NO_CATCH;
1301 var uncaughtPromiseError = value;
1302 try {
1303 // Here we throws a new Error to print more readable error log
1304 // and if the value is not an error, zone.js builds an `Error`
1305 // Object here to attach the stack information.
1306 throw new Error('Uncaught (in promise): ' + readableObjectToString(value) +
1307 (value && value.stack ? '\n' + value.stack : ''));
1308 }
1309 catch (err) {
1310 uncaughtPromiseError = err;
1311 }
1312 if (isDisableWrappingUncaughtPromiseRejection) {
1313 // If disable wrapping uncaught promise reject
1314 // use the value instead of wrapping it.
1315 uncaughtPromiseError.throwOriginal = true;
1316 }
1317 uncaughtPromiseError.rejection = value;
1318 uncaughtPromiseError.promise = promise;
1319 uncaughtPromiseError.zone = Zone.current;
1320 uncaughtPromiseError.task = Zone.currentTask;
1321 _uncaughtPromiseErrors.push(uncaughtPromiseError);
1322 api.scheduleMicroTask(); // to make sure that it is running
1323 }
1324 }
1325 }
1326 // Resolving an already resolved promise is a noop.
1327 return promise;
1328 }
1329 var REJECTION_HANDLED_HANDLER = __symbol__('rejectionHandledHandler');
1330 function clearRejectedNoCatch(promise) {
1331 if (promise[symbolState] === REJECTED_NO_CATCH) {
1332 // if the promise is rejected no catch status
1333 // and queue.length > 0, means there is a error handler
1334 // here to handle the rejected promise, we should trigger
1335 // windows.rejectionhandled eventHandler or nodejs rejectionHandled
1336 // eventHandler
1337 try {
1338 var handler = Zone[REJECTION_HANDLED_HANDLER];
1339 if (handler && typeof handler === 'function') {
1340 handler.call(this, { rejection: promise[symbolValue], promise: promise });
1341 }
1342 }
1343 catch (err) {
1344 }
1345 promise[symbolState] = REJECTED;
1346 for (var i = 0; i < _uncaughtPromiseErrors.length; i++) {
1347 if (promise === _uncaughtPromiseErrors[i].promise) {
1348 _uncaughtPromiseErrors.splice(i, 1);
1349 }
1350 }
1351 }
1352 }
1353 function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) {
1354 clearRejectedNoCatch(promise);
1355 var promiseState = promise[symbolState];
1356 var delegate = promiseState ?
1357 (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution :
1358 (typeof onRejected === 'function') ? onRejected : forwardRejection;
1359 zone.scheduleMicroTask(source, function () {
1360 try {
1361 var parentPromiseValue = promise[symbolValue];
1362 var isFinallyPromise = !!chainPromise && symbolFinally === chainPromise[symbolFinally];
1363 if (isFinallyPromise) {
1364 // if the promise is generated from finally call, keep parent promise's state and value
1365 chainPromise[symbolParentPromiseValue] = parentPromiseValue;
1366 chainPromise[symbolParentPromiseState] = promiseState;
1367 }
1368 // should not pass value to finally callback
1369 var value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ?
1370 [] :
1371 [parentPromiseValue]);
1372 resolvePromise(chainPromise, true, value);
1373 }
1374 catch (error) {
1375 // if error occurs, should always return this error
1376 resolvePromise(chainPromise, false, error);
1377 }
1378 }, chainPromise);
1379 }
1380 var ZONE_AWARE_PROMISE_TO_STRING = 'function ZoneAwarePromise() { [native code] }';
1381 var noop = function () { };
1382 var ZoneAwarePromise = /** @class */ (function () {
1383 function ZoneAwarePromise(executor) {
1384 var promise = this;
1385 if (!(promise instanceof ZoneAwarePromise)) {
1386 throw new Error('Must be an instanceof Promise.');
1387 }
1388 promise[symbolState] = UNRESOLVED;
1389 promise[symbolValue] = []; // queue;
1390 try {
1391 executor && executor(makeResolver(promise, RESOLVED), makeResolver(promise, REJECTED));
1392 }
1393 catch (error) {
1394 resolvePromise(promise, false, error);
1395 }
1396 }
1397 ZoneAwarePromise.toString = function () {
1398 return ZONE_AWARE_PROMISE_TO_STRING;
1399 };
1400 ZoneAwarePromise.resolve = function (value) {
1401 return resolvePromise(new this(null), RESOLVED, value);
1402 };
1403 ZoneAwarePromise.reject = function (error) {
1404 return resolvePromise(new this(null), REJECTED, error);
1405 };
1406 ZoneAwarePromise.race = function (values) {
1407 var resolve;
1408 var reject;
1409 var promise = new this(function (res, rej) {
1410 resolve = res;
1411 reject = rej;
1412 });
1413 function onResolve(value) {
1414 resolve(value);
1415 }
1416 function onReject(error) {
1417 reject(error);
1418 }
1419 for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
1420 var value = values_1[_i];
1421 if (!isThenable(value)) {
1422 value = this.resolve(value);
1423 }
1424 value.then(onResolve, onReject);
1425 }
1426 return promise;
1427 };
1428 ZoneAwarePromise.all = function (values) {
1429 return ZoneAwarePromise.allWithCallback(values);
1430 };
1431 ZoneAwarePromise.allSettled = function (values) {
1432 var P = this && this.prototype instanceof ZoneAwarePromise ? this : ZoneAwarePromise;
1433 return P.allWithCallback(values, {
1434 thenCallback: function (value) { return ({ status: 'fulfilled', value: value }); },
1435 errorCallback: function (err) { return ({ status: 'rejected', reason: err }); }
1436 });
1437 };
1438 ZoneAwarePromise.allWithCallback = function (values, callback) {
1439 var resolve;
1440 var reject;
1441 var promise = new this(function (res, rej) {
1442 resolve = res;
1443 reject = rej;
1444 });
1445 // Start at 2 to prevent prematurely resolving if .then is called immediately.
1446 var unresolvedCount = 2;
1447 var valueIndex = 0;
1448 var resolvedValues = [];
1449 var _loop_3 = function (value) {
1450 if (!isThenable(value)) {
1451 value = this_1.resolve(value);
1452 }
1453 var curValueIndex = valueIndex;
1454 try {
1455 value.then(function (value) {
1456 resolvedValues[curValueIndex] = callback ? callback.thenCallback(value) : value;
1457 unresolvedCount--;
1458 if (unresolvedCount === 0) {
1459 resolve(resolvedValues);
1460 }
1461 }, function (err) {
1462 if (!callback) {
1463 reject(err);
1464 }
1465 else {
1466 resolvedValues[curValueIndex] = callback.errorCallback(err);
1467 unresolvedCount--;
1468 if (unresolvedCount === 0) {
1469 resolve(resolvedValues);
1470 }
1471 }
1472 });
1473 }
1474 catch (thenErr) {
1475 reject(thenErr);
1476 }
1477 unresolvedCount++;
1478 valueIndex++;
1479 };
1480 var this_1 = this;
1481 for (var _i = 0, values_2 = values; _i < values_2.length; _i++) {
1482 var value = values_2[_i];
1483 _loop_3(value);
1484 }
1485 // Make the unresolvedCount zero-based again.
1486 unresolvedCount -= 2;
1487 if (unresolvedCount === 0) {
1488 resolve(resolvedValues);
1489 }
1490 return promise;
1491 };
1492 Object.defineProperty(ZoneAwarePromise.prototype, Symbol.toStringTag, {
1493 get: function () {
1494 return 'Promise';
1495 },
1496 enumerable: false,
1497 configurable: true
1498 });
1499 Object.defineProperty(ZoneAwarePromise.prototype, Symbol.species, {
1500 get: function () {
1501 return ZoneAwarePromise;
1502 },
1503 enumerable: false,
1504 configurable: true
1505 });
1506 ZoneAwarePromise.prototype.then = function (onFulfilled, onRejected) {
1507 var C = this.constructor[Symbol.species];
1508 if (!C || typeof C !== 'function') {
1509 C = this.constructor || ZoneAwarePromise;
1510 }
1511 var chainPromise = new C(noop);
1512 var zone = Zone.current;
1513 if (this[symbolState] == UNRESOLVED) {
1514 this[symbolValue].push(zone, chainPromise, onFulfilled, onRejected);
1515 }
1516 else {
1517 scheduleResolveOrReject(this, zone, chainPromise, onFulfilled, onRejected);
1518 }
1519 return chainPromise;
1520 };
1521 ZoneAwarePromise.prototype.catch = function (onRejected) {
1522 return this.then(null, onRejected);
1523 };
1524 ZoneAwarePromise.prototype.finally = function (onFinally) {
1525 var C = this.constructor[Symbol.species];
1526 if (!C || typeof C !== 'function') {
1527 C = ZoneAwarePromise;
1528 }
1529 var chainPromise = new C(noop);
1530 chainPromise[symbolFinally] = symbolFinally;
1531 var zone = Zone.current;
1532 if (this[symbolState] == UNRESOLVED) {
1533 this[symbolValue].push(zone, chainPromise, onFinally, onFinally);
1534 }
1535 else {
1536 scheduleResolveOrReject(this, zone, chainPromise, onFinally, onFinally);
1537 }
1538 return chainPromise;
1539 };
1540 return ZoneAwarePromise;
1541 }());
1542 // Protect against aggressive optimizers dropping seemingly unused properties.
1543 // E.g. Closure Compiler in advanced mode.
1544 ZoneAwarePromise['resolve'] = ZoneAwarePromise.resolve;
1545 ZoneAwarePromise['reject'] = ZoneAwarePromise.reject;
1546 ZoneAwarePromise['race'] = ZoneAwarePromise.race;
1547 ZoneAwarePromise['all'] = ZoneAwarePromise.all;
1548 var NativePromise = global[symbolPromise] = global['Promise'];
1549 global['Promise'] = ZoneAwarePromise;
1550 var symbolThenPatched = __symbol__('thenPatched');
1551 function patchThen(Ctor) {
1552 var proto = Ctor.prototype;
1553 var prop = ObjectGetOwnPropertyDescriptor(proto, 'then');
1554 if (prop && (prop.writable === false || !prop.configurable)) {
1555 // check Ctor.prototype.then propertyDescriptor is writable or not
1556 // in meteor env, writable is false, we should ignore such case
1557 return;
1558 }
1559 var originalThen = proto.then;
1560 // Keep a reference to the original method.
1561 proto[symbolThen] = originalThen;
1562 Ctor.prototype.then = function (onResolve, onReject) {
1563 var _this = this;
1564 var wrapped = new ZoneAwarePromise(function (resolve, reject) {
1565 originalThen.call(_this, resolve, reject);
1566 });
1567 return wrapped.then(onResolve, onReject);
1568 };
1569 Ctor[symbolThenPatched] = true;
1570 }
1571 api.patchThen = patchThen;
1572 function zoneify(fn) {
1573 return function (self, args) {
1574 var resultPromise = fn.apply(self, args);
1575 if (resultPromise instanceof ZoneAwarePromise) {
1576 return resultPromise;
1577 }
1578 var ctor = resultPromise.constructor;
1579 if (!ctor[symbolThenPatched]) {
1580 patchThen(ctor);
1581 }
1582 return resultPromise;
1583 };
1584 }
1585 if (NativePromise) {
1586 patchThen(NativePromise);
1587 patchMethod(global, 'fetch', function (delegate) { return zoneify(delegate); });
1588 }
1589 // This is not part of public API, but it is useful for tests, so we expose it.
1590 Promise[Zone.__symbol__('uncaughtPromiseErrors')] = _uncaughtPromiseErrors;
1591 return ZoneAwarePromise;
1592 });
1593 /**
1594 * @license
1595 * Copyright Google LLC All Rights Reserved.
1596 *
1597 * Use of this source code is governed by an MIT-style license that can be
1598 * found in the LICENSE file at https://angular.io/license
1599 */
1600 // override Function.prototype.toString to make zone.js patched function
1601 // look like native function
1602 Zone.__load_patch('toString', function (global) {
1603 // patch Func.prototype.toString to let them look like native
1604 var originalFunctionToString = Function.prototype.toString;
1605 var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate');
1606 var PROMISE_SYMBOL = zoneSymbol('Promise');
1607 var ERROR_SYMBOL = zoneSymbol('Error');
1608 var newFunctionToString = function toString() {
1609 if (typeof this === 'function') {
1610 var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL];
1611 if (originalDelegate) {
1612 if (typeof originalDelegate === 'function') {
1613 return originalFunctionToString.call(originalDelegate);
1614 }
1615 else {
1616 return Object.prototype.toString.call(originalDelegate);
1617 }
1618 }
1619 if (this === Promise) {
1620 var nativePromise = global[PROMISE_SYMBOL];
1621 if (nativePromise) {
1622 return originalFunctionToString.call(nativePromise);
1623 }
1624 }
1625 if (this === Error) {
1626 var nativeError = global[ERROR_SYMBOL];
1627 if (nativeError) {
1628 return originalFunctionToString.call(nativeError);
1629 }
1630 }
1631 }
1632 return originalFunctionToString.call(this);
1633 };
1634 newFunctionToString[ORIGINAL_DELEGATE_SYMBOL] = originalFunctionToString;
1635 Function.prototype.toString = newFunctionToString;
1636 // patch Object.prototype.toString to let them look like native
1637 var originalObjectToString = Object.prototype.toString;
1638 var PROMISE_OBJECT_TO_STRING = '[object Promise]';
1639 Object.prototype.toString = function () {
1640 if (typeof Promise === 'function' && this instanceof Promise) {
1641 return PROMISE_OBJECT_TO_STRING;
1642 }
1643 return originalObjectToString.call(this);
1644 };
1645 });
1646 /**
1647 * @license
1648 * Copyright Google LLC All Rights Reserved.
1649 *
1650 * Use of this source code is governed by an MIT-style license that can be
1651 * found in the LICENSE file at https://angular.io/license
1652 */
1653 var passiveSupported = false;
1654 if (typeof window !== 'undefined') {
1655 try {
1656 var options = Object.defineProperty({}, 'passive', {
1657 get: function () {
1658 passiveSupported = true;
1659 }
1660 });
1661 window.addEventListener('test', options, options);
1662 window.removeEventListener('test', options, options);
1663 }
1664 catch (err) {
1665 passiveSupported = false;
1666 }
1667 }
1668 // an identifier to tell ZoneTask do not create a new invoke closure
1669 var OPTIMIZED_ZONE_EVENT_TASK_DATA = {
1670 useG: true
1671 };
1672 var zoneSymbolEventNames$1 = {};
1673 var globalSources = {};
1674 var EVENT_NAME_SYMBOL_REGX = new RegExp('^' + ZONE_SYMBOL_PREFIX + '(\\w+)(true|false)$');
1675 var IMMEDIATE_PROPAGATION_SYMBOL = zoneSymbol('propagationStopped');
1676 function prepareEventNames(eventName, eventNameToString) {
1677 var falseEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + FALSE_STR;
1678 var trueEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + TRUE_STR;
1679 var symbol = ZONE_SYMBOL_PREFIX + falseEventName;
1680 var symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
1681 zoneSymbolEventNames$1[eventName] = {};
1682 zoneSymbolEventNames$1[eventName][FALSE_STR] = symbol;
1683 zoneSymbolEventNames$1[eventName][TRUE_STR] = symbolCapture;
1684 }
1685 function patchEventTarget(_global, apis, patchOptions) {
1686 var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR;
1687 var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR;
1688 var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners';
1689 var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners';
1690 var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER);
1691 var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':';
1692 var PREPEND_EVENT_LISTENER = 'prependListener';
1693 var PREPEND_EVENT_LISTENER_SOURCE = '.' + PREPEND_EVENT_LISTENER + ':';
1694 var invokeTask = function (task, target, event) {
1695 // for better performance, check isRemoved which is set
1696 // by removeEventListener
1697 if (task.isRemoved) {
1698 return;
1699 }
1700 var delegate = task.callback;
1701 if (typeof delegate === 'object' && delegate.handleEvent) {
1702 // create the bind version of handleEvent when invoke
1703 task.callback = function (event) { return delegate.handleEvent(event); };
1704 task.originalDelegate = delegate;
1705 }
1706 // invoke static task.invoke
1707 task.invoke(task, target, [event]);
1708 var options = task.options;
1709 if (options && typeof options === 'object' && options.once) {
1710 // if options.once is true, after invoke once remove listener here
1711 // only browser need to do this, nodejs eventEmitter will cal removeListener
1712 // inside EventEmitter.once
1713 var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback;
1714 target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options);
1715 }
1716 };
1717 // global shared zoneAwareCallback to handle all event callback with capture = false
1718 var globalZoneAwareCallback = function (event) {
1719 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
1720 // event will be undefined, so we need to use window.event
1721 event = event || _global.event;
1722 if (!event) {
1723 return;
1724 }
1725 // event.target is needed for Samsung TV and SourceBuffer
1726 // || global is needed https://github.com/angular/zone.js/issues/190
1727 var target = this || event.target || _global;
1728 var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]];
1729 if (tasks) {
1730 // invoke all tasks which attached to current target with given event.type and capture = false
1731 // for performance concern, if task.length === 1, just invoke
1732 if (tasks.length === 1) {
1733 invokeTask(tasks[0], target, event);
1734 }
1735 else {
1736 // https://github.com/angular/zone.js/issues/836
1737 // copy the tasks array before invoke, to avoid
1738 // the callback will remove itself or other listener
1739 var copyTasks = tasks.slice();
1740 for (var i = 0; i < copyTasks.length; i++) {
1741 if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
1742 break;
1743 }
1744 invokeTask(copyTasks[i], target, event);
1745 }
1746 }
1747 }
1748 };
1749 // global shared zoneAwareCallback to handle all event callback with capture = true
1750 var globalZoneAwareCaptureCallback = function (event) {
1751 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
1752 // event will be undefined, so we need to use window.event
1753 event = event || _global.event;
1754 if (!event) {
1755 return;
1756 }
1757 // event.target is needed for Samsung TV and SourceBuffer
1758 // || global is needed https://github.com/angular/zone.js/issues/190
1759 var target = this || event.target || _global;
1760 var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]];
1761 if (tasks) {
1762 // invoke all tasks which attached to current target with given event.type and capture = false
1763 // for performance concern, if task.length === 1, just invoke
1764 if (tasks.length === 1) {
1765 invokeTask(tasks[0], target, event);
1766 }
1767 else {
1768 // https://github.com/angular/zone.js/issues/836
1769 // copy the tasks array before invoke, to avoid
1770 // the callback will remove itself or other listener
1771 var copyTasks = tasks.slice();
1772 for (var i = 0; i < copyTasks.length; i++) {
1773 if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
1774 break;
1775 }
1776 invokeTask(copyTasks[i], target, event);
1777 }
1778 }
1779 }
1780 };
1781 function patchEventTargetMethods(obj, patchOptions) {
1782 if (!obj) {
1783 return false;
1784 }
1785 var useGlobalCallback = true;
1786 if (patchOptions && patchOptions.useG !== undefined) {
1787 useGlobalCallback = patchOptions.useG;
1788 }
1789 var validateHandler = patchOptions && patchOptions.vh;
1790 var checkDuplicate = true;
1791 if (patchOptions && patchOptions.chkDup !== undefined) {
1792 checkDuplicate = patchOptions.chkDup;
1793 }
1794 var returnTarget = false;
1795 if (patchOptions && patchOptions.rt !== undefined) {
1796 returnTarget = patchOptions.rt;
1797 }
1798 var proto = obj;
1799 while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) {
1800 proto = ObjectGetPrototypeOf(proto);
1801 }
1802 if (!proto && obj[ADD_EVENT_LISTENER]) {
1803 // somehow we did not find it, but we can see it. This happens on IE for Window properties.
1804 proto = obj;
1805 }
1806 if (!proto) {
1807 return false;
1808 }
1809 if (proto[zoneSymbolAddEventListener]) {
1810 return false;
1811 }
1812 var eventNameToString = patchOptions && patchOptions.eventNameToString;
1813 // a shared global taskData to pass data for scheduleEventTask
1814 // so we do not need to create a new object just for pass some data
1815 var taskData = {};
1816 var nativeAddEventListener = proto[zoneSymbolAddEventListener] = proto[ADD_EVENT_LISTENER];
1817 var nativeRemoveEventListener = proto[zoneSymbol(REMOVE_EVENT_LISTENER)] =
1818 proto[REMOVE_EVENT_LISTENER];
1819 var nativeListeners = proto[zoneSymbol(LISTENERS_EVENT_LISTENER)] =
1820 proto[LISTENERS_EVENT_LISTENER];
1821 var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] =
1822 proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER];
1823 var nativePrependEventListener;
1824 if (patchOptions && patchOptions.prepend) {
1825 nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] =
1826 proto[patchOptions.prepend];
1827 }
1828 /**
1829 * This util function will build an option object with passive option
1830 * to handle all possible input from the user.
1831 */
1832 function buildEventListenerOptions(options, passive) {
1833 if (!passiveSupported && typeof options === 'object' && options) {
1834 // doesn't support passive but user want to pass an object as options.
1835 // this will not work on some old browser, so we just pass a boolean
1836 // as useCapture parameter
1837 return !!options.capture;
1838 }
1839 if (!passiveSupported || !passive) {
1840 return options;
1841 }
1842 if (typeof options === 'boolean') {
1843 return { capture: options, passive: true };
1844 }
1845 if (!options) {
1846 return { passive: true };
1847 }
1848 if (typeof options === 'object' && options.passive !== false) {
1849 return Object.assign(Object.assign({}, options), { passive: true });
1850 }
1851 return options;
1852 }
1853 var customScheduleGlobal = function (task) {
1854 // if there is already a task for the eventName + capture,
1855 // just return, because we use the shared globalZoneAwareCallback here.
1856 if (taskData.isExisting) {
1857 return;
1858 }
1859 return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options);
1860 };
1861 var customCancelGlobal = function (task) {
1862 // if task is not marked as isRemoved, this call is directly
1863 // from Zone.prototype.cancelTask, we should remove the task
1864 // from tasksList of target first
1865 if (!task.isRemoved) {
1866 var symbolEventNames = zoneSymbolEventNames$1[task.eventName];
1867 var symbolEventName = void 0;
1868 if (symbolEventNames) {
1869 symbolEventName = symbolEventNames[task.capture ? TRUE_STR : FALSE_STR];
1870 }
1871 var existingTasks = symbolEventName && task.target[symbolEventName];
1872 if (existingTasks) {
1873 for (var i = 0; i < existingTasks.length; i++) {
1874 var existingTask = existingTasks[i];
1875 if (existingTask === task) {
1876 existingTasks.splice(i, 1);
1877 // set isRemoved to data for faster invokeTask check
1878 task.isRemoved = true;
1879 if (existingTasks.length === 0) {
1880 // all tasks for the eventName + capture have gone,
1881 // remove globalZoneAwareCallback and remove the task cache from target
1882 task.allRemoved = true;
1883 task.target[symbolEventName] = null;
1884 }
1885 break;
1886 }
1887 }
1888 }
1889 }
1890 // if all tasks for the eventName + capture have gone,
1891 // we will really remove the global event callback,
1892 // if not, return
1893 if (!task.allRemoved) {
1894 return;
1895 }
1896 return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options);
1897 };
1898 var customScheduleNonGlobal = function (task) {
1899 return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
1900 };
1901 var customSchedulePrepend = function (task) {
1902 return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
1903 };
1904 var customCancelNonGlobal = function (task) {
1905 return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options);
1906 };
1907 var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal;
1908 var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal;
1909 var compareTaskCallbackVsDelegate = function (task, delegate) {
1910 var typeOfDelegate = typeof delegate;
1911 return (typeOfDelegate === 'function' && task.callback === delegate) ||
1912 (typeOfDelegate === 'object' && task.originalDelegate === delegate);
1913 };
1914 var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate;
1915 var unpatchedEvents = Zone[zoneSymbol('UNPATCHED_EVENTS')];
1916 var passiveEvents = _global[zoneSymbol('PASSIVE_EVENTS')];
1917 var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) {
1918 if (returnTarget === void 0) { returnTarget = false; }
1919 if (prepend === void 0) { prepend = false; }
1920 return function () {
1921 var target = this || _global;
1922 var eventName = arguments[0];
1923 if (patchOptions && patchOptions.transferEventName) {
1924 eventName = patchOptions.transferEventName(eventName);
1925 }
1926 var delegate = arguments[1];
1927 if (!delegate) {
1928 return nativeListener.apply(this, arguments);
1929 }
1930 if (isNode && eventName === 'uncaughtException') {
1931 // don't patch uncaughtException of nodejs to prevent endless loop
1932 return nativeListener.apply(this, arguments);
1933 }
1934 // don't create the bind delegate function for handleEvent
1935 // case here to improve addEventListener performance
1936 // we will create the bind delegate when invoke
1937 var isHandleEvent = false;
1938 if (typeof delegate !== 'function') {
1939 if (!delegate.handleEvent) {
1940 return nativeListener.apply(this, arguments);
1941 }
1942 isHandleEvent = true;
1943 }
1944 if (validateHandler && !validateHandler(nativeListener, delegate, target, arguments)) {
1945 return;
1946 }
1947 var passive = passiveSupported && !!passiveEvents && passiveEvents.indexOf(eventName) !== -1;
1948 var options = buildEventListenerOptions(arguments[2], passive);
1949 if (unpatchedEvents) {
1950 // check upatched list
1951 for (var i = 0; i < unpatchedEvents.length; i++) {
1952 if (eventName === unpatchedEvents[i]) {
1953 if (passive) {
1954 return nativeListener.call(target, eventName, delegate, options);
1955 }
1956 else {
1957 return nativeListener.apply(this, arguments);
1958 }
1959 }
1960 }
1961 }
1962 var capture = !options ? false : typeof options === 'boolean' ? true : options.capture;
1963 var once = options && typeof options === 'object' ? options.once : false;
1964 var zone = Zone.current;
1965 var symbolEventNames = zoneSymbolEventNames$1[eventName];
1966 if (!symbolEventNames) {
1967 prepareEventNames(eventName, eventNameToString);
1968 symbolEventNames = zoneSymbolEventNames$1[eventName];
1969 }
1970 var symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
1971 var existingTasks = target[symbolEventName];
1972 var isExisting = false;
1973 if (existingTasks) {
1974 // already have task registered
1975 isExisting = true;
1976 if (checkDuplicate) {
1977 for (var i = 0; i < existingTasks.length; i++) {
1978 if (compare(existingTasks[i], delegate)) {
1979 // same callback, same capture, same event name, just return
1980 return;
1981 }
1982 }
1983 }
1984 }
1985 else {
1986 existingTasks = target[symbolEventName] = [];
1987 }
1988 var source;
1989 var constructorName = target.constructor['name'];
1990 var targetSource = globalSources[constructorName];
1991 if (targetSource) {
1992 source = targetSource[eventName];
1993 }
1994 if (!source) {
1995 source = constructorName + addSource +
1996 (eventNameToString ? eventNameToString(eventName) : eventName);
1997 }
1998 // do not create a new object as task.data to pass those things
1999 // just use the global shared one
2000 taskData.options = options;
2001 if (once) {
2002 // if addEventListener with once options, we don't pass it to
2003 // native addEventListener, instead we keep the once setting
2004 // and handle ourselves.
2005 taskData.options.once = false;
2006 }
2007 taskData.target = target;
2008 taskData.capture = capture;
2009 taskData.eventName = eventName;
2010 taskData.isExisting = isExisting;
2011 var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : undefined;
2012 // keep taskData into data to allow onScheduleEventTask to access the task information
2013 if (data) {
2014 data.taskData = taskData;
2015 }
2016 var task = zone.scheduleEventTask(source, delegate, data, customScheduleFn, customCancelFn);
2017 // should clear taskData.target to avoid memory leak
2018 // issue, https://github.com/angular/angular/issues/20442
2019 taskData.target = null;
2020 // need to clear up taskData because it is a global object
2021 if (data) {
2022 data.taskData = null;
2023 }
2024 // have to save those information to task in case
2025 // application may call task.zone.cancelTask() directly
2026 if (once) {
2027 options.once = true;
2028 }
2029 if (!(!passiveSupported && typeof task.options === 'boolean')) {
2030 // if not support passive, and we pass an option object
2031 // to addEventListener, we should save the options to task
2032 task.options = options;
2033 }
2034 task.target = target;
2035 task.capture = capture;
2036 task.eventName = eventName;
2037 if (isHandleEvent) {
2038 // save original delegate for compare to check duplicate
2039 task.originalDelegate = delegate;
2040 }
2041 if (!prepend) {
2042 existingTasks.push(task);
2043 }
2044 else {
2045 existingTasks.unshift(task);
2046 }
2047 if (returnTarget) {
2048 return target;
2049 }
2050 };
2051 };
2052 proto[ADD_EVENT_LISTENER] = makeAddListener(nativeAddEventListener, ADD_EVENT_LISTENER_SOURCE, customSchedule, customCancel, returnTarget);
2053 if (nativePrependEventListener) {
2054 proto[PREPEND_EVENT_LISTENER] = makeAddListener(nativePrependEventListener, PREPEND_EVENT_LISTENER_SOURCE, customSchedulePrepend, customCancel, returnTarget, true);
2055 }
2056 proto[REMOVE_EVENT_LISTENER] = function () {
2057 var target = this || _global;
2058 var eventName = arguments[0];
2059 if (patchOptions && patchOptions.transferEventName) {
2060 eventName = patchOptions.transferEventName(eventName);
2061 }
2062 var options = arguments[2];
2063 var capture = !options ? false : typeof options === 'boolean' ? true : options.capture;
2064 var delegate = arguments[1];
2065 if (!delegate) {
2066 return nativeRemoveEventListener.apply(this, arguments);
2067 }
2068 if (validateHandler &&
2069 !validateHandler(nativeRemoveEventListener, delegate, target, arguments)) {
2070 return;
2071 }
2072 var symbolEventNames = zoneSymbolEventNames$1[eventName];
2073 var symbolEventName;
2074 if (symbolEventNames) {
2075 symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
2076 }
2077 var existingTasks = symbolEventName && target[symbolEventName];
2078 if (existingTasks) {
2079 for (var i = 0; i < existingTasks.length; i++) {
2080 var existingTask = existingTasks[i];
2081 if (compare(existingTask, delegate)) {
2082 existingTasks.splice(i, 1);
2083 // set isRemoved to data for faster invokeTask check
2084 existingTask.isRemoved = true;
2085 if (existingTasks.length === 0) {
2086 // all tasks for the eventName + capture have gone,
2087 // remove globalZoneAwareCallback and remove the task cache from target
2088 existingTask.allRemoved = true;
2089 target[symbolEventName] = null;
2090 // in the target, we have an event listener which is added by on_property
2091 // such as target.onclick = function() {}, so we need to clear this internal
2092 // property too if all delegates all removed
2093 if (typeof eventName === 'string') {
2094 var onPropertySymbol = ZONE_SYMBOL_PREFIX + 'ON_PROPERTY' + eventName;
2095 target[onPropertySymbol] = null;
2096 }
2097 }
2098 existingTask.zone.cancelTask(existingTask);
2099 if (returnTarget) {
2100 return target;
2101 }
2102 return;
2103 }
2104 }
2105 }
2106 // issue 930, didn't find the event name or callback
2107 // from zone kept existingTasks, the callback maybe
2108 // added outside of zone, we need to call native removeEventListener
2109 // to try to remove it.
2110 return nativeRemoveEventListener.apply(this, arguments);
2111 };
2112 proto[LISTENERS_EVENT_LISTENER] = function () {
2113 var target = this || _global;
2114 var eventName = arguments[0];
2115 if (patchOptions && patchOptions.transferEventName) {
2116 eventName = patchOptions.transferEventName(eventName);
2117 }
2118 var listeners = [];
2119 var tasks = findEventTasks(target, eventNameToString ? eventNameToString(eventName) : eventName);
2120 for (var i = 0; i < tasks.length; i++) {
2121 var task = tasks[i];
2122 var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2123 listeners.push(delegate);
2124 }
2125 return listeners;
2126 };
2127 proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER] = function () {
2128 var target = this || _global;
2129 var eventName = arguments[0];
2130 if (!eventName) {
2131 var keys = Object.keys(target);
2132 for (var i = 0; i < keys.length; i++) {
2133 var prop = keys[i];
2134 var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
2135 var evtName = match && match[1];
2136 // in nodejs EventEmitter, removeListener event is
2137 // used for monitoring the removeListener call,
2138 // so just keep removeListener eventListener until
2139 // all other eventListeners are removed
2140 if (evtName && evtName !== 'removeListener') {
2141 this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName);
2142 }
2143 }
2144 // remove removeListener listener finally
2145 this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener');
2146 }
2147 else {
2148 if (patchOptions && patchOptions.transferEventName) {
2149 eventName = patchOptions.transferEventName(eventName);
2150 }
2151 var symbolEventNames = zoneSymbolEventNames$1[eventName];
2152 if (symbolEventNames) {
2153 var symbolEventName = symbolEventNames[FALSE_STR];
2154 var symbolCaptureEventName = symbolEventNames[TRUE_STR];
2155 var tasks = target[symbolEventName];
2156 var captureTasks = target[symbolCaptureEventName];
2157 if (tasks) {
2158 var removeTasks = tasks.slice();
2159 for (var i = 0; i < removeTasks.length; i++) {
2160 var task = removeTasks[i];
2161 var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2162 this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
2163 }
2164 }
2165 if (captureTasks) {
2166 var removeTasks = captureTasks.slice();
2167 for (var i = 0; i < removeTasks.length; i++) {
2168 var task = removeTasks[i];
2169 var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2170 this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
2171 }
2172 }
2173 }
2174 }
2175 if (returnTarget) {
2176 return this;
2177 }
2178 };
2179 // for native toString patch
2180 attachOriginToPatched(proto[ADD_EVENT_LISTENER], nativeAddEventListener);
2181 attachOriginToPatched(proto[REMOVE_EVENT_LISTENER], nativeRemoveEventListener);
2182 if (nativeRemoveAllListeners) {
2183 attachOriginToPatched(proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER], nativeRemoveAllListeners);
2184 }
2185 if (nativeListeners) {
2186 attachOriginToPatched(proto[LISTENERS_EVENT_LISTENER], nativeListeners);
2187 }
2188 return true;
2189 }
2190 var results = [];
2191 for (var i = 0; i < apis.length; i++) {
2192 results[i] = patchEventTargetMethods(apis[i], patchOptions);
2193 }
2194 return results;
2195 }
2196 function findEventTasks(target, eventName) {
2197 if (!eventName) {
2198 var foundTasks = [];
2199 for (var prop in target) {
2200 var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
2201 var evtName = match && match[1];
2202 if (evtName && (!eventName || evtName === eventName)) {
2203 var tasks = target[prop];
2204 if (tasks) {
2205 for (var i = 0; i < tasks.length; i++) {
2206 foundTasks.push(tasks[i]);
2207 }
2208 }
2209 }
2210 }
2211 return foundTasks;
2212 }
2213 var symbolEventName = zoneSymbolEventNames$1[eventName];
2214 if (!symbolEventName) {
2215 prepareEventNames(eventName);
2216 symbolEventName = zoneSymbolEventNames$1[eventName];
2217 }
2218 var captureFalseTasks = target[symbolEventName[FALSE_STR]];
2219 var captureTrueTasks = target[symbolEventName[TRUE_STR]];
2220 if (!captureFalseTasks) {
2221 return captureTrueTasks ? captureTrueTasks.slice() : [];
2222 }
2223 else {
2224 return captureTrueTasks ? captureFalseTasks.concat(captureTrueTasks) :
2225 captureFalseTasks.slice();
2226 }
2227 }
2228 function patchEventPrototype(global, api) {
2229 var Event = global['Event'];
2230 if (Event && Event.prototype) {
2231 api.patchMethod(Event.prototype, 'stopImmediatePropagation', function (delegate) { return function (self, args) {
2232 self[IMMEDIATE_PROPAGATION_SYMBOL] = true;
2233 // we need to call the native stopImmediatePropagation
2234 // in case in some hybrid application, some part of
2235 // application will be controlled by zone, some are not
2236 delegate && delegate.apply(self, args);
2237 }; });
2238 }
2239 }
2240 /**
2241 * @license
2242 * Copyright Google LLC All Rights Reserved.
2243 *
2244 * Use of this source code is governed by an MIT-style license that can be
2245 * found in the LICENSE file at https://angular.io/license
2246 */
2247 function patchCallbacks(api, target, targetName, method, callbacks) {
2248 var symbol = Zone.__symbol__(method);
2249 if (target[symbol]) {
2250 return;
2251 }
2252 var nativeDelegate = target[symbol] = target[method];
2253 target[method] = function (name, opts, options) {
2254 if (opts && opts.prototype) {
2255 callbacks.forEach(function (callback) {
2256 var source = targetName + "." + method + "::" + callback;
2257 var prototype = opts.prototype;
2258 if (prototype.hasOwnProperty(callback)) {
2259 var descriptor = api.ObjectGetOwnPropertyDescriptor(prototype, callback);
2260 if (descriptor && descriptor.value) {
2261 descriptor.value = api.wrapWithCurrentZone(descriptor.value, source);
2262 api._redefineProperty(opts.prototype, callback, descriptor);
2263 }
2264 else if (prototype[callback]) {
2265 prototype[callback] = api.wrapWithCurrentZone(prototype[callback], source);
2266 }
2267 }
2268 else if (prototype[callback]) {
2269 prototype[callback] = api.wrapWithCurrentZone(prototype[callback], source);
2270 }
2271 });
2272 }
2273 return nativeDelegate.call(target, name, opts, options);
2274 };
2275 api.attachOriginToPatched(target[method], nativeDelegate);
2276 }
2277 /**
2278 * @license
2279 * Copyright Google LLC All Rights Reserved.
2280 *
2281 * Use of this source code is governed by an MIT-style license that can be
2282 * found in the LICENSE file at https://angular.io/license
2283 */
2284 var globalEventHandlersEventNames = [
2285 'abort',
2286 'animationcancel',
2287 'animationend',
2288 'animationiteration',
2289 'auxclick',
2290 'beforeinput',
2291 'blur',
2292 'cancel',
2293 'canplay',
2294 'canplaythrough',
2295 'change',
2296 'compositionstart',
2297 'compositionupdate',
2298 'compositionend',
2299 'cuechange',
2300 'click',
2301 'close',
2302 'contextmenu',
2303 'curechange',
2304 'dblclick',
2305 'drag',
2306 'dragend',
2307 'dragenter',
2308 'dragexit',
2309 'dragleave',
2310 'dragover',
2311 'drop',
2312 'durationchange',
2313 'emptied',
2314 'ended',
2315 'error',
2316 'focus',
2317 'focusin',
2318 'focusout',
2319 'gotpointercapture',
2320 'input',
2321 'invalid',
2322 'keydown',
2323 'keypress',
2324 'keyup',
2325 'load',
2326 'loadstart',
2327 'loadeddata',
2328 'loadedmetadata',
2329 'lostpointercapture',
2330 'mousedown',
2331 'mouseenter',
2332 'mouseleave',
2333 'mousemove',
2334 'mouseout',
2335 'mouseover',
2336 'mouseup',
2337 'mousewheel',
2338 'orientationchange',
2339 'pause',
2340 'play',
2341 'playing',
2342 'pointercancel',
2343 'pointerdown',
2344 'pointerenter',
2345 'pointerleave',
2346 'pointerlockchange',
2347 'mozpointerlockchange',
2348 'webkitpointerlockerchange',
2349 'pointerlockerror',
2350 'mozpointerlockerror',
2351 'webkitpointerlockerror',
2352 'pointermove',
2353 'pointout',
2354 'pointerover',
2355 'pointerup',
2356 'progress',
2357 'ratechange',
2358 'reset',
2359 'resize',
2360 'scroll',
2361 'seeked',
2362 'seeking',
2363 'select',
2364 'selectionchange',
2365 'selectstart',
2366 'show',
2367 'sort',
2368 'stalled',
2369 'submit',
2370 'suspend',
2371 'timeupdate',
2372 'volumechange',
2373 'touchcancel',
2374 'touchmove',
2375 'touchstart',
2376 'touchend',
2377 'transitioncancel',
2378 'transitionend',
2379 'waiting',
2380 'wheel'
2381 ];
2382 var documentEventNames = [
2383 'afterscriptexecute', 'beforescriptexecute', 'DOMContentLoaded', 'freeze', 'fullscreenchange',
2384 'mozfullscreenchange', 'webkitfullscreenchange', 'msfullscreenchange', 'fullscreenerror',
2385 'mozfullscreenerror', 'webkitfullscreenerror', 'msfullscreenerror', 'readystatechange',
2386 'visibilitychange', 'resume'
2387 ];
2388 var windowEventNames = [
2389 'absolutedeviceorientation',
2390 'afterinput',
2391 'afterprint',
2392 'appinstalled',
2393 'beforeinstallprompt',
2394 'beforeprint',
2395 'beforeunload',
2396 'devicelight',
2397 'devicemotion',
2398 'deviceorientation',
2399 'deviceorientationabsolute',
2400 'deviceproximity',
2401 'hashchange',
2402 'languagechange',
2403 'message',
2404 'mozbeforepaint',
2405 'offline',
2406 'online',
2407 'paint',
2408 'pageshow',
2409 'pagehide',
2410 'popstate',
2411 'rejectionhandled',
2412 'storage',
2413 'unhandledrejection',
2414 'unload',
2415 'userproximity',
2416 'vrdisplayconnected',
2417 'vrdisplaydisconnected',
2418 'vrdisplaypresentchange'
2419 ];
2420 var htmlElementEventNames = [
2421 'beforecopy', 'beforecut', 'beforepaste', 'copy', 'cut', 'paste', 'dragstart', 'loadend',
2422 'animationstart', 'search', 'transitionrun', 'transitionstart', 'webkitanimationend',
2423 'webkitanimationiteration', 'webkitanimationstart', 'webkittransitionend'
2424 ];
2425 var mediaElementEventNames = ['encrypted', 'waitingforkey', 'msneedkey', 'mozinterruptbegin', 'mozinterruptend'];
2426 var ieElementEventNames = [
2427 'activate',
2428 'afterupdate',
2429 'ariarequest',
2430 'beforeactivate',
2431 'beforedeactivate',
2432 'beforeeditfocus',
2433 'beforeupdate',
2434 'cellchange',
2435 'controlselect',
2436 'dataavailable',
2437 'datasetchanged',
2438 'datasetcomplete',
2439 'errorupdate',
2440 'filterchange',
2441 'layoutcomplete',
2442 'losecapture',
2443 'move',
2444 'moveend',
2445 'movestart',
2446 'propertychange',
2447 'resizeend',
2448 'resizestart',
2449 'rowenter',
2450 'rowexit',
2451 'rowsdelete',
2452 'rowsinserted',
2453 'command',
2454 'compassneedscalibration',
2455 'deactivate',
2456 'help',
2457 'mscontentzoom',
2458 'msmanipulationstatechanged',
2459 'msgesturechange',
2460 'msgesturedoubletap',
2461 'msgestureend',
2462 'msgesturehold',
2463 'msgesturestart',
2464 'msgesturetap',
2465 'msgotpointercapture',
2466 'msinertiastart',
2467 'mslostpointercapture',
2468 'mspointercancel',
2469 'mspointerdown',
2470 'mspointerenter',
2471 'mspointerhover',
2472 'mspointerleave',
2473 'mspointermove',
2474 'mspointerout',
2475 'mspointerover',
2476 'mspointerup',
2477 'pointerout',
2478 'mssitemodejumplistitemremoved',
2479 'msthumbnailclick',
2480 'stop',
2481 'storagecommit'
2482 ];
2483 var webglEventNames = ['webglcontextrestored', 'webglcontextlost', 'webglcontextcreationerror'];
2484 var formEventNames = ['autocomplete', 'autocompleteerror'];
2485 var detailEventNames = ['toggle'];
2486 var frameEventNames = ['load'];
2487 var frameSetEventNames = ['blur', 'error', 'focus', 'load', 'resize', 'scroll', 'messageerror'];
2488 var marqueeEventNames = ['bounce', 'finish', 'start'];
2489 var XMLHttpRequestEventNames = [
2490 'loadstart', 'progress', 'abort', 'error', 'load', 'progress', 'timeout', 'loadend',
2491 'readystatechange'
2492 ];
2493 var IDBIndexEventNames = ['upgradeneeded', 'complete', 'abort', 'success', 'error', 'blocked', 'versionchange', 'close'];
2494 var websocketEventNames = ['close', 'error', 'open', 'message'];
2495 var workerEventNames = ['error', 'message'];
2496 var eventNames = globalEventHandlersEventNames.concat(webglEventNames, formEventNames, detailEventNames, documentEventNames, windowEventNames, htmlElementEventNames, ieElementEventNames);
2497 function filterProperties(target, onProperties, ignoreProperties) {
2498 if (!ignoreProperties || ignoreProperties.length === 0) {
2499 return onProperties;
2500 }
2501 var tip = ignoreProperties.filter(function (ip) { return ip.target === target; });
2502 if (!tip || tip.length === 0) {
2503 return onProperties;
2504 }
2505 var targetIgnoreProperties = tip[0].ignoreProperties;
2506 return onProperties.filter(function (op) { return targetIgnoreProperties.indexOf(op) === -1; });
2507 }
2508 function patchFilteredProperties(target, onProperties, ignoreProperties, prototype) {
2509 // check whether target is available, sometimes target will be undefined
2510 // because different browser or some 3rd party plugin.
2511 if (!target) {
2512 return;
2513 }
2514 var filteredProperties = filterProperties(target, onProperties, ignoreProperties);
2515 patchOnProperties(target, filteredProperties, prototype);
2516 }
2517 function propertyDescriptorPatch(api, _global) {
2518 if (isNode && !isMix) {
2519 return;
2520 }
2521 if (Zone[api.symbol('patchEvents')]) {
2522 // events are already been patched by legacy patch.
2523 return;
2524 }
2525 var supportsWebSocket = typeof WebSocket !== 'undefined';
2526 var ignoreProperties = _global['__Zone_ignore_on_properties'];
2527 // for browsers that we can patch the descriptor: Chrome & Firefox
2528 if (isBrowser) {
2529 var internalWindow_1 = window;
2530 var ignoreErrorProperties = isIE() ? [{ target: internalWindow_1, ignoreProperties: ['error'] }] : [];
2531 // in IE/Edge, onProp not exist in window object, but in WindowPrototype
2532 // so we need to pass WindowPrototype to check onProp exist or not
2533 patchFilteredProperties(internalWindow_1, eventNames.concat(['messageerror']), ignoreProperties ? ignoreProperties.concat(ignoreErrorProperties) : ignoreProperties, ObjectGetPrototypeOf(internalWindow_1));
2534 patchFilteredProperties(Document.prototype, eventNames, ignoreProperties);
2535 if (typeof internalWindow_1['SVGElement'] !== 'undefined') {
2536 patchFilteredProperties(internalWindow_1['SVGElement'].prototype, eventNames, ignoreProperties);
2537 }
2538 patchFilteredProperties(Element.prototype, eventNames, ignoreProperties);
2539 patchFilteredProperties(HTMLElement.prototype, eventNames, ignoreProperties);
2540 patchFilteredProperties(HTMLMediaElement.prototype, mediaElementEventNames, ignoreProperties);
2541 patchFilteredProperties(HTMLFrameSetElement.prototype, windowEventNames.concat(frameSetEventNames), ignoreProperties);
2542 patchFilteredProperties(HTMLBodyElement.prototype, windowEventNames.concat(frameSetEventNames), ignoreProperties);
2543 patchFilteredProperties(HTMLFrameElement.prototype, frameEventNames, ignoreProperties);
2544 patchFilteredProperties(HTMLIFrameElement.prototype, frameEventNames, ignoreProperties);
2545 var HTMLMarqueeElement_1 = internalWindow_1['HTMLMarqueeElement'];
2546 if (HTMLMarqueeElement_1) {
2547 patchFilteredProperties(HTMLMarqueeElement_1.prototype, marqueeEventNames, ignoreProperties);
2548 }
2549 var Worker_1 = internalWindow_1['Worker'];
2550 if (Worker_1) {
2551 patchFilteredProperties(Worker_1.prototype, workerEventNames, ignoreProperties);
2552 }
2553 }
2554 var XMLHttpRequest = _global['XMLHttpRequest'];
2555 if (XMLHttpRequest) {
2556 // XMLHttpRequest is not available in ServiceWorker, so we need to check here
2557 patchFilteredProperties(XMLHttpRequest.prototype, XMLHttpRequestEventNames, ignoreProperties);
2558 }
2559 var XMLHttpRequestEventTarget = _global['XMLHttpRequestEventTarget'];
2560 if (XMLHttpRequestEventTarget) {
2561 patchFilteredProperties(XMLHttpRequestEventTarget && XMLHttpRequestEventTarget.prototype, XMLHttpRequestEventNames, ignoreProperties);
2562 }
2563 if (typeof IDBIndex !== 'undefined') {
2564 patchFilteredProperties(IDBIndex.prototype, IDBIndexEventNames, ignoreProperties);
2565 patchFilteredProperties(IDBRequest.prototype, IDBIndexEventNames, ignoreProperties);
2566 patchFilteredProperties(IDBOpenDBRequest.prototype, IDBIndexEventNames, ignoreProperties);
2567 patchFilteredProperties(IDBDatabase.prototype, IDBIndexEventNames, ignoreProperties);
2568 patchFilteredProperties(IDBTransaction.prototype, IDBIndexEventNames, ignoreProperties);
2569 patchFilteredProperties(IDBCursor.prototype, IDBIndexEventNames, ignoreProperties);
2570 }
2571 if (supportsWebSocket) {
2572 patchFilteredProperties(WebSocket.prototype, websocketEventNames, ignoreProperties);
2573 }
2574 }
2575 /**
2576 * @license
2577 * Copyright Google LLC All Rights Reserved.
2578 *
2579 * Use of this source code is governed by an MIT-style license that can be
2580 * found in the LICENSE file at https://angular.io/license
2581 */
2582 Zone.__load_patch('util', function (global, Zone, api) {
2583 api.patchOnProperties = patchOnProperties;
2584 api.patchMethod = patchMethod;
2585 api.bindArguments = bindArguments;
2586 api.patchMacroTask = patchMacroTask;
2587 // In earlier version of zone.js (<0.9.0), we use env name `__zone_symbol__BLACK_LISTED_EVENTS` to
2588 // define which events will not be patched by `Zone.js`.
2589 // In newer version (>=0.9.0), we change the env name to `__zone_symbol__UNPATCHED_EVENTS` to keep
2590 // the name consistent with angular repo.
2591 // The `__zone_symbol__BLACK_LISTED_EVENTS` is deprecated, but it is still be supported for
2592 // backwards compatibility.
2593 var SYMBOL_BLACK_LISTED_EVENTS = Zone.__symbol__('BLACK_LISTED_EVENTS');
2594 var SYMBOL_UNPATCHED_EVENTS = Zone.__symbol__('UNPATCHED_EVENTS');
2595 if (global[SYMBOL_UNPATCHED_EVENTS]) {
2596 global[SYMBOL_BLACK_LISTED_EVENTS] = global[SYMBOL_UNPATCHED_EVENTS];
2597 }
2598 if (global[SYMBOL_BLACK_LISTED_EVENTS]) {
2599 Zone[SYMBOL_BLACK_LISTED_EVENTS] = Zone[SYMBOL_UNPATCHED_EVENTS] =
2600 global[SYMBOL_BLACK_LISTED_EVENTS];
2601 }
2602 api.patchEventPrototype = patchEventPrototype;
2603 api.patchEventTarget = patchEventTarget;
2604 api.isIEOrEdge = isIEOrEdge;
2605 api.ObjectDefineProperty = ObjectDefineProperty;
2606 api.ObjectGetOwnPropertyDescriptor = ObjectGetOwnPropertyDescriptor;
2607 api.ObjectCreate = ObjectCreate;
2608 api.ArraySlice = ArraySlice;
2609 api.patchClass = patchClass;
2610 api.wrapWithCurrentZone = wrapWithCurrentZone;
2611 api.filterProperties = filterProperties;
2612 api.attachOriginToPatched = attachOriginToPatched;
2613 api._redefineProperty = Object.defineProperty;
2614 api.patchCallbacks = patchCallbacks;
2615 api.getGlobalObjects = function () { return ({
2616 globalSources: globalSources,
2617 zoneSymbolEventNames: zoneSymbolEventNames$1,
2618 eventNames: eventNames,
2619 isBrowser: isBrowser,
2620 isMix: isMix,
2621 isNode: isNode,
2622 TRUE_STR: TRUE_STR,
2623 FALSE_STR: FALSE_STR,
2624 ZONE_SYMBOL_PREFIX: ZONE_SYMBOL_PREFIX,
2625 ADD_EVENT_LISTENER_STR: ADD_EVENT_LISTENER_STR,
2626 REMOVE_EVENT_LISTENER_STR: REMOVE_EVENT_LISTENER_STR
2627 }); };
2628 });
2629 /**
2630 * @license
2631 * Copyright Google LLC All Rights Reserved.
2632 *
2633 * Use of this source code is governed by an MIT-style license that can be
2634 * found in the LICENSE file at https://angular.io/license
2635 */
2636 var taskSymbol = zoneSymbol('zoneTask');
2637 function patchTimer(window, setName, cancelName, nameSuffix) {
2638 var setNative = null;
2639 var clearNative = null;
2640 setName += nameSuffix;
2641 cancelName += nameSuffix;
2642 var tasksByHandleId = {};
2643 function scheduleTask(task) {
2644 var data = task.data;
2645 data.args[0] = function () {
2646 return task.invoke.apply(this, arguments);
2647 };
2648 data.handleId = setNative.apply(window, data.args);
2649 return task;
2650 }
2651 function clearTask(task) {
2652 return clearNative.call(window, task.data.handleId);
2653 }
2654 setNative =
2655 patchMethod(window, setName, function (delegate) { return function (self, args) {
2656 if (typeof args[0] === 'function') {
2657 var options_1 = {
2658 isPeriodic: nameSuffix === 'Interval',
2659 delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 :
2660 undefined,
2661 args: args
2662 };
2663 var callback_1 = args[0];
2664 args[0] = function timer() {
2665 try {
2666 return callback_1.apply(this, arguments);
2667 }
2668 finally {
2669 // issue-934, task will be cancelled
2670 // even it is a periodic task such as
2671 // setInterval
2672 // https://github.com/angular/angular/issues/40387
2673 // Cleanup tasksByHandleId should be handled before scheduleTask
2674 // Since some zoneSpec may intercept and doesn't trigger
2675 // scheduleFn(scheduleTask) provided here.
2676 if (!(options_1.isPeriodic)) {
2677 if (typeof options_1.handleId === 'number') {
2678 // in non-nodejs env, we remove timerId
2679 // from local cache
2680 delete tasksByHandleId[options_1.handleId];
2681 }
2682 else if (options_1.handleId) {
2683 // Node returns complex objects as handleIds
2684 // we remove task reference from timer object
2685 options_1.handleId[taskSymbol] = null;
2686 }
2687 }
2688 }
2689 };
2690 var task = scheduleMacroTaskWithCurrentZone(setName, args[0], options_1, scheduleTask, clearTask);
2691 if (!task) {
2692 return task;
2693 }
2694 // Node.js must additionally support the ref and unref functions.
2695 var handle = task.data.handleId;
2696 if (typeof handle === 'number') {
2697 // for non nodejs env, we save handleId: task
2698 // mapping in local cache for clearTimeout
2699 tasksByHandleId[handle] = task;
2700 }
2701 else if (handle) {
2702 // for nodejs env, we save task
2703 // reference in timerId Object for clearTimeout
2704 handle[taskSymbol] = task;
2705 }
2706 // check whether handle is null, because some polyfill or browser
2707 // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame
2708 if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' &&
2709 typeof handle.unref === 'function') {
2710 task.ref = handle.ref.bind(handle);
2711 task.unref = handle.unref.bind(handle);
2712 }
2713 if (typeof handle === 'number' || handle) {
2714 return handle;
2715 }
2716 return task;
2717 }
2718 else {
2719 // cause an error by calling it directly.
2720 return delegate.apply(window, args);
2721 }
2722 }; });
2723 clearNative =
2724 patchMethod(window, cancelName, function (delegate) { return function (self, args) {
2725 var id = args[0];
2726 var task;
2727 if (typeof id === 'number') {
2728 // non nodejs env.
2729 task = tasksByHandleId[id];
2730 }
2731 else {
2732 // nodejs env.
2733 task = id && id[taskSymbol];
2734 // other environments.
2735 if (!task) {
2736 task = id;
2737 }
2738 }
2739 if (task && typeof task.type === 'string') {
2740 if (task.state !== 'notScheduled' &&
2741 (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) {
2742 if (typeof id === 'number') {
2743 delete tasksByHandleId[id];
2744 }
2745 else if (id) {
2746 id[taskSymbol] = null;
2747 }
2748 // Do not cancel already canceled functions
2749 task.zone.cancelTask(task);
2750 }
2751 }
2752 else {
2753 // cause an error by calling it directly.
2754 delegate.apply(window, args);
2755 }
2756 }; });
2757 }
2758 /**
2759 * @license
2760 * Copyright Google LLC All Rights Reserved.
2761 *
2762 * Use of this source code is governed by an MIT-style license that can be
2763 * found in the LICENSE file at https://angular.io/license
2764 */
2765 function patchCustomElements(_global, api) {
2766 var _a = api.getGlobalObjects(), isBrowser = _a.isBrowser, isMix = _a.isMix;
2767 if ((!isBrowser && !isMix) || !_global['customElements'] || !('customElements' in _global)) {
2768 return;
2769 }
2770 var callbacks = ['connectedCallback', 'disconnectedCallback', 'adoptedCallback', 'attributeChangedCallback'];
2771 api.patchCallbacks(api, _global.customElements, 'customElements', 'define', callbacks);
2772 }
2773 /**
2774 * @license
2775 * Copyright Google LLC All Rights Reserved.
2776 *
2777 * Use of this source code is governed by an MIT-style license that can be
2778 * found in the LICENSE file at https://angular.io/license
2779 */
2780 function eventTargetPatch(_global, api) {
2781 if (Zone[api.symbol('patchEventTarget')]) {
2782 // EventTarget is already patched.
2783 return;
2784 }
2785 var _a = api.getGlobalObjects(), eventNames = _a.eventNames, zoneSymbolEventNames = _a.zoneSymbolEventNames, TRUE_STR = _a.TRUE_STR, FALSE_STR = _a.FALSE_STR, ZONE_SYMBOL_PREFIX = _a.ZONE_SYMBOL_PREFIX;
2786 // predefine all __zone_symbol__ + eventName + true/false string
2787 for (var i = 0; i < eventNames.length; i++) {
2788 var eventName = eventNames[i];
2789 var falseEventName = eventName + FALSE_STR;
2790 var trueEventName = eventName + TRUE_STR;
2791 var symbol = ZONE_SYMBOL_PREFIX + falseEventName;
2792 var symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
2793 zoneSymbolEventNames[eventName] = {};
2794 zoneSymbolEventNames[eventName][FALSE_STR] = symbol;
2795 zoneSymbolEventNames[eventName][TRUE_STR] = symbolCapture;
2796 }
2797 var EVENT_TARGET = _global['EventTarget'];
2798 if (!EVENT_TARGET || !EVENT_TARGET.prototype) {
2799 return;
2800 }
2801 api.patchEventTarget(_global, [EVENT_TARGET && EVENT_TARGET.prototype]);
2802 return true;
2803 }
2804 function patchEvent(global, api) {
2805 api.patchEventPrototype(global, api);
2806 }
2807 /**
2808 * @license
2809 * Copyright Google LLC All Rights Reserved.
2810 *
2811 * Use of this source code is governed by an MIT-style license that can be
2812 * found in the LICENSE file at https://angular.io/license
2813 */
2814 Zone.__load_patch('legacy', function (global) {
2815 var legacyPatch = global[Zone.__symbol__('legacyPatch')];
2816 if (legacyPatch) {
2817 legacyPatch();
2818 }
2819 });
2820 Zone.__load_patch('queueMicrotask', function (global, Zone, api) {
2821 api.patchMethod(global, 'queueMicrotask', function (delegate) {
2822 return function (self, args) {
2823 Zone.current.scheduleMicroTask('queueMicrotask', args[0]);
2824 };
2825 });
2826 });
2827 Zone.__load_patch('timers', function (global) {
2828 var set = 'set';
2829 var clear = 'clear';
2830 patchTimer(global, set, clear, 'Timeout');
2831 patchTimer(global, set, clear, 'Interval');
2832 patchTimer(global, set, clear, 'Immediate');
2833 });
2834 Zone.__load_patch('requestAnimationFrame', function (global) {
2835 patchTimer(global, 'request', 'cancel', 'AnimationFrame');
2836 patchTimer(global, 'mozRequest', 'mozCancel', 'AnimationFrame');
2837 patchTimer(global, 'webkitRequest', 'webkitCancel', 'AnimationFrame');
2838 });
2839 Zone.__load_patch('blocking', function (global, Zone) {
2840 var blockingMethods = ['alert', 'prompt', 'confirm'];
2841 for (var i = 0; i < blockingMethods.length; i++) {
2842 var name_2 = blockingMethods[i];
2843 patchMethod(global, name_2, function (delegate, symbol, name) {
2844 return function (s, args) {
2845 return Zone.current.run(delegate, global, args, name);
2846 };
2847 });
2848 }
2849 });
2850 Zone.__load_patch('EventTarget', function (global, Zone, api) {
2851 patchEvent(global, api);
2852 eventTargetPatch(global, api);
2853 // patch XMLHttpRequestEventTarget's addEventListener/removeEventListener
2854 var XMLHttpRequestEventTarget = global['XMLHttpRequestEventTarget'];
2855 if (XMLHttpRequestEventTarget && XMLHttpRequestEventTarget.prototype) {
2856 api.patchEventTarget(global, [XMLHttpRequestEventTarget.prototype]);
2857 }
2858 });
2859 Zone.__load_patch('MutationObserver', function (global, Zone, api) {
2860 patchClass('MutationObserver');
2861 patchClass('WebKitMutationObserver');
2862 });
2863 Zone.__load_patch('IntersectionObserver', function (global, Zone, api) {
2864 patchClass('IntersectionObserver');
2865 });
2866 Zone.__load_patch('FileReader', function (global, Zone, api) {
2867 patchClass('FileReader');
2868 });
2869 Zone.__load_patch('on_property', function (global, Zone, api) {
2870 propertyDescriptorPatch(api, global);
2871 });
2872 Zone.__load_patch('customElements', function (global, Zone, api) {
2873 patchCustomElements(global, api);
2874 });
2875 Zone.__load_patch('XHR', function (global, Zone) {
2876 // Treat XMLHttpRequest as a macrotask.
2877 patchXHR(global);
2878 var XHR_TASK = zoneSymbol('xhrTask');
2879 var XHR_SYNC = zoneSymbol('xhrSync');
2880 var XHR_LISTENER = zoneSymbol('xhrListener');
2881 var XHR_SCHEDULED = zoneSymbol('xhrScheduled');
2882 var XHR_URL = zoneSymbol('xhrURL');
2883 var XHR_ERROR_BEFORE_SCHEDULED = zoneSymbol('xhrErrorBeforeScheduled');
2884 function patchXHR(window) {
2885 var XMLHttpRequest = window['XMLHttpRequest'];
2886 if (!XMLHttpRequest) {
2887 // XMLHttpRequest is not available in service worker
2888 return;
2889 }
2890 var XMLHttpRequestPrototype = XMLHttpRequest.prototype;
2891 function findPendingTask(target) {
2892 return target[XHR_TASK];
2893 }
2894 var oriAddListener = XMLHttpRequestPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER];
2895 var oriRemoveListener = XMLHttpRequestPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
2896 if (!oriAddListener) {
2897 var XMLHttpRequestEventTarget_1 = window['XMLHttpRequestEventTarget'];
2898 if (XMLHttpRequestEventTarget_1) {
2899 var XMLHttpRequestEventTargetPrototype = XMLHttpRequestEventTarget_1.prototype;
2900 oriAddListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_ADD_EVENT_LISTENER];
2901 oriRemoveListener = XMLHttpRequestEventTargetPrototype[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
2902 }
2903 }
2904 var READY_STATE_CHANGE = 'readystatechange';
2905 var SCHEDULED = 'scheduled';
2906 function scheduleTask(task) {
2907 var data = task.data;
2908 var target = data.target;
2909 target[XHR_SCHEDULED] = false;
2910 target[XHR_ERROR_BEFORE_SCHEDULED] = false;
2911 // remove existing event listener
2912 var listener = target[XHR_LISTENER];
2913 if (!oriAddListener) {
2914 oriAddListener = target[ZONE_SYMBOL_ADD_EVENT_LISTENER];
2915 oriRemoveListener = target[ZONE_SYMBOL_REMOVE_EVENT_LISTENER];
2916 }
2917 if (listener) {
2918 oriRemoveListener.call(target, READY_STATE_CHANGE, listener);
2919 }
2920 var newListener = target[XHR_LISTENER] = function () {
2921 if (target.readyState === target.DONE) {
2922 // sometimes on some browsers XMLHttpRequest will fire onreadystatechange with
2923 // readyState=4 multiple times, so we need to check task state here
2924 if (!data.aborted && target[XHR_SCHEDULED] && task.state === SCHEDULED) {
2925 // check whether the xhr has registered onload listener
2926 // if that is the case, the task should invoke after all
2927 // onload listeners finish.
2928 // Also if the request failed without response (status = 0), the load event handler
2929 // will not be triggered, in that case, we should also invoke the placeholder callback
2930 // to close the XMLHttpRequest::send macroTask.
2931 // https://github.com/angular/angular/issues/38795
2932 var loadTasks = target[Zone.__symbol__('loadfalse')];
2933 if (target.status !== 0 && loadTasks && loadTasks.length > 0) {
2934 var oriInvoke_1 = task.invoke;
2935 task.invoke = function () {
2936 // need to load the tasks again, because in other
2937 // load listener, they may remove themselves
2938 var loadTasks = target[Zone.__symbol__('loadfalse')];
2939 for (var i = 0; i < loadTasks.length; i++) {
2940 if (loadTasks[i] === task) {
2941 loadTasks.splice(i, 1);
2942 }
2943 }
2944 if (!data.aborted && task.state === SCHEDULED) {
2945 oriInvoke_1.call(task);
2946 }
2947 };
2948 loadTasks.push(task);
2949 }
2950 else {
2951 task.invoke();
2952 }
2953 }
2954 else if (!data.aborted && target[XHR_SCHEDULED] === false) {
2955 // error occurs when xhr.send()
2956 target[XHR_ERROR_BEFORE_SCHEDULED] = true;
2957 }
2958 }
2959 };
2960 oriAddListener.call(target, READY_STATE_CHANGE, newListener);
2961 var storedTask = target[XHR_TASK];
2962 if (!storedTask) {
2963 target[XHR_TASK] = task;
2964 }
2965 sendNative.apply(target, data.args);
2966 target[XHR_SCHEDULED] = true;
2967 return task;
2968 }
2969 function placeholderCallback() { }
2970 function clearTask(task) {
2971 var data = task.data;
2972 // Note - ideally, we would call data.target.removeEventListener here, but it's too late
2973 // to prevent it from firing. So instead, we store info for the event listener.
2974 data.aborted = true;
2975 return abortNative.apply(data.target, data.args);
2976 }
2977 var openNative = patchMethod(XMLHttpRequestPrototype, 'open', function () { return function (self, args) {
2978 self[XHR_SYNC] = args[2] == false;
2979 self[XHR_URL] = args[1];
2980 return openNative.apply(self, args);
2981 }; });
2982 var XMLHTTPREQUEST_SOURCE = 'XMLHttpRequest.send';
2983 var fetchTaskAborting = zoneSymbol('fetchTaskAborting');
2984 var fetchTaskScheduling = zoneSymbol('fetchTaskScheduling');
2985 var sendNative = patchMethod(XMLHttpRequestPrototype, 'send', function () { return function (self, args) {
2986 if (Zone.current[fetchTaskScheduling] === true) {
2987 // a fetch is scheduling, so we are using xhr to polyfill fetch
2988 // and because we already schedule macroTask for fetch, we should
2989 // not schedule a macroTask for xhr again
2990 return sendNative.apply(self, args);
2991 }
2992 if (self[XHR_SYNC]) {
2993 // if the XHR is sync there is no task to schedule, just execute the code.
2994 return sendNative.apply(self, args);
2995 }
2996 else {
2997 var options = { target: self, url: self[XHR_URL], isPeriodic: false, args: args, aborted: false };
2998 var task = scheduleMacroTaskWithCurrentZone(XMLHTTPREQUEST_SOURCE, placeholderCallback, options, scheduleTask, clearTask);
2999 if (self && self[XHR_ERROR_BEFORE_SCHEDULED] === true && !options.aborted &&
3000 task.state === SCHEDULED) {
3001 // xhr request throw error when send
3002 // we should invoke task instead of leaving a scheduled
3003 // pending macroTask
3004 task.invoke();
3005 }
3006 }
3007 }; });
3008 var abortNative = patchMethod(XMLHttpRequestPrototype, 'abort', function () { return function (self, args) {
3009 var task = findPendingTask(self);
3010 if (task && typeof task.type == 'string') {
3011 // If the XHR has already completed, do nothing.
3012 // If the XHR has already been aborted, do nothing.
3013 // Fix #569, call abort multiple times before done will cause
3014 // macroTask task count be negative number
3015 if (task.cancelFn == null || (task.data && task.data.aborted)) {
3016 return;
3017 }
3018 task.zone.cancelTask(task);
3019 }
3020 else if (Zone.current[fetchTaskAborting] === true) {
3021 // the abort is called from fetch polyfill, we need to call native abort of XHR.
3022 return abortNative.apply(self, args);
3023 }
3024 // Otherwise, we are trying to abort an XHR which has not yet been sent, so there is no
3025 // task
3026 // to cancel. Do nothing.
3027 }; });
3028 }
3029 });
3030 Zone.__load_patch('geolocation', function (global) {
3031 /// GEO_LOCATION
3032 if (global['navigator'] && global['navigator'].geolocation) {
3033 patchPrototype(global['navigator'].geolocation, ['getCurrentPosition', 'watchPosition']);
3034 }
3035 });
3036 Zone.__load_patch('PromiseRejectionEvent', function (global, Zone) {
3037 // handle unhandled promise rejection
3038 function findPromiseRejectionHandler(evtName) {
3039 return function (e) {
3040 var eventTasks = findEventTasks(global, evtName);
3041 eventTasks.forEach(function (eventTask) {
3042 // windows has added unhandledrejection event listener
3043 // trigger the event listener
3044 var PromiseRejectionEvent = global['PromiseRejectionEvent'];
3045 if (PromiseRejectionEvent) {
3046 var evt = new PromiseRejectionEvent(evtName, { promise: e.promise, reason: e.rejection });
3047 eventTask.invoke(evt);
3048 }
3049 });
3050 };
3051 }
3052 if (global['PromiseRejectionEvent']) {
3053 Zone[zoneSymbol('unhandledPromiseRejectionHandler')] =
3054 findPromiseRejectionHandler('unhandledrejection');
3055 Zone[zoneSymbol('rejectionHandledHandler')] =
3056 findPromiseRejectionHandler('rejectionhandled');
3057 }
3058 });
3059 /**
3060 * @license
3061 * Copyright Google LLC All Rights Reserved.
3062 *
3063 * Use of this source code is governed by an MIT-style license that can be
3064 * found in the LICENSE file at https://angular.io/license
3065 */
3066 Zone.__load_patch('node_util', function (global, Zone, api) {
3067 api.patchOnProperties = patchOnProperties;
3068 api.patchMethod = patchMethod;
3069 api.bindArguments = bindArguments;
3070 api.patchMacroTask = patchMacroTask;
3071 setShouldCopySymbolProperties(true);
3072 });
3073 /**
3074 * @license
3075 * Copyright Google LLC All Rights Reserved.
3076 *
3077 * Use of this source code is governed by an MIT-style license that can be
3078 * found in the LICENSE file at https://angular.io/license
3079 */
3080 Zone.__load_patch('EventEmitter', function (global) {
3081 // For EventEmitter
3082 var EE_ADD_LISTENER = 'addListener';
3083 var EE_PREPEND_LISTENER = 'prependListener';
3084 var EE_REMOVE_LISTENER = 'removeListener';
3085 var EE_REMOVE_ALL_LISTENER = 'removeAllListeners';
3086 var EE_LISTENERS = 'listeners';
3087 var EE_ON = 'on';
3088 var EE_OFF = 'off';
3089 var compareTaskCallbackVsDelegate = function (task, delegate) {
3090 // same callback, same capture, same event name, just return
3091 return task.callback === delegate || task.callback.listener === delegate;
3092 };
3093 var eventNameToString = function (eventName) {
3094 if (typeof eventName === 'string') {
3095 return eventName;
3096 }
3097 if (!eventName) {
3098 return '';
3099 }
3100 return eventName.toString().replace('(', '_').replace(')', '_');
3101 };
3102 function patchEventEmitterMethods(obj) {
3103 var result = patchEventTarget(global, [obj], {
3104 useG: false,
3105 add: EE_ADD_LISTENER,
3106 rm: EE_REMOVE_LISTENER,
3107 prepend: EE_PREPEND_LISTENER,
3108 rmAll: EE_REMOVE_ALL_LISTENER,
3109 listeners: EE_LISTENERS,
3110 chkDup: false,
3111 rt: true,
3112 diff: compareTaskCallbackVsDelegate,
3113 eventNameToString: eventNameToString
3114 });
3115 if (result && result[0]) {
3116 obj[EE_ON] = obj[EE_ADD_LISTENER];
3117 obj[EE_OFF] = obj[EE_REMOVE_LISTENER];
3118 }
3119 }
3120 // EventEmitter
3121 var events;
3122 try {
3123 events = require('events');
3124 }
3125 catch (err) {
3126 }
3127 if (events && events.EventEmitter) {
3128 patchEventEmitterMethods(events.EventEmitter.prototype);
3129 }
3130 });
3131 /**
3132 * @license
3133 * Copyright Google LLC All Rights Reserved.
3134 *
3135 * Use of this source code is governed by an MIT-style license that can be
3136 * found in the LICENSE file at https://angular.io/license
3137 */
3138 Zone.__load_patch('fs', function () {
3139 var fs;
3140 try {
3141 fs = require('fs');
3142 }
3143 catch (err) {
3144 }
3145 // watch, watchFile, unwatchFile has been patched
3146 // because EventEmitter has been patched
3147 var TO_PATCH_MACROTASK_METHODS = [
3148 'access', 'appendFile', 'chmod', 'chown', 'close', 'exists', 'fchmod',
3149 'fchown', 'fdatasync', 'fstat', 'fsync', 'ftruncate', 'futimes', 'lchmod',
3150 'lchown', 'link', 'lstat', 'mkdir', 'mkdtemp', 'open', 'read',
3151 'readdir', 'readFile', 'readlink', 'realpath', 'rename', 'rmdir', 'stat',
3152 'symlink', 'truncate', 'unlink', 'utimes', 'write', 'writeFile',
3153 ];
3154 if (fs) {
3155 TO_PATCH_MACROTASK_METHODS.filter(function (name) { return !!fs[name] && typeof fs[name] === 'function'; })
3156 .forEach(function (name) {
3157 patchMacroTask(fs, name, function (self, args) {
3158 return {
3159 name: 'fs.' + name,
3160 args: args,
3161 cbIdx: args.length > 0 ? args.length - 1 : -1,
3162 target: self
3163 };
3164 });
3165 });
3166 }
3167 });
3168 /**
3169 * @license
3170 * Copyright Google LLC All Rights Reserved.
3171 *
3172 * Use of this source code is governed by an MIT-style license that can be
3173 * found in the LICENSE file at https://angular.io/license
3174 */
3175 var set = 'set';
3176 var clear = 'clear';
3177 Zone.__load_patch('node_timers', function (global, Zone) {
3178 // Timers
3179 var globalUseTimeoutFromTimer = false;
3180 try {
3181 var timers = require('timers');
3182 var globalEqualTimersTimeout = global.setTimeout === timers.setTimeout;
3183 if (!globalEqualTimersTimeout && !isMix) {
3184 // 1. if isMix, then we are in mix environment such as Electron
3185 // we should only patch timers.setTimeout because global.setTimeout
3186 // have been patched
3187 // 2. if global.setTimeout not equal timers.setTimeout, check
3188 // whether global.setTimeout use timers.setTimeout or not
3189 var originSetTimeout_1 = timers.setTimeout;
3190 timers.setTimeout = function () {
3191 globalUseTimeoutFromTimer = true;
3192 return originSetTimeout_1.apply(this, arguments);
3193 };
3194 var detectTimeout = global.setTimeout(function () { }, 100);
3195 clearTimeout(detectTimeout);
3196 timers.setTimeout = originSetTimeout_1;
3197 }
3198 patchTimer(timers, set, clear, 'Timeout');
3199 patchTimer(timers, set, clear, 'Interval');
3200 patchTimer(timers, set, clear, 'Immediate');
3201 }
3202 catch (error) {
3203 // timers module not exists, for example, when we using nativeScript
3204 // timers is not available
3205 }
3206 if (isMix) {
3207 // if we are in mix environment, such as Electron,
3208 // the global.setTimeout has already been patched,
3209 // so we just patch timers.setTimeout
3210 return;
3211 }
3212 if (!globalUseTimeoutFromTimer) {
3213 // 1. global setTimeout equals timers setTimeout
3214 // 2. or global don't use timers setTimeout(maybe some other library patch setTimeout)
3215 // 3. or load timers module error happens, we should patch global setTimeout
3216 patchTimer(global, set, clear, 'Timeout');
3217 patchTimer(global, set, clear, 'Interval');
3218 patchTimer(global, set, clear, 'Immediate');
3219 }
3220 else {
3221 // global use timers setTimeout, but not equals
3222 // this happens when use nodejs v0.10.x, global setTimeout will
3223 // use a lazy load version of timers setTimeout
3224 // we should not double patch timer's setTimeout
3225 // so we only store the __symbol__ for consistency
3226 global[Zone.__symbol__('setTimeout')] = global.setTimeout;
3227 global[Zone.__symbol__('setInterval')] = global.setInterval;
3228 global[Zone.__symbol__('setImmediate')] = global.setImmediate;
3229 }
3230 });
3231 // patch process related methods
3232 Zone.__load_patch('nextTick', function () {
3233 // patch nextTick as microTask
3234 patchMicroTask(process, 'nextTick', function (self, args) {
3235 return {
3236 name: 'process.nextTick',
3237 args: args,
3238 cbIdx: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1,
3239 target: process
3240 };
3241 });
3242 });
3243 Zone.__load_patch('handleUnhandledPromiseRejection', function (global, Zone, api) {
3244 Zone[api.symbol('unhandledPromiseRejectionHandler')] =
3245 findProcessPromiseRejectionHandler('unhandledRejection');
3246 Zone[api.symbol('rejectionHandledHandler')] =
3247 findProcessPromiseRejectionHandler('rejectionHandled');
3248 // handle unhandled promise rejection
3249 function findProcessPromiseRejectionHandler(evtName) {
3250 return function (e) {
3251 var eventTasks = findEventTasks(process, evtName);
3252 eventTasks.forEach(function (eventTask) {
3253 // process has added unhandledrejection event listener
3254 // trigger the event listener
3255 if (evtName === 'unhandledRejection') {
3256 eventTask.invoke(e.rejection, e.promise);
3257 }
3258 else if (evtName === 'rejectionHandled') {
3259 eventTask.invoke(e.promise);
3260 }
3261 });
3262 };
3263 }
3264 });
3265 // Crypto
3266 Zone.__load_patch('crypto', function () {
3267 var crypto;
3268 try {
3269 crypto = require('crypto');
3270 }
3271 catch (err) {
3272 }
3273 // use the generic patchMacroTask to patch crypto
3274 if (crypto) {
3275 var methodNames = ['randomBytes', 'pbkdf2'];
3276 methodNames.forEach(function (name) {
3277 patchMacroTask(crypto, name, function (self, args) {
3278 return {
3279 name: 'crypto.' + name,
3280 args: args,
3281 cbIdx: (args.length > 0 && typeof args[args.length - 1] === 'function') ?
3282 args.length - 1 :
3283 -1,
3284 target: crypto
3285 };
3286 });
3287 });
3288 }
3289 });
3290 Zone.__load_patch('console', function (global, Zone) {
3291 var consoleMethods = ['dir', 'log', 'info', 'error', 'warn', 'assert', 'debug', 'timeEnd', 'trace'];
3292 consoleMethods.forEach(function (m) {
3293 var originalMethod = console[Zone.__symbol__(m)] = console[m];
3294 if (originalMethod) {
3295 console[m] = function () {
3296 var args = ArraySlice.call(arguments);
3297 if (Zone.current === Zone.root) {
3298 return originalMethod.apply(this, args);
3299 }
3300 else {
3301 return Zone.root.run(originalMethod, this, args);
3302 }
3303 };
3304 }
3305 });
3306 });
3307})));
Note: See TracBrowser for help on using the repository browser.