MCPcopy Index your code
hub / github.com/angular/angular / patchPromise

Function patchPromise

packages/zone.js/lib/common/promise.ts:12–642  ·  view source on GitHub ↗
(Zone: ZoneType)

Source from the content-addressed store, hash-verified

10import {patchMethod} from './utils';
11
12export function patchPromise(Zone: ZoneType): void {
13 Zone.__load_patch('ZoneAwarePromise', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
14 const ObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
15 const ObjectDefineProperty = Object.defineProperty;
16
17 function readableObjectToString(obj: any) {
18 if (obj && obj.toString === Object.prototype.toString) {
19 const className = obj.constructor && obj.constructor.name;
20 return (className ? className : '') + ': ' + JSON.stringify(obj);
21 }
22
23 return obj ? obj.toString() : Object.prototype.toString.call(obj);
24 }
25
26 const __symbol__ = api.symbol;
27 const _uncaughtPromiseErrors: UncaughtPromiseError[] = [];
28 const isDisableWrappingUncaughtPromiseRejection =
29 global[__symbol__('DISABLE_WRAPPING_UNCAUGHT_PROMISE_REJECTION')] !== false;
30 const symbolPromise = __symbol__('Promise');
31 const symbolThen = __symbol__('then');
32 const creationTrace = '__creationTrace__';
33
34 api.onUnhandledError = (e: any) => {
35 if (api.showUncaughtError()) {
36 const rejection = e && e.rejection;
37 if (rejection && e.zone && e.task) {
38 console.error(
39 'Unhandled Promise rejection:',
40 rejection instanceof Error ? rejection.message : rejection,
41 '; Zone:',
42 (<Zone>e.zone).name,
43 '; Task:',
44 e.task && (<Task>e.task).source,
45 '; Value:',
46 rejection,
47 rejection instanceof Error ? rejection.stack : undefined,
48 );
49 } else {
50 console.error(e);
51 }
52 }
53 };
54
55 api.microtaskDrainDone = () => {
56 while (_uncaughtPromiseErrors.length) {
57 const uncaughtPromiseError: UncaughtPromiseError = _uncaughtPromiseErrors.shift()!;
58 try {
59 uncaughtPromiseError.zone.runGuarded(() => {
60 if (uncaughtPromiseError.throwOriginal) {
61 throw uncaughtPromiseError.rejection;
62 }
63 throw uncaughtPromiseError;
64 });
65 } catch (error) {
66 handleUnhandledRejection(error);
67 }
68 }
69 };

Callers 4

patchCommonFunction · 0.90
rollupMainFunction · 0.90

Calls 9

patchMethodFunction · 0.90
__symbol__Function · 0.85
handleUnhandledRejectionFunction · 0.85
patchThenFunction · 0.85
zoneifyFunction · 0.85
__symbol__Method · 0.80
__load_patchMethod · 0.65
errorMethod · 0.65
runGuardedMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…