Skip to content

Commit

Permalink
fix: correct oversights & editing errors in virtual object code
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Nov 5, 2020
1 parent 311dc41 commit 581fb91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 9 additions & 3 deletions packages/SwingSet/src/kernel/virtualObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export function makeCache(size, fetch, store) {
}
}
liveTable.delete(lruTail.vobjID);
store(lruTail.vobjID, lruTail.rawData);
if (lruTail.dirty) {
store(lruTail.vobjID, lruTail.rawData);
lruTail.dirty = false;
}
lruTail.rawData = null;
if (lruTail.prev) {
lruTail.prev.next = undefined;
Expand Down Expand Up @@ -115,7 +118,7 @@ export function makeCache(size, fetch, store) {
* @param {*} m The vat's marshaler.
* @param {number} cacheSize How many virtual objects this manager should cache
* in memory.
* @returns {*} a new virtual object manager.
* @returns {Object} a new virtual object manager.
*
* The virtual object manager allows the creation of persistent objects that do
* not need to occupy memory when they are not in use. It provides four
Expand Down Expand Up @@ -395,6 +398,7 @@ export function makeVirtualObjectManager(
const serializedValue = m.serialize(value);
ensureState(innerSelf);
innerSelf.rawData[prop] = serializedValue;
innerSelf.dirty = true;
},
});
}
Expand Down Expand Up @@ -437,8 +441,9 @@ export function makeVirtualObjectManager(
const innerSelf = { vobjID, rawData: initialData };
const initialRepresentative = makeRepresentative(innerSelf, true);
const initialize = initialRepresentative.initialize;
delete initialRepresentative.initialize;
harden(initialRepresentative);
if (initialize) {
delete initialRepresentative.initialize;
initialize(...args);
}
delete initialData[initializationInProgress];
Expand All @@ -453,6 +458,7 @@ export function makeVirtualObjectManager(
}
innerSelf.rawData = rawData;
innerSelf.wrapData(initialData);
innerSelf.dirty = true;
return initialRepresentative;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function makeThing(n) {
return {
vobjID: `t${n}`,
rawData: `thing #${n}`,
dirty: true,
};
}

Expand Down Expand Up @@ -71,6 +72,7 @@ test('cache overflow and refresh', t => {

// lookup that has no effect
things[0] = cache.lookup('t0'); // cache: t0, t2, t5, t4
things[0].dirty = true; // pretend we changed it
t.is(things[0].rawData, 'thing #0');
t.is(things[3].rawData, null);
t.deepEqual(store.getLog(), [
Expand Down Expand Up @@ -100,7 +102,6 @@ test('cache overflow and refresh', t => {
['store', 't2', 'thing #2'],
['store', 't0', 'thing #0'],
['store', 't4', 'thing #4'],
['store', 't1', 'thing #1'],
]);
t.deepEqual(store.dump(), [
['t0', 'thing #0'],
Expand All @@ -114,16 +115,22 @@ test('cache overflow and refresh', t => {
// verify that changes get written
things[0] = cache.lookup('t0'); // cache: t0
things[0].rawData = 'new thing #0';
things[0].dirty = true;
things[1] = cache.lookup('t1'); // cache: t1, t0
things[1].rawData = 'new thing #1';
things[1].dirty = true;
things[2] = cache.lookup('t2'); // cache: t2, t1, t0
things[2].rawData = 'new thing #2';
things[2].dirty = true;
things[3] = cache.lookup('t3'); // cache: t3, t2, t1, t0
things[3].rawData = 'new thing #3';
things[3].dirty = true;
things[4] = cache.lookup('t4'); // cache: t4, t3, t2, t1
things[4].rawData = 'new thing #4';
things[4].dirty = true;
things[5] = cache.lookup('t5'); // cache: t5, t4, t3, t2
things[5].rawData = 'new thing #5';
things[5].dirty = true;
t.is(things[0].rawData, null);
t.is(things[5].rawData, 'new thing #5');
t.deepEqual(store.getLog(), [
Expand Down

0 comments on commit 581fb91

Please sign in to comment.