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 | */
|
---|
14 | /**
|
---|
15 | * @fileoverview
|
---|
16 | * @suppress {missingRequire}
|
---|
17 | */
|
---|
18 | (function (global) {
|
---|
19 | // Detect and setup WTF.
|
---|
20 | let wtfTrace = null;
|
---|
21 | let wtfEvents = null;
|
---|
22 | const wtfEnabled = (function () {
|
---|
23 | const wtf = global['wtf'];
|
---|
24 | if (wtf) {
|
---|
25 | wtfTrace = wtf.trace;
|
---|
26 | if (wtfTrace) {
|
---|
27 | wtfEvents = wtfTrace.events;
|
---|
28 | return true;
|
---|
29 | }
|
---|
30 | }
|
---|
31 | return false;
|
---|
32 | })();
|
---|
33 | class WtfZoneSpec {
|
---|
34 | constructor() {
|
---|
35 | this.name = 'WTF';
|
---|
36 | }
|
---|
37 | onFork(parentZoneDelegate, currentZone, targetZone, zoneSpec) {
|
---|
38 | const retValue = parentZoneDelegate.fork(targetZone, zoneSpec);
|
---|
39 | WtfZoneSpec.forkInstance(zonePathName(targetZone), retValue.name);
|
---|
40 | return retValue;
|
---|
41 | }
|
---|
42 | onInvoke(parentZoneDelegate, currentZone, targetZone, delegate, applyThis, applyArgs, source) {
|
---|
43 | const src = source || 'unknown';
|
---|
44 | let scope = WtfZoneSpec.invokeScope[src];
|
---|
45 | if (!scope) {
|
---|
46 | scope = WtfZoneSpec.invokeScope[src] =
|
---|
47 | wtfEvents.createScope(`Zone:invoke:${source}(ascii zone)`);
|
---|
48 | }
|
---|
49 | return wtfTrace.leaveScope(scope(zonePathName(targetZone)), parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source));
|
---|
50 | }
|
---|
51 | onHandleError(parentZoneDelegate, currentZone, targetZone, error) {
|
---|
52 | return parentZoneDelegate.handleError(targetZone, error);
|
---|
53 | }
|
---|
54 | onScheduleTask(parentZoneDelegate, currentZone, targetZone, task) {
|
---|
55 | const key = task.type + ':' + task.source;
|
---|
56 | let instance = WtfZoneSpec.scheduleInstance[key];
|
---|
57 | if (!instance) {
|
---|
58 | instance = WtfZoneSpec.scheduleInstance[key] =
|
---|
59 | wtfEvents.createInstance(`Zone:schedule:${key}(ascii zone, any data)`);
|
---|
60 | }
|
---|
61 | const retValue = parentZoneDelegate.scheduleTask(targetZone, task);
|
---|
62 | instance(zonePathName(targetZone), shallowObj(task.data, 2));
|
---|
63 | return retValue;
|
---|
64 | }
|
---|
65 | onInvokeTask(parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs) {
|
---|
66 | const source = task.source;
|
---|
67 | let scope = WtfZoneSpec.invokeTaskScope[source];
|
---|
68 | if (!scope) {
|
---|
69 | scope = WtfZoneSpec.invokeTaskScope[source] =
|
---|
70 | wtfEvents.createScope(`Zone:invokeTask:${source}(ascii zone)`);
|
---|
71 | }
|
---|
72 | return wtfTrace.leaveScope(scope(zonePathName(targetZone)), parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs));
|
---|
73 | }
|
---|
74 | onCancelTask(parentZoneDelegate, currentZone, targetZone, task) {
|
---|
75 | const key = task.source;
|
---|
76 | let instance = WtfZoneSpec.cancelInstance[key];
|
---|
77 | if (!instance) {
|
---|
78 | instance = WtfZoneSpec.cancelInstance[key] =
|
---|
79 | wtfEvents.createInstance(`Zone:cancel:${key}(ascii zone, any options)`);
|
---|
80 | }
|
---|
81 | const retValue = parentZoneDelegate.cancelTask(targetZone, task);
|
---|
82 | instance(zonePathName(targetZone), shallowObj(task.data, 2));
|
---|
83 | return retValue;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | WtfZoneSpec.forkInstance = wtfEnabled ? wtfEvents.createInstance('Zone:fork(ascii zone, ascii newZone)') : null;
|
---|
87 | WtfZoneSpec.scheduleInstance = {};
|
---|
88 | WtfZoneSpec.cancelInstance = {};
|
---|
89 | WtfZoneSpec.invokeScope = {};
|
---|
90 | WtfZoneSpec.invokeTaskScope = {};
|
---|
91 | function shallowObj(obj, depth) {
|
---|
92 | if (!obj || !depth)
|
---|
93 | return null;
|
---|
94 | const out = {};
|
---|
95 | for (const key in obj) {
|
---|
96 | if (obj.hasOwnProperty(key)) {
|
---|
97 | // explicit : any due to https://github.com/microsoft/TypeScript/issues/33191
|
---|
98 | let value = obj[key];
|
---|
99 | switch (typeof value) {
|
---|
100 | case 'object':
|
---|
101 | const name = value && value.constructor && value.constructor.name;
|
---|
102 | value = name == Object.name ? shallowObj(value, depth - 1) : name;
|
---|
103 | break;
|
---|
104 | case 'function':
|
---|
105 | value = value.name || undefined;
|
---|
106 | break;
|
---|
107 | }
|
---|
108 | out[key] = value;
|
---|
109 | }
|
---|
110 | }
|
---|
111 | return out;
|
---|
112 | }
|
---|
113 | function zonePathName(zone) {
|
---|
114 | let name = zone.name;
|
---|
115 | let localZone = zone.parent;
|
---|
116 | while (localZone != null) {
|
---|
117 | name = localZone.name + '::' + name;
|
---|
118 | localZone = localZone.parent;
|
---|
119 | }
|
---|
120 | return name;
|
---|
121 | }
|
---|
122 | Zone['wtfZoneSpec'] = !wtfEnabled ? null : new WtfZoneSpec();
|
---|
123 | })(typeof window === 'object' && window || typeof self === 'object' && self || global);
|
---|