source: trip-planner-front/node_modules/zone.js/fesm2015/zone-bluebird.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 3.7 KB
Line 
1'use strict';
2/**
3 * @license Angular v12.0.0-next.0
4 * (c) 2010-2020 Google LLC. https://angular.io/
5 * License: MIT
6 */
7/**
8 * @license
9 * Copyright Google LLC All Rights Reserved.
10 *
11 * Use of this source code is governed by an MIT-style license that can be
12 * found in the LICENSE file at https://angular.io/license
13 */
14Zone.__load_patch('bluebird', (global, Zone, api) => {
15 // TODO: @JiaLiPassion, we can automatically patch bluebird
16 // if global.Promise = Bluebird, but sometimes in nodejs,
17 // global.Promise is not Bluebird, and Bluebird is just be
18 // used by other libraries such as sequelize, so I think it is
19 // safe to just expose a method to patch Bluebird explicitly
20 const BLUEBIRD = 'bluebird';
21 Zone[Zone.__symbol__(BLUEBIRD)] = function patchBluebird(Bluebird) {
22 // patch method of Bluebird.prototype which not using `then` internally
23 const bluebirdApis = ['then', 'spread', 'finally'];
24 bluebirdApis.forEach(bapi => {
25 api.patchMethod(Bluebird.prototype, bapi, (delegate) => (self, args) => {
26 const zone = Zone.current;
27 for (let i = 0; i < args.length; i++) {
28 const func = args[i];
29 if (typeof func === 'function') {
30 args[i] = function () {
31 const argSelf = this;
32 const argArgs = arguments;
33 return new Bluebird((res, rej) => {
34 zone.scheduleMicroTask('Promise.then', () => {
35 try {
36 res(func.apply(argSelf, argArgs));
37 }
38 catch (error) {
39 rej(error);
40 }
41 });
42 });
43 };
44 }
45 }
46 return delegate.apply(self, args);
47 });
48 });
49 if (typeof window !== 'undefined') {
50 window.addEventListener('unhandledrejection', function (event) {
51 const error = event.detail && event.detail.reason;
52 if (error && error.isHandledByZone) {
53 event.preventDefault();
54 if (typeof event.stopImmediatePropagation === 'function') {
55 event.stopImmediatePropagation();
56 }
57 }
58 });
59 }
60 else if (typeof process !== 'undefined') {
61 process.on('unhandledRejection', (reason, p) => {
62 if (reason && reason.isHandledByZone) {
63 const listeners = process.listeners('unhandledRejection');
64 if (listeners) {
65 // remove unhandledRejection listeners so the callback
66 // will not be triggered.
67 process.removeAllListeners('unhandledRejection');
68 process.nextTick(() => {
69 listeners.forEach(listener => process.on('unhandledRejection', listener));
70 });
71 }
72 }
73 });
74 }
75 Bluebird.onPossiblyUnhandledRejection(function (e, promise) {
76 try {
77 Zone.current.runGuarded(() => {
78 e.isHandledByZone = true;
79 throw e;
80 });
81 }
82 catch (err) {
83 err.isHandledByZone = false;
84 api.onUnhandledError(err);
85 }
86 });
87 // override global promise
88 global.Promise = Bluebird;
89 };
90});
Note: See TracBrowser for help on using the repository browser.