WeakRefDeref.js 573 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var callBound = require('call-bind/callBound');
  3. var $TypeError = require('es-errors/type');
  4. var $deref = callBound('WeakRef.prototype.deref', true);
  5. var isWeakRef = require('is-weakref');
  6. var AddToKeptObjects = require('./AddToKeptObjects');
  7. // https://262.ecma-international.org/12.0/#sec-weakrefderef
  8. module.exports = function WeakRefDeref(weakRef) {
  9. if (!isWeakRef(weakRef)) {
  10. throw new $TypeError('Assertion failed: `weakRef` must be a WeakRef');
  11. }
  12. var target = $deref(weakRef);
  13. if (target) {
  14. AddToKeptObjects(target);
  15. }
  16. return target;
  17. };