Skip to content

Commit f9b5133

Browse files
committed
fix: use WeakSet for disavowals, improve comments, tidy vatPowers
1 parent 2490de5 commit f9b5133

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

packages/SwingSet/src/kernel/liveSlots.js

+19-25
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ function build(
7070
/** Map vat slot strings -> in-vat object references. */
7171
const slotToVal = new Map();
7272

73-
/** Map disavowed Presences to the Error which kills the vat if you try to
74-
* talk to them */
75-
const disavowedPresences = new WeakMap();
73+
/** Remember disavowed Presences which will kill the vat if you try to talk
74+
* to them */
75+
const disavowedPresences = new WeakSet();
76+
const disavowalError = harden(Error(`this Presence has been disavowed`));
7677

7778
const importedPromisesByPromiseID = new Map();
7879
let nextExportID = 1;
@@ -89,11 +90,10 @@ function build(
8990
applyMethod(o, prop, args, returnedP) {
9091
// Support: o~.[prop](...args) remote method invocation
9192
lsdebug(`makeImportedPresence handler.applyMethod (${slot})`);
92-
const err = disavowedPresences.get(o);
93-
if (err) {
93+
if (disavowedPresences.has(o)) {
9494
// eslint-disable-next-line no-use-before-define
95-
exitVatWithFailure(err);
96-
throw err;
95+
exitVatWithFailure(disavowalError);
96+
throw disavowalError;
9797
}
9898
// eslint-disable-next-line no-use-before-define
9999
return queueMessage(slot, prop, args, returnedP);
@@ -273,11 +273,10 @@ function build(
273273
if (isPromise(val)) {
274274
slot = exportPromise(val);
275275
} else {
276-
const err = disavowedPresences.get(val);
277-
if (err) {
276+
if (disavowedPresences.has(val)) {
278277
// eslint-disable-next-line no-use-before-define
279-
exitVatWithFailure(err);
280-
throw err; // cannot reference a disavowed object
278+
exitVatWithFailure(disavowalError);
279+
throw disavowalError; // cannot reference a disavowed object
281280
}
282281
assert.equal(passStyleOf(val), REMOTE_STYLE);
283282
slot = exportPassByPresence();
@@ -641,8 +640,7 @@ function build(
641640
assert.equal(allocatedByVat, false, X`attempt to disavow an export`);
642641
valToSlot.delete(presence);
643642
slotToVal.delete(slot);
644-
const err = harden(Error(`this Presence has been disavowed`));
645-
disavowedPresences.set(presence, err);
643+
disavowedPresences.add(presence);
646644

647645
syscall.dropImports([slot]);
648646
}
@@ -659,22 +657,18 @@ function build(
659657
assert(!didRoot);
660658
didRoot = true;
661659

662-
const disavowPowers = {};
660+
const vpow = {
661+
D,
662+
exitVat,
663+
exitVatWithFailure,
664+
...vatPowers,
665+
};
663666
if (enableDisavow) {
664-
disavowPowers.disavow = disavow;
667+
vpow.disavow = disavow;
665668
}
666669

667670
// here we finally invoke the vat code, and get back the root object
668-
const rootObject = buildRootObject(
669-
harden({
670-
D,
671-
exitVat,
672-
exitVatWithFailure,
673-
...disavowPowers,
674-
...vatPowers,
675-
}),
676-
harden(vatParameters),
677-
);
671+
const rootObject = buildRootObject(harden(vpow), harden(vatParameters));
678672
assert.equal(passStyleOf(rootObject), REMOTE_STYLE);
679673

680674
const rootSlot = makeVatSlot('object', true, 0n);

packages/SwingSet/src/kernel/vatTranslator.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ function makeTranslateVatSyscallToKernelSyscall(vatID, kernelKeeper) {
184184

185185
function translateDropImports(vrefs) {
186186
assert(Array.isArray(vrefs), X`dropImport() given non-Array ${vrefs}`);
187-
// We delete clist entries as we translate, which will decref the krefs.
188-
// When we're done with that loop, we hand the set of krefs to
189-
// kernelSyscall so it can check newly-decremented refcounts against zero,
190-
// and maybe delete even more.
187+
// We delete clist entries as we translate, which will (TODO) decref the
188+
// krefs. When we're done with that loop, we hand the set of krefs to
189+
// kernelSyscall so it can (TODO) check newly-decremented refcounts
190+
// against zero, and maybe delete even more.
191191
const krefs = vrefs.map(vref => {
192192
insistVatType('object', vref);
193193
const kref = mapVatSlotToKernelSlot(vref);

0 commit comments

Comments
 (0)