index.js 826 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var callBound = require('call-bound');
  3. /** @type {undefined | ((value: ThisParameterType<typeof FinalizationRegistry.prototype.register>, ...args: Parameters<typeof FinalizationRegistry.prototype.register>) => ReturnType<typeof FinalizationRegistry.prototype.register>)} */
  4. var $register = callBound('FinalizationRegistry.prototype.register', true);
  5. /** @type {import('.')} */
  6. module.exports = $register
  7. ? function isFinalizationRegistry(value) {
  8. if (!value || typeof value !== 'object') {
  9. return false;
  10. }
  11. try {
  12. // @ts-expect-error TS can't figure out that it's always truthy here
  13. $register(value, {}, null);
  14. return true;
  15. } catch (e) {
  16. return false;
  17. }
  18. }
  19. // @ts-ignore unused var
  20. : function isFinalizationRegistry(value) { // eslint-disable-line no-unused-vars
  21. return false;
  22. };