UNPKG

tc39-weakrefs-shim

Version:
27 lines 894 B
import makePrivates from "../utils/privates.js"; import isObject from "../utils/lodash/isObject.js"; export class WeakRefSlots { constructor(targetInfo) { this.targetInfo = targetInfo; } } export function createWeakRefClassShim(jobs, getInfo, getTarget, initSlots = target => new WeakRefSlots(getInfo(target))) { const privates = makePrivates(); class WeakRef { constructor(target) { if (!isObject(target)) throw new TypeError(); jobs.keepDuringJob(target); privates.init(this, initSlots(target, this)); } deref() { const slots = privates(this); const target = getTarget(slots.targetInfo); if (target) jobs.keepDuringJob(target); return target; } } return [WeakRef, privates]; } //# sourceMappingURL=WeakRef.js.map