wtf.umd.js 5.7 KB

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