index.js 438 B

123456789101112131415161718192021
  1. 'use strict';
  2. var callBound = require('call-bind/callBound');
  3. var $deref = callBound('WeakRef.prototype.deref', true);
  4. module.exports = typeof WeakRef === 'undefined'
  5. ? function isWeakRef(value) { // eslint-disable-line no-unused-vars
  6. return false;
  7. }
  8. : function isWeakRef(value) {
  9. if (!value || typeof value !== 'object') {
  10. return false;
  11. }
  12. try {
  13. $deref(value);
  14. return true;
  15. } catch (e) {
  16. return false;
  17. }
  18. };