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