source: trip-planner-front/node_modules/zone.js/fesm2015/zone-node.js@ b738035

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

initial commit

  • Property mode set to 100644
File size: 103.5 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/**
8 * @license
9 * Copyright Google LLC All Rights Reserved.
10 *
11 * Use of this source code is governed by an MIT-style license that can be
12 * found in the LICENSE file at https://angular.io/license
13 */
14const Zone$1 = (function (global) {
15 const performance = global['performance'];
16 function mark(name) {
17 performance && performance['mark'] && performance['mark'](name);
18 }
19 function performanceMeasure(name, label) {
20 performance && performance['measure'] && performance['measure'](name, label);
21 }
22 mark('Zone');
23 // Initialize before it's accessed below.
24 // __Zone_symbol_prefix global can be used to override the default zone
25 // symbol prefix with a custom one if needed.
26 const symbolPrefix = global['__Zone_symbol_prefix'] || '__zone_symbol__';
27 function __symbol__(name) {
28 return symbolPrefix + name;
29 }
30 const checkDuplicate = global[__symbol__('forceDuplicateZoneCheck')] === true;
31 if (global['Zone']) {
32 // if global['Zone'] already exists (maybe zone.js was already loaded or
33 // some other lib also registered a global object named Zone), we may need
34 // to throw an error, but sometimes user may not want this error.
35 // For example,
36 // we have two web pages, page1 includes zone.js, page2 doesn't.
37 // and the 1st time user load page1 and page2, everything work fine,
38 // but when user load page2 again, error occurs because global['Zone'] already exists.
39 // so we add a flag to let user choose whether to throw this error or not.
40 // By default, if existing Zone is from zone.js, we will not throw the error.
41 if (checkDuplicate || typeof global['Zone'].__symbol__ !== 'function') {
42 throw new Error('Zone already loaded.');
43 }
44 else {
45 return global['Zone'];
46 }
47 }
48 class Zone {
49 constructor(parent, zoneSpec) {
50 this._parent = parent;
51 this._name = zoneSpec ? zoneSpec.name || 'unnamed' : '<root>';
52 this._properties = zoneSpec && zoneSpec.properties || {};
53 this._zoneDelegate =
54 new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec);
55 }
56 static assertZonePatched() {
57 if (global['Promise'] !== patches['ZoneAwarePromise']) {
58 throw new Error('Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' +
59 'has been overwritten.\n' +
60 'Most likely cause is that a Promise polyfill has been loaded ' +
61 'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' +
62 'If you must load one, do so before loading zone.js.)');
63 }
64 }
65 static get root() {
66 let zone = Zone.current;
67 while (zone.parent) {
68 zone = zone.parent;
69 }
70 return zone;
71 }
72 static get current() {
73 return _currentZoneFrame.zone;
74 }
75 static get currentTask() {
76 return _currentTask;
77 }
78 // tslint:disable-next-line:require-internal-with-underscore
79 static __load_patch(name, fn, ignoreDuplicate = false) {
80 if (patches.hasOwnProperty(name)) {
81 // `checkDuplicate` option is defined from global variable
82 // so it works for all modules.
83 // `ignoreDuplicate` can work for the specified module
84 if (!ignoreDuplicate && checkDuplicate) {
85 throw Error('Already loaded patch: ' + name);
86 }
87 }
88 else if (!global['__Zone_disable_' + name]) {
89 const perfName = 'Zone:' + name;
90 mark(perfName);
91 patches[name] = fn(global, Zone, _api);
92 performanceMeasure(perfName, perfName);
93 }
94 }
95 get parent() {
96 return this._parent;
97 }
98 get name() {
99 return this._name;
100 }
101 get(key) {
102 const zone = this.getZoneWith(key);
103 if (zone)
104 return zone._properties[key];
105 }
106 getZoneWith(key) {
107 let current = this;
108 while (current) {
109 if (current._properties.hasOwnProperty(key)) {
110 return current;
111 }
112 current = current._parent;
113 }
114 return null;
115 }
116 fork(zoneSpec) {
117 if (!zoneSpec)
118 throw new Error('ZoneSpec required!');
119 return this._zoneDelegate.fork(this, zoneSpec);
120 }
121 wrap(callback, source) {
122 if (typeof callback !== 'function') {
123 throw new Error('Expecting function got: ' + callback);
124 }
125 const _callback = this._zoneDelegate.intercept(this, callback, source);
126 const zone = this;
127 return function () {
128 return zone.runGuarded(_callback, this, arguments, source);
129 };
130 }
131 run(callback, applyThis, applyArgs, source) {
132 _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
133 try {
134 return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
135 }
136 finally {
137 _currentZoneFrame = _currentZoneFrame.parent;
138 }
139 }
140 runGuarded(callback, applyThis = null, applyArgs, source) {
141 _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
142 try {
143 try {
144 return this._zoneDelegate.invoke(this, callback, applyThis, applyArgs, source);
145 }
146 catch (error) {
147 if (this._zoneDelegate.handleError(this, error)) {
148 throw error;
149 }
150 }
151 }
152 finally {
153 _currentZoneFrame = _currentZoneFrame.parent;
154 }
155 }
156 runTask(task, applyThis, applyArgs) {
157 if (task.zone != this) {
158 throw new Error('A task can only be run in the zone of creation! (Creation: ' +
159 (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
160 }
161 // https://github.com/angular/zone.js/issues/778, sometimes eventTask
162 // will run in notScheduled(canceled) state, we should not try to
163 // run such kind of task but just return
164 if (task.state === notScheduled && (task.type === eventTask || task.type === macroTask)) {
165 return;
166 }
167 const reEntryGuard = task.state != running;
168 reEntryGuard && task._transitionTo(running, scheduled);
169 task.runCount++;
170 const previousTask = _currentTask;
171 _currentTask = task;
172 _currentZoneFrame = { parent: _currentZoneFrame, zone: this };
173 try {
174 if (task.type == macroTask && task.data && !task.data.isPeriodic) {
175 task.cancelFn = undefined;
176 }
177 try {
178 return this._zoneDelegate.invokeTask(this, task, applyThis, applyArgs);
179 }
180 catch (error) {
181 if (this._zoneDelegate.handleError(this, error)) {
182 throw error;
183 }
184 }
185 }
186 finally {
187 // if the task's state is notScheduled or unknown, then it has already been cancelled
188 // we should not reset the state to scheduled
189 if (task.state !== notScheduled && task.state !== unknown) {
190 if (task.type == eventTask || (task.data && task.data.isPeriodic)) {
191 reEntryGuard && task._transitionTo(scheduled, running);
192 }
193 else {
194 task.runCount = 0;
195 this._updateTaskCount(task, -1);
196 reEntryGuard &&
197 task._transitionTo(notScheduled, running, notScheduled);
198 }
199 }
200 _currentZoneFrame = _currentZoneFrame.parent;
201 _currentTask = previousTask;
202 }
203 }
204 scheduleTask(task) {
205 if (task.zone && task.zone !== this) {
206 // check if the task was rescheduled, the newZone
207 // should not be the children of the original zone
208 let newZone = this;
209 while (newZone) {
210 if (newZone === task.zone) {
211 throw Error(`can not reschedule task to ${this.name} which is descendants of the original zone ${task.zone.name}`);
212 }
213 newZone = newZone.parent;
214 }
215 }
216 task._transitionTo(scheduling, notScheduled);
217 const zoneDelegates = [];
218 task._zoneDelegates = zoneDelegates;
219 task._zone = this;
220 try {
221 task = this._zoneDelegate.scheduleTask(this, task);
222 }
223 catch (err) {
224 // should set task's state to unknown when scheduleTask throw error
225 // because the err may from reschedule, so the fromState maybe notScheduled
226 task._transitionTo(unknown, scheduling, notScheduled);
227 // TODO: @JiaLiPassion, should we check the result from handleError?
228 this._zoneDelegate.handleError(this, err);
229 throw err;
230 }
231 if (task._zoneDelegates === zoneDelegates) {
232 // we have to check because internally the delegate can reschedule the task.
233 this._updateTaskCount(task, 1);
234 }
235 if (task.state == scheduling) {
236 task._transitionTo(scheduled, scheduling);
237 }
238 return task;
239 }
240 scheduleMicroTask(source, callback, data, customSchedule) {
241 return this.scheduleTask(new ZoneTask(microTask, source, callback, data, customSchedule, undefined));
242 }
243 scheduleMacroTask(source, callback, data, customSchedule, customCancel) {
244 return this.scheduleTask(new ZoneTask(macroTask, source, callback, data, customSchedule, customCancel));
245 }
246 scheduleEventTask(source, callback, data, customSchedule, customCancel) {
247 return this.scheduleTask(new ZoneTask(eventTask, source, callback, data, customSchedule, customCancel));
248 }
249 cancelTask(task) {
250 if (task.zone != this)
251 throw new Error('A task can only be cancelled in the zone of creation! (Creation: ' +
252 (task.zone || NO_ZONE).name + '; Execution: ' + this.name + ')');
253 task._transitionTo(canceling, scheduled, running);
254 try {
255 this._zoneDelegate.cancelTask(this, task);
256 }
257 catch (err) {
258 // if error occurs when cancelTask, transit the state to unknown
259 task._transitionTo(unknown, canceling);
260 this._zoneDelegate.handleError(this, err);
261 throw err;
262 }
263 this._updateTaskCount(task, -1);
264 task._transitionTo(notScheduled, canceling);
265 task.runCount = 0;
266 return task;
267 }
268 _updateTaskCount(task, count) {
269 const zoneDelegates = task._zoneDelegates;
270 if (count == -1) {
271 task._zoneDelegates = null;
272 }
273 for (let i = 0; i < zoneDelegates.length; i++) {
274 zoneDelegates[i]._updateTaskCount(task.type, count);
275 }
276 }
277 }
278 // tslint:disable-next-line:require-internal-with-underscore
279 Zone.__symbol__ = __symbol__;
280 const DELEGATE_ZS = {
281 name: '',
282 onHasTask: (delegate, _, target, hasTaskState) => delegate.hasTask(target, hasTaskState),
283 onScheduleTask: (delegate, _, target, task) => delegate.scheduleTask(target, task),
284 onInvokeTask: (delegate, _, target, task, applyThis, applyArgs) => delegate.invokeTask(target, task, applyThis, applyArgs),
285 onCancelTask: (delegate, _, target, task) => delegate.cancelTask(target, task)
286 };
287 class ZoneDelegate {
288 constructor(zone, parentDelegate, zoneSpec) {
289 this._taskCounts = { 'microTask': 0, 'macroTask': 0, 'eventTask': 0 };
290 this.zone = zone;
291 this._parentDelegate = parentDelegate;
292 this._forkZS = zoneSpec && (zoneSpec && zoneSpec.onFork ? zoneSpec : parentDelegate._forkZS);
293 this._forkDlgt = zoneSpec && (zoneSpec.onFork ? parentDelegate : parentDelegate._forkDlgt);
294 this._forkCurrZone =
295 zoneSpec && (zoneSpec.onFork ? this.zone : parentDelegate._forkCurrZone);
296 this._interceptZS =
297 zoneSpec && (zoneSpec.onIntercept ? zoneSpec : parentDelegate._interceptZS);
298 this._interceptDlgt =
299 zoneSpec && (zoneSpec.onIntercept ? parentDelegate : parentDelegate._interceptDlgt);
300 this._interceptCurrZone =
301 zoneSpec && (zoneSpec.onIntercept ? this.zone : parentDelegate._interceptCurrZone);
302 this._invokeZS = zoneSpec && (zoneSpec.onInvoke ? zoneSpec : parentDelegate._invokeZS);
303 this._invokeDlgt =
304 zoneSpec && (zoneSpec.onInvoke ? parentDelegate : parentDelegate._invokeDlgt);
305 this._invokeCurrZone =
306 zoneSpec && (zoneSpec.onInvoke ? this.zone : parentDelegate._invokeCurrZone);
307 this._handleErrorZS =
308 zoneSpec && (zoneSpec.onHandleError ? zoneSpec : parentDelegate._handleErrorZS);
309 this._handleErrorDlgt =
310 zoneSpec && (zoneSpec.onHandleError ? parentDelegate : parentDelegate._handleErrorDlgt);
311 this._handleErrorCurrZone =
312 zoneSpec && (zoneSpec.onHandleError ? this.zone : parentDelegate._handleErrorCurrZone);
313 this._scheduleTaskZS =
314 zoneSpec && (zoneSpec.onScheduleTask ? zoneSpec : parentDelegate._scheduleTaskZS);
315 this._scheduleTaskDlgt = zoneSpec &&
316 (zoneSpec.onScheduleTask ? parentDelegate : parentDelegate._scheduleTaskDlgt);
317 this._scheduleTaskCurrZone =
318 zoneSpec && (zoneSpec.onScheduleTask ? this.zone : parentDelegate._scheduleTaskCurrZone);
319 this._invokeTaskZS =
320 zoneSpec && (zoneSpec.onInvokeTask ? zoneSpec : parentDelegate._invokeTaskZS);
321 this._invokeTaskDlgt =
322 zoneSpec && (zoneSpec.onInvokeTask ? parentDelegate : parentDelegate._invokeTaskDlgt);
323 this._invokeTaskCurrZone =
324 zoneSpec && (zoneSpec.onInvokeTask ? this.zone : parentDelegate._invokeTaskCurrZone);
325 this._cancelTaskZS =
326 zoneSpec && (zoneSpec.onCancelTask ? zoneSpec : parentDelegate._cancelTaskZS);
327 this._cancelTaskDlgt =
328 zoneSpec && (zoneSpec.onCancelTask ? parentDelegate : parentDelegate._cancelTaskDlgt);
329 this._cancelTaskCurrZone =
330 zoneSpec && (zoneSpec.onCancelTask ? this.zone : parentDelegate._cancelTaskCurrZone);
331 this._hasTaskZS = null;
332 this._hasTaskDlgt = null;
333 this._hasTaskDlgtOwner = null;
334 this._hasTaskCurrZone = null;
335 const zoneSpecHasTask = zoneSpec && zoneSpec.onHasTask;
336 const parentHasTask = parentDelegate && parentDelegate._hasTaskZS;
337 if (zoneSpecHasTask || parentHasTask) {
338 // If we need to report hasTask, than this ZS needs to do ref counting on tasks. In such
339 // a case all task related interceptors must go through this ZD. We can't short circuit it.
340 this._hasTaskZS = zoneSpecHasTask ? zoneSpec : DELEGATE_ZS;
341 this._hasTaskDlgt = parentDelegate;
342 this._hasTaskDlgtOwner = this;
343 this._hasTaskCurrZone = zone;
344 if (!zoneSpec.onScheduleTask) {
345 this._scheduleTaskZS = DELEGATE_ZS;
346 this._scheduleTaskDlgt = parentDelegate;
347 this._scheduleTaskCurrZone = this.zone;
348 }
349 if (!zoneSpec.onInvokeTask) {
350 this._invokeTaskZS = DELEGATE_ZS;
351 this._invokeTaskDlgt = parentDelegate;
352 this._invokeTaskCurrZone = this.zone;
353 }
354 if (!zoneSpec.onCancelTask) {
355 this._cancelTaskZS = DELEGATE_ZS;
356 this._cancelTaskDlgt = parentDelegate;
357 this._cancelTaskCurrZone = this.zone;
358 }
359 }
360 }
361 fork(targetZone, zoneSpec) {
362 return this._forkZS ? this._forkZS.onFork(this._forkDlgt, this.zone, targetZone, zoneSpec) :
363 new Zone(targetZone, zoneSpec);
364 }
365 intercept(targetZone, callback, source) {
366 return this._interceptZS ?
367 this._interceptZS.onIntercept(this._interceptDlgt, this._interceptCurrZone, targetZone, callback, source) :
368 callback;
369 }
370 invoke(targetZone, callback, applyThis, applyArgs, source) {
371 return this._invokeZS ? this._invokeZS.onInvoke(this._invokeDlgt, this._invokeCurrZone, targetZone, callback, applyThis, applyArgs, source) :
372 callback.apply(applyThis, applyArgs);
373 }
374 handleError(targetZone, error) {
375 return this._handleErrorZS ?
376 this._handleErrorZS.onHandleError(this._handleErrorDlgt, this._handleErrorCurrZone, targetZone, error) :
377 true;
378 }
379 scheduleTask(targetZone, task) {
380 let returnTask = task;
381 if (this._scheduleTaskZS) {
382 if (this._hasTaskZS) {
383 returnTask._zoneDelegates.push(this._hasTaskDlgtOwner);
384 }
385 // clang-format off
386 returnTask = this._scheduleTaskZS.onScheduleTask(this._scheduleTaskDlgt, this._scheduleTaskCurrZone, targetZone, task);
387 // clang-format on
388 if (!returnTask)
389 returnTask = task;
390 }
391 else {
392 if (task.scheduleFn) {
393 task.scheduleFn(task);
394 }
395 else if (task.type == microTask) {
396 scheduleMicroTask(task);
397 }
398 else {
399 throw new Error('Task is missing scheduleFn.');
400 }
401 }
402 return returnTask;
403 }
404 invokeTask(targetZone, task, applyThis, applyArgs) {
405 return this._invokeTaskZS ? this._invokeTaskZS.onInvokeTask(this._invokeTaskDlgt, this._invokeTaskCurrZone, targetZone, task, applyThis, applyArgs) :
406 task.callback.apply(applyThis, applyArgs);
407 }
408 cancelTask(targetZone, task) {
409 let value;
410 if (this._cancelTaskZS) {
411 value = this._cancelTaskZS.onCancelTask(this._cancelTaskDlgt, this._cancelTaskCurrZone, targetZone, task);
412 }
413 else {
414 if (!task.cancelFn) {
415 throw Error('Task is not cancelable');
416 }
417 value = task.cancelFn(task);
418 }
419 return value;
420 }
421 hasTask(targetZone, isEmpty) {
422 // hasTask should not throw error so other ZoneDelegate
423 // can still trigger hasTask callback
424 try {
425 this._hasTaskZS &&
426 this._hasTaskZS.onHasTask(this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty);
427 }
428 catch (err) {
429 this.handleError(targetZone, err);
430 }
431 }
432 // tslint:disable-next-line:require-internal-with-underscore
433 _updateTaskCount(type, count) {
434 const counts = this._taskCounts;
435 const prev = counts[type];
436 const next = counts[type] = prev + count;
437 if (next < 0) {
438 throw new Error('More tasks executed then were scheduled.');
439 }
440 if (prev == 0 || next == 0) {
441 const isEmpty = {
442 microTask: counts['microTask'] > 0,
443 macroTask: counts['macroTask'] > 0,
444 eventTask: counts['eventTask'] > 0,
445 change: type
446 };
447 this.hasTask(this.zone, isEmpty);
448 }
449 }
450 }
451 class ZoneTask {
452 constructor(type, source, callback, options, scheduleFn, cancelFn) {
453 // tslint:disable-next-line:require-internal-with-underscore
454 this._zone = null;
455 this.runCount = 0;
456 // tslint:disable-next-line:require-internal-with-underscore
457 this._zoneDelegates = null;
458 // tslint:disable-next-line:require-internal-with-underscore
459 this._state = 'notScheduled';
460 this.type = type;
461 this.source = source;
462 this.data = options;
463 this.scheduleFn = scheduleFn;
464 this.cancelFn = cancelFn;
465 if (!callback) {
466 throw new Error('callback is not defined');
467 }
468 this.callback = callback;
469 const self = this;
470 // TODO: @JiaLiPassion options should have interface
471 if (type === eventTask && options && options.useG) {
472 this.invoke = ZoneTask.invokeTask;
473 }
474 else {
475 this.invoke = function () {
476 return ZoneTask.invokeTask.call(global, self, this, arguments);
477 };
478 }
479 }
480 static invokeTask(task, target, args) {
481 if (!task) {
482 task = this;
483 }
484 _numberOfNestedTaskFrames++;
485 try {
486 task.runCount++;
487 return task.zone.runTask(task, target, args);
488 }
489 finally {
490 if (_numberOfNestedTaskFrames == 1) {
491 drainMicroTaskQueue();
492 }
493 _numberOfNestedTaskFrames--;
494 }
495 }
496 get zone() {
497 return this._zone;
498 }
499 get state() {
500 return this._state;
501 }
502 cancelScheduleRequest() {
503 this._transitionTo(notScheduled, scheduling);
504 }
505 // tslint:disable-next-line:require-internal-with-underscore
506 _transitionTo(toState, fromState1, fromState2) {
507 if (this._state === fromState1 || this._state === fromState2) {
508 this._state = toState;
509 if (toState == notScheduled) {
510 this._zoneDelegates = null;
511 }
512 }
513 else {
514 throw new Error(`${this.type} '${this.source}': can not transition to '${toState}', expecting state '${fromState1}'${fromState2 ? ' or \'' + fromState2 + '\'' : ''}, was '${this._state}'.`);
515 }
516 }
517 toString() {
518 if (this.data && typeof this.data.handleId !== 'undefined') {
519 return this.data.handleId.toString();
520 }
521 else {
522 return Object.prototype.toString.call(this);
523 }
524 }
525 // add toJSON method to prevent cyclic error when
526 // call JSON.stringify(zoneTask)
527 toJSON() {
528 return {
529 type: this.type,
530 state: this.state,
531 source: this.source,
532 zone: this.zone.name,
533 runCount: this.runCount
534 };
535 }
536 }
537 //////////////////////////////////////////////////////
538 //////////////////////////////////////////////////////
539 /// MICROTASK QUEUE
540 //////////////////////////////////////////////////////
541 //////////////////////////////////////////////////////
542 const symbolSetTimeout = __symbol__('setTimeout');
543 const symbolPromise = __symbol__('Promise');
544 const symbolThen = __symbol__('then');
545 let _microTaskQueue = [];
546 let _isDrainingMicrotaskQueue = false;
547 let nativeMicroTaskQueuePromise;
548 function scheduleMicroTask(task) {
549 // if we are not running in any task, and there has not been anything scheduled
550 // we must bootstrap the initial task creation by manually scheduling the drain
551 if (_numberOfNestedTaskFrames === 0 && _microTaskQueue.length === 0) {
552 // We are not running in Task, so we need to kickstart the microtask queue.
553 if (!nativeMicroTaskQueuePromise) {
554 if (global[symbolPromise]) {
555 nativeMicroTaskQueuePromise = global[symbolPromise].resolve(0);
556 }
557 }
558 if (nativeMicroTaskQueuePromise) {
559 let nativeThen = nativeMicroTaskQueuePromise[symbolThen];
560 if (!nativeThen) {
561 // native Promise is not patchable, we need to use `then` directly
562 // issue 1078
563 nativeThen = nativeMicroTaskQueuePromise['then'];
564 }
565 nativeThen.call(nativeMicroTaskQueuePromise, drainMicroTaskQueue);
566 }
567 else {
568 global[symbolSetTimeout](drainMicroTaskQueue, 0);
569 }
570 }
571 task && _microTaskQueue.push(task);
572 }
573 function drainMicroTaskQueue() {
574 if (!_isDrainingMicrotaskQueue) {
575 _isDrainingMicrotaskQueue = true;
576 while (_microTaskQueue.length) {
577 const queue = _microTaskQueue;
578 _microTaskQueue = [];
579 for (let i = 0; i < queue.length; i++) {
580 const task = queue[i];
581 try {
582 task.zone.runTask(task, null, null);
583 }
584 catch (error) {
585 _api.onUnhandledError(error);
586 }
587 }
588 }
589 _api.microtaskDrainDone();
590 _isDrainingMicrotaskQueue = false;
591 }
592 }
593 //////////////////////////////////////////////////////
594 //////////////////////////////////////////////////////
595 /// BOOTSTRAP
596 //////////////////////////////////////////////////////
597 //////////////////////////////////////////////////////
598 const NO_ZONE = { name: 'NO ZONE' };
599 const notScheduled = 'notScheduled', scheduling = 'scheduling', scheduled = 'scheduled', running = 'running', canceling = 'canceling', unknown = 'unknown';
600 const microTask = 'microTask', macroTask = 'macroTask', eventTask = 'eventTask';
601 const patches = {};
602 const _api = {
603 symbol: __symbol__,
604 currentZoneFrame: () => _currentZoneFrame,
605 onUnhandledError: noop,
606 microtaskDrainDone: noop,
607 scheduleMicroTask: scheduleMicroTask,
608 showUncaughtError: () => !Zone[__symbol__('ignoreConsoleErrorUncaughtError')],
609 patchEventTarget: () => [],
610 patchOnProperties: noop,
611 patchMethod: () => noop,
612 bindArguments: () => [],
613 patchThen: () => noop,
614 patchMacroTask: () => noop,
615 patchEventPrototype: () => noop,
616 isIEOrEdge: () => false,
617 getGlobalObjects: () => undefined,
618 ObjectDefineProperty: () => noop,
619 ObjectGetOwnPropertyDescriptor: () => undefined,
620 ObjectCreate: () => undefined,
621 ArraySlice: () => [],
622 patchClass: () => noop,
623 wrapWithCurrentZone: () => noop,
624 filterProperties: () => [],
625 attachOriginToPatched: () => noop,
626 _redefineProperty: () => noop,
627 patchCallbacks: () => noop
628 };
629 let _currentZoneFrame = { parent: null, zone: new Zone(null, null) };
630 let _currentTask = null;
631 let _numberOfNestedTaskFrames = 0;
632 function noop() { }
633 performanceMeasure('Zone', 'Zone');
634 return global['Zone'] = Zone;
635})(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global);
636
637/**
638 * @license
639 * Copyright Google LLC All Rights Reserved.
640 *
641 * Use of this source code is governed by an MIT-style license that can be
642 * found in the LICENSE file at https://angular.io/license
643 */
644/**
645 * Suppress closure compiler errors about unknown 'Zone' variable
646 * @fileoverview
647 * @suppress {undefinedVars,globalThis,missingRequire}
648 */
649/// <reference types="node"/>
650// issue #989, to reduce bundle size, use short name
651/** Object.getOwnPropertyDescriptor */
652const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
653/** Object.defineProperty */
654const ObjectDefineProperty = Object.defineProperty;
655/** Object.getPrototypeOf */
656const ObjectGetPrototypeOf = Object.getPrototypeOf;
657/** Array.prototype.slice */
658const ArraySlice = Array.prototype.slice;
659/** addEventListener string const */
660const ADD_EVENT_LISTENER_STR = 'addEventListener';
661/** removeEventListener string const */
662const REMOVE_EVENT_LISTENER_STR = 'removeEventListener';
663/** zoneSymbol addEventListener */
664const ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR);
665/** zoneSymbol removeEventListener */
666const ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR);
667/** true string const */
668const TRUE_STR = 'true';
669/** false string const */
670const FALSE_STR = 'false';
671/** Zone symbol prefix string const. */
672const ZONE_SYMBOL_PREFIX = Zone.__symbol__('');
673function wrapWithCurrentZone(callback, source) {
674 return Zone.current.wrap(callback, source);
675}
676function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) {
677 return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel);
678}
679const zoneSymbol = Zone.__symbol__;
680const isWindowExists = typeof window !== 'undefined';
681const internalWindow = isWindowExists ? window : undefined;
682const _global = isWindowExists && internalWindow || typeof self === 'object' && self || global;
683const REMOVE_ATTRIBUTE = 'removeAttribute';
684const NULL_ON_PROP_VALUE = [null];
685function bindArguments(args, source) {
686 for (let i = args.length - 1; i >= 0; i--) {
687 if (typeof args[i] === 'function') {
688 args[i] = wrapWithCurrentZone(args[i], source + '_' + i);
689 }
690 }
691 return args;
692}
693function isPropertyWritable(propertyDesc) {
694 if (!propertyDesc) {
695 return true;
696 }
697 if (propertyDesc.writable === false) {
698 return false;
699 }
700 return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined');
701}
702const isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope);
703// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
704// this code.
705const isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' &&
706 {}.toString.call(_global.process) === '[object process]');
707const isBrowser = !isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']);
708// we are in electron of nw, so we are both browser and nodejs
709// Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
710// this code.
711const isMix = typeof _global.process !== 'undefined' &&
712 {}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
713 !!(isWindowExists && internalWindow['HTMLElement']);
714const zoneSymbolEventNames = {};
715const wrapFn = function (event) {
716 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
717 // event will be undefined, so we need to use window.event
718 event = event || _global.event;
719 if (!event) {
720 return;
721 }
722 let eventNameSymbol = zoneSymbolEventNames[event.type];
723 if (!eventNameSymbol) {
724 eventNameSymbol = zoneSymbolEventNames[event.type] = zoneSymbol('ON_PROPERTY' + event.type);
725 }
726 const target = this || event.target || _global;
727 const listener = target[eventNameSymbol];
728 let result;
729 if (isBrowser && target === internalWindow && event.type === 'error') {
730 // window.onerror have different signiture
731 // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror#window.onerror
732 // and onerror callback will prevent default when callback return true
733 const errorEvent = event;
734 result = listener &&
735 listener.call(this, errorEvent.message, errorEvent.filename, errorEvent.lineno, errorEvent.colno, errorEvent.error);
736 if (result === true) {
737 event.preventDefault();
738 }
739 }
740 else {
741 result = listener && listener.apply(this, arguments);
742 if (result != undefined && !result) {
743 event.preventDefault();
744 }
745 }
746 return result;
747};
748function patchProperty(obj, prop, prototype) {
749 let desc = ObjectGetOwnPropertyDescriptor(obj, prop);
750 if (!desc && prototype) {
751 // when patch window object, use prototype to check prop exist or not
752 const prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop);
753 if (prototypeDesc) {
754 desc = { enumerable: true, configurable: true };
755 }
756 }
757 // if the descriptor not exists or is not configurable
758 // just return
759 if (!desc || !desc.configurable) {
760 return;
761 }
762 const onPropPatchedSymbol = zoneSymbol('on' + prop + 'patched');
763 if (obj.hasOwnProperty(onPropPatchedSymbol) && obj[onPropPatchedSymbol]) {
764 return;
765 }
766 // A property descriptor cannot have getter/setter and be writable
767 // deleting the writable and value properties avoids this error:
768 //
769 // TypeError: property descriptors must not specify a value or be writable when a
770 // getter or setter has been specified
771 delete desc.writable;
772 delete desc.value;
773 const originalDescGet = desc.get;
774 const originalDescSet = desc.set;
775 // substr(2) cuz 'onclick' -> 'click', etc
776 const eventName = prop.substr(2);
777 let eventNameSymbol = zoneSymbolEventNames[eventName];
778 if (!eventNameSymbol) {
779 eventNameSymbol = zoneSymbolEventNames[eventName] = zoneSymbol('ON_PROPERTY' + eventName);
780 }
781 desc.set = function (newValue) {
782 // in some of windows's onproperty callback, this is undefined
783 // so we need to check it
784 let target = this;
785 if (!target && obj === _global) {
786 target = _global;
787 }
788 if (!target) {
789 return;
790 }
791 let previousValue = target[eventNameSymbol];
792 if (previousValue) {
793 target.removeEventListener(eventName, wrapFn);
794 }
795 // issue #978, when onload handler was added before loading zone.js
796 // we should remove it with originalDescSet
797 if (originalDescSet) {
798 originalDescSet.apply(target, NULL_ON_PROP_VALUE);
799 }
800 if (typeof newValue === 'function') {
801 target[eventNameSymbol] = newValue;
802 target.addEventListener(eventName, wrapFn, false);
803 }
804 else {
805 target[eventNameSymbol] = null;
806 }
807 };
808 // The getter would return undefined for unassigned properties but the default value of an
809 // unassigned property is null
810 desc.get = function () {
811 // in some of windows's onproperty callback, this is undefined
812 // so we need to check it
813 let target = this;
814 if (!target && obj === _global) {
815 target = _global;
816 }
817 if (!target) {
818 return null;
819 }
820 const listener = target[eventNameSymbol];
821 if (listener) {
822 return listener;
823 }
824 else if (originalDescGet) {
825 // result will be null when use inline event attribute,
826 // such as <button onclick="func();">OK</button>
827 // because the onclick function is internal raw uncompiled handler
828 // the onclick will be evaluated when first time event was triggered or
829 // the property is accessed, https://github.com/angular/zone.js/issues/525
830 // so we should use original native get to retrieve the handler
831 let value = originalDescGet && originalDescGet.call(this);
832 if (value) {
833 desc.set.call(this, value);
834 if (typeof target[REMOVE_ATTRIBUTE] === 'function') {
835 target.removeAttribute(prop);
836 }
837 return value;
838 }
839 }
840 return null;
841 };
842 ObjectDefineProperty(obj, prop, desc);
843 obj[onPropPatchedSymbol] = true;
844}
845function patchOnProperties(obj, properties, prototype) {
846 if (properties) {
847 for (let i = 0; i < properties.length; i++) {
848 patchProperty(obj, 'on' + properties[i], prototype);
849 }
850 }
851 else {
852 const onProperties = [];
853 for (const prop in obj) {
854 if (prop.substr(0, 2) == 'on') {
855 onProperties.push(prop);
856 }
857 }
858 for (let j = 0; j < onProperties.length; j++) {
859 patchProperty(obj, onProperties[j], prototype);
860 }
861 }
862}
863const originalInstanceKey = zoneSymbol('originalInstance');
864function copySymbolProperties(src, dest) {
865 if (typeof Object.getOwnPropertySymbols !== 'function') {
866 return;
867 }
868 const symbols = Object.getOwnPropertySymbols(src);
869 symbols.forEach((symbol) => {
870 const desc = Object.getOwnPropertyDescriptor(src, symbol);
871 Object.defineProperty(dest, symbol, {
872 get: function () {
873 return src[symbol];
874 },
875 set: function (value) {
876 if (desc && (!desc.writable || typeof desc.set !== 'function')) {
877 // if src[symbol] is not writable or not have a setter, just return
878 return;
879 }
880 src[symbol] = value;
881 },
882 enumerable: desc ? desc.enumerable : true,
883 configurable: desc ? desc.configurable : true
884 });
885 });
886}
887let shouldCopySymbolProperties = false;
888function setShouldCopySymbolProperties(flag) {
889 shouldCopySymbolProperties = flag;
890}
891function patchMethod(target, name, patchFn) {
892 let proto = target;
893 while (proto && !proto.hasOwnProperty(name)) {
894 proto = ObjectGetPrototypeOf(proto);
895 }
896 if (!proto && target[name]) {
897 // somehow we did not find it, but we can see it. This happens on IE for Window properties.
898 proto = target;
899 }
900 const delegateName = zoneSymbol(name);
901 let delegate = null;
902 if (proto && (!(delegate = proto[delegateName]) || !proto.hasOwnProperty(delegateName))) {
903 delegate = proto[delegateName] = proto[name];
904 // check whether proto[name] is writable
905 // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
906 const desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
907 if (isPropertyWritable(desc)) {
908 const patchDelegate = patchFn(delegate, delegateName, name);
909 proto[name] = function () {
910 return patchDelegate(this, arguments);
911 };
912 attachOriginToPatched(proto[name], delegate);
913 if (shouldCopySymbolProperties) {
914 copySymbolProperties(delegate, proto[name]);
915 }
916 }
917 }
918 return delegate;
919}
920// TODO: @JiaLiPassion, support cancel task later if necessary
921function patchMacroTask(obj, funcName, metaCreator) {
922 let setNative = null;
923 function scheduleTask(task) {
924 const data = task.data;
925 data.args[data.cbIdx] = function () {
926 task.invoke.apply(this, arguments);
927 };
928 setNative.apply(data.target, data.args);
929 return task;
930 }
931 setNative = patchMethod(obj, funcName, (delegate) => function (self, args) {
932 const meta = metaCreator(self, args);
933 if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
934 return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask);
935 }
936 else {
937 // cause an error by calling it directly.
938 return delegate.apply(self, args);
939 }
940 });
941}
942function patchMicroTask(obj, funcName, metaCreator) {
943 let setNative = null;
944 function scheduleTask(task) {
945 const data = task.data;
946 data.args[data.cbIdx] = function () {
947 task.invoke.apply(this, arguments);
948 };
949 setNative.apply(data.target, data.args);
950 return task;
951 }
952 setNative = patchMethod(obj, funcName, (delegate) => function (self, args) {
953 const meta = metaCreator(self, args);
954 if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
955 return Zone.current.scheduleMicroTask(meta.name, args[meta.cbIdx], meta, scheduleTask);
956 }
957 else {
958 // cause an error by calling it directly.
959 return delegate.apply(self, args);
960 }
961 });
962}
963function attachOriginToPatched(patched, original) {
964 patched[zoneSymbol('OriginalDelegate')] = original;
965}
966
967/**
968 * @license
969 * Copyright Google LLC All Rights Reserved.
970 *
971 * Use of this source code is governed by an MIT-style license that can be
972 * found in the LICENSE file at https://angular.io/license
973 */
974Zone.__load_patch('ZoneAwarePromise', (global, Zone, api) => {
975 const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
976 const ObjectDefineProperty = Object.defineProperty;
977 function readableObjectToString(obj) {
978 if (obj && obj.toString === Object.prototype.toString) {
979 const className = obj.constructor && obj.constructor.name;
980 return (className ? className : '') + ': ' + JSON.stringify(obj);
981 }
982 return obj ? obj.toString() : Object.prototype.toString.call(obj);
983 }
984 const __symbol__ = api.symbol;
985 const _uncaughtPromiseErrors = [];
986 const isDisableWrappingUncaughtPromiseRejection = global[__symbol__('DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION')] === true;
987 const symbolPromise = __symbol__('Promise');
988 const symbolThen = __symbol__('then');
989 const creationTrace = '__creationTrace__';
990 api.onUnhandledError = (e) => {
991 if (api.showUncaughtError()) {
992 const rejection = e && e.rejection;
993 if (rejection) {
994 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);
995 }
996 else {
997 console.error(e);
998 }
999 }
1000 };
1001 api.microtaskDrainDone = () => {
1002 while (_uncaughtPromiseErrors.length) {
1003 const uncaughtPromiseError = _uncaughtPromiseErrors.shift();
1004 try {
1005 uncaughtPromiseError.zone.runGuarded(() => {
1006 if (uncaughtPromiseError.throwOriginal) {
1007 throw uncaughtPromiseError.rejection;
1008 }
1009 throw uncaughtPromiseError;
1010 });
1011 }
1012 catch (error) {
1013 handleUnhandledRejection(error);
1014 }
1015 }
1016 };
1017 const UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__('unhandledPromiseRejectionHandler');
1018 function handleUnhandledRejection(e) {
1019 api.onUnhandledError(e);
1020 try {
1021 const handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL];
1022 if (typeof handler === 'function') {
1023 handler.call(this, e);
1024 }
1025 }
1026 catch (err) {
1027 }
1028 }
1029 function isThenable(value) {
1030 return value && value.then;
1031 }
1032 function forwardResolution(value) {
1033 return value;
1034 }
1035 function forwardRejection(rejection) {
1036 return ZoneAwarePromise.reject(rejection);
1037 }
1038 const symbolState = __symbol__('state');
1039 const symbolValue = __symbol__('value');
1040 const symbolFinally = __symbol__('finally');
1041 const symbolParentPromiseValue = __symbol__('parentPromiseValue');
1042 const symbolParentPromiseState = __symbol__('parentPromiseState');
1043 const source = 'Promise.then';
1044 const UNRESOLVED = null;
1045 const RESOLVED = true;
1046 const REJECTED = false;
1047 const REJECTED_NO_CATCH = 0;
1048 function makeResolver(promise, state) {
1049 return (v) => {
1050 try {
1051 resolvePromise(promise, state, v);
1052 }
1053 catch (err) {
1054 resolvePromise(promise, false, err);
1055 }
1056 // Do not return value or you will break the Promise spec.
1057 };
1058 }
1059 const once = function () {
1060 let wasCalled = false;
1061 return function wrapper(wrappedFunction) {
1062 return function () {
1063 if (wasCalled) {
1064 return;
1065 }
1066 wasCalled = true;
1067 wrappedFunction.apply(null, arguments);
1068 };
1069 };
1070 };
1071 const TYPE_ERROR = 'Promise resolved with itself';
1072 const CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace');
1073 // Promise Resolution
1074 function resolvePromise(promise, state, value) {
1075 const onceWrapper = once();
1076 if (promise === value) {
1077 throw new TypeError(TYPE_ERROR);
1078 }
1079 if (promise[symbolState] === UNRESOLVED) {
1080 // should only get value.then once based on promise spec.
1081 let then = null;
1082 try {
1083 if (typeof value === 'object' || typeof value === 'function') {
1084 then = value && value.then;
1085 }
1086 }
1087 catch (err) {
1088 onceWrapper(() => {
1089 resolvePromise(promise, false, err);
1090 })();
1091 return promise;
1092 }
1093 // if (value instanceof ZoneAwarePromise) {
1094 if (state !== REJECTED && value instanceof ZoneAwarePromise &&
1095 value.hasOwnProperty(symbolState) && value.hasOwnProperty(symbolValue) &&
1096 value[symbolState] !== UNRESOLVED) {
1097 clearRejectedNoCatch(value);
1098 resolvePromise(promise, value[symbolState], value[symbolValue]);
1099 }
1100 else if (state !== REJECTED && typeof then === 'function') {
1101 try {
1102 then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)));
1103 }
1104 catch (err) {
1105 onceWrapper(() => {
1106 resolvePromise(promise, false, err);
1107 })();
1108 }
1109 }
1110 else {
1111 promise[symbolState] = state;
1112 const queue = promise[symbolValue];
1113 promise[symbolValue] = value;
1114 if (promise[symbolFinally] === symbolFinally) {
1115 // the promise is generated by Promise.prototype.finally
1116 if (state === RESOLVED) {
1117 // the state is resolved, should ignore the value
1118 // and use parent promise value
1119 promise[symbolState] = promise[symbolParentPromiseState];
1120 promise[symbolValue] = promise[symbolParentPromiseValue];
1121 }
1122 }
1123 // record task information in value when error occurs, so we can
1124 // do some additional work such as render longStackTrace
1125 if (state === REJECTED && value instanceof Error) {
1126 // check if longStackTraceZone is here
1127 const trace = Zone.currentTask && Zone.currentTask.data &&
1128 Zone.currentTask.data[creationTrace];
1129 if (trace) {
1130 // only keep the long stack trace into error when in longStackTraceZone
1131 ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace });
1132 }
1133 }
1134 for (let i = 0; i < queue.length;) {
1135 scheduleResolveOrReject(promise, queue[i++], queue[i++], queue[i++], queue[i++]);
1136 }
1137 if (queue.length == 0 && state == REJECTED) {
1138 promise[symbolState] = REJECTED_NO_CATCH;
1139 let uncaughtPromiseError = value;
1140 try {
1141 // Here we throws a new Error to print more readable error log
1142 // and if the value is not an error, zone.js builds an `Error`
1143 // Object here to attach the stack information.
1144 throw new Error('Uncaught (in promise): ' + readableObjectToString(value) +
1145 (value && value.stack ? '\n' + value.stack : ''));
1146 }
1147 catch (err) {
1148 uncaughtPromiseError = err;
1149 }
1150 if (isDisableWrappingUncaughtPromiseRejection) {
1151 // If disable wrapping uncaught promise reject
1152 // use the value instead of wrapping it.
1153 uncaughtPromiseError.throwOriginal = true;
1154 }
1155 uncaughtPromiseError.rejection = value;
1156 uncaughtPromiseError.promise = promise;
1157 uncaughtPromiseError.zone = Zone.current;
1158 uncaughtPromiseError.task = Zone.currentTask;
1159 _uncaughtPromiseErrors.push(uncaughtPromiseError);
1160 api.scheduleMicroTask(); // to make sure that it is running
1161 }
1162 }
1163 }
1164 // Resolving an already resolved promise is a noop.
1165 return promise;
1166 }
1167 const REJECTION_HANDLED_HANDLER = __symbol__('rejectionHandledHandler');
1168 function clearRejectedNoCatch(promise) {
1169 if (promise[symbolState] === REJECTED_NO_CATCH) {
1170 // if the promise is rejected no catch status
1171 // and queue.length > 0, means there is a error handler
1172 // here to handle the rejected promise, we should trigger
1173 // windows.rejectionhandled eventHandler or nodejs rejectionHandled
1174 // eventHandler
1175 try {
1176 const handler = Zone[REJECTION_HANDLED_HANDLER];
1177 if (handler && typeof handler === 'function') {
1178 handler.call(this, { rejection: promise[symbolValue], promise: promise });
1179 }
1180 }
1181 catch (err) {
1182 }
1183 promise[symbolState] = REJECTED;
1184 for (let i = 0; i < _uncaughtPromiseErrors.length; i++) {
1185 if (promise === _uncaughtPromiseErrors[i].promise) {
1186 _uncaughtPromiseErrors.splice(i, 1);
1187 }
1188 }
1189 }
1190 }
1191 function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) {
1192 clearRejectedNoCatch(promise);
1193 const promiseState = promise[symbolState];
1194 const delegate = promiseState ?
1195 (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution :
1196 (typeof onRejected === 'function') ? onRejected : forwardRejection;
1197 zone.scheduleMicroTask(source, () => {
1198 try {
1199 const parentPromiseValue = promise[symbolValue];
1200 const isFinallyPromise = !!chainPromise && symbolFinally === chainPromise[symbolFinally];
1201 if (isFinallyPromise) {
1202 // if the promise is generated from finally call, keep parent promise's state and value
1203 chainPromise[symbolParentPromiseValue] = parentPromiseValue;
1204 chainPromise[symbolParentPromiseState] = promiseState;
1205 }
1206 // should not pass value to finally callback
1207 const value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ?
1208 [] :
1209 [parentPromiseValue]);
1210 resolvePromise(chainPromise, true, value);
1211 }
1212 catch (error) {
1213 // if error occurs, should always return this error
1214 resolvePromise(chainPromise, false, error);
1215 }
1216 }, chainPromise);
1217 }
1218 const ZONE_AWARE_PROMISE_TO_STRING = 'function ZoneAwarePromise() { [native code] }';
1219 const noop = function () { };
1220 class ZoneAwarePromise {
1221 static toString() {
1222 return ZONE_AWARE_PROMISE_TO_STRING;
1223 }
1224 static resolve(value) {
1225 return resolvePromise(new this(null), RESOLVED, value);
1226 }
1227 static reject(error) {
1228 return resolvePromise(new this(null), REJECTED, error);
1229 }
1230 static race(values) {
1231 let resolve;
1232 let reject;
1233 let promise = new this((res, rej) => {
1234 resolve = res;
1235 reject = rej;
1236 });
1237 function onResolve(value) {
1238 resolve(value);
1239 }
1240 function onReject(error) {
1241 reject(error);
1242 }
1243 for (let value of values) {
1244 if (!isThenable(value)) {
1245 value = this.resolve(value);
1246 }
1247 value.then(onResolve, onReject);
1248 }
1249 return promise;
1250 }
1251 static all(values) {
1252 return ZoneAwarePromise.allWithCallback(values);
1253 }
1254 static allSettled(values) {
1255 const P = this && this.prototype instanceof ZoneAwarePromise ? this : ZoneAwarePromise;
1256 return P.allWithCallback(values, {
1257 thenCallback: (value) => ({ status: 'fulfilled', value }),
1258 errorCallback: (err) => ({ status: 'rejected', reason: err })
1259 });
1260 }
1261 static allWithCallback(values, callback) {
1262 let resolve;
1263 let reject;
1264 let promise = new this((res, rej) => {
1265 resolve = res;
1266 reject = rej;
1267 });
1268 // Start at 2 to prevent prematurely resolving if .then is called immediately.
1269 let unresolvedCount = 2;
1270 let valueIndex = 0;
1271 const resolvedValues = [];
1272 for (let value of values) {
1273 if (!isThenable(value)) {
1274 value = this.resolve(value);
1275 }
1276 const curValueIndex = valueIndex;
1277 try {
1278 value.then((value) => {
1279 resolvedValues[curValueIndex] = callback ? callback.thenCallback(value) : value;
1280 unresolvedCount--;
1281 if (unresolvedCount === 0) {
1282 resolve(resolvedValues);
1283 }
1284 }, (err) => {
1285 if (!callback) {
1286 reject(err);
1287 }
1288 else {
1289 resolvedValues[curValueIndex] = callback.errorCallback(err);
1290 unresolvedCount--;
1291 if (unresolvedCount === 0) {
1292 resolve(resolvedValues);
1293 }
1294 }
1295 });
1296 }
1297 catch (thenErr) {
1298 reject(thenErr);
1299 }
1300 unresolvedCount++;
1301 valueIndex++;
1302 }
1303 // Make the unresolvedCount zero-based again.
1304 unresolvedCount -= 2;
1305 if (unresolvedCount === 0) {
1306 resolve(resolvedValues);
1307 }
1308 return promise;
1309 }
1310 constructor(executor) {
1311 const promise = this;
1312 if (!(promise instanceof ZoneAwarePromise)) {
1313 throw new Error('Must be an instanceof Promise.');
1314 }
1315 promise[symbolState] = UNRESOLVED;
1316 promise[symbolValue] = []; // queue;
1317 try {
1318 executor && executor(makeResolver(promise, RESOLVED), makeResolver(promise, REJECTED));
1319 }
1320 catch (error) {
1321 resolvePromise(promise, false, error);
1322 }
1323 }
1324 get [Symbol.toStringTag]() {
1325 return 'Promise';
1326 }
1327 get [Symbol.species]() {
1328 return ZoneAwarePromise;
1329 }
1330 then(onFulfilled, onRejected) {
1331 let C = this.constructor[Symbol.species];
1332 if (!C || typeof C !== 'function') {
1333 C = this.constructor || ZoneAwarePromise;
1334 }
1335 const chainPromise = new C(noop);
1336 const zone = Zone.current;
1337 if (this[symbolState] == UNRESOLVED) {
1338 this[symbolValue].push(zone, chainPromise, onFulfilled, onRejected);
1339 }
1340 else {
1341 scheduleResolveOrReject(this, zone, chainPromise, onFulfilled, onRejected);
1342 }
1343 return chainPromise;
1344 }
1345 catch(onRejected) {
1346 return this.then(null, onRejected);
1347 }
1348 finally(onFinally) {
1349 let C = this.constructor[Symbol.species];
1350 if (!C || typeof C !== 'function') {
1351 C = ZoneAwarePromise;
1352 }
1353 const chainPromise = new C(noop);
1354 chainPromise[symbolFinally] = symbolFinally;
1355 const zone = Zone.current;
1356 if (this[symbolState] == UNRESOLVED) {
1357 this[symbolValue].push(zone, chainPromise, onFinally, onFinally);
1358 }
1359 else {
1360 scheduleResolveOrReject(this, zone, chainPromise, onFinally, onFinally);
1361 }
1362 return chainPromise;
1363 }
1364 }
1365 // Protect against aggressive optimizers dropping seemingly unused properties.
1366 // E.g. Closure Compiler in advanced mode.
1367 ZoneAwarePromise['resolve'] = ZoneAwarePromise.resolve;
1368 ZoneAwarePromise['reject'] = ZoneAwarePromise.reject;
1369 ZoneAwarePromise['race'] = ZoneAwarePromise.race;
1370 ZoneAwarePromise['all'] = ZoneAwarePromise.all;
1371 const NativePromise = global[symbolPromise] = global['Promise'];
1372 global['Promise'] = ZoneAwarePromise;
1373 const symbolThenPatched = __symbol__('thenPatched');
1374 function patchThen(Ctor) {
1375 const proto = Ctor.prototype;
1376 const prop = ObjectGetOwnPropertyDescriptor(proto, 'then');
1377 if (prop && (prop.writable === false || !prop.configurable)) {
1378 // check Ctor.prototype.then propertyDescriptor is writable or not
1379 // in meteor env, writable is false, we should ignore such case
1380 return;
1381 }
1382 const originalThen = proto.then;
1383 // Keep a reference to the original method.
1384 proto[symbolThen] = originalThen;
1385 Ctor.prototype.then = function (onResolve, onReject) {
1386 const wrapped = new ZoneAwarePromise((resolve, reject) => {
1387 originalThen.call(this, resolve, reject);
1388 });
1389 return wrapped.then(onResolve, onReject);
1390 };
1391 Ctor[symbolThenPatched] = true;
1392 }
1393 api.patchThen = patchThen;
1394 function zoneify(fn) {
1395 return function (self, args) {
1396 let resultPromise = fn.apply(self, args);
1397 if (resultPromise instanceof ZoneAwarePromise) {
1398 return resultPromise;
1399 }
1400 let ctor = resultPromise.constructor;
1401 if (!ctor[symbolThenPatched]) {
1402 patchThen(ctor);
1403 }
1404 return resultPromise;
1405 };
1406 }
1407 if (NativePromise) {
1408 patchThen(NativePromise);
1409 patchMethod(global, 'fetch', delegate => zoneify(delegate));
1410 }
1411 // This is not part of public API, but it is useful for tests, so we expose it.
1412 Promise[Zone.__symbol__('uncaughtPromiseErrors')] = _uncaughtPromiseErrors;
1413 return ZoneAwarePromise;
1414});
1415
1416/**
1417 * @license
1418 * Copyright Google LLC All Rights Reserved.
1419 *
1420 * Use of this source code is governed by an MIT-style license that can be
1421 * found in the LICENSE file at https://angular.io/license
1422 */
1423// override Function.prototype.toString to make zone.js patched function
1424// look like native function
1425Zone.__load_patch('toString', (global) => {
1426 // patch Func.prototype.toString to let them look like native
1427 const originalFunctionToString = Function.prototype.toString;
1428 const ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate');
1429 const PROMISE_SYMBOL = zoneSymbol('Promise');
1430 const ERROR_SYMBOL = zoneSymbol('Error');
1431 const newFunctionToString = function toString() {
1432 if (typeof this === 'function') {
1433 const originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL];
1434 if (originalDelegate) {
1435 if (typeof originalDelegate === 'function') {
1436 return originalFunctionToString.call(originalDelegate);
1437 }
1438 else {
1439 return Object.prototype.toString.call(originalDelegate);
1440 }
1441 }
1442 if (this === Promise) {
1443 const nativePromise = global[PROMISE_SYMBOL];
1444 if (nativePromise) {
1445 return originalFunctionToString.call(nativePromise);
1446 }
1447 }
1448 if (this === Error) {
1449 const nativeError = global[ERROR_SYMBOL];
1450 if (nativeError) {
1451 return originalFunctionToString.call(nativeError);
1452 }
1453 }
1454 }
1455 return originalFunctionToString.call(this);
1456 };
1457 newFunctionToString[ORIGINAL_DELEGATE_SYMBOL] = originalFunctionToString;
1458 Function.prototype.toString = newFunctionToString;
1459 // patch Object.prototype.toString to let them look like native
1460 const originalObjectToString = Object.prototype.toString;
1461 const PROMISE_OBJECT_TO_STRING = '[object Promise]';
1462 Object.prototype.toString = function () {
1463 if (typeof Promise === 'function' && this instanceof Promise) {
1464 return PROMISE_OBJECT_TO_STRING;
1465 }
1466 return originalObjectToString.call(this);
1467 };
1468});
1469
1470/**
1471 * @license
1472 * Copyright Google LLC All Rights Reserved.
1473 *
1474 * Use of this source code is governed by an MIT-style license that can be
1475 * found in the LICENSE file at https://angular.io/license
1476 */
1477Zone.__load_patch('node_util', (global, Zone, api) => {
1478 api.patchOnProperties = patchOnProperties;
1479 api.patchMethod = patchMethod;
1480 api.bindArguments = bindArguments;
1481 api.patchMacroTask = patchMacroTask;
1482 setShouldCopySymbolProperties(true);
1483});
1484
1485/**
1486 * @license
1487 * Copyright Google LLC All Rights Reserved.
1488 *
1489 * Use of this source code is governed by an MIT-style license that can be
1490 * found in the LICENSE file at https://angular.io/license
1491 */
1492let passiveSupported = false;
1493if (typeof window !== 'undefined') {
1494 try {
1495 const options = Object.defineProperty({}, 'passive', {
1496 get: function () {
1497 passiveSupported = true;
1498 }
1499 });
1500 window.addEventListener('test', options, options);
1501 window.removeEventListener('test', options, options);
1502 }
1503 catch (err) {
1504 passiveSupported = false;
1505 }
1506}
1507// an identifier to tell ZoneTask do not create a new invoke closure
1508const OPTIMIZED_ZONE_EVENT_TASK_DATA = {
1509 useG: true
1510};
1511const zoneSymbolEventNames$1 = {};
1512const globalSources = {};
1513const EVENT_NAME_SYMBOL_REGX = new RegExp('^' + ZONE_SYMBOL_PREFIX + '(\\w+)(true|false)$');
1514const IMMEDIATE_PROPAGATION_SYMBOL = zoneSymbol('propagationStopped');
1515function prepareEventNames(eventName, eventNameToString) {
1516 const falseEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + FALSE_STR;
1517 const trueEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + TRUE_STR;
1518 const symbol = ZONE_SYMBOL_PREFIX + falseEventName;
1519 const symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
1520 zoneSymbolEventNames$1[eventName] = {};
1521 zoneSymbolEventNames$1[eventName][FALSE_STR] = symbol;
1522 zoneSymbolEventNames$1[eventName][TRUE_STR] = symbolCapture;
1523}
1524function patchEventTarget(_global, apis, patchOptions) {
1525 const ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR;
1526 const REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR;
1527 const LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners';
1528 const REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners';
1529 const zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER);
1530 const ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':';
1531 const PREPEND_EVENT_LISTENER = 'prependListener';
1532 const PREPEND_EVENT_LISTENER_SOURCE = '.' + PREPEND_EVENT_LISTENER + ':';
1533 const invokeTask = function (task, target, event) {
1534 // for better performance, check isRemoved which is set
1535 // by removeEventListener
1536 if (task.isRemoved) {
1537 return;
1538 }
1539 const delegate = task.callback;
1540 if (typeof delegate === 'object' && delegate.handleEvent) {
1541 // create the bind version of handleEvent when invoke
1542 task.callback = (event) => delegate.handleEvent(event);
1543 task.originalDelegate = delegate;
1544 }
1545 // invoke static task.invoke
1546 task.invoke(task, target, [event]);
1547 const options = task.options;
1548 if (options && typeof options === 'object' && options.once) {
1549 // if options.once is true, after invoke once remove listener here
1550 // only browser need to do this, nodejs eventEmitter will cal removeListener
1551 // inside EventEmitter.once
1552 const delegate = task.originalDelegate ? task.originalDelegate : task.callback;
1553 target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate, options);
1554 }
1555 };
1556 // global shared zoneAwareCallback to handle all event callback with capture = false
1557 const globalZoneAwareCallback = function (event) {
1558 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
1559 // event will be undefined, so we need to use window.event
1560 event = event || _global.event;
1561 if (!event) {
1562 return;
1563 }
1564 // event.target is needed for Samsung TV and SourceBuffer
1565 // || global is needed https://github.com/angular/zone.js/issues/190
1566 const target = this || event.target || _global;
1567 const tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]];
1568 if (tasks) {
1569 // invoke all tasks which attached to current target with given event.type and capture = false
1570 // for performance concern, if task.length === 1, just invoke
1571 if (tasks.length === 1) {
1572 invokeTask(tasks[0], target, event);
1573 }
1574 else {
1575 // https://github.com/angular/zone.js/issues/836
1576 // copy the tasks array before invoke, to avoid
1577 // the callback will remove itself or other listener
1578 const copyTasks = tasks.slice();
1579 for (let i = 0; i < copyTasks.length; i++) {
1580 if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
1581 break;
1582 }
1583 invokeTask(copyTasks[i], target, event);
1584 }
1585 }
1586 }
1587 };
1588 // global shared zoneAwareCallback to handle all event callback with capture = true
1589 const globalZoneAwareCaptureCallback = function (event) {
1590 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
1591 // event will be undefined, so we need to use window.event
1592 event = event || _global.event;
1593 if (!event) {
1594 return;
1595 }
1596 // event.target is needed for Samsung TV and SourceBuffer
1597 // || global is needed https://github.com/angular/zone.js/issues/190
1598 const target = this || event.target || _global;
1599 const tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]];
1600 if (tasks) {
1601 // invoke all tasks which attached to current target with given event.type and capture = false
1602 // for performance concern, if task.length === 1, just invoke
1603 if (tasks.length === 1) {
1604 invokeTask(tasks[0], target, event);
1605 }
1606 else {
1607 // https://github.com/angular/zone.js/issues/836
1608 // copy the tasks array before invoke, to avoid
1609 // the callback will remove itself or other listener
1610 const copyTasks = tasks.slice();
1611 for (let i = 0; i < copyTasks.length; i++) {
1612 if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
1613 break;
1614 }
1615 invokeTask(copyTasks[i], target, event);
1616 }
1617 }
1618 }
1619 };
1620 function patchEventTargetMethods(obj, patchOptions) {
1621 if (!obj) {
1622 return false;
1623 }
1624 let useGlobalCallback = true;
1625 if (patchOptions && patchOptions.useG !== undefined) {
1626 useGlobalCallback = patchOptions.useG;
1627 }
1628 const validateHandler = patchOptions && patchOptions.vh;
1629 let checkDuplicate = true;
1630 if (patchOptions && patchOptions.chkDup !== undefined) {
1631 checkDuplicate = patchOptions.chkDup;
1632 }
1633 let returnTarget = false;
1634 if (patchOptions && patchOptions.rt !== undefined) {
1635 returnTarget = patchOptions.rt;
1636 }
1637 let proto = obj;
1638 while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) {
1639 proto = ObjectGetPrototypeOf(proto);
1640 }
1641 if (!proto && obj[ADD_EVENT_LISTENER]) {
1642 // somehow we did not find it, but we can see it. This happens on IE for Window properties.
1643 proto = obj;
1644 }
1645 if (!proto) {
1646 return false;
1647 }
1648 if (proto[zoneSymbolAddEventListener]) {
1649 return false;
1650 }
1651 const eventNameToString = patchOptions && patchOptions.eventNameToString;
1652 // a shared global taskData to pass data for scheduleEventTask
1653 // so we do not need to create a new object just for pass some data
1654 const taskData = {};
1655 const nativeAddEventListener = proto[zoneSymbolAddEventListener] = proto[ADD_EVENT_LISTENER];
1656 const nativeRemoveEventListener = proto[zoneSymbol(REMOVE_EVENT_LISTENER)] =
1657 proto[REMOVE_EVENT_LISTENER];
1658 const nativeListeners = proto[zoneSymbol(LISTENERS_EVENT_LISTENER)] =
1659 proto[LISTENERS_EVENT_LISTENER];
1660 const nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] =
1661 proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER];
1662 let nativePrependEventListener;
1663 if (patchOptions && patchOptions.prepend) {
1664 nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] =
1665 proto[patchOptions.prepend];
1666 }
1667 /**
1668 * This util function will build an option object with passive option
1669 * to handle all possible input from the user.
1670 */
1671 function buildEventListenerOptions(options, passive) {
1672 if (!passiveSupported && typeof options === 'object' && options) {
1673 // doesn't support passive but user want to pass an object as options.
1674 // this will not work on some old browser, so we just pass a boolean
1675 // as useCapture parameter
1676 return !!options.capture;
1677 }
1678 if (!passiveSupported || !passive) {
1679 return options;
1680 }
1681 if (typeof options === 'boolean') {
1682 return { capture: options, passive: true };
1683 }
1684 if (!options) {
1685 return { passive: true };
1686 }
1687 if (typeof options === 'object' && options.passive !== false) {
1688 return Object.assign(Object.assign({}, options), { passive: true });
1689 }
1690 return options;
1691 }
1692 const customScheduleGlobal = function (task) {
1693 // if there is already a task for the eventName + capture,
1694 // just return, because we use the shared globalZoneAwareCallback here.
1695 if (taskData.isExisting) {
1696 return;
1697 }
1698 return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options);
1699 };
1700 const customCancelGlobal = function (task) {
1701 // if task is not marked as isRemoved, this call is directly
1702 // from Zone.prototype.cancelTask, we should remove the task
1703 // from tasksList of target first
1704 if (!task.isRemoved) {
1705 const symbolEventNames = zoneSymbolEventNames$1[task.eventName];
1706 let symbolEventName;
1707 if (symbolEventNames) {
1708 symbolEventName = symbolEventNames[task.capture ? TRUE_STR : FALSE_STR];
1709 }
1710 const existingTasks = symbolEventName && task.target[symbolEventName];
1711 if (existingTasks) {
1712 for (let i = 0; i < existingTasks.length; i++) {
1713 const existingTask = existingTasks[i];
1714 if (existingTask === task) {
1715 existingTasks.splice(i, 1);
1716 // set isRemoved to data for faster invokeTask check
1717 task.isRemoved = true;
1718 if (existingTasks.length === 0) {
1719 // all tasks for the eventName + capture have gone,
1720 // remove globalZoneAwareCallback and remove the task cache from target
1721 task.allRemoved = true;
1722 task.target[symbolEventName] = null;
1723 }
1724 break;
1725 }
1726 }
1727 }
1728 }
1729 // if all tasks for the eventName + capture have gone,
1730 // we will really remove the global event callback,
1731 // if not, return
1732 if (!task.allRemoved) {
1733 return;
1734 }
1735 return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options);
1736 };
1737 const customScheduleNonGlobal = function (task) {
1738 return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
1739 };
1740 const customSchedulePrepend = function (task) {
1741 return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
1742 };
1743 const customCancelNonGlobal = function (task) {
1744 return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options);
1745 };
1746 const customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal;
1747 const customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal;
1748 const compareTaskCallbackVsDelegate = function (task, delegate) {
1749 const typeOfDelegate = typeof delegate;
1750 return (typeOfDelegate === 'function' && task.callback === delegate) ||
1751 (typeOfDelegate === 'object' && task.originalDelegate === delegate);
1752 };
1753 const compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate;
1754 const unpatchedEvents = Zone[zoneSymbol('UNPATCHED_EVENTS')];
1755 const passiveEvents = _global[zoneSymbol('PASSIVE_EVENTS')];
1756 const makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget = false, prepend = false) {
1757 return function () {
1758 const target = this || _global;
1759 let eventName = arguments[0];
1760 if (patchOptions && patchOptions.transferEventName) {
1761 eventName = patchOptions.transferEventName(eventName);
1762 }
1763 let delegate = arguments[1];
1764 if (!delegate) {
1765 return nativeListener.apply(this, arguments);
1766 }
1767 if (isNode && eventName === 'uncaughtException') {
1768 // don't patch uncaughtException of nodejs to prevent endless loop
1769 return nativeListener.apply(this, arguments);
1770 }
1771 // don't create the bind delegate function for handleEvent
1772 // case here to improve addEventListener performance
1773 // we will create the bind delegate when invoke
1774 let isHandleEvent = false;
1775 if (typeof delegate !== 'function') {
1776 if (!delegate.handleEvent) {
1777 return nativeListener.apply(this, arguments);
1778 }
1779 isHandleEvent = true;
1780 }
1781 if (validateHandler && !validateHandler(nativeListener, delegate, target, arguments)) {
1782 return;
1783 }
1784 const passive = passiveSupported && !!passiveEvents && passiveEvents.indexOf(eventName) !== -1;
1785 const options = buildEventListenerOptions(arguments[2], passive);
1786 if (unpatchedEvents) {
1787 // check upatched list
1788 for (let i = 0; i < unpatchedEvents.length; i++) {
1789 if (eventName === unpatchedEvents[i]) {
1790 if (passive) {
1791 return nativeListener.call(target, eventName, delegate, options);
1792 }
1793 else {
1794 return nativeListener.apply(this, arguments);
1795 }
1796 }
1797 }
1798 }
1799 const capture = !options ? false : typeof options === 'boolean' ? true : options.capture;
1800 const once = options && typeof options === 'object' ? options.once : false;
1801 const zone = Zone.current;
1802 let symbolEventNames = zoneSymbolEventNames$1[eventName];
1803 if (!symbolEventNames) {
1804 prepareEventNames(eventName, eventNameToString);
1805 symbolEventNames = zoneSymbolEventNames$1[eventName];
1806 }
1807 const symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
1808 let existingTasks = target[symbolEventName];
1809 let isExisting = false;
1810 if (existingTasks) {
1811 // already have task registered
1812 isExisting = true;
1813 if (checkDuplicate) {
1814 for (let i = 0; i < existingTasks.length; i++) {
1815 if (compare(existingTasks[i], delegate)) {
1816 // same callback, same capture, same event name, just return
1817 return;
1818 }
1819 }
1820 }
1821 }
1822 else {
1823 existingTasks = target[symbolEventName] = [];
1824 }
1825 let source;
1826 const constructorName = target.constructor['name'];
1827 const targetSource = globalSources[constructorName];
1828 if (targetSource) {
1829 source = targetSource[eventName];
1830 }
1831 if (!source) {
1832 source = constructorName + addSource +
1833 (eventNameToString ? eventNameToString(eventName) : eventName);
1834 }
1835 // do not create a new object as task.data to pass those things
1836 // just use the global shared one
1837 taskData.options = options;
1838 if (once) {
1839 // if addEventListener with once options, we don't pass it to
1840 // native addEventListener, instead we keep the once setting
1841 // and handle ourselves.
1842 taskData.options.once = false;
1843 }
1844 taskData.target = target;
1845 taskData.capture = capture;
1846 taskData.eventName = eventName;
1847 taskData.isExisting = isExisting;
1848 const data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : undefined;
1849 // keep taskData into data to allow onScheduleEventTask to access the task information
1850 if (data) {
1851 data.taskData = taskData;
1852 }
1853 const task = zone.scheduleEventTask(source, delegate, data, customScheduleFn, customCancelFn);
1854 // should clear taskData.target to avoid memory leak
1855 // issue, https://github.com/angular/angular/issues/20442
1856 taskData.target = null;
1857 // need to clear up taskData because it is a global object
1858 if (data) {
1859 data.taskData = null;
1860 }
1861 // have to save those information to task in case
1862 // application may call task.zone.cancelTask() directly
1863 if (once) {
1864 options.once = true;
1865 }
1866 if (!(!passiveSupported && typeof task.options === 'boolean')) {
1867 // if not support passive, and we pass an option object
1868 // to addEventListener, we should save the options to task
1869 task.options = options;
1870 }
1871 task.target = target;
1872 task.capture = capture;
1873 task.eventName = eventName;
1874 if (isHandleEvent) {
1875 // save original delegate for compare to check duplicate
1876 task.originalDelegate = delegate;
1877 }
1878 if (!prepend) {
1879 existingTasks.push(task);
1880 }
1881 else {
1882 existingTasks.unshift(task);
1883 }
1884 if (returnTarget) {
1885 return target;
1886 }
1887 };
1888 };
1889 proto[ADD_EVENT_LISTENER] = makeAddListener(nativeAddEventListener, ADD_EVENT_LISTENER_SOURCE, customSchedule, customCancel, returnTarget);
1890 if (nativePrependEventListener) {
1891 proto[PREPEND_EVENT_LISTENER] = makeAddListener(nativePrependEventListener, PREPEND_EVENT_LISTENER_SOURCE, customSchedulePrepend, customCancel, returnTarget, true);
1892 }
1893 proto[REMOVE_EVENT_LISTENER] = function () {
1894 const target = this || _global;
1895 let eventName = arguments[0];
1896 if (patchOptions && patchOptions.transferEventName) {
1897 eventName = patchOptions.transferEventName(eventName);
1898 }
1899 const options = arguments[2];
1900 const capture = !options ? false : typeof options === 'boolean' ? true : options.capture;
1901 const delegate = arguments[1];
1902 if (!delegate) {
1903 return nativeRemoveEventListener.apply(this, arguments);
1904 }
1905 if (validateHandler &&
1906 !validateHandler(nativeRemoveEventListener, delegate, target, arguments)) {
1907 return;
1908 }
1909 const symbolEventNames = zoneSymbolEventNames$1[eventName];
1910 let symbolEventName;
1911 if (symbolEventNames) {
1912 symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
1913 }
1914 const existingTasks = symbolEventName && target[symbolEventName];
1915 if (existingTasks) {
1916 for (let i = 0; i < existingTasks.length; i++) {
1917 const existingTask = existingTasks[i];
1918 if (compare(existingTask, delegate)) {
1919 existingTasks.splice(i, 1);
1920 // set isRemoved to data for faster invokeTask check
1921 existingTask.isRemoved = true;
1922 if (existingTasks.length === 0) {
1923 // all tasks for the eventName + capture have gone,
1924 // remove globalZoneAwareCallback and remove the task cache from target
1925 existingTask.allRemoved = true;
1926 target[symbolEventName] = null;
1927 // in the target, we have an event listener which is added by on_property
1928 // such as target.onclick = function() {}, so we need to clear this internal
1929 // property too if all delegates all removed
1930 if (typeof eventName === 'string') {
1931 const onPropertySymbol = ZONE_SYMBOL_PREFIX + 'ON_PROPERTY' + eventName;
1932 target[onPropertySymbol] = null;
1933 }
1934 }
1935 existingTask.zone.cancelTask(existingTask);
1936 if (returnTarget) {
1937 return target;
1938 }
1939 return;
1940 }
1941 }
1942 }
1943 // issue 930, didn't find the event name or callback
1944 // from zone kept existingTasks, the callback maybe
1945 // added outside of zone, we need to call native removeEventListener
1946 // to try to remove it.
1947 return nativeRemoveEventListener.apply(this, arguments);
1948 };
1949 proto[LISTENERS_EVENT_LISTENER] = function () {
1950 const target = this || _global;
1951 let eventName = arguments[0];
1952 if (patchOptions && patchOptions.transferEventName) {
1953 eventName = patchOptions.transferEventName(eventName);
1954 }
1955 const listeners = [];
1956 const tasks = findEventTasks(target, eventNameToString ? eventNameToString(eventName) : eventName);
1957 for (let i = 0; i < tasks.length; i++) {
1958 const task = tasks[i];
1959 let delegate = task.originalDelegate ? task.originalDelegate : task.callback;
1960 listeners.push(delegate);
1961 }
1962 return listeners;
1963 };
1964 proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER] = function () {
1965 const target = this || _global;
1966 let eventName = arguments[0];
1967 if (!eventName) {
1968 const keys = Object.keys(target);
1969 for (let i = 0; i < keys.length; i++) {
1970 const prop = keys[i];
1971 const match = EVENT_NAME_SYMBOL_REGX.exec(prop);
1972 let evtName = match && match[1];
1973 // in nodejs EventEmitter, removeListener event is
1974 // used for monitoring the removeListener call,
1975 // so just keep removeListener eventListener until
1976 // all other eventListeners are removed
1977 if (evtName && evtName !== 'removeListener') {
1978 this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName);
1979 }
1980 }
1981 // remove removeListener listener finally
1982 this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener');
1983 }
1984 else {
1985 if (patchOptions && patchOptions.transferEventName) {
1986 eventName = patchOptions.transferEventName(eventName);
1987 }
1988 const symbolEventNames = zoneSymbolEventNames$1[eventName];
1989 if (symbolEventNames) {
1990 const symbolEventName = symbolEventNames[FALSE_STR];
1991 const symbolCaptureEventName = symbolEventNames[TRUE_STR];
1992 const tasks = target[symbolEventName];
1993 const captureTasks = target[symbolCaptureEventName];
1994 if (tasks) {
1995 const removeTasks = tasks.slice();
1996 for (let i = 0; i < removeTasks.length; i++) {
1997 const task = removeTasks[i];
1998 let delegate = task.originalDelegate ? task.originalDelegate : task.callback;
1999 this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
2000 }
2001 }
2002 if (captureTasks) {
2003 const removeTasks = captureTasks.slice();
2004 for (let i = 0; i < removeTasks.length; i++) {
2005 const task = removeTasks[i];
2006 let delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2007 this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
2008 }
2009 }
2010 }
2011 }
2012 if (returnTarget) {
2013 return this;
2014 }
2015 };
2016 // for native toString patch
2017 attachOriginToPatched(proto[ADD_EVENT_LISTENER], nativeAddEventListener);
2018 attachOriginToPatched(proto[REMOVE_EVENT_LISTENER], nativeRemoveEventListener);
2019 if (nativeRemoveAllListeners) {
2020 attachOriginToPatched(proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER], nativeRemoveAllListeners);
2021 }
2022 if (nativeListeners) {
2023 attachOriginToPatched(proto[LISTENERS_EVENT_LISTENER], nativeListeners);
2024 }
2025 return true;
2026 }
2027 let results = [];
2028 for (let i = 0; i < apis.length; i++) {
2029 results[i] = patchEventTargetMethods(apis[i], patchOptions);
2030 }
2031 return results;
2032}
2033function findEventTasks(target, eventName) {
2034 if (!eventName) {
2035 const foundTasks = [];
2036 for (let prop in target) {
2037 const match = EVENT_NAME_SYMBOL_REGX.exec(prop);
2038 let evtName = match && match[1];
2039 if (evtName && (!eventName || evtName === eventName)) {
2040 const tasks = target[prop];
2041 if (tasks) {
2042 for (let i = 0; i < tasks.length; i++) {
2043 foundTasks.push(tasks[i]);
2044 }
2045 }
2046 }
2047 }
2048 return foundTasks;
2049 }
2050 let symbolEventName = zoneSymbolEventNames$1[eventName];
2051 if (!symbolEventName) {
2052 prepareEventNames(eventName);
2053 symbolEventName = zoneSymbolEventNames$1[eventName];
2054 }
2055 const captureFalseTasks = target[symbolEventName[FALSE_STR]];
2056 const captureTrueTasks = target[symbolEventName[TRUE_STR]];
2057 if (!captureFalseTasks) {
2058 return captureTrueTasks ? captureTrueTasks.slice() : [];
2059 }
2060 else {
2061 return captureTrueTasks ? captureFalseTasks.concat(captureTrueTasks) :
2062 captureFalseTasks.slice();
2063 }
2064}
2065
2066/**
2067 * @license
2068 * Copyright Google LLC All Rights Reserved.
2069 *
2070 * Use of this source code is governed by an MIT-style license that can be
2071 * found in the LICENSE file at https://angular.io/license
2072 */
2073Zone.__load_patch('EventEmitter', (global) => {
2074 // For EventEmitter
2075 const EE_ADD_LISTENER = 'addListener';
2076 const EE_PREPEND_LISTENER = 'prependListener';
2077 const EE_REMOVE_LISTENER = 'removeListener';
2078 const EE_REMOVE_ALL_LISTENER = 'removeAllListeners';
2079 const EE_LISTENERS = 'listeners';
2080 const EE_ON = 'on';
2081 const EE_OFF = 'off';
2082 const compareTaskCallbackVsDelegate = function (task, delegate) {
2083 // same callback, same capture, same event name, just return
2084 return task.callback === delegate || task.callback.listener === delegate;
2085 };
2086 const eventNameToString = function (eventName) {
2087 if (typeof eventName === 'string') {
2088 return eventName;
2089 }
2090 if (!eventName) {
2091 return '';
2092 }
2093 return eventName.toString().replace('(', '_').replace(')', '_');
2094 };
2095 function patchEventEmitterMethods(obj) {
2096 const result = patchEventTarget(global, [obj], {
2097 useG: false,
2098 add: EE_ADD_LISTENER,
2099 rm: EE_REMOVE_LISTENER,
2100 prepend: EE_PREPEND_LISTENER,
2101 rmAll: EE_REMOVE_ALL_LISTENER,
2102 listeners: EE_LISTENERS,
2103 chkDup: false,
2104 rt: true,
2105 diff: compareTaskCallbackVsDelegate,
2106 eventNameToString: eventNameToString
2107 });
2108 if (result && result[0]) {
2109 obj[EE_ON] = obj[EE_ADD_LISTENER];
2110 obj[EE_OFF] = obj[EE_REMOVE_LISTENER];
2111 }
2112 }
2113 // EventEmitter
2114 let events;
2115 try {
2116 events = require('events');
2117 }
2118 catch (err) {
2119 }
2120 if (events && events.EventEmitter) {
2121 patchEventEmitterMethods(events.EventEmitter.prototype);
2122 }
2123});
2124
2125/**
2126 * @license
2127 * Copyright Google LLC All Rights Reserved.
2128 *
2129 * Use of this source code is governed by an MIT-style license that can be
2130 * found in the LICENSE file at https://angular.io/license
2131 */
2132Zone.__load_patch('fs', () => {
2133 let fs;
2134 try {
2135 fs = require('fs');
2136 }
2137 catch (err) {
2138 }
2139 // watch, watchFile, unwatchFile has been patched
2140 // because EventEmitter has been patched
2141 const TO_PATCH_MACROTASK_METHODS = [
2142 'access', 'appendFile', 'chmod', 'chown', 'close', 'exists', 'fchmod',
2143 'fchown', 'fdatasync', 'fstat', 'fsync', 'ftruncate', 'futimes', 'lchmod',
2144 'lchown', 'link', 'lstat', 'mkdir', 'mkdtemp', 'open', 'read',
2145 'readdir', 'readFile', 'readlink', 'realpath', 'rename', 'rmdir', 'stat',
2146 'symlink', 'truncate', 'unlink', 'utimes', 'write', 'writeFile',
2147 ];
2148 if (fs) {
2149 TO_PATCH_MACROTASK_METHODS.filter(name => !!fs[name] && typeof fs[name] === 'function')
2150 .forEach(name => {
2151 patchMacroTask(fs, name, (self, args) => {
2152 return {
2153 name: 'fs.' + name,
2154 args: args,
2155 cbIdx: args.length > 0 ? args.length - 1 : -1,
2156 target: self
2157 };
2158 });
2159 });
2160 }
2161});
2162
2163/**
2164 * @license
2165 * Copyright Google LLC All Rights Reserved.
2166 *
2167 * Use of this source code is governed by an MIT-style license that can be
2168 * found in the LICENSE file at https://angular.io/license
2169 */
2170const taskSymbol = zoneSymbol('zoneTask');
2171function patchTimer(window, setName, cancelName, nameSuffix) {
2172 let setNative = null;
2173 let clearNative = null;
2174 setName += nameSuffix;
2175 cancelName += nameSuffix;
2176 const tasksByHandleId = {};
2177 function scheduleTask(task) {
2178 const data = task.data;
2179 data.args[0] = function () {
2180 return task.invoke.apply(this, arguments);
2181 };
2182 data.handleId = setNative.apply(window, data.args);
2183 return task;
2184 }
2185 function clearTask(task) {
2186 return clearNative.call(window, task.data.handleId);
2187 }
2188 setNative =
2189 patchMethod(window, setName, (delegate) => function (self, args) {
2190 if (typeof args[0] === 'function') {
2191 const options = {
2192 isPeriodic: nameSuffix === 'Interval',
2193 delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 :
2194 undefined,
2195 args: args
2196 };
2197 const callback = args[0];
2198 args[0] = function timer() {
2199 try {
2200 return callback.apply(this, arguments);
2201 }
2202 finally {
2203 // issue-934, task will be cancelled
2204 // even it is a periodic task such as
2205 // setInterval
2206 // https://github.com/angular/angular/issues/40387
2207 // Cleanup tasksByHandleId should be handled before scheduleTask
2208 // Since some zoneSpec may intercept and doesn't trigger
2209 // scheduleFn(scheduleTask) provided here.
2210 if (!(options.isPeriodic)) {
2211 if (typeof options.handleId === 'number') {
2212 // in non-nodejs env, we remove timerId
2213 // from local cache
2214 delete tasksByHandleId[options.handleId];
2215 }
2216 else if (options.handleId) {
2217 // Node returns complex objects as handleIds
2218 // we remove task reference from timer object
2219 options.handleId[taskSymbol] = null;
2220 }
2221 }
2222 }
2223 };
2224 const task = scheduleMacroTaskWithCurrentZone(setName, args[0], options, scheduleTask, clearTask);
2225 if (!task) {
2226 return task;
2227 }
2228 // Node.js must additionally support the ref and unref functions.
2229 const handle = task.data.handleId;
2230 if (typeof handle === 'number') {
2231 // for non nodejs env, we save handleId: task
2232 // mapping in local cache for clearTimeout
2233 tasksByHandleId[handle] = task;
2234 }
2235 else if (handle) {
2236 // for nodejs env, we save task
2237 // reference in timerId Object for clearTimeout
2238 handle[taskSymbol] = task;
2239 }
2240 // check whether handle is null, because some polyfill or browser
2241 // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame
2242 if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' &&
2243 typeof handle.unref === 'function') {
2244 task.ref = handle.ref.bind(handle);
2245 task.unref = handle.unref.bind(handle);
2246 }
2247 if (typeof handle === 'number' || handle) {
2248 return handle;
2249 }
2250 return task;
2251 }
2252 else {
2253 // cause an error by calling it directly.
2254 return delegate.apply(window, args);
2255 }
2256 });
2257 clearNative =
2258 patchMethod(window, cancelName, (delegate) => function (self, args) {
2259 const id = args[0];
2260 let task;
2261 if (typeof id === 'number') {
2262 // non nodejs env.
2263 task = tasksByHandleId[id];
2264 }
2265 else {
2266 // nodejs env.
2267 task = id && id[taskSymbol];
2268 // other environments.
2269 if (!task) {
2270 task = id;
2271 }
2272 }
2273 if (task && typeof task.type === 'string') {
2274 if (task.state !== 'notScheduled' &&
2275 (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) {
2276 if (typeof id === 'number') {
2277 delete tasksByHandleId[id];
2278 }
2279 else if (id) {
2280 id[taskSymbol] = null;
2281 }
2282 // Do not cancel already canceled functions
2283 task.zone.cancelTask(task);
2284 }
2285 }
2286 else {
2287 // cause an error by calling it directly.
2288 delegate.apply(window, args);
2289 }
2290 });
2291}
2292
2293/**
2294 * @license
2295 * Copyright Google LLC All Rights Reserved.
2296 *
2297 * Use of this source code is governed by an MIT-style license that can be
2298 * found in the LICENSE file at https://angular.io/license
2299 */
2300const set = 'set';
2301const clear = 'clear';
2302Zone.__load_patch('node_timers', (global, Zone) => {
2303 // Timers
2304 let globalUseTimeoutFromTimer = false;
2305 try {
2306 const timers = require('timers');
2307 let globalEqualTimersTimeout = global.setTimeout === timers.setTimeout;
2308 if (!globalEqualTimersTimeout && !isMix) {
2309 // 1. if isMix, then we are in mix environment such as Electron
2310 // we should only patch timers.setTimeout because global.setTimeout
2311 // have been patched
2312 // 2. if global.setTimeout not equal timers.setTimeout, check
2313 // whether global.setTimeout use timers.setTimeout or not
2314 const originSetTimeout = timers.setTimeout;
2315 timers.setTimeout = function () {
2316 globalUseTimeoutFromTimer = true;
2317 return originSetTimeout.apply(this, arguments);
2318 };
2319 const detectTimeout = global.setTimeout(() => { }, 100);
2320 clearTimeout(detectTimeout);
2321 timers.setTimeout = originSetTimeout;
2322 }
2323 patchTimer(timers, set, clear, 'Timeout');
2324 patchTimer(timers, set, clear, 'Interval');
2325 patchTimer(timers, set, clear, 'Immediate');
2326 }
2327 catch (error) {
2328 // timers module not exists, for example, when we using nativeScript
2329 // timers is not available
2330 }
2331 if (isMix) {
2332 // if we are in mix environment, such as Electron,
2333 // the global.setTimeout has already been patched,
2334 // so we just patch timers.setTimeout
2335 return;
2336 }
2337 if (!globalUseTimeoutFromTimer) {
2338 // 1. global setTimeout equals timers setTimeout
2339 // 2. or global don't use timers setTimeout(maybe some other library patch setTimeout)
2340 // 3. or load timers module error happens, we should patch global setTimeout
2341 patchTimer(global, set, clear, 'Timeout');
2342 patchTimer(global, set, clear, 'Interval');
2343 patchTimer(global, set, clear, 'Immediate');
2344 }
2345 else {
2346 // global use timers setTimeout, but not equals
2347 // this happens when use nodejs v0.10.x, global setTimeout will
2348 // use a lazy load version of timers setTimeout
2349 // we should not double patch timer's setTimeout
2350 // so we only store the __symbol__ for consistency
2351 global[Zone.__symbol__('setTimeout')] = global.setTimeout;
2352 global[Zone.__symbol__('setInterval')] = global.setInterval;
2353 global[Zone.__symbol__('setImmediate')] = global.setImmediate;
2354 }
2355});
2356// patch process related methods
2357Zone.__load_patch('nextTick', () => {
2358 // patch nextTick as microTask
2359 patchMicroTask(process, 'nextTick', (self, args) => {
2360 return {
2361 name: 'process.nextTick',
2362 args: args,
2363 cbIdx: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1,
2364 target: process
2365 };
2366 });
2367});
2368Zone.__load_patch('handleUnhandledPromiseRejection', (global, Zone, api) => {
2369 Zone[api.symbol('unhandledPromiseRejectionHandler')] =
2370 findProcessPromiseRejectionHandler('unhandledRejection');
2371 Zone[api.symbol('rejectionHandledHandler')] =
2372 findProcessPromiseRejectionHandler('rejectionHandled');
2373 // handle unhandled promise rejection
2374 function findProcessPromiseRejectionHandler(evtName) {
2375 return function (e) {
2376 const eventTasks = findEventTasks(process, evtName);
2377 eventTasks.forEach(eventTask => {
2378 // process has added unhandledrejection event listener
2379 // trigger the event listener
2380 if (evtName === 'unhandledRejection') {
2381 eventTask.invoke(e.rejection, e.promise);
2382 }
2383 else if (evtName === 'rejectionHandled') {
2384 eventTask.invoke(e.promise);
2385 }
2386 });
2387 };
2388 }
2389});
2390// Crypto
2391Zone.__load_patch('crypto', () => {
2392 let crypto;
2393 try {
2394 crypto = require('crypto');
2395 }
2396 catch (err) {
2397 }
2398 // use the generic patchMacroTask to patch crypto
2399 if (crypto) {
2400 const methodNames = ['randomBytes', 'pbkdf2'];
2401 methodNames.forEach(name => {
2402 patchMacroTask(crypto, name, (self, args) => {
2403 return {
2404 name: 'crypto.' + name,
2405 args: args,
2406 cbIdx: (args.length > 0 && typeof args[args.length - 1] === 'function') ?
2407 args.length - 1 :
2408 -1,
2409 target: crypto
2410 };
2411 });
2412 });
2413 }
2414});
2415Zone.__load_patch('console', (global, Zone) => {
2416 const consoleMethods = ['dir', 'log', 'info', 'error', 'warn', 'assert', 'debug', 'timeEnd', 'trace'];
2417 consoleMethods.forEach((m) => {
2418 const originalMethod = console[Zone.__symbol__(m)] = console[m];
2419 if (originalMethod) {
2420 console[m] = function () {
2421 const args = ArraySlice.call(arguments);
2422 if (Zone.current === Zone.root) {
2423 return originalMethod.apply(this, args);
2424 }
2425 else {
2426 return Zone.root.run(originalMethod, this, args);
2427 }
2428 };
2429 }
2430 });
2431});
Note: See TracBrowser for help on using the repository browser.