wtf.umd.js 5.7 KB

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