source: trip-planner-front/node_modules/zone.js/bundles/zone-node.umd.js@ 76712b2

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

initial commit

  • Property mode set to 100644
File size: 116.9 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 /** Array.prototype.slice */
695 var ArraySlice = Array.prototype.slice;
696 /** addEventListener string const */
697 var ADD_EVENT_LISTENER_STR = 'addEventListener';
698 /** removeEventListener string const */
699 var REMOVE_EVENT_LISTENER_STR = 'removeEventListener';
700 /** zoneSymbol addEventListener */
701 var ZONE_SYMBOL_ADD_EVENT_LISTENER = Zone.__symbol__(ADD_EVENT_LISTENER_STR);
702 /** zoneSymbol removeEventListener */
703 var ZONE_SYMBOL_REMOVE_EVENT_LISTENER = Zone.__symbol__(REMOVE_EVENT_LISTENER_STR);
704 /** true string const */
705 var TRUE_STR = 'true';
706 /** false string const */
707 var FALSE_STR = 'false';
708 /** Zone symbol prefix string const. */
709 var ZONE_SYMBOL_PREFIX = Zone.__symbol__('');
710 function wrapWithCurrentZone(callback, source) {
711 return Zone.current.wrap(callback, source);
712 }
713 function scheduleMacroTaskWithCurrentZone(source, callback, data, customSchedule, customCancel) {
714 return Zone.current.scheduleMacroTask(source, callback, data, customSchedule, customCancel);
715 }
716 var zoneSymbol = Zone.__symbol__;
717 var isWindowExists = typeof window !== 'undefined';
718 var internalWindow = isWindowExists ? window : undefined;
719 var _global = isWindowExists && internalWindow || typeof self === 'object' && self || global;
720 var REMOVE_ATTRIBUTE = 'removeAttribute';
721 var NULL_ON_PROP_VALUE = [null];
722 function bindArguments(args, source) {
723 for (var i = args.length - 1; i >= 0; i--) {
724 if (typeof args[i] === 'function') {
725 args[i] = wrapWithCurrentZone(args[i], source + '_' + i);
726 }
727 }
728 return args;
729 }
730 function isPropertyWritable(propertyDesc) {
731 if (!propertyDesc) {
732 return true;
733 }
734 if (propertyDesc.writable === false) {
735 return false;
736 }
737 return !(typeof propertyDesc.get === 'function' && typeof propertyDesc.set === 'undefined');
738 }
739 var isWebWorker = (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope);
740 // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
741 // this code.
742 var isNode = (!('nw' in _global) && typeof _global.process !== 'undefined' &&
743 {}.toString.call(_global.process) === '[object process]');
744 var isBrowser = !isNode && !isWebWorker && !!(isWindowExists && internalWindow['HTMLElement']);
745 // we are in electron of nw, so we are both browser and nodejs
746 // Make sure to access `process` through `_global` so that WebPack does not accidentally browserify
747 // this code.
748 var isMix = typeof _global.process !== 'undefined' &&
749 {}.toString.call(_global.process) === '[object process]' && !isWebWorker &&
750 !!(isWindowExists && internalWindow['HTMLElement']);
751 var zoneSymbolEventNames = {};
752 var wrapFn = function (event) {
753 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
754 // event will be undefined, so we need to use window.event
755 event = event || _global.event;
756 if (!event) {
757 return;
758 }
759 var eventNameSymbol = zoneSymbolEventNames[event.type];
760 if (!eventNameSymbol) {
761 eventNameSymbol = zoneSymbolEventNames[event.type] = zoneSymbol('ON_PROPERTY' + event.type);
762 }
763 var target = this || event.target || _global;
764 var listener = target[eventNameSymbol];
765 var result;
766 if (isBrowser && target === internalWindow && event.type === 'error') {
767 // window.onerror have different signiture
768 // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror#window.onerror
769 // and onerror callback will prevent default when callback return true
770 var errorEvent = event;
771 result = listener &&
772 listener.call(this, errorEvent.message, errorEvent.filename, errorEvent.lineno, errorEvent.colno, errorEvent.error);
773 if (result === true) {
774 event.preventDefault();
775 }
776 }
777 else {
778 result = listener && listener.apply(this, arguments);
779 if (result != undefined && !result) {
780 event.preventDefault();
781 }
782 }
783 return result;
784 };
785 function patchProperty(obj, prop, prototype) {
786 var desc = ObjectGetOwnPropertyDescriptor(obj, prop);
787 if (!desc && prototype) {
788 // when patch window object, use prototype to check prop exist or not
789 var prototypeDesc = ObjectGetOwnPropertyDescriptor(prototype, prop);
790 if (prototypeDesc) {
791 desc = { enumerable: true, configurable: true };
792 }
793 }
794 // if the descriptor not exists or is not configurable
795 // just return
796 if (!desc || !desc.configurable) {
797 return;
798 }
799 var onPropPatchedSymbol = zoneSymbol('on' + prop + 'patched');
800 if (obj.hasOwnProperty(onPropPatchedSymbol) && obj[onPropPatchedSymbol]) {
801 return;
802 }
803 // A property descriptor cannot have getter/setter and be writable
804 // deleting the writable and value properties avoids this error:
805 //
806 // TypeError: property descriptors must not specify a value or be writable when a
807 // getter or setter has been specified
808 delete desc.writable;
809 delete desc.value;
810 var originalDescGet = desc.get;
811 var originalDescSet = desc.set;
812 // substr(2) cuz 'onclick' -> 'click', etc
813 var eventName = prop.substr(2);
814 var eventNameSymbol = zoneSymbolEventNames[eventName];
815 if (!eventNameSymbol) {
816 eventNameSymbol = zoneSymbolEventNames[eventName] = zoneSymbol('ON_PROPERTY' + eventName);
817 }
818 desc.set = function (newValue) {
819 // in some of windows's onproperty callback, this is undefined
820 // so we need to check it
821 var target = this;
822 if (!target && obj === _global) {
823 target = _global;
824 }
825 if (!target) {
826 return;
827 }
828 var previousValue = target[eventNameSymbol];
829 if (previousValue) {
830 target.removeEventListener(eventName, wrapFn);
831 }
832 // issue #978, when onload handler was added before loading zone.js
833 // we should remove it with originalDescSet
834 if (originalDescSet) {
835 originalDescSet.apply(target, NULL_ON_PROP_VALUE);
836 }
837 if (typeof newValue === 'function') {
838 target[eventNameSymbol] = newValue;
839 target.addEventListener(eventName, wrapFn, false);
840 }
841 else {
842 target[eventNameSymbol] = null;
843 }
844 };
845 // The getter would return undefined for unassigned properties but the default value of an
846 // unassigned property is null
847 desc.get = function () {
848 // in some of windows's onproperty callback, this is undefined
849 // so we need to check it
850 var target = this;
851 if (!target && obj === _global) {
852 target = _global;
853 }
854 if (!target) {
855 return null;
856 }
857 var listener = target[eventNameSymbol];
858 if (listener) {
859 return listener;
860 }
861 else if (originalDescGet) {
862 // result will be null when use inline event attribute,
863 // such as <button onclick="func();">OK</button>
864 // because the onclick function is internal raw uncompiled handler
865 // the onclick will be evaluated when first time event was triggered or
866 // the property is accessed, https://github.com/angular/zone.js/issues/525
867 // so we should use original native get to retrieve the handler
868 var value = originalDescGet && originalDescGet.call(this);
869 if (value) {
870 desc.set.call(this, value);
871 if (typeof target[REMOVE_ATTRIBUTE] === 'function') {
872 target.removeAttribute(prop);
873 }
874 return value;
875 }
876 }
877 return null;
878 };
879 ObjectDefineProperty(obj, prop, desc);
880 obj[onPropPatchedSymbol] = true;
881 }
882 function patchOnProperties(obj, properties, prototype) {
883 if (properties) {
884 for (var i = 0; i < properties.length; i++) {
885 patchProperty(obj, 'on' + properties[i], prototype);
886 }
887 }
888 else {
889 var onProperties = [];
890 for (var prop in obj) {
891 if (prop.substr(0, 2) == 'on') {
892 onProperties.push(prop);
893 }
894 }
895 for (var j = 0; j < onProperties.length; j++) {
896 patchProperty(obj, onProperties[j], prototype);
897 }
898 }
899 }
900 var originalInstanceKey = zoneSymbol('originalInstance');
901 function copySymbolProperties(src, dest) {
902 if (typeof Object.getOwnPropertySymbols !== 'function') {
903 return;
904 }
905 var symbols = Object.getOwnPropertySymbols(src);
906 symbols.forEach(function (symbol) {
907 var desc = Object.getOwnPropertyDescriptor(src, symbol);
908 Object.defineProperty(dest, symbol, {
909 get: function () {
910 return src[symbol];
911 },
912 set: function (value) {
913 if (desc && (!desc.writable || typeof desc.set !== 'function')) {
914 // if src[symbol] is not writable or not have a setter, just return
915 return;
916 }
917 src[symbol] = value;
918 },
919 enumerable: desc ? desc.enumerable : true,
920 configurable: desc ? desc.configurable : true
921 });
922 });
923 }
924 var shouldCopySymbolProperties = false;
925 function setShouldCopySymbolProperties(flag) {
926 shouldCopySymbolProperties = flag;
927 }
928 function patchMethod(target, name, patchFn) {
929 var proto = target;
930 while (proto && !proto.hasOwnProperty(name)) {
931 proto = ObjectGetPrototypeOf(proto);
932 }
933 if (!proto && target[name]) {
934 // somehow we did not find it, but we can see it. This happens on IE for Window properties.
935 proto = target;
936 }
937 var delegateName = zoneSymbol(name);
938 var delegate = null;
939 if (proto && (!(delegate = proto[delegateName]) || !proto.hasOwnProperty(delegateName))) {
940 delegate = proto[delegateName] = proto[name];
941 // check whether proto[name] is writable
942 // some property is readonly in safari, such as HtmlCanvasElement.prototype.toBlob
943 var desc = proto && ObjectGetOwnPropertyDescriptor(proto, name);
944 if (isPropertyWritable(desc)) {
945 var patchDelegate_1 = patchFn(delegate, delegateName, name);
946 proto[name] = function () {
947 return patchDelegate_1(this, arguments);
948 };
949 attachOriginToPatched(proto[name], delegate);
950 if (shouldCopySymbolProperties) {
951 copySymbolProperties(delegate, proto[name]);
952 }
953 }
954 }
955 return delegate;
956 }
957 // TODO: @JiaLiPassion, support cancel task later if necessary
958 function patchMacroTask(obj, funcName, metaCreator) {
959 var setNative = null;
960 function scheduleTask(task) {
961 var data = task.data;
962 data.args[data.cbIdx] = function () {
963 task.invoke.apply(this, arguments);
964 };
965 setNative.apply(data.target, data.args);
966 return task;
967 }
968 setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
969 var meta = metaCreator(self, args);
970 if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
971 return scheduleMacroTaskWithCurrentZone(meta.name, args[meta.cbIdx], meta, scheduleTask);
972 }
973 else {
974 // cause an error by calling it directly.
975 return delegate.apply(self, args);
976 }
977 }; });
978 }
979 function patchMicroTask(obj, funcName, metaCreator) {
980 var setNative = null;
981 function scheduleTask(task) {
982 var data = task.data;
983 data.args[data.cbIdx] = function () {
984 task.invoke.apply(this, arguments);
985 };
986 setNative.apply(data.target, data.args);
987 return task;
988 }
989 setNative = patchMethod(obj, funcName, function (delegate) { return function (self, args) {
990 var meta = metaCreator(self, args);
991 if (meta.cbIdx >= 0 && typeof args[meta.cbIdx] === 'function') {
992 return Zone.current.scheduleMicroTask(meta.name, args[meta.cbIdx], meta, scheduleTask);
993 }
994 else {
995 // cause an error by calling it directly.
996 return delegate.apply(self, args);
997 }
998 }; });
999 }
1000 function attachOriginToPatched(patched, original) {
1001 patched[zoneSymbol('OriginalDelegate')] = original;
1002 }
1003 /**
1004 * @license
1005 * Copyright Google LLC All Rights Reserved.
1006 *
1007 * Use of this source code is governed by an MIT-style license that can be
1008 * found in the LICENSE file at https://angular.io/license
1009 */
1010 Zone.__load_patch('ZoneAwarePromise', function (global, Zone, api) {
1011 var ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
1012 var ObjectDefineProperty = Object.defineProperty;
1013 function readableObjectToString(obj) {
1014 if (obj && obj.toString === Object.prototype.toString) {
1015 var className = obj.constructor && obj.constructor.name;
1016 return (className ? className : '') + ': ' + JSON.stringify(obj);
1017 }
1018 return obj ? obj.toString() : Object.prototype.toString.call(obj);
1019 }
1020 var __symbol__ = api.symbol;
1021 var _uncaughtPromiseErrors = [];
1022 var isDisableWrappingUncaughtPromiseRejection = global[__symbol__('DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION')] === true;
1023 var symbolPromise = __symbol__('Promise');
1024 var symbolThen = __symbol__('then');
1025 var creationTrace = '__creationTrace__';
1026 api.onUnhandledError = function (e) {
1027 if (api.showUncaughtError()) {
1028 var rejection = e && e.rejection;
1029 if (rejection) {
1030 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);
1031 }
1032 else {
1033 console.error(e);
1034 }
1035 }
1036 };
1037 api.microtaskDrainDone = function () {
1038 var _loop_1 = function () {
1039 var uncaughtPromiseError = _uncaughtPromiseErrors.shift();
1040 try {
1041 uncaughtPromiseError.zone.runGuarded(function () {
1042 if (uncaughtPromiseError.throwOriginal) {
1043 throw uncaughtPromiseError.rejection;
1044 }
1045 throw uncaughtPromiseError;
1046 });
1047 }
1048 catch (error) {
1049 handleUnhandledRejection(error);
1050 }
1051 };
1052 while (_uncaughtPromiseErrors.length) {
1053 _loop_1();
1054 }
1055 };
1056 var UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL = __symbol__('unhandledPromiseRejectionHandler');
1057 function handleUnhandledRejection(e) {
1058 api.onUnhandledError(e);
1059 try {
1060 var handler = Zone[UNHANDLED_PROMISE_REJECTION_HANDLER_SYMBOL];
1061 if (typeof handler === 'function') {
1062 handler.call(this, e);
1063 }
1064 }
1065 catch (err) {
1066 }
1067 }
1068 function isThenable(value) {
1069 return value && value.then;
1070 }
1071 function forwardResolution(value) {
1072 return value;
1073 }
1074 function forwardRejection(rejection) {
1075 return ZoneAwarePromise.reject(rejection);
1076 }
1077 var symbolState = __symbol__('state');
1078 var symbolValue = __symbol__('value');
1079 var symbolFinally = __symbol__('finally');
1080 var symbolParentPromiseValue = __symbol__('parentPromiseValue');
1081 var symbolParentPromiseState = __symbol__('parentPromiseState');
1082 var source = 'Promise.then';
1083 var UNRESOLVED = null;
1084 var RESOLVED = true;
1085 var REJECTED = false;
1086 var REJECTED_NO_CATCH = 0;
1087 function makeResolver(promise, state) {
1088 return function (v) {
1089 try {
1090 resolvePromise(promise, state, v);
1091 }
1092 catch (err) {
1093 resolvePromise(promise, false, err);
1094 }
1095 // Do not return value or you will break the Promise spec.
1096 };
1097 }
1098 var once = function () {
1099 var wasCalled = false;
1100 return function wrapper(wrappedFunction) {
1101 return function () {
1102 if (wasCalled) {
1103 return;
1104 }
1105 wasCalled = true;
1106 wrappedFunction.apply(null, arguments);
1107 };
1108 };
1109 };
1110 var TYPE_ERROR = 'Promise resolved with itself';
1111 var CURRENT_TASK_TRACE_SYMBOL = __symbol__('currentTaskTrace');
1112 // Promise Resolution
1113 function resolvePromise(promise, state, value) {
1114 var onceWrapper = once();
1115 if (promise === value) {
1116 throw new TypeError(TYPE_ERROR);
1117 }
1118 if (promise[symbolState] === UNRESOLVED) {
1119 // should only get value.then once based on promise spec.
1120 var then = null;
1121 try {
1122 if (typeof value === 'object' || typeof value === 'function') {
1123 then = value && value.then;
1124 }
1125 }
1126 catch (err) {
1127 onceWrapper(function () {
1128 resolvePromise(promise, false, err);
1129 })();
1130 return promise;
1131 }
1132 // if (value instanceof ZoneAwarePromise) {
1133 if (state !== REJECTED && value instanceof ZoneAwarePromise &&
1134 value.hasOwnProperty(symbolState) && value.hasOwnProperty(symbolValue) &&
1135 value[symbolState] !== UNRESOLVED) {
1136 clearRejectedNoCatch(value);
1137 resolvePromise(promise, value[symbolState], value[symbolValue]);
1138 }
1139 else if (state !== REJECTED && typeof then === 'function') {
1140 try {
1141 then.call(value, onceWrapper(makeResolver(promise, state)), onceWrapper(makeResolver(promise, false)));
1142 }
1143 catch (err) {
1144 onceWrapper(function () {
1145 resolvePromise(promise, false, err);
1146 })();
1147 }
1148 }
1149 else {
1150 promise[symbolState] = state;
1151 var queue = promise[symbolValue];
1152 promise[symbolValue] = value;
1153 if (promise[symbolFinally] === symbolFinally) {
1154 // the promise is generated by Promise.prototype.finally
1155 if (state === RESOLVED) {
1156 // the state is resolved, should ignore the value
1157 // and use parent promise value
1158 promise[symbolState] = promise[symbolParentPromiseState];
1159 promise[symbolValue] = promise[symbolParentPromiseValue];
1160 }
1161 }
1162 // record task information in value when error occurs, so we can
1163 // do some additional work such as render longStackTrace
1164 if (state === REJECTED && value instanceof Error) {
1165 // check if longStackTraceZone is here
1166 var trace = Zone.currentTask && Zone.currentTask.data &&
1167 Zone.currentTask.data[creationTrace];
1168 if (trace) {
1169 // only keep the long stack trace into error when in longStackTraceZone
1170 ObjectDefineProperty(value, CURRENT_TASK_TRACE_SYMBOL, { configurable: true, enumerable: false, writable: true, value: trace });
1171 }
1172 }
1173 for (var i = 0; i < queue.length;) {
1174 scheduleResolveOrReject(promise, queue[i++], queue[i++], queue[i++], queue[i++]);
1175 }
1176 if (queue.length == 0 && state == REJECTED) {
1177 promise[symbolState] = REJECTED_NO_CATCH;
1178 var uncaughtPromiseError = value;
1179 try {
1180 // Here we throws a new Error to print more readable error log
1181 // and if the value is not an error, zone.js builds an `Error`
1182 // Object here to attach the stack information.
1183 throw new Error('Uncaught (in promise): ' + readableObjectToString(value) +
1184 (value && value.stack ? '\n' + value.stack : ''));
1185 }
1186 catch (err) {
1187 uncaughtPromiseError = err;
1188 }
1189 if (isDisableWrappingUncaughtPromiseRejection) {
1190 // If disable wrapping uncaught promise reject
1191 // use the value instead of wrapping it.
1192 uncaughtPromiseError.throwOriginal = true;
1193 }
1194 uncaughtPromiseError.rejection = value;
1195 uncaughtPromiseError.promise = promise;
1196 uncaughtPromiseError.zone = Zone.current;
1197 uncaughtPromiseError.task = Zone.currentTask;
1198 _uncaughtPromiseErrors.push(uncaughtPromiseError);
1199 api.scheduleMicroTask(); // to make sure that it is running
1200 }
1201 }
1202 }
1203 // Resolving an already resolved promise is a noop.
1204 return promise;
1205 }
1206 var REJECTION_HANDLED_HANDLER = __symbol__('rejectionHandledHandler');
1207 function clearRejectedNoCatch(promise) {
1208 if (promise[symbolState] === REJECTED_NO_CATCH) {
1209 // if the promise is rejected no catch status
1210 // and queue.length > 0, means there is a error handler
1211 // here to handle the rejected promise, we should trigger
1212 // windows.rejectionhandled eventHandler or nodejs rejectionHandled
1213 // eventHandler
1214 try {
1215 var handler = Zone[REJECTION_HANDLED_HANDLER];
1216 if (handler && typeof handler === 'function') {
1217 handler.call(this, { rejection: promise[symbolValue], promise: promise });
1218 }
1219 }
1220 catch (err) {
1221 }
1222 promise[symbolState] = REJECTED;
1223 for (var i = 0; i < _uncaughtPromiseErrors.length; i++) {
1224 if (promise === _uncaughtPromiseErrors[i].promise) {
1225 _uncaughtPromiseErrors.splice(i, 1);
1226 }
1227 }
1228 }
1229 }
1230 function scheduleResolveOrReject(promise, zone, chainPromise, onFulfilled, onRejected) {
1231 clearRejectedNoCatch(promise);
1232 var promiseState = promise[symbolState];
1233 var delegate = promiseState ?
1234 (typeof onFulfilled === 'function') ? onFulfilled : forwardResolution :
1235 (typeof onRejected === 'function') ? onRejected : forwardRejection;
1236 zone.scheduleMicroTask(source, function () {
1237 try {
1238 var parentPromiseValue = promise[symbolValue];
1239 var isFinallyPromise = !!chainPromise && symbolFinally === chainPromise[symbolFinally];
1240 if (isFinallyPromise) {
1241 // if the promise is generated from finally call, keep parent promise's state and value
1242 chainPromise[symbolParentPromiseValue] = parentPromiseValue;
1243 chainPromise[symbolParentPromiseState] = promiseState;
1244 }
1245 // should not pass value to finally callback
1246 var value = zone.run(delegate, undefined, isFinallyPromise && delegate !== forwardRejection && delegate !== forwardResolution ?
1247 [] :
1248 [parentPromiseValue]);
1249 resolvePromise(chainPromise, true, value);
1250 }
1251 catch (error) {
1252 // if error occurs, should always return this error
1253 resolvePromise(chainPromise, false, error);
1254 }
1255 }, chainPromise);
1256 }
1257 var ZONE_AWARE_PROMISE_TO_STRING = 'function ZoneAwarePromise() { [native code] }';
1258 var noop = function () { };
1259 var ZoneAwarePromise = /** @class */ (function () {
1260 function ZoneAwarePromise(executor) {
1261 var promise = this;
1262 if (!(promise instanceof ZoneAwarePromise)) {
1263 throw new Error('Must be an instanceof Promise.');
1264 }
1265 promise[symbolState] = UNRESOLVED;
1266 promise[symbolValue] = []; // queue;
1267 try {
1268 executor && executor(makeResolver(promise, RESOLVED), makeResolver(promise, REJECTED));
1269 }
1270 catch (error) {
1271 resolvePromise(promise, false, error);
1272 }
1273 }
1274 ZoneAwarePromise.toString = function () {
1275 return ZONE_AWARE_PROMISE_TO_STRING;
1276 };
1277 ZoneAwarePromise.resolve = function (value) {
1278 return resolvePromise(new this(null), RESOLVED, value);
1279 };
1280 ZoneAwarePromise.reject = function (error) {
1281 return resolvePromise(new this(null), REJECTED, error);
1282 };
1283 ZoneAwarePromise.race = function (values) {
1284 var resolve;
1285 var reject;
1286 var promise = new this(function (res, rej) {
1287 resolve = res;
1288 reject = rej;
1289 });
1290 function onResolve(value) {
1291 resolve(value);
1292 }
1293 function onReject(error) {
1294 reject(error);
1295 }
1296 for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
1297 var value = values_1[_i];
1298 if (!isThenable(value)) {
1299 value = this.resolve(value);
1300 }
1301 value.then(onResolve, onReject);
1302 }
1303 return promise;
1304 };
1305 ZoneAwarePromise.all = function (values) {
1306 return ZoneAwarePromise.allWithCallback(values);
1307 };
1308 ZoneAwarePromise.allSettled = function (values) {
1309 var P = this && this.prototype instanceof ZoneAwarePromise ? this : ZoneAwarePromise;
1310 return P.allWithCallback(values, {
1311 thenCallback: function (value) { return ({ status: 'fulfilled', value: value }); },
1312 errorCallback: function (err) { return ({ status: 'rejected', reason: err }); }
1313 });
1314 };
1315 ZoneAwarePromise.allWithCallback = function (values, callback) {
1316 var resolve;
1317 var reject;
1318 var promise = new this(function (res, rej) {
1319 resolve = res;
1320 reject = rej;
1321 });
1322 // Start at 2 to prevent prematurely resolving if .then is called immediately.
1323 var unresolvedCount = 2;
1324 var valueIndex = 0;
1325 var resolvedValues = [];
1326 var _loop_2 = function (value) {
1327 if (!isThenable(value)) {
1328 value = this_1.resolve(value);
1329 }
1330 var curValueIndex = valueIndex;
1331 try {
1332 value.then(function (value) {
1333 resolvedValues[curValueIndex] = callback ? callback.thenCallback(value) : value;
1334 unresolvedCount--;
1335 if (unresolvedCount === 0) {
1336 resolve(resolvedValues);
1337 }
1338 }, function (err) {
1339 if (!callback) {
1340 reject(err);
1341 }
1342 else {
1343 resolvedValues[curValueIndex] = callback.errorCallback(err);
1344 unresolvedCount--;
1345 if (unresolvedCount === 0) {
1346 resolve(resolvedValues);
1347 }
1348 }
1349 });
1350 }
1351 catch (thenErr) {
1352 reject(thenErr);
1353 }
1354 unresolvedCount++;
1355 valueIndex++;
1356 };
1357 var this_1 = this;
1358 for (var _i = 0, values_2 = values; _i < values_2.length; _i++) {
1359 var value = values_2[_i];
1360 _loop_2(value);
1361 }
1362 // Make the unresolvedCount zero-based again.
1363 unresolvedCount -= 2;
1364 if (unresolvedCount === 0) {
1365 resolve(resolvedValues);
1366 }
1367 return promise;
1368 };
1369 Object.defineProperty(ZoneAwarePromise.prototype, Symbol.toStringTag, {
1370 get: function () {
1371 return 'Promise';
1372 },
1373 enumerable: false,
1374 configurable: true
1375 });
1376 Object.defineProperty(ZoneAwarePromise.prototype, Symbol.species, {
1377 get: function () {
1378 return ZoneAwarePromise;
1379 },
1380 enumerable: false,
1381 configurable: true
1382 });
1383 ZoneAwarePromise.prototype.then = function (onFulfilled, onRejected) {
1384 var C = this.constructor[Symbol.species];
1385 if (!C || typeof C !== 'function') {
1386 C = this.constructor || ZoneAwarePromise;
1387 }
1388 var chainPromise = new C(noop);
1389 var zone = Zone.current;
1390 if (this[symbolState] == UNRESOLVED) {
1391 this[symbolValue].push(zone, chainPromise, onFulfilled, onRejected);
1392 }
1393 else {
1394 scheduleResolveOrReject(this, zone, chainPromise, onFulfilled, onRejected);
1395 }
1396 return chainPromise;
1397 };
1398 ZoneAwarePromise.prototype.catch = function (onRejected) {
1399 return this.then(null, onRejected);
1400 };
1401 ZoneAwarePromise.prototype.finally = function (onFinally) {
1402 var C = this.constructor[Symbol.species];
1403 if (!C || typeof C !== 'function') {
1404 C = ZoneAwarePromise;
1405 }
1406 var chainPromise = new C(noop);
1407 chainPromise[symbolFinally] = symbolFinally;
1408 var zone = Zone.current;
1409 if (this[symbolState] == UNRESOLVED) {
1410 this[symbolValue].push(zone, chainPromise, onFinally, onFinally);
1411 }
1412 else {
1413 scheduleResolveOrReject(this, zone, chainPromise, onFinally, onFinally);
1414 }
1415 return chainPromise;
1416 };
1417 return ZoneAwarePromise;
1418 }());
1419 // Protect against aggressive optimizers dropping seemingly unused properties.
1420 // E.g. Closure Compiler in advanced mode.
1421 ZoneAwarePromise['resolve'] = ZoneAwarePromise.resolve;
1422 ZoneAwarePromise['reject'] = ZoneAwarePromise.reject;
1423 ZoneAwarePromise['race'] = ZoneAwarePromise.race;
1424 ZoneAwarePromise['all'] = ZoneAwarePromise.all;
1425 var NativePromise = global[symbolPromise] = global['Promise'];
1426 global['Promise'] = ZoneAwarePromise;
1427 var symbolThenPatched = __symbol__('thenPatched');
1428 function patchThen(Ctor) {
1429 var proto = Ctor.prototype;
1430 var prop = ObjectGetOwnPropertyDescriptor(proto, 'then');
1431 if (prop && (prop.writable === false || !prop.configurable)) {
1432 // check Ctor.prototype.then propertyDescriptor is writable or not
1433 // in meteor env, writable is false, we should ignore such case
1434 return;
1435 }
1436 var originalThen = proto.then;
1437 // Keep a reference to the original method.
1438 proto[symbolThen] = originalThen;
1439 Ctor.prototype.then = function (onResolve, onReject) {
1440 var _this = this;
1441 var wrapped = new ZoneAwarePromise(function (resolve, reject) {
1442 originalThen.call(_this, resolve, reject);
1443 });
1444 return wrapped.then(onResolve, onReject);
1445 };
1446 Ctor[symbolThenPatched] = true;
1447 }
1448 api.patchThen = patchThen;
1449 function zoneify(fn) {
1450 return function (self, args) {
1451 var resultPromise = fn.apply(self, args);
1452 if (resultPromise instanceof ZoneAwarePromise) {
1453 return resultPromise;
1454 }
1455 var ctor = resultPromise.constructor;
1456 if (!ctor[symbolThenPatched]) {
1457 patchThen(ctor);
1458 }
1459 return resultPromise;
1460 };
1461 }
1462 if (NativePromise) {
1463 patchThen(NativePromise);
1464 patchMethod(global, 'fetch', function (delegate) { return zoneify(delegate); });
1465 }
1466 // This is not part of public API, but it is useful for tests, so we expose it.
1467 Promise[Zone.__symbol__('uncaughtPromiseErrors')] = _uncaughtPromiseErrors;
1468 return ZoneAwarePromise;
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 */
1477 // override Function.prototype.toString to make zone.js patched function
1478 // look like native function
1479 Zone.__load_patch('toString', function (global) {
1480 // patch Func.prototype.toString to let them look like native
1481 var originalFunctionToString = Function.prototype.toString;
1482 var ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate');
1483 var PROMISE_SYMBOL = zoneSymbol('Promise');
1484 var ERROR_SYMBOL = zoneSymbol('Error');
1485 var newFunctionToString = function toString() {
1486 if (typeof this === 'function') {
1487 var originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL];
1488 if (originalDelegate) {
1489 if (typeof originalDelegate === 'function') {
1490 return originalFunctionToString.call(originalDelegate);
1491 }
1492 else {
1493 return Object.prototype.toString.call(originalDelegate);
1494 }
1495 }
1496 if (this === Promise) {
1497 var nativePromise = global[PROMISE_SYMBOL];
1498 if (nativePromise) {
1499 return originalFunctionToString.call(nativePromise);
1500 }
1501 }
1502 if (this === Error) {
1503 var nativeError = global[ERROR_SYMBOL];
1504 if (nativeError) {
1505 return originalFunctionToString.call(nativeError);
1506 }
1507 }
1508 }
1509 return originalFunctionToString.call(this);
1510 };
1511 newFunctionToString[ORIGINAL_DELEGATE_SYMBOL] = originalFunctionToString;
1512 Function.prototype.toString = newFunctionToString;
1513 // patch Object.prototype.toString to let them look like native
1514 var originalObjectToString = Object.prototype.toString;
1515 var PROMISE_OBJECT_TO_STRING = '[object Promise]';
1516 Object.prototype.toString = function () {
1517 if (typeof Promise === 'function' && this instanceof Promise) {
1518 return PROMISE_OBJECT_TO_STRING;
1519 }
1520 return originalObjectToString.call(this);
1521 };
1522 });
1523 /**
1524 * @license
1525 * Copyright Google LLC All Rights Reserved.
1526 *
1527 * Use of this source code is governed by an MIT-style license that can be
1528 * found in the LICENSE file at https://angular.io/license
1529 */
1530 Zone.__load_patch('node_util', function (global, Zone, api) {
1531 api.patchOnProperties = patchOnProperties;
1532 api.patchMethod = patchMethod;
1533 api.bindArguments = bindArguments;
1534 api.patchMacroTask = patchMacroTask;
1535 setShouldCopySymbolProperties(true);
1536 });
1537 /**
1538 * @license
1539 * Copyright Google LLC All Rights Reserved.
1540 *
1541 * Use of this source code is governed by an MIT-style license that can be
1542 * found in the LICENSE file at https://angular.io/license
1543 */
1544 var passiveSupported = false;
1545 if (typeof window !== 'undefined') {
1546 try {
1547 var options = Object.defineProperty({}, 'passive', {
1548 get: function () {
1549 passiveSupported = true;
1550 }
1551 });
1552 window.addEventListener('test', options, options);
1553 window.removeEventListener('test', options, options);
1554 }
1555 catch (err) {
1556 passiveSupported = false;
1557 }
1558 }
1559 // an identifier to tell ZoneTask do not create a new invoke closure
1560 var OPTIMIZED_ZONE_EVENT_TASK_DATA = {
1561 useG: true
1562 };
1563 var zoneSymbolEventNames$1 = {};
1564 var globalSources = {};
1565 var EVENT_NAME_SYMBOL_REGX = new RegExp('^' + ZONE_SYMBOL_PREFIX + '(\\w+)(true|false)$');
1566 var IMMEDIATE_PROPAGATION_SYMBOL = zoneSymbol('propagationStopped');
1567 function prepareEventNames(eventName, eventNameToString) {
1568 var falseEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + FALSE_STR;
1569 var trueEventName = (eventNameToString ? eventNameToString(eventName) : eventName) + TRUE_STR;
1570 var symbol = ZONE_SYMBOL_PREFIX + falseEventName;
1571 var symbolCapture = ZONE_SYMBOL_PREFIX + trueEventName;
1572 zoneSymbolEventNames$1[eventName] = {};
1573 zoneSymbolEventNames$1[eventName][FALSE_STR] = symbol;
1574 zoneSymbolEventNames$1[eventName][TRUE_STR] = symbolCapture;
1575 }
1576 function patchEventTarget(_global, apis, patchOptions) {
1577 var ADD_EVENT_LISTENER = (patchOptions && patchOptions.add) || ADD_EVENT_LISTENER_STR;
1578 var REMOVE_EVENT_LISTENER = (patchOptions && patchOptions.rm) || REMOVE_EVENT_LISTENER_STR;
1579 var LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.listeners) || 'eventListeners';
1580 var REMOVE_ALL_LISTENERS_EVENT_LISTENER = (patchOptions && patchOptions.rmAll) || 'removeAllListeners';
1581 var zoneSymbolAddEventListener = zoneSymbol(ADD_EVENT_LISTENER);
1582 var ADD_EVENT_LISTENER_SOURCE = '.' + ADD_EVENT_LISTENER + ':';
1583 var PREPEND_EVENT_LISTENER = 'prependListener';
1584 var PREPEND_EVENT_LISTENER_SOURCE = '.' + PREPEND_EVENT_LISTENER + ':';
1585 var invokeTask = function (task, target, event) {
1586 // for better performance, check isRemoved which is set
1587 // by removeEventListener
1588 if (task.isRemoved) {
1589 return;
1590 }
1591 var delegate = task.callback;
1592 if (typeof delegate === 'object' && delegate.handleEvent) {
1593 // create the bind version of handleEvent when invoke
1594 task.callback = function (event) { return delegate.handleEvent(event); };
1595 task.originalDelegate = delegate;
1596 }
1597 // invoke static task.invoke
1598 task.invoke(task, target, [event]);
1599 var options = task.options;
1600 if (options && typeof options === 'object' && options.once) {
1601 // if options.once is true, after invoke once remove listener here
1602 // only browser need to do this, nodejs eventEmitter will cal removeListener
1603 // inside EventEmitter.once
1604 var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback;
1605 target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options);
1606 }
1607 };
1608 // global shared zoneAwareCallback to handle all event callback with capture = false
1609 var globalZoneAwareCallback = function (event) {
1610 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
1611 // event will be undefined, so we need to use window.event
1612 event = event || _global.event;
1613 if (!event) {
1614 return;
1615 }
1616 // event.target is needed for Samsung TV and SourceBuffer
1617 // || global is needed https://github.com/angular/zone.js/issues/190
1618 var target = this || event.target || _global;
1619 var tasks = target[zoneSymbolEventNames$1[event.type][FALSE_STR]];
1620 if (tasks) {
1621 // invoke all tasks which attached to current target with given event.type and capture = false
1622 // for performance concern, if task.length === 1, just invoke
1623 if (tasks.length === 1) {
1624 invokeTask(tasks[0], target, event);
1625 }
1626 else {
1627 // https://github.com/angular/zone.js/issues/836
1628 // copy the tasks array before invoke, to avoid
1629 // the callback will remove itself or other listener
1630 var copyTasks = tasks.slice();
1631 for (var i = 0; i < copyTasks.length; i++) {
1632 if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
1633 break;
1634 }
1635 invokeTask(copyTasks[i], target, event);
1636 }
1637 }
1638 }
1639 };
1640 // global shared zoneAwareCallback to handle all event callback with capture = true
1641 var globalZoneAwareCaptureCallback = function (event) {
1642 // https://github.com/angular/zone.js/issues/911, in IE, sometimes
1643 // event will be undefined, so we need to use window.event
1644 event = event || _global.event;
1645 if (!event) {
1646 return;
1647 }
1648 // event.target is needed for Samsung TV and SourceBuffer
1649 // || global is needed https://github.com/angular/zone.js/issues/190
1650 var target = this || event.target || _global;
1651 var tasks = target[zoneSymbolEventNames$1[event.type][TRUE_STR]];
1652 if (tasks) {
1653 // invoke all tasks which attached to current target with given event.type and capture = false
1654 // for performance concern, if task.length === 1, just invoke
1655 if (tasks.length === 1) {
1656 invokeTask(tasks[0], target, event);
1657 }
1658 else {
1659 // https://github.com/angular/zone.js/issues/836
1660 // copy the tasks array before invoke, to avoid
1661 // the callback will remove itself or other listener
1662 var copyTasks = tasks.slice();
1663 for (var i = 0; i < copyTasks.length; i++) {
1664 if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {
1665 break;
1666 }
1667 invokeTask(copyTasks[i], target, event);
1668 }
1669 }
1670 }
1671 };
1672 function patchEventTargetMethods(obj, patchOptions) {
1673 if (!obj) {
1674 return false;
1675 }
1676 var useGlobalCallback = true;
1677 if (patchOptions && patchOptions.useG !== undefined) {
1678 useGlobalCallback = patchOptions.useG;
1679 }
1680 var validateHandler = patchOptions && patchOptions.vh;
1681 var checkDuplicate = true;
1682 if (patchOptions && patchOptions.chkDup !== undefined) {
1683 checkDuplicate = patchOptions.chkDup;
1684 }
1685 var returnTarget = false;
1686 if (patchOptions && patchOptions.rt !== undefined) {
1687 returnTarget = patchOptions.rt;
1688 }
1689 var proto = obj;
1690 while (proto && !proto.hasOwnProperty(ADD_EVENT_LISTENER)) {
1691 proto = ObjectGetPrototypeOf(proto);
1692 }
1693 if (!proto && obj[ADD_EVENT_LISTENER]) {
1694 // somehow we did not find it, but we can see it. This happens on IE for Window properties.
1695 proto = obj;
1696 }
1697 if (!proto) {
1698 return false;
1699 }
1700 if (proto[zoneSymbolAddEventListener]) {
1701 return false;
1702 }
1703 var eventNameToString = patchOptions && patchOptions.eventNameToString;
1704 // a shared global taskData to pass data for scheduleEventTask
1705 // so we do not need to create a new object just for pass some data
1706 var taskData = {};
1707 var nativeAddEventListener = proto[zoneSymbolAddEventListener] = proto[ADD_EVENT_LISTENER];
1708 var nativeRemoveEventListener = proto[zoneSymbol(REMOVE_EVENT_LISTENER)] =
1709 proto[REMOVE_EVENT_LISTENER];
1710 var nativeListeners = proto[zoneSymbol(LISTENERS_EVENT_LISTENER)] =
1711 proto[LISTENERS_EVENT_LISTENER];
1712 var nativeRemoveAllListeners = proto[zoneSymbol(REMOVE_ALL_LISTENERS_EVENT_LISTENER)] =
1713 proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER];
1714 var nativePrependEventListener;
1715 if (patchOptions && patchOptions.prepend) {
1716 nativePrependEventListener = proto[zoneSymbol(patchOptions.prepend)] =
1717 proto[patchOptions.prepend];
1718 }
1719 /**
1720 * This util function will build an option object with passive option
1721 * to handle all possible input from the user.
1722 */
1723 function buildEventListenerOptions(options, passive) {
1724 if (!passiveSupported && typeof options === 'object' && options) {
1725 // doesn't support passive but user want to pass an object as options.
1726 // this will not work on some old browser, so we just pass a boolean
1727 // as useCapture parameter
1728 return !!options.capture;
1729 }
1730 if (!passiveSupported || !passive) {
1731 return options;
1732 }
1733 if (typeof options === 'boolean') {
1734 return { capture: options, passive: true };
1735 }
1736 if (!options) {
1737 return { passive: true };
1738 }
1739 if (typeof options === 'object' && options.passive !== false) {
1740 return Object.assign(Object.assign({}, options), { passive: true });
1741 }
1742 return options;
1743 }
1744 var customScheduleGlobal = function (task) {
1745 // if there is already a task for the eventName + capture,
1746 // just return, because we use the shared globalZoneAwareCallback here.
1747 if (taskData.isExisting) {
1748 return;
1749 }
1750 return nativeAddEventListener.call(taskData.target, taskData.eventName, taskData.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, taskData.options);
1751 };
1752 var customCancelGlobal = function (task) {
1753 // if task is not marked as isRemoved, this call is directly
1754 // from Zone.prototype.cancelTask, we should remove the task
1755 // from tasksList of target first
1756 if (!task.isRemoved) {
1757 var symbolEventNames = zoneSymbolEventNames$1[task.eventName];
1758 var symbolEventName = void 0;
1759 if (symbolEventNames) {
1760 symbolEventName = symbolEventNames[task.capture ? TRUE_STR : FALSE_STR];
1761 }
1762 var existingTasks = symbolEventName && task.target[symbolEventName];
1763 if (existingTasks) {
1764 for (var i = 0; i < existingTasks.length; i++) {
1765 var existingTask = existingTasks[i];
1766 if (existingTask === task) {
1767 existingTasks.splice(i, 1);
1768 // set isRemoved to data for faster invokeTask check
1769 task.isRemoved = true;
1770 if (existingTasks.length === 0) {
1771 // all tasks for the eventName + capture have gone,
1772 // remove globalZoneAwareCallback and remove the task cache from target
1773 task.allRemoved = true;
1774 task.target[symbolEventName] = null;
1775 }
1776 break;
1777 }
1778 }
1779 }
1780 }
1781 // if all tasks for the eventName + capture have gone,
1782 // we will really remove the global event callback,
1783 // if not, return
1784 if (!task.allRemoved) {
1785 return;
1786 }
1787 return nativeRemoveEventListener.call(task.target, task.eventName, task.capture ? globalZoneAwareCaptureCallback : globalZoneAwareCallback, task.options);
1788 };
1789 var customScheduleNonGlobal = function (task) {
1790 return nativeAddEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
1791 };
1792 var customSchedulePrepend = function (task) {
1793 return nativePrependEventListener.call(taskData.target, taskData.eventName, task.invoke, taskData.options);
1794 };
1795 var customCancelNonGlobal = function (task) {
1796 return nativeRemoveEventListener.call(task.target, task.eventName, task.invoke, task.options);
1797 };
1798 var customSchedule = useGlobalCallback ? customScheduleGlobal : customScheduleNonGlobal;
1799 var customCancel = useGlobalCallback ? customCancelGlobal : customCancelNonGlobal;
1800 var compareTaskCallbackVsDelegate = function (task, delegate) {
1801 var typeOfDelegate = typeof delegate;
1802 return (typeOfDelegate === 'function' && task.callback === delegate) ||
1803 (typeOfDelegate === 'object' && task.originalDelegate === delegate);
1804 };
1805 var compare = (patchOptions && patchOptions.diff) ? patchOptions.diff : compareTaskCallbackVsDelegate;
1806 var unpatchedEvents = Zone[zoneSymbol('UNPATCHED_EVENTS')];
1807 var passiveEvents = _global[zoneSymbol('PASSIVE_EVENTS')];
1808 var makeAddListener = function (nativeListener, addSource, customScheduleFn, customCancelFn, returnTarget, prepend) {
1809 if (returnTarget === void 0) { returnTarget = false; }
1810 if (prepend === void 0) { prepend = false; }
1811 return function () {
1812 var target = this || _global;
1813 var eventName = arguments[0];
1814 if (patchOptions && patchOptions.transferEventName) {
1815 eventName = patchOptions.transferEventName(eventName);
1816 }
1817 var delegate = arguments[1];
1818 if (!delegate) {
1819 return nativeListener.apply(this, arguments);
1820 }
1821 if (isNode && eventName === 'uncaughtException') {
1822 // don't patch uncaughtException of nodejs to prevent endless loop
1823 return nativeListener.apply(this, arguments);
1824 }
1825 // don't create the bind delegate function for handleEvent
1826 // case here to improve addEventListener performance
1827 // we will create the bind delegate when invoke
1828 var isHandleEvent = false;
1829 if (typeof delegate !== 'function') {
1830 if (!delegate.handleEvent) {
1831 return nativeListener.apply(this, arguments);
1832 }
1833 isHandleEvent = true;
1834 }
1835 if (validateHandler && !validateHandler(nativeListener, delegate, target, arguments)) {
1836 return;
1837 }
1838 var passive = passiveSupported && !!passiveEvents && passiveEvents.indexOf(eventName) !== -1;
1839 var options = buildEventListenerOptions(arguments[2], passive);
1840 if (unpatchedEvents) {
1841 // check upatched list
1842 for (var i = 0; i < unpatchedEvents.length; i++) {
1843 if (eventName === unpatchedEvents[i]) {
1844 if (passive) {
1845 return nativeListener.call(target, eventName, delegate, options);
1846 }
1847 else {
1848 return nativeListener.apply(this, arguments);
1849 }
1850 }
1851 }
1852 }
1853 var capture = !options ? false : typeof options === 'boolean' ? true : options.capture;
1854 var once = options && typeof options === 'object' ? options.once : false;
1855 var zone = Zone.current;
1856 var symbolEventNames = zoneSymbolEventNames$1[eventName];
1857 if (!symbolEventNames) {
1858 prepareEventNames(eventName, eventNameToString);
1859 symbolEventNames = zoneSymbolEventNames$1[eventName];
1860 }
1861 var symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
1862 var existingTasks = target[symbolEventName];
1863 var isExisting = false;
1864 if (existingTasks) {
1865 // already have task registered
1866 isExisting = true;
1867 if (checkDuplicate) {
1868 for (var i = 0; i < existingTasks.length; i++) {
1869 if (compare(existingTasks[i], delegate)) {
1870 // same callback, same capture, same event name, just return
1871 return;
1872 }
1873 }
1874 }
1875 }
1876 else {
1877 existingTasks = target[symbolEventName] = [];
1878 }
1879 var source;
1880 var constructorName = target.constructor['name'];
1881 var targetSource = globalSources[constructorName];
1882 if (targetSource) {
1883 source = targetSource[eventName];
1884 }
1885 if (!source) {
1886 source = constructorName + addSource +
1887 (eventNameToString ? eventNameToString(eventName) : eventName);
1888 }
1889 // do not create a new object as task.data to pass those things
1890 // just use the global shared one
1891 taskData.options = options;
1892 if (once) {
1893 // if addEventListener with once options, we don't pass it to
1894 // native addEventListener, instead we keep the once setting
1895 // and handle ourselves.
1896 taskData.options.once = false;
1897 }
1898 taskData.target = target;
1899 taskData.capture = capture;
1900 taskData.eventName = eventName;
1901 taskData.isExisting = isExisting;
1902 var data = useGlobalCallback ? OPTIMIZED_ZONE_EVENT_TASK_DATA : undefined;
1903 // keep taskData into data to allow onScheduleEventTask to access the task information
1904 if (data) {
1905 data.taskData = taskData;
1906 }
1907 var task = zone.scheduleEventTask(source, delegate, data, customScheduleFn, customCancelFn);
1908 // should clear taskData.target to avoid memory leak
1909 // issue, https://github.com/angular/angular/issues/20442
1910 taskData.target = null;
1911 // need to clear up taskData because it is a global object
1912 if (data) {
1913 data.taskData = null;
1914 }
1915 // have to save those information to task in case
1916 // application may call task.zone.cancelTask() directly
1917 if (once) {
1918 options.once = true;
1919 }
1920 if (!(!passiveSupported && typeof task.options === 'boolean')) {
1921 // if not support passive, and we pass an option object
1922 // to addEventListener, we should save the options to task
1923 task.options = options;
1924 }
1925 task.target = target;
1926 task.capture = capture;
1927 task.eventName = eventName;
1928 if (isHandleEvent) {
1929 // save original delegate for compare to check duplicate
1930 task.originalDelegate = delegate;
1931 }
1932 if (!prepend) {
1933 existingTasks.push(task);
1934 }
1935 else {
1936 existingTasks.unshift(task);
1937 }
1938 if (returnTarget) {
1939 return target;
1940 }
1941 };
1942 };
1943 proto[ADD_EVENT_LISTENER] = makeAddListener(nativeAddEventListener, ADD_EVENT_LISTENER_SOURCE, customSchedule, customCancel, returnTarget);
1944 if (nativePrependEventListener) {
1945 proto[PREPEND_EVENT_LISTENER] = makeAddListener(nativePrependEventListener, PREPEND_EVENT_LISTENER_SOURCE, customSchedulePrepend, customCancel, returnTarget, true);
1946 }
1947 proto[REMOVE_EVENT_LISTENER] = function () {
1948 var target = this || _global;
1949 var eventName = arguments[0];
1950 if (patchOptions && patchOptions.transferEventName) {
1951 eventName = patchOptions.transferEventName(eventName);
1952 }
1953 var options = arguments[2];
1954 var capture = !options ? false : typeof options === 'boolean' ? true : options.capture;
1955 var delegate = arguments[1];
1956 if (!delegate) {
1957 return nativeRemoveEventListener.apply(this, arguments);
1958 }
1959 if (validateHandler &&
1960 !validateHandler(nativeRemoveEventListener, delegate, target, arguments)) {
1961 return;
1962 }
1963 var symbolEventNames = zoneSymbolEventNames$1[eventName];
1964 var symbolEventName;
1965 if (symbolEventNames) {
1966 symbolEventName = symbolEventNames[capture ? TRUE_STR : FALSE_STR];
1967 }
1968 var existingTasks = symbolEventName && target[symbolEventName];
1969 if (existingTasks) {
1970 for (var i = 0; i < existingTasks.length; i++) {
1971 var existingTask = existingTasks[i];
1972 if (compare(existingTask, delegate)) {
1973 existingTasks.splice(i, 1);
1974 // set isRemoved to data for faster invokeTask check
1975 existingTask.isRemoved = true;
1976 if (existingTasks.length === 0) {
1977 // all tasks for the eventName + capture have gone,
1978 // remove globalZoneAwareCallback and remove the task cache from target
1979 existingTask.allRemoved = true;
1980 target[symbolEventName] = null;
1981 // in the target, we have an event listener which is added by on_property
1982 // such as target.onclick = function() {}, so we need to clear this internal
1983 // property too if all delegates all removed
1984 if (typeof eventName === 'string') {
1985 var onPropertySymbol = ZONE_SYMBOL_PREFIX + 'ON_PROPERTY' + eventName;
1986 target[onPropertySymbol] = null;
1987 }
1988 }
1989 existingTask.zone.cancelTask(existingTask);
1990 if (returnTarget) {
1991 return target;
1992 }
1993 return;
1994 }
1995 }
1996 }
1997 // issue 930, didn't find the event name or callback
1998 // from zone kept existingTasks, the callback maybe
1999 // added outside of zone, we need to call native removeEventListener
2000 // to try to remove it.
2001 return nativeRemoveEventListener.apply(this, arguments);
2002 };
2003 proto[LISTENERS_EVENT_LISTENER] = function () {
2004 var target = this || _global;
2005 var eventName = arguments[0];
2006 if (patchOptions && patchOptions.transferEventName) {
2007 eventName = patchOptions.transferEventName(eventName);
2008 }
2009 var listeners = [];
2010 var tasks = findEventTasks(target, eventNameToString ? eventNameToString(eventName) : eventName);
2011 for (var i = 0; i < tasks.length; i++) {
2012 var task = tasks[i];
2013 var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2014 listeners.push(delegate);
2015 }
2016 return listeners;
2017 };
2018 proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER] = function () {
2019 var target = this || _global;
2020 var eventName = arguments[0];
2021 if (!eventName) {
2022 var keys = Object.keys(target);
2023 for (var i = 0; i < keys.length; i++) {
2024 var prop = keys[i];
2025 var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
2026 var evtName = match && match[1];
2027 // in nodejs EventEmitter, removeListener event is
2028 // used for monitoring the removeListener call,
2029 // so just keep removeListener eventListener until
2030 // all other eventListeners are removed
2031 if (evtName && evtName !== 'removeListener') {
2032 this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, evtName);
2033 }
2034 }
2035 // remove removeListener listener finally
2036 this[REMOVE_ALL_LISTENERS_EVENT_LISTENER].call(this, 'removeListener');
2037 }
2038 else {
2039 if (patchOptions && patchOptions.transferEventName) {
2040 eventName = patchOptions.transferEventName(eventName);
2041 }
2042 var symbolEventNames = zoneSymbolEventNames$1[eventName];
2043 if (symbolEventNames) {
2044 var symbolEventName = symbolEventNames[FALSE_STR];
2045 var symbolCaptureEventName = symbolEventNames[TRUE_STR];
2046 var tasks = target[symbolEventName];
2047 var captureTasks = target[symbolCaptureEventName];
2048 if (tasks) {
2049 var removeTasks = tasks.slice();
2050 for (var i = 0; i < removeTasks.length; i++) {
2051 var task = removeTasks[i];
2052 var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2053 this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
2054 }
2055 }
2056 if (captureTasks) {
2057 var removeTasks = captureTasks.slice();
2058 for (var i = 0; i < removeTasks.length; i++) {
2059 var task = removeTasks[i];
2060 var delegate = task.originalDelegate ? task.originalDelegate : task.callback;
2061 this[REMOVE_EVENT_LISTENER].call(this, eventName, delegate, task.options);
2062 }
2063 }
2064 }
2065 }
2066 if (returnTarget) {
2067 return this;
2068 }
2069 };
2070 // for native toString patch
2071 attachOriginToPatched(proto[ADD_EVENT_LISTENER], nativeAddEventListener);
2072 attachOriginToPatched(proto[REMOVE_EVENT_LISTENER], nativeRemoveEventListener);
2073 if (nativeRemoveAllListeners) {
2074 attachOriginToPatched(proto[REMOVE_ALL_LISTENERS_EVENT_LISTENER], nativeRemoveAllListeners);
2075 }
2076 if (nativeListeners) {
2077 attachOriginToPatched(proto[LISTENERS_EVENT_LISTENER], nativeListeners);
2078 }
2079 return true;
2080 }
2081 var results = [];
2082 for (var i = 0; i < apis.length; i++) {
2083 results[i] = patchEventTargetMethods(apis[i], patchOptions);
2084 }
2085 return results;
2086 }
2087 function findEventTasks(target, eventName) {
2088 if (!eventName) {
2089 var foundTasks = [];
2090 for (var prop in target) {
2091 var match = EVENT_NAME_SYMBOL_REGX.exec(prop);
2092 var evtName = match && match[1];
2093 if (evtName && (!eventName || evtName === eventName)) {
2094 var tasks = target[prop];
2095 if (tasks) {
2096 for (var i = 0; i < tasks.length; i++) {
2097 foundTasks.push(tasks[i]);
2098 }
2099 }
2100 }
2101 }
2102 return foundTasks;
2103 }
2104 var symbolEventName = zoneSymbolEventNames$1[eventName];
2105 if (!symbolEventName) {
2106 prepareEventNames(eventName);
2107 symbolEventName = zoneSymbolEventNames$1[eventName];
2108 }
2109 var captureFalseTasks = target[symbolEventName[FALSE_STR]];
2110 var captureTrueTasks = target[symbolEventName[TRUE_STR]];
2111 if (!captureFalseTasks) {
2112 return captureTrueTasks ? captureTrueTasks.slice() : [];
2113 }
2114 else {
2115 return captureTrueTasks ? captureFalseTasks.concat(captureTrueTasks) :
2116 captureFalseTasks.slice();
2117 }
2118 }
2119 /**
2120 * @license
2121 * Copyright Google LLC All Rights Reserved.
2122 *
2123 * Use of this source code is governed by an MIT-style license that can be
2124 * found in the LICENSE file at https://angular.io/license
2125 */
2126 Zone.__load_patch('EventEmitter', function (global) {
2127 // For EventEmitter
2128 var EE_ADD_LISTENER = 'addListener';
2129 var EE_PREPEND_LISTENER = 'prependListener';
2130 var EE_REMOVE_LISTENER = 'removeListener';
2131 var EE_REMOVE_ALL_LISTENER = 'removeAllListeners';
2132 var EE_LISTENERS = 'listeners';
2133 var EE_ON = 'on';
2134 var EE_OFF = 'off';
2135 var compareTaskCallbackVsDelegate = function (task, delegate) {
2136 // same callback, same capture, same event name, just return
2137 return task.callback === delegate || task.callback.listener === delegate;
2138 };
2139 var eventNameToString = function (eventName) {
2140 if (typeof eventName === 'string') {
2141 return eventName;
2142 }
2143 if (!eventName) {
2144 return '';
2145 }
2146 return eventName.toString().replace('(', '_').replace(')', '_');
2147 };
2148 function patchEventEmitterMethods(obj) {
2149 var result = patchEventTarget(global, [obj], {
2150 useG: false,
2151 add: EE_ADD_LISTENER,
2152 rm: EE_REMOVE_LISTENER,
2153 prepend: EE_PREPEND_LISTENER,
2154 rmAll: EE_REMOVE_ALL_LISTENER,
2155 listeners: EE_LISTENERS,
2156 chkDup: false,
2157 rt: true,
2158 diff: compareTaskCallbackVsDelegate,
2159 eventNameToString: eventNameToString
2160 });
2161 if (result && result[0]) {
2162 obj[EE_ON] = obj[EE_ADD_LISTENER];
2163 obj[EE_OFF] = obj[EE_REMOVE_LISTENER];
2164 }
2165 }
2166 // EventEmitter
2167 var events;
2168 try {
2169 events = require('events');
2170 }
2171 catch (err) {
2172 }
2173 if (events && events.EventEmitter) {
2174 patchEventEmitterMethods(events.EventEmitter.prototype);
2175 }
2176 });
2177 /**
2178 * @license
2179 * Copyright Google LLC All Rights Reserved.
2180 *
2181 * Use of this source code is governed by an MIT-style license that can be
2182 * found in the LICENSE file at https://angular.io/license
2183 */
2184 Zone.__load_patch('fs', function () {
2185 var fs;
2186 try {
2187 fs = require('fs');
2188 }
2189 catch (err) {
2190 }
2191 // watch, watchFile, unwatchFile has been patched
2192 // because EventEmitter has been patched
2193 var TO_PATCH_MACROTASK_METHODS = [
2194 'access', 'appendFile', 'chmod', 'chown', 'close', 'exists', 'fchmod',
2195 'fchown', 'fdatasync', 'fstat', 'fsync', 'ftruncate', 'futimes', 'lchmod',
2196 'lchown', 'link', 'lstat', 'mkdir', 'mkdtemp', 'open', 'read',
2197 'readdir', 'readFile', 'readlink', 'realpath', 'rename', 'rmdir', 'stat',
2198 'symlink', 'truncate', 'unlink', 'utimes', 'write', 'writeFile',
2199 ];
2200 if (fs) {
2201 TO_PATCH_MACROTASK_METHODS.filter(function (name) { return !!fs[name] && typeof fs[name] === 'function'; })
2202 .forEach(function (name) {
2203 patchMacroTask(fs, name, function (self, args) {
2204 return {
2205 name: 'fs.' + name,
2206 args: args,
2207 cbIdx: args.length > 0 ? args.length - 1 : -1,
2208 target: self
2209 };
2210 });
2211 });
2212 }
2213 });
2214 /**
2215 * @license
2216 * Copyright Google LLC All Rights Reserved.
2217 *
2218 * Use of this source code is governed by an MIT-style license that can be
2219 * found in the LICENSE file at https://angular.io/license
2220 */
2221 var taskSymbol = zoneSymbol('zoneTask');
2222 function patchTimer(window, setName, cancelName, nameSuffix) {
2223 var setNative = null;
2224 var clearNative = null;
2225 setName += nameSuffix;
2226 cancelName += nameSuffix;
2227 var tasksByHandleId = {};
2228 function scheduleTask(task) {
2229 var data = task.data;
2230 data.args[0] = function () {
2231 return task.invoke.apply(this, arguments);
2232 };
2233 data.handleId = setNative.apply(window, data.args);
2234 return task;
2235 }
2236 function clearTask(task) {
2237 return clearNative.call(window, task.data.handleId);
2238 }
2239 setNative =
2240 patchMethod(window, setName, function (delegate) { return function (self, args) {
2241 if (typeof args[0] === 'function') {
2242 var options_1 = {
2243 isPeriodic: nameSuffix === 'Interval',
2244 delay: (nameSuffix === 'Timeout' || nameSuffix === 'Interval') ? args[1] || 0 :
2245 undefined,
2246 args: args
2247 };
2248 var callback_1 = args[0];
2249 args[0] = function timer() {
2250 try {
2251 return callback_1.apply(this, arguments);
2252 }
2253 finally {
2254 // issue-934, task will be cancelled
2255 // even it is a periodic task such as
2256 // setInterval
2257 // https://github.com/angular/angular/issues/40387
2258 // Cleanup tasksByHandleId should be handled before scheduleTask
2259 // Since some zoneSpec may intercept and doesn't trigger
2260 // scheduleFn(scheduleTask) provided here.
2261 if (!(options_1.isPeriodic)) {
2262 if (typeof options_1.handleId === 'number') {
2263 // in non-nodejs env, we remove timerId
2264 // from local cache
2265 delete tasksByHandleId[options_1.handleId];
2266 }
2267 else if (options_1.handleId) {
2268 // Node returns complex objects as handleIds
2269 // we remove task reference from timer object
2270 options_1.handleId[taskSymbol] = null;
2271 }
2272 }
2273 }
2274 };
2275 var task = scheduleMacroTaskWithCurrentZone(setName, args[0], options_1, scheduleTask, clearTask);
2276 if (!task) {
2277 return task;
2278 }
2279 // Node.js must additionally support the ref and unref functions.
2280 var handle = task.data.handleId;
2281 if (typeof handle === 'number') {
2282 // for non nodejs env, we save handleId: task
2283 // mapping in local cache for clearTimeout
2284 tasksByHandleId[handle] = task;
2285 }
2286 else if (handle) {
2287 // for nodejs env, we save task
2288 // reference in timerId Object for clearTimeout
2289 handle[taskSymbol] = task;
2290 }
2291 // check whether handle is null, because some polyfill or browser
2292 // may return undefined from setTimeout/setInterval/setImmediate/requestAnimationFrame
2293 if (handle && handle.ref && handle.unref && typeof handle.ref === 'function' &&
2294 typeof handle.unref === 'function') {
2295 task.ref = handle.ref.bind(handle);
2296 task.unref = handle.unref.bind(handle);
2297 }
2298 if (typeof handle === 'number' || handle) {
2299 return handle;
2300 }
2301 return task;
2302 }
2303 else {
2304 // cause an error by calling it directly.
2305 return delegate.apply(window, args);
2306 }
2307 }; });
2308 clearNative =
2309 patchMethod(window, cancelName, function (delegate) { return function (self, args) {
2310 var id = args[0];
2311 var task;
2312 if (typeof id === 'number') {
2313 // non nodejs env.
2314 task = tasksByHandleId[id];
2315 }
2316 else {
2317 // nodejs env.
2318 task = id && id[taskSymbol];
2319 // other environments.
2320 if (!task) {
2321 task = id;
2322 }
2323 }
2324 if (task && typeof task.type === 'string') {
2325 if (task.state !== 'notScheduled' &&
2326 (task.cancelFn && task.data.isPeriodic || task.runCount === 0)) {
2327 if (typeof id === 'number') {
2328 delete tasksByHandleId[id];
2329 }
2330 else if (id) {
2331 id[taskSymbol] = null;
2332 }
2333 // Do not cancel already canceled functions
2334 task.zone.cancelTask(task);
2335 }
2336 }
2337 else {
2338 // cause an error by calling it directly.
2339 delegate.apply(window, args);
2340 }
2341 }; });
2342 }
2343 /**
2344 * @license
2345 * Copyright Google LLC All Rights Reserved.
2346 *
2347 * Use of this source code is governed by an MIT-style license that can be
2348 * found in the LICENSE file at https://angular.io/license
2349 */
2350 var set = 'set';
2351 var clear = 'clear';
2352 Zone.__load_patch('node_timers', function (global, Zone) {
2353 // Timers
2354 var globalUseTimeoutFromTimer = false;
2355 try {
2356 var timers = require('timers');
2357 var globalEqualTimersTimeout = global.setTimeout === timers.setTimeout;
2358 if (!globalEqualTimersTimeout && !isMix) {
2359 // 1. if isMix, then we are in mix environment such as Electron
2360 // we should only patch timers.setTimeout because global.setTimeout
2361 // have been patched
2362 // 2. if global.setTimeout not equal timers.setTimeout, check
2363 // whether global.setTimeout use timers.setTimeout or not
2364 var originSetTimeout_1 = timers.setTimeout;
2365 timers.setTimeout = function () {
2366 globalUseTimeoutFromTimer = true;
2367 return originSetTimeout_1.apply(this, arguments);
2368 };
2369 var detectTimeout = global.setTimeout(function () { }, 100);
2370 clearTimeout(detectTimeout);
2371 timers.setTimeout = originSetTimeout_1;
2372 }
2373 patchTimer(timers, set, clear, 'Timeout');
2374 patchTimer(timers, set, clear, 'Interval');
2375 patchTimer(timers, set, clear, 'Immediate');
2376 }
2377 catch (error) {
2378 // timers module not exists, for example, when we using nativeScript
2379 // timers is not available
2380 }
2381 if (isMix) {
2382 // if we are in mix environment, such as Electron,
2383 // the global.setTimeout has already been patched,
2384 // so we just patch timers.setTimeout
2385 return;
2386 }
2387 if (!globalUseTimeoutFromTimer) {
2388 // 1. global setTimeout equals timers setTimeout
2389 // 2. or global don't use timers setTimeout(maybe some other library patch setTimeout)
2390 // 3. or load timers module error happens, we should patch global setTimeout
2391 patchTimer(global, set, clear, 'Timeout');
2392 patchTimer(global, set, clear, 'Interval');
2393 patchTimer(global, set, clear, 'Immediate');
2394 }
2395 else {
2396 // global use timers setTimeout, but not equals
2397 // this happens when use nodejs v0.10.x, global setTimeout will
2398 // use a lazy load version of timers setTimeout
2399 // we should not double patch timer's setTimeout
2400 // so we only store the __symbol__ for consistency
2401 global[Zone.__symbol__('setTimeout')] = global.setTimeout;
2402 global[Zone.__symbol__('setInterval')] = global.setInterval;
2403 global[Zone.__symbol__('setImmediate')] = global.setImmediate;
2404 }
2405 });
2406 // patch process related methods
2407 Zone.__load_patch('nextTick', function () {
2408 // patch nextTick as microTask
2409 patchMicroTask(process, 'nextTick', function (self, args) {
2410 return {
2411 name: 'process.nextTick',
2412 args: args,
2413 cbIdx: (args.length > 0 && typeof args[0] === 'function') ? 0 : -1,
2414 target: process
2415 };
2416 });
2417 });
2418 Zone.__load_patch('handleUnhandledPromiseRejection', function (global, Zone, api) {
2419 Zone[api.symbol('unhandledPromiseRejectionHandler')] =
2420 findProcessPromiseRejectionHandler('unhandledRejection');
2421 Zone[api.symbol('rejectionHandledHandler')] =
2422 findProcessPromiseRejectionHandler('rejectionHandled');
2423 // handle unhandled promise rejection
2424 function findProcessPromiseRejectionHandler(evtName) {
2425 return function (e) {
2426 var eventTasks = findEventTasks(process, evtName);
2427 eventTasks.forEach(function (eventTask) {
2428 // process has added unhandledrejection event listener
2429 // trigger the event listener
2430 if (evtName === 'unhandledRejection') {
2431 eventTask.invoke(e.rejection, e.promise);
2432 }
2433 else if (evtName === 'rejectionHandled') {
2434 eventTask.invoke(e.promise);
2435 }
2436 });
2437 };
2438 }
2439 });
2440 // Crypto
2441 Zone.__load_patch('crypto', function () {
2442 var crypto;
2443 try {
2444 crypto = require('crypto');
2445 }
2446 catch (err) {
2447 }
2448 // use the generic patchMacroTask to patch crypto
2449 if (crypto) {
2450 var methodNames = ['randomBytes', 'pbkdf2'];
2451 methodNames.forEach(function (name) {
2452 patchMacroTask(crypto, name, function (self, args) {
2453 return {
2454 name: 'crypto.' + name,
2455 args: args,
2456 cbIdx: (args.length > 0 && typeof args[args.length - 1] === 'function') ?
2457 args.length - 1 :
2458 -1,
2459 target: crypto
2460 };
2461 });
2462 });
2463 }
2464 });
2465 Zone.__load_patch('console', function (global, Zone) {
2466 var consoleMethods = ['dir', 'log', 'info', 'error', 'warn', 'assert', 'debug', 'timeEnd', 'trace'];
2467 consoleMethods.forEach(function (m) {
2468 var originalMethod = console[Zone.__symbol__(m)] = console[m];
2469 if (originalMethod) {
2470 console[m] = function () {
2471 var args = ArraySlice.call(arguments);
2472 if (Zone.current === Zone.root) {
2473 return originalMethod.apply(this, args);
2474 }
2475 else {
2476 return Zone.root.run(originalMethod, this, args);
2477 }
2478 };
2479 }
2480 });
2481 });
2482})));
Note: See TracBrowser for help on using the repository browser.