Skip to content

Commit

Permalink
context.facets was an array, needs to be a record
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Mar 28, 2023
1 parent ba19a1e commit c645b4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/swingset-liveslots/src/virtualObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
23 changes: 23 additions & 0 deletions packages/swingset-liveslots/test/virtual-objects/test-facets.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit c645b4a

Please sign in to comment.