wtf.umd.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use strict';
  2. /**
  3. * @license Angular v<unknown>
  4. * (c) 2010-2025 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. // 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. WtfZoneSpec.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 = WtfZoneSpec.invokeScope[src];
  44. if (!scope) {
  45. scope = WtfZoneSpec.invokeScope[src] = wtfEvents.createScope("Zone:invoke:".concat(source, "(ascii zone)"));
  46. }
  47. return wtfTrace.leaveScope(scope(zonePathName(targetZone)), parentZoneDelegate.invoke(targetZone, delegate, applyThis, applyArgs, source));
  48. };
  49. WtfZoneSpec.prototype.onHandleError = function (parentZoneDelegate, currentZone, targetZone, error) {
  50. return parentZoneDelegate.handleError(targetZone, error);
  51. };
  52. WtfZoneSpec.prototype.onScheduleTask = function (parentZoneDelegate, currentZone, targetZone, task) {
  53. var key = task.type + ':' + task.source;
  54. var instance = WtfZoneSpec.scheduleInstance[key];
  55. if (!instance) {
  56. instance = WtfZoneSpec.scheduleInstance[key] = wtfEvents.createInstance("Zone:schedule:".concat(key, "(ascii zone, any data)"));
  57. }
  58. var retValue = parentZoneDelegate.scheduleTask(targetZone, task);
  59. instance(zonePathName(targetZone), shallowObj(task.data, 2));
  60. return retValue;
  61. };
  62. WtfZoneSpec.prototype.onInvokeTask = function (parentZoneDelegate, currentZone, targetZone, task, applyThis, applyArgs) {
  63. var source = task.source;
  64. var scope = WtfZoneSpec.invokeTaskScope[source];
  65. if (!scope) {
  66. scope = WtfZoneSpec.invokeTaskScope[source] = wtfEvents.createScope("Zone:invokeTask:".concat(source, "(ascii zone)"));
  67. }
  68. return wtfTrace.leaveScope(scope(zonePathName(targetZone)), parentZoneDelegate.invokeTask(targetZone, task, applyThis, applyArgs));
  69. };
  70. WtfZoneSpec.prototype.onCancelTask = function (parentZoneDelegate, currentZone, targetZone, task) {
  71. var key = task.source;
  72. var instance = WtfZoneSpec.cancelInstance[key];
  73. if (!instance) {
  74. instance = WtfZoneSpec.cancelInstance[key] = wtfEvents.createInstance("Zone:cancel:".concat(key, "(ascii zone, any options)"));
  75. }
  76. var retValue = parentZoneDelegate.cancelTask(targetZone, task);
  77. instance(zonePathName(targetZone), shallowObj(task.data, 2));
  78. return retValue;
  79. };
  80. WtfZoneSpec.forkInstance = wtfEnabled
  81. ? wtfEvents.createInstance('Zone:fork(ascii zone, ascii newZone)')
  82. : null;
  83. WtfZoneSpec.scheduleInstance = {};
  84. WtfZoneSpec.cancelInstance = {};
  85. WtfZoneSpec.invokeScope = {};
  86. WtfZoneSpec.invokeTaskScope = {};
  87. return WtfZoneSpec;
  88. }());
  89. function shallowObj(obj, depth) {
  90. if (!obj || !depth)
  91. return null;
  92. var out = {};
  93. for (var key in obj) {
  94. if (obj.hasOwnProperty(key)) {
  95. // explicit : any due to https://github.com/microsoft/TypeScript/issues/33191
  96. var value = obj[key];
  97. switch (typeof value) {
  98. case 'object':
  99. var name_1 = value && value.constructor && value.constructor.name;
  100. value = name_1 == Object.name ? shallowObj(value, depth - 1) : name_1;
  101. break;
  102. case 'function':
  103. value = value.name || undefined;
  104. break;
  105. }
  106. out[key] = value;
  107. }
  108. }
  109. return out;
  110. }
  111. function zonePathName(zone) {
  112. var name = zone.name;
  113. var localZone = zone.parent;
  114. while (localZone != null) {
  115. name = localZone.name + '::' + name;
  116. localZone = localZone.parent;
  117. }
  118. return name;
  119. }
  120. Zone['wtfZoneSpec'] = !wtfEnabled ? null : new WtfZoneSpec();
  121. }
  122. patchWtf(Zone);
  123. }));