MemUtil.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: BI Dashboard
  7. *| (C) Copyright IBM Corp. 2019
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. /**
  14. * Event helper class
  15. **/
  16. define([], function () {
  17. var destroyedPrototypes = new WeakMap();
  18. var emptyFunction = function emptyFunction() {};
  19. var MemUtil = function () {
  20. function MemUtil() {
  21. _classCallCheck(this, MemUtil);
  22. }
  23. /**
  24. * Destroy an object - clear all attribute and set all functions to empty functions
  25. */
  26. MemUtil.destroy = function destroy(object) {
  27. var destroyedProto = destroyedPrototypes.get(object.__proto__);
  28. if (!destroyedProto) {
  29. destroyedProto = {};
  30. destroyedPrototypes.set(object.__proto__, destroyedProto);
  31. for (var prop in object.__proto__) {
  32. if (typeof object.__proto__[prop] === 'function') {
  33. destroyedProto[prop] = emptyFunction;
  34. }
  35. }
  36. }
  37. for (var _prop in object) {
  38. // clear everything referenced by this object in case someone is still holding on to it.
  39. if (Object.prototype.hasOwnProperty.call(object, _prop)) {
  40. if (typeof object[_prop] === 'function') {
  41. object[_prop] = emptyFunction;
  42. } else {
  43. delete object[_prop];
  44. }
  45. }
  46. }
  47. object.__proto__ = destroyedProto;
  48. object.__destroyed__ = true;
  49. };
  50. MemUtil.isDestroyed = function isDestroyed(object) {
  51. return object.__destroyed__;
  52. };
  53. return MemUtil;
  54. }();
  55. return MemUtil;
  56. });
  57. //# sourceMappingURL=MemUtil.js.map