Skip to content

Commit 9871903

Browse files
committed
fix: fake needs to be more real to work outside SwingSet unit tests
1 parent d4f5025 commit 9871903

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/SwingSet/tools/fakeVirtualObjectManager.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,26 @@ export function makeFakeVirtualObjectManager(cacheSize = 100) {
3030
}
3131

3232
const valToSlot = new WeakMap();
33+
const slotToVal = new Map();
3334

3435
function fakeConvertValToSlot(val) {
36+
if (!valToSlot.has(val)) {
37+
const slot = `o+${fakeAllocateExportID()}`;
38+
valToSlot.set(val, slot);
39+
slotToVal.set(slot, val);
40+
}
3541
return valToSlot.get(val);
3642
}
3743

3844
function fakeConvertSlotToVal(slot) {
3945
const { type, virtual } = parseVatSlot(slot);
40-
assert(
41-
virtual,
42-
'fakeConvertSlotToVal only works with virtual object references',
43-
);
4446
assert.equal(type, 'object');
45-
// eslint-disable-next-line no-use-before-define
46-
return makeVirtualObjectRepresentative(slot);
47+
if (virtual) {
48+
// eslint-disable-next-line no-use-before-define
49+
return makeVirtualObjectRepresentative(slot);
50+
} else {
51+
return slotToVal.get(slot);
52+
}
4753
}
4854

4955
// eslint-disable-next-line no-use-before-define

0 commit comments

Comments
 (0)