Skip to content

Commit

Permalink
fix(SwingSet): makeFakeVirtualObjectManager takes weak=true
Browse files Browse the repository at this point in the history
Change `makeFakeVirtualObjectManager` to accept a `{ weak: true }` option, to
use the same "slotToVal holds WeakRef" pattern as liveslots does. We need
this to test the VOM retaining Remotables, since a strong `slotToVal`
reference would cause a false positive.
  • Loading branch information
warner committed May 21, 2021
1 parent 65d2e17 commit e3ab2e1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/SwingSet/tools/fakeVirtualObjectManager.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* global WeakRef */
import { makeMarshal } from '@agoric/marshal';
import { assert } from '@agoric/assert';
import { parseVatSlot } from '../src/parseVatSlots';

import { makeVirtualObjectManager } from '../src/kernel/virtualObjectManager';

export function makeFakeVirtualObjectManager(options = {}) {
const { cacheSize = 100, log } = options;
const { cacheSize = 100, log, weak = false } = options;
const fakeStore = new Map();

function dumpStore() {
Expand Down Expand Up @@ -46,6 +47,10 @@ export function makeFakeVirtualObjectManager(options = {}) {
return exportID;
}

// note: The real liveslots slotToVal() maps slots (vrefs) to a WeakRef,
// and the WeakRef may or may not contain the target value. Use
// options={weak:true} to match that behavior, or the default weak:false to
// keep strong references.
const valToSlot = new WeakMap();
const slotToVal = new Map();

Expand All @@ -54,12 +59,12 @@ export function makeFakeVirtualObjectManager(options = {}) {
}

function setValForSlot(slot, val) {
slotToVal.set(slot, val);
slotToVal.set(slot, weak ? new WeakRef(val) : val);
}

function getValForSlot(slot) {
const d = slotToVal.get(slot);
return d;
return d && (weak ? d.deref() : d);
}

function fakeConvertValToSlot(val) {
Expand Down

0 comments on commit e3ab2e1

Please sign in to comment.