source: trip-planner-front/node_modules/zone.js/dist/zone-patch-promise-test.js@ 76712b2

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

initial commit

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[6a3a178]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 /**
20 * Promise for async/fakeAsync zoneSpec test
21 * can support async operation which not supported by zone.js
22 * such as
23 * it ('test jsonp in AsyncZone', async() => {
24 * new Promise(res => {
25 * jsonp(url, (data) => {
26 * // success callback
27 * res(data);
28 * });
29 * }).then((jsonpResult) => {
30 * // get jsonp result.
31 *
32 * // user will expect AsyncZoneSpec wait for
33 * // then, but because jsonp is not zone aware
34 * // AsyncZone will finish before then is called.
35 * });
36 * });
37 */
38 Zone.__load_patch('promisefortest', function (global, Zone, api) {
39 var symbolState = api.symbol('state');
40 var UNRESOLVED = null;
41 var symbolParentUnresolved = api.symbol('parentUnresolved');
42 // patch Promise.prototype.then to keep an internal
43 // number for tracking unresolved chained promise
44 // we will decrease this number when the parent promise
45 // being resolved/rejected and chained promise was
46 // scheduled as a microTask.
47 // so we can know such kind of chained promise still
48 // not resolved in AsyncTestZone
49 Promise[api.symbol('patchPromiseForTest')] = function patchPromiseForTest() {
50 var oriThen = Promise[Zone.__symbol__('ZonePromiseThen')];
51 if (oriThen) {
52 return;
53 }
54 oriThen = Promise[Zone.__symbol__('ZonePromiseThen')] = Promise.prototype.then;
55 Promise.prototype.then = function () {
56 var chained = oriThen.apply(this, arguments);
57 if (this[symbolState] === UNRESOLVED) {
58 // parent promise is unresolved.
59 var asyncTestZoneSpec = Zone.current.get('AsyncTestZoneSpec');
60 if (asyncTestZoneSpec) {
61 asyncTestZoneSpec.unresolvedChainedPromiseCount++;
62 chained[symbolParentUnresolved] = true;
63 }
64 }
65 return chained;
66 };
67 };
68 Promise[api.symbol('unPatchPromiseForTest')] = function unpatchPromiseForTest() {
69 // restore origin then
70 var oriThen = Promise[Zone.__symbol__('ZonePromiseThen')];
71 if (oriThen) {
72 Promise.prototype.then = oriThen;
73 Promise[Zone.__symbol__('ZonePromiseThen')] = undefined;
74 }
75 };
76 });
77})));
Note: See TracBrowser for help on using the repository browser.