Skip to content

Commit 581fb91

Browse files
committed
fix: correct oversights & editing errors in virtual object code
1 parent 311dc41 commit 581fb91

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/SwingSet/src/kernel/virtualObjectManager.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ export function makeCache(size, fetch, store) {
3737
}
3838
}
3939
liveTable.delete(lruTail.vobjID);
40-
store(lruTail.vobjID, lruTail.rawData);
40+
if (lruTail.dirty) {
41+
store(lruTail.vobjID, lruTail.rawData);
42+
lruTail.dirty = false;
43+
}
4144
lruTail.rawData = null;
4245
if (lruTail.prev) {
4346
lruTail.prev.next = undefined;
@@ -115,7 +118,7 @@ export function makeCache(size, fetch, store) {
115118
* @param {*} m The vat's marshaler.
116119
* @param {number} cacheSize How many virtual objects this manager should cache
117120
* in memory.
118-
* @returns {*} a new virtual object manager.
121+
* @returns {Object} a new virtual object manager.
119122
*
120123
* The virtual object manager allows the creation of persistent objects that do
121124
* not need to occupy memory when they are not in use. It provides four
@@ -395,6 +398,7 @@ export function makeVirtualObjectManager(
395398
const serializedValue = m.serialize(value);
396399
ensureState(innerSelf);
397400
innerSelf.rawData[prop] = serializedValue;
401+
innerSelf.dirty = true;
398402
},
399403
});
400404
}
@@ -437,8 +441,9 @@ export function makeVirtualObjectManager(
437441
const innerSelf = { vobjID, rawData: initialData };
438442
const initialRepresentative = makeRepresentative(innerSelf, true);
439443
const initialize = initialRepresentative.initialize;
444+
delete initialRepresentative.initialize;
445+
harden(initialRepresentative);
440446
if (initialize) {
441-
delete initialRepresentative.initialize;
442447
initialize(...args);
443448
}
444449
delete initialData[initializationInProgress];
@@ -453,6 +458,7 @@ export function makeVirtualObjectManager(
453458
}
454459
innerSelf.rawData = rawData;
455460
innerSelf.wrapData(initialData);
461+
innerSelf.dirty = true;
456462
return initialRepresentative;
457463
}
458464

packages/SwingSet/test/virtualObjects/test-virtualObjectCache.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function makeThing(n) {
3737
return {
3838
vobjID: `t${n}`,
3939
rawData: `thing #${n}`,
40+
dirty: true,
4041
};
4142
}
4243

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

7273
// lookup that has no effect
7374
things[0] = cache.lookup('t0'); // cache: t0, t2, t5, t4
75+
things[0].dirty = true; // pretend we changed it
7476
t.is(things[0].rawData, 'thing #0');
7577
t.is(things[3].rawData, null);
7678
t.deepEqual(store.getLog(), [
@@ -100,7 +102,6 @@ test('cache overflow and refresh', t => {
100102
['store', 't2', 'thing #2'],
101103
['store', 't0', 'thing #0'],
102104
['store', 't4', 'thing #4'],
103-
['store', 't1', 'thing #1'],
104105
]);
105106
t.deepEqual(store.dump(), [
106107
['t0', 'thing #0'],
@@ -114,16 +115,22 @@ test('cache overflow and refresh', t => {
114115
// verify that changes get written
115116
things[0] = cache.lookup('t0'); // cache: t0
116117
things[0].rawData = 'new thing #0';
118+
things[0].dirty = true;
117119
things[1] = cache.lookup('t1'); // cache: t1, t0
118120
things[1].rawData = 'new thing #1';
121+
things[1].dirty = true;
119122
things[2] = cache.lookup('t2'); // cache: t2, t1, t0
120123
things[2].rawData = 'new thing #2';
124+
things[2].dirty = true;
121125
things[3] = cache.lookup('t3'); // cache: t3, t2, t1, t0
122126
things[3].rawData = 'new thing #3';
127+
things[3].dirty = true;
123128
things[4] = cache.lookup('t4'); // cache: t4, t3, t2, t1
124129
things[4].rawData = 'new thing #4';
130+
things[4].dirty = true;
125131
things[5] = cache.lookup('t5'); // cache: t5, t4, t3, t2
126132
things[5].rawData = 'new thing #5';
133+
things[5].dirty = true;
127134
t.is(things[0].rawData, null);
128135
t.is(things[5].rawData, 'new thing #5');
129136
t.deepEqual(store.getLog(), [

0 commit comments

Comments
 (0)