UI for Zipcoin Blue

to-string.ts 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. import {zoneSymbol} from './utils';
  9. // override Function.prototype.toString to make zone.js patched function
  10. // look like native function
  11. Zone.__load_patch('toString', (global: any) => {
  12. // patch Func.prototype.toString to let them look like native
  13. const originalFunctionToString = Function.prototype.toString;
  14. const ORIGINAL_DELEGATE_SYMBOL = zoneSymbol('OriginalDelegate');
  15. const PROMISE_SYMBOL = zoneSymbol('Promise');
  16. const ERROR_SYMBOL = zoneSymbol('Error');
  17. const newFunctionToString = function toString() {
  18. if (typeof this === 'function') {
  19. const originalDelegate = this[ORIGINAL_DELEGATE_SYMBOL];
  20. if (originalDelegate) {
  21. if (typeof originalDelegate === 'function') {
  22. return originalFunctionToString.apply(this[ORIGINAL_DELEGATE_SYMBOL], arguments);
  23. } else {
  24. return Object.prototype.toString.call(originalDelegate);
  25. }
  26. }
  27. if (this === Promise) {
  28. const nativePromise = global[PROMISE_SYMBOL];
  29. if (nativePromise) {
  30. return originalFunctionToString.apply(nativePromise, arguments);
  31. }
  32. }
  33. if (this === Error) {
  34. const nativeError = global[ERROR_SYMBOL];
  35. if (nativeError) {
  36. return originalFunctionToString.apply(nativeError, arguments);
  37. }
  38. }
  39. }
  40. return originalFunctionToString.apply(this, arguments);
  41. };
  42. (newFunctionToString as any)[ORIGINAL_DELEGATE_SYMBOL] = originalFunctionToString;
  43. Function.prototype.toString = newFunctionToString;
  44. // patch Object.prototype.toString to let them look like native
  45. const originalObjectToString = Object.prototype.toString;
  46. const PROMISE_OBJECT_TO_STRING = '[object Promise]';
  47. Object.prototype.toString = function() {
  48. if (this instanceof Promise) {
  49. return PROMISE_OBJECT_TO_STRING;
  50. }
  51. return originalObjectToString.apply(this, arguments);
  52. };
  53. });