Skip to content

Commit

Permalink
style: cleanups from #8009
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jul 6, 2023
1 parent ff1e301 commit 9d7072b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 25 deletions.
35 changes: 22 additions & 13 deletions packages/swingset-liveslots/src/virtualObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ import {

/** @template T @typedef {import('@agoric/vat-data').DefineKindOptions<T>} DefineKindOptions */

const { hasOwn, defineProperty, getOwnPropertyNames } = Object;
const { hasOwn, defineProperty, getOwnPropertyNames, entries } = Object;
const { ownKeys } = Reflect;
const { quote: q } = assert;

// See https://github.com/Agoric/agoric-sdk/issues/8005
// Once agoric-sdk is upgraded to depend on endo post
// https://github.com/endojs/endo/pull/1606 then remove this
// definition of `b` and say instead
// ```js
// const { quote: q, base: b } = assert;
// ```
const b = index => q(Number(index));

// import { kdebug } from './kdebug.js';

// TODO Use environment-options.js currently in ses/src after factoring it out
Expand Down Expand Up @@ -141,9 +150,8 @@ const makeContextCache = (makeState, makeContext) => {
* @param {*} getSlotForVal
* @returns {ContextProvider}
*/
const makeContextProvider = (contextCache, getSlotForVal) => {
return harden(rep => contextCache.get(getSlotForVal(rep)));
};
const makeContextProvider = (contextCache, getSlotForVal) =>
harden(rep => contextCache.get(getSlotForVal(rep)));

const makeContextProviderKit = (contextCache, getSlotForVal, facetNames) => {
/** @type { Record<string, any> } */
Expand Down Expand Up @@ -260,15 +268,15 @@ const makeFacets = (
};

const insistDurableCapdata = (vrm, what, capdata, valueFor) => {
capdata.slots.forEach((vref, idx) => {
for (const [idx, vref] of entries(capdata.slots)) {
if (!vrm.isDurable(vref)) {
if (valueFor) {
Fail`value for ${what} is not durable: slot ${q(idx)} of ${capdata}`;
Fail`value for ${what} is not durable: slot ${b(idx)} of ${capdata}`;
} else {
Fail`${what} is not durable: slot ${q(idx)} of ${capdata}`;
Fail`${what} is not durable: slot ${b(idx)} of ${capdata}`;
}
}
});
}
};

const insistSameCapData = (oldCD, newCD) => {
Expand All @@ -281,11 +289,11 @@ const insistSameCapData = (oldCD, newCD) => {
if (oldCD.slots.length !== newCD.slots.length) {
Fail`durable Kind stateShape mismatch (slots.length)`;
}
oldCD.slots.forEach((oldVref, idx) => {
for (const [idx, oldVref] of entries(oldCD.slots)) {
if (newCD.slots[idx] !== oldVref) {
Fail`durable Kind stateShape mismatch (slot[${idx}])`;
}
});
}
};

/**
Expand Down Expand Up @@ -707,7 +715,7 @@ export const makeVirtualObjectManager = (
durableKindDescriptor = undefined, // only for durables
) => {
const {
finish,
finish = undefined,
stateShape = undefined,
thisfulMethods = false,
interfaceGuard = undefined,
Expand Down Expand Up @@ -974,9 +982,9 @@ export const makeVirtualObjectManager = (
let doMoreGC = false;
const record = dataCache.get(baseRef);
for (const valueCD of Object.values(record.capdatas)) {
valueCD.slots.forEach(vref => {
for (const vref of valueCD.slots) {
doMoreGC = vrm.removeReachableVref(vref) || doMoreGC;
});
}
}
dataCache.delete(baseRef);
return doMoreGC;
Expand Down Expand Up @@ -1015,6 +1023,7 @@ export const makeVirtualObjectManager = (
if (isDurable) {
insistDurableCapdata(vrm, prop, valueCD, true);
}
// eslint-disable-next-line github/array-foreach
valueCD.slots.forEach(vrm.addReachableVref);
capdatas[prop] = valueCD;
valueMap.set(prop, value);
Expand Down
60 changes: 48 additions & 12 deletions packages/vat-data/src/exo-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ export const makeExoUtils = VatData => {
* @param {string} tag
* @param {any} interfaceGuard
* @param {I} init
* @param {T & ThisType<{ self: T, state: ReturnType<I> }>} methods
* @param {DefineKindOptions<{ self: T, state: ReturnType<I> }>} [options]
* @param {T & ThisType<{
* self: T,
* state: ReturnType<I>
* }>} methods
* @param {DefineKindOptions<{
* self: T,
* state: ReturnType<I>
* }>} [options]
* @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
*/
const defineVirtualExoClass = (tag, interfaceGuard, init, methods, options) =>
Expand All @@ -107,8 +113,14 @@ export const makeExoUtils = VatData => {
* @param {string} tag
* @param {any} interfaceGuardKit
* @param {I} init
* @param {T & ThisType<{ facets: T, state: ReturnType<I> }> } facets
* @param {DefineKindOptions<{ facets: T, state: ReturnType<I> }>} [options]
* @param {T & ThisType<{
* facets: T,
* state: ReturnType<I>
* }> } facets
* @param {DefineKindOptions<{
* facets: T,
* state: ReturnType<I>
* }>} [options]
* @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
*/
const defineVirtualExoClassKit = (
Expand All @@ -132,8 +144,14 @@ export const makeExoUtils = VatData => {
* @param {DurableKindHandle} kindHandle
* @param {any} interfaceGuard
* @param {I} init
* @param {T & ThisType<{ self: T, state: ReturnType<I> }>} methods
* @param {DefineKindOptions<{ self: T, state: ReturnType<I> }>} [options]
* @param {T & ThisType<{
* self: T,
* state: ReturnType<I>
* }>} methods
* @param {DefineKindOptions<{
* self: T,
* state: ReturnType<I>
* }>} [options]
* @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
*/
const defineDurableExoClass = (
Expand All @@ -157,8 +175,14 @@ export const makeExoUtils = VatData => {
* @param {DurableKindHandle} kindHandle
* @param {any} interfaceGuardKit
* @param {I} init
* @param {T & ThisType<{ facets: T, state: ReturnType<I>}> } facets
* @param {DefineKindOptions<{ facets: T, state: ReturnType<I>}>} [options]
* @param {T & ThisType<{
* facets: T,
* state: ReturnType<I>
* }> } facets
* @param {DefineKindOptions<{
* facets: T,
* state: ReturnType<I>
* }>} [options]
* @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
*/
const defineDurableExoClassKit = (
Expand All @@ -183,8 +207,14 @@ export const makeExoUtils = VatData => {
* @param {string} kindName
* @param {any} interfaceGuard
* @param {I} init
* @param {T & ThisType<{ self: T, state: ReturnType<I> }>} methods
* @param {DefineKindOptions<{ self: T, state: ReturnType<I> }>} [options]
* @param {T & ThisType<{
* self: T,
* state: ReturnType<I>
* }>} methods
* @param {DefineKindOptions<{
* self: T,
* state: ReturnType<I>
* }>} [options]
* @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
*/
const prepareExoClass = (
Expand Down Expand Up @@ -212,8 +242,14 @@ export const makeExoUtils = VatData => {
* @param {string} kindName
* @param {any} interfaceGuardKit
* @param {I} init
* @param {T & ThisType<{ facets: T, state: ReturnType<I> }> } facets
* @param {DefineKindOptions<{ facets: T, state: ReturnType<I> }>} [options]
* @param {T & ThisType<{
* facets: T,
* state: ReturnType<I>
* }> } facets
* @param {DefineKindOptions<{
* facets: T,
* state: ReturnType<I>
* }>} [options]
* @returns {(...args: Parameters<I>) => (T & RemotableBrand<{}, T>)}
*/
const prepareExoClassKit = (
Expand Down

0 comments on commit 9d7072b

Please sign in to comment.