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