wtf.js 5.6 KB

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