diff --git a/packages/swingset-liveslots/src/virtualObjectManager.js b/packages/swingset-liveslots/src/virtualObjectManager.js index 408777452ee..301cc8f0e0f 100644 --- a/packages/swingset-liveslots/src/virtualObjectManager.js +++ b/packages/swingset-liveslots/src/virtualObjectManager.js @@ -16,10 +16,19 @@ import { /** @template T @typedef {import('@agoric/vat-data').DefineKindOptions} 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 @@ -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 } */ @@ -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) => { @@ -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}])`; } - }); + } }; /** @@ -707,7 +715,7 @@ export const makeVirtualObjectManager = ( durableKindDescriptor = undefined, // only for durables ) => { const { - finish, + finish = undefined, stateShape = undefined, thisfulMethods = false, interfaceGuard = undefined, @@ -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; @@ -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); diff --git a/packages/vat-data/src/exo-utils.js b/packages/vat-data/src/exo-utils.js index fd6d5880caf..1eff5dffa26 100644 --- a/packages/vat-data/src/exo-utils.js +++ b/packages/vat-data/src/exo-utils.js @@ -88,8 +88,14 @@ export const makeExoUtils = VatData => { * @param {string} tag * @param {any} interfaceGuard * @param {I} init - * @param {T & ThisType<{ self: T, state: ReturnType }>} methods - * @param {DefineKindOptions<{ self: T, state: ReturnType }>} [options] + * @param {T & ThisType<{ + * self: T, + * state: ReturnType + * }>} methods + * @param {DefineKindOptions<{ + * self: T, + * state: ReturnType + * }>} [options] * @returns {(...args: Parameters) => (T & RemotableBrand<{}, T>)} */ const defineVirtualExoClass = (tag, interfaceGuard, init, methods, options) => @@ -107,8 +113,14 @@ export const makeExoUtils = VatData => { * @param {string} tag * @param {any} interfaceGuardKit * @param {I} init - * @param {T & ThisType<{ facets: T, state: ReturnType }> } facets - * @param {DefineKindOptions<{ facets: T, state: ReturnType }>} [options] + * @param {T & ThisType<{ + * facets: T, + * state: ReturnType + * }> } facets + * @param {DefineKindOptions<{ + * facets: T, + * state: ReturnType + * }>} [options] * @returns {(...args: Parameters) => (T & RemotableBrand<{}, T>)} */ const defineVirtualExoClassKit = ( @@ -132,8 +144,14 @@ export const makeExoUtils = VatData => { * @param {DurableKindHandle} kindHandle * @param {any} interfaceGuard * @param {I} init - * @param {T & ThisType<{ self: T, state: ReturnType }>} methods - * @param {DefineKindOptions<{ self: T, state: ReturnType }>} [options] + * @param {T & ThisType<{ + * self: T, + * state: ReturnType + * }>} methods + * @param {DefineKindOptions<{ + * self: T, + * state: ReturnType + * }>} [options] * @returns {(...args: Parameters) => (T & RemotableBrand<{}, T>)} */ const defineDurableExoClass = ( @@ -157,8 +175,14 @@ export const makeExoUtils = VatData => { * @param {DurableKindHandle} kindHandle * @param {any} interfaceGuardKit * @param {I} init - * @param {T & ThisType<{ facets: T, state: ReturnType}> } facets - * @param {DefineKindOptions<{ facets: T, state: ReturnType}>} [options] + * @param {T & ThisType<{ + * facets: T, + * state: ReturnType + * }> } facets + * @param {DefineKindOptions<{ + * facets: T, + * state: ReturnType + * }>} [options] * @returns {(...args: Parameters) => (T & RemotableBrand<{}, T>)} */ const defineDurableExoClassKit = ( @@ -183,8 +207,14 @@ export const makeExoUtils = VatData => { * @param {string} kindName * @param {any} interfaceGuard * @param {I} init - * @param {T & ThisType<{ self: T, state: ReturnType }>} methods - * @param {DefineKindOptions<{ self: T, state: ReturnType }>} [options] + * @param {T & ThisType<{ + * self: T, + * state: ReturnType + * }>} methods + * @param {DefineKindOptions<{ + * self: T, + * state: ReturnType + * }>} [options] * @returns {(...args: Parameters) => (T & RemotableBrand<{}, T>)} */ const prepareExoClass = ( @@ -212,8 +242,14 @@ export const makeExoUtils = VatData => { * @param {string} kindName * @param {any} interfaceGuardKit * @param {I} init - * @param {T & ThisType<{ facets: T, state: ReturnType }> } facets - * @param {DefineKindOptions<{ facets: T, state: ReturnType }>} [options] + * @param {T & ThisType<{ + * facets: T, + * state: ReturnType + * }> } facets + * @param {DefineKindOptions<{ + * facets: T, + * state: ReturnType + * }>} [options] * @returns {(...args: Parameters) => (T & RemotableBrand<{}, T>)} */ const prepareExoClassKit = (