Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _util() {
  7. const data = require('util');
  8. _util = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _v() {
  14. const data = require('v8');
  15. _v = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _vm() {
  21. const data = require('vm');
  22. _vm = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _jestGetType() {
  28. const data = require('jest-get-type');
  29. _jestGetType = function () {
  30. return data;
  31. };
  32. return data;
  33. }
  34. function _prettyFormat() {
  35. const data = require('pretty-format');
  36. _prettyFormat = function () {
  37. return data;
  38. };
  39. return data;
  40. }
  41. function _defineProperty(obj, key, value) {
  42. if (key in obj) {
  43. Object.defineProperty(obj, key, {
  44. value: value,
  45. enumerable: true,
  46. configurable: true,
  47. writable: true
  48. });
  49. } else {
  50. obj[key] = value;
  51. }
  52. return obj;
  53. }
  54. const tick = (0, _util().promisify)(setImmediate);
  55. class _default {
  56. constructor(value) {
  57. _defineProperty(this, '_isReferenceBeingHeld', void 0);
  58. if ((0, _jestGetType().isPrimitive)(value)) {
  59. throw new TypeError(
  60. [
  61. 'Primitives cannot leak memory.',
  62. 'You passed a ' +
  63. typeof value +
  64. ': <' +
  65. (0, _prettyFormat().format)(value) +
  66. '>'
  67. ].join(' ')
  68. );
  69. }
  70. let weak;
  71. try {
  72. // eslint-disable-next-line import/no-extraneous-dependencies
  73. weak = require('weak-napi');
  74. } catch (err) {
  75. if (!err || err.code !== 'MODULE_NOT_FOUND') {
  76. throw err;
  77. }
  78. throw new Error(
  79. 'The leaking detection mechanism requires the "weak-napi" package to be installed and work. ' +
  80. 'Please install it as a dependency on your main project'
  81. );
  82. }
  83. weak(value, () => (this._isReferenceBeingHeld = false));
  84. this._isReferenceBeingHeld = true; // Ensure value is not leaked by the closure created by the "weak" callback.
  85. value = null;
  86. }
  87. async isLeaking() {
  88. this._runGarbageCollector(); // wait some ticks to allow GC to run properly, see https://github.com/nodejs/node/issues/34636#issuecomment-669366235
  89. for (let i = 0; i < 10; i++) {
  90. await tick();
  91. }
  92. return this._isReferenceBeingHeld;
  93. }
  94. _runGarbageCollector() {
  95. const isGarbageCollectorHidden = !global.gc; // GC is usually hidden, so we have to expose it before running.
  96. (0, _v().setFlagsFromString)('--expose-gc');
  97. (0, _vm().runInNewContext)('gc')(); // The GC was not initially exposed, so let's hide it again.
  98. if (isGarbageCollectorHidden) {
  99. (0, _v().setFlagsFromString)('--no-expose-gc');
  100. }
  101. }
  102. }
  103. exports.default = _default;