diff --git a/packages/swingset-liveslots/src/virtualObjectManager.js b/packages/swingset-liveslots/src/virtualObjectManager.js index 041cd6cef3d3..ca2ea865262a 100644 --- a/packages/swingset-liveslots/src/virtualObjectManager.js +++ b/packages/swingset-liveslots/src/virtualObjectManager.js @@ -800,9 +800,12 @@ export function makeVirtualObjectManager( function makeContext(baseRef, state) { // baseRef came from valToSlot, so must be in slotToVal const val = requiredValForSlot(baseRef); - // val is either 'self' or 'facets' + // val is either 'self' or an array of facets if (multifaceted) { - return harden({ state, facets: val }); + // but userspace needs a record of named facets + const facets = {}; + facetNames.forEach((name, idx) => (facets[name] = val[idx])); + return harden({ state, facets }); } return harden({ state, self: val }); } diff --git a/packages/swingset-liveslots/test/virtual-objects/test-facets.js b/packages/swingset-liveslots/test/virtual-objects/test-facets.js new file mode 100644 index 000000000000..f604a1dd82c5 --- /dev/null +++ b/packages/swingset-liveslots/test/virtual-objects/test-facets.js @@ -0,0 +1,23 @@ +import test from 'ava'; +import '@endo/init/debug.js'; + +import { makeFakeVirtualObjectManager } from '../../tools/fakeVirtualSupport.js'; + +test('facets', async t => { + const vom = makeFakeVirtualObjectManager(); + const init = () => ({ value: 0 }); + const behavior = { + mutable: { + set: ({ state }, value) => (state.value = value), + get: ({ state }) => state.value, + getImmutable: ({ facets }) => facets.immutable, + }, + immutable: { + get: ({ state }) => state.value, + }, + }; + const makeThing = vom.defineKindMulti('thing', init, behavior); + const thing1 = makeThing(); + thing1.mutable.set(1); + t.is(thing1.mutable.getImmutable(), thing1.immutable); +});