UI for Zipcoin Blue

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
  10. typeof define === 'function' && define.amd ? define(factory) :
  11. (factory());
  12. }(this, (function () { 'use strict';
  13. /**
  14. * @license
  15. * Copyright Google Inc. All Rights Reserved.
  16. *
  17. * Use of this source code is governed by an MIT-style license that can be
  18. * found in the LICENSE file at https://angular.io/license
  19. */
  20. /**
  21. * @fileoverview
  22. * @suppress {globalThis,undefinedVars}
  23. */
  24. Zone.__load_patch('Error', function (global, Zone, api) {
  25. /*
  26. * This code patches Error so that:
  27. * - It ignores un-needed stack frames.
  28. * - It Shows the associated Zone for reach frame.
  29. */
  30. var blacklistedStackFramesSymbol = api.symbol('blacklistedStackFrames');
  31. var NativeError = global[api.symbol('Error')] = global['Error'];
  32. // Store the frames which should be removed from the stack frames
  33. var blackListedStackFrames = {};
  34. // We must find the frame where Error was created, otherwise we assume we don't understand stack
  35. var zoneAwareFrame1;
  36. var zoneAwareFrame2;
  37. global['Error'] = ZoneAwareError;
  38. var stackRewrite = 'stackRewrite';
  39. /**
  40. * This is ZoneAwareError which processes the stack frame and cleans up extra frames as well as
  41. * adds zone information to it.
  42. */
  43. function ZoneAwareError() {
  44. var _this = this;
  45. // We always have to return native error otherwise the browser console will not work.
  46. var error = NativeError.apply(this, arguments);
  47. // Save original stack trace
  48. var originalStack = error['originalStack'] = error.stack;
  49. // Process the stack trace and rewrite the frames.
  50. if (ZoneAwareError[stackRewrite] && originalStack) {
  51. var frames_1 = originalStack.split('\n');
  52. var zoneFrame = api.currentZoneFrame();
  53. var i = 0;
  54. // Find the first frame
  55. while (!(frames_1[i] === zoneAwareFrame1 || frames_1[i] === zoneAwareFrame2) &&
  56. i < frames_1.length) {
  57. i++;
  58. }
  59. for (; i < frames_1.length && zoneFrame; i++) {
  60. var frame = frames_1[i];
  61. if (frame.trim()) {
  62. switch (blackListedStackFrames[frame]) {
  63. case 0 /* blackList */:
  64. frames_1.splice(i, 1);
  65. i--;
  66. break;
  67. case 1 /* transition */:
  68. if (zoneFrame.parent) {
  69. // This is the special frame where zone changed. Print and process it accordingly
  70. zoneFrame = zoneFrame.parent;
  71. }
  72. else {
  73. zoneFrame = null;
  74. }
  75. frames_1.splice(i, 1);
  76. i--;
  77. break;
  78. default:
  79. frames_1[i] += " [" + zoneFrame.zone.name + "]";
  80. }
  81. }
  82. }
  83. try {
  84. error.stack = error.zoneAwareStack = frames_1.join('\n');
  85. }
  86. catch (e) {
  87. // ignore as some browsers don't allow overriding of stack
  88. }
  89. }
  90. if (this instanceof NativeError && this.constructor != NativeError) {
  91. // We got called with a `new` operator AND we are subclass of ZoneAwareError
  92. // in that case we have to copy all of our properties to `this`.
  93. Object.keys(error).concat('stack', 'message').forEach(function (key) {
  94. var value = error[key];
  95. if (value !== undefined) {
  96. try {
  97. _this[key] = value;
  98. }
  99. catch (e) {
  100. // ignore the assignment in case it is a setter and it throws.
  101. }
  102. }
  103. });
  104. return this;
  105. }
  106. return error;
  107. }
  108. // Copy the prototype so that instanceof operator works as expected
  109. ZoneAwareError.prototype = NativeError.prototype;
  110. ZoneAwareError[blacklistedStackFramesSymbol] = blackListedStackFrames;
  111. ZoneAwareError[stackRewrite] = false;
  112. // those properties need special handling
  113. var specialPropertyNames = ['stackTraceLimit', 'captureStackTrace', 'prepareStackTrace'];
  114. // those properties of NativeError should be set to ZoneAwareError
  115. var nativeErrorProperties = Object.keys(NativeError);
  116. if (nativeErrorProperties) {
  117. nativeErrorProperties.forEach(function (prop) {
  118. if (specialPropertyNames.filter(function (sp) { return sp === prop; }).length === 0) {
  119. Object.defineProperty(ZoneAwareError, prop, {
  120. get: function () {
  121. return NativeError[prop];
  122. },
  123. set: function (value) {
  124. NativeError[prop] = value;
  125. }
  126. });
  127. }
  128. });
  129. }
  130. if (NativeError.hasOwnProperty('stackTraceLimit')) {
  131. // Extend default stack limit as we will be removing few frames.
  132. NativeError.stackTraceLimit = Math.max(NativeError.stackTraceLimit, 15);
  133. // make sure that ZoneAwareError has the same property which forwards to NativeError.
  134. Object.defineProperty(ZoneAwareError, 'stackTraceLimit', {
  135. get: function () {
  136. return NativeError.stackTraceLimit;
  137. },
  138. set: function (value) {
  139. return NativeError.stackTraceLimit = value;
  140. }
  141. });
  142. }
  143. if (NativeError.hasOwnProperty('captureStackTrace')) {
  144. Object.defineProperty(ZoneAwareError, 'captureStackTrace', {
  145. // add named function here because we need to remove this
  146. // stack frame when prepareStackTrace below
  147. value: function zoneCaptureStackTrace(targetObject, constructorOpt) {
  148. NativeError.captureStackTrace(targetObject, constructorOpt);
  149. }
  150. });
  151. }
  152. var ZONE_CAPTURESTACKTRACE = 'zoneCaptureStackTrace';
  153. Object.defineProperty(ZoneAwareError, 'prepareStackTrace', {
  154. get: function () {
  155. return NativeError.prepareStackTrace;
  156. },
  157. set: function (value) {
  158. if (!value || typeof value !== 'function') {
  159. return NativeError.prepareStackTrace = value;
  160. }
  161. return NativeError.prepareStackTrace = function (error, structuredStackTrace) {
  162. // remove additional stack information from ZoneAwareError.captureStackTrace
  163. if (structuredStackTrace) {
  164. for (var i = 0; i < structuredStackTrace.length; i++) {
  165. var st = structuredStackTrace[i];
  166. // remove the first function which name is zoneCaptureStackTrace
  167. if (st.getFunctionName() === ZONE_CAPTURESTACKTRACE) {
  168. structuredStackTrace.splice(i, 1);
  169. break;
  170. }
  171. }
  172. }
  173. return value.call(this, error, structuredStackTrace);
  174. };
  175. }
  176. });
  177. // Now we need to populate the `blacklistedStackFrames` as well as find the
  178. // run/runGuarded/runTask frames. This is done by creating a detect zone and then threading
  179. // the execution through all of the above methods so that we can look at the stack trace and
  180. // find the frames of interest.
  181. var ZONE_AWARE_ERROR = 'ZoneAwareError';
  182. var ERROR_DOT = 'Error.';
  183. var EMPTY = '';
  184. var RUN_GUARDED = 'runGuarded';
  185. var RUN_TASK = 'runTask';
  186. var RUN = 'run';
  187. var BRACKETS = '(';
  188. var AT = '@';
  189. var detectZone = Zone.current.fork({
  190. name: 'detect',
  191. onHandleError: function (parentZD, current, target, error) {
  192. if (error.originalStack && Error === ZoneAwareError) {
  193. var frames_2 = error.originalStack.split(/\n/);
  194. var runFrame = false, runGuardedFrame = false, runTaskFrame = false;
  195. while (frames_2.length) {
  196. var frame = frames_2.shift();
  197. // On safari it is possible to have stack frame with no line number.
  198. // This check makes sure that we don't filter frames on name only (must have
  199. // line number)
  200. if (/:\d+:\d+/.test(frame)) {
  201. // Get rid of the path so that we don't accidentally find function name in path.
  202. // In chrome the separator is `(` and `@` in FF and safari
  203. // Chrome: at Zone.run (zone.js:100)
  204. // Chrome: at Zone.run (http://localhost:9876/base/build/lib/zone.js:100:24)
  205. // FireFox: Zone.prototype.run@http://localhost:9876/base/build/lib/zone.js:101:24
  206. // Safari: run@http://localhost:9876/base/build/lib/zone.js:101:24
  207. var fnName = frame.split(BRACKETS)[0].split(AT)[0];
  208. var frameType = 1;
  209. if (fnName.indexOf(ZONE_AWARE_ERROR) !== -1) {
  210. zoneAwareFrame1 = frame;
  211. zoneAwareFrame2 = frame.replace(ERROR_DOT, EMPTY);
  212. blackListedStackFrames[zoneAwareFrame2] = 0 /* blackList */;
  213. }
  214. if (fnName.indexOf(RUN_GUARDED) !== -1) {
  215. runGuardedFrame = true;
  216. }
  217. else if (fnName.indexOf(RUN_TASK) !== -1) {
  218. runTaskFrame = true;
  219. }
  220. else if (fnName.indexOf(RUN) !== -1) {
  221. runFrame = true;
  222. }
  223. else {
  224. frameType = 0 /* blackList */;
  225. }
  226. blackListedStackFrames[frame] = frameType;
  227. // Once we find all of the frames we can stop looking.
  228. if (runFrame && runGuardedFrame && runTaskFrame) {
  229. ZoneAwareError[stackRewrite] = true;
  230. break;
  231. }
  232. }
  233. }
  234. }
  235. return false;
  236. }
  237. });
  238. // carefully constructor a stack frame which contains all of the frames of interest which
  239. // need to be detected and blacklisted.
  240. var childDetectZone = detectZone.fork({
  241. name: 'child',
  242. onScheduleTask: function (delegate, curr, target, task) {
  243. return delegate.scheduleTask(target, task);
  244. },
  245. onInvokeTask: function (delegate, curr, target, task, applyThis, applyArgs) {
  246. return delegate.invokeTask(target, task, applyThis, applyArgs);
  247. },
  248. onCancelTask: function (delegate, curr, target, task) {
  249. return delegate.cancelTask(target, task);
  250. },
  251. onInvoke: function (delegate, curr, target, callback, applyThis, applyArgs, source) {
  252. return delegate.invoke(target, callback, applyThis, applyArgs, source);
  253. }
  254. });
  255. // we need to detect all zone related frames, it will
  256. // exceed default stackTraceLimit, so we set it to
  257. // larger number here, and restore it after detect finish.
  258. var originalStackTraceLimit = Error.stackTraceLimit;
  259. Error.stackTraceLimit = 100;
  260. // we schedule event/micro/macro task, and invoke them
  261. // when onSchedule, so we can get all stack traces for
  262. // all kinds of tasks with one error thrown.
  263. childDetectZone.run(function () {
  264. childDetectZone.runGuarded(function () {
  265. var fakeTransitionTo = function () { };
  266. childDetectZone.scheduleEventTask(blacklistedStackFramesSymbol, function () {
  267. childDetectZone.scheduleMacroTask(blacklistedStackFramesSymbol, function () {
  268. childDetectZone.scheduleMicroTask(blacklistedStackFramesSymbol, function () {
  269. throw new ZoneAwareError(ZoneAwareError, NativeError);
  270. }, null, function (t) {
  271. t._transitionTo = fakeTransitionTo;
  272. t.invoke();
  273. });
  274. }, null, function (t) {
  275. t._transitionTo = fakeTransitionTo;
  276. t.invoke();
  277. }, function () { });
  278. }, null, function (t) {
  279. t._transitionTo = fakeTransitionTo;
  280. t.invoke();
  281. }, function () { });
  282. });
  283. });
  284. Error.stackTraceLimit = originalStackTraceLimit;
  285. });
  286. })));