Skip to content

Commit

Permalink
Merge pull request #7304 from Agoric/markm-isolate-exo-api-change
Browse files Browse the repository at this point in the history
fix: only the exo api change
  • Loading branch information
mergify[bot] authored Apr 1, 2023
2 parents 397b0d0 + 5cf3bf1 commit 6ee9369
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
8 changes: 6 additions & 2 deletions packages/store/src/patterns/exo-makers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const defineExoClass = (
const contextMap = new WeakMap();
const prototype = defendPrototype(
tag,
contextMap,
self => contextMap.get(self),
methods,
true,
interfaceGuard,
Expand Down Expand Up @@ -113,9 +113,13 @@ export const defineExoClassKit = (
{ finish = undefined } = {},
) => {
const contextMapKit = objectMap(methodsKit, () => new WeakMap());
const getContextKit = objectMap(
methodsKit,
(_v, name) => facet => contextMapKit[name].get(facet),
);
const prototypeKit = defendPrototypeKit(
tag,
contextMapKit,
getContextKit,
methodsKit,
true,
interfaceGuardKit,
Expand Down
24 changes: 14 additions & 10 deletions packages/store/src/patterns/exo-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,29 @@ const defendMethod = (method, methodGuard, label) => {
}
};

/**
* @typedef { (representative: any) => any } ContextProvider
*/

/**
*
* @param {string} methodTag
* @param {WeakMap} contextMap
* @param {ContextProvider} contextProvider
* @param {CallableFunction} behaviorMethod
* @param {boolean} [thisfulMethods]
* @param {MethodGuard} [methodGuard]
*/
const bindMethod = (
methodTag,
contextMap,
contextProvider,
behaviorMethod,
thisfulMethods = false,
methodGuard = undefined,
) => {
assert.typeof(behaviorMethod, 'function');

const getContext = self => {
const context = contextMap.get(self);
const context = contextProvider(self);
context ||
Fail`${q(methodTag)} may only be applied to a valid instance: ${self}`;
return context;
Expand Down Expand Up @@ -173,15 +177,15 @@ const bindMethod = (
/**
* @template {Record<string | symbol, CallableFunction>} T
* @param {string} tag
* @param {WeakMap} contextMap
* @param {ContextProvider} contextProvider
* @param {T} behaviorMethods
* @param {boolean} [thisfulMethods]
* @param {InterfaceGuard} [interfaceGuard]
* @returns {T & import('@endo/eventual-send').RemotableBrand<{}, T>}
*/
export const defendPrototype = (
tag,
contextMap,
contextProvider,
behaviorMethods,
thisfulMethods = false,
interfaceGuard = undefined,
Expand Down Expand Up @@ -218,7 +222,7 @@ export const defendPrototype = (
for (const prop of methodNames) {
prototype[prop] = bindMethod(
`In ${q(prop)} method of (${tag})`,
contextMap,
contextProvider,
behaviorMethods[prop],
thisfulMethods,
// TODO some tool does not yet understand the `?.[` syntax
Expand All @@ -232,14 +236,14 @@ harden(defendPrototype);

/**
* @param {string} tag
* @param {Record<string, WeakMap>} contextMapKit
* @param {Record<string, ContextProvider>} contextProviderKit
* @param {Record<string, Record<string | symbol, CallableFunction>>} behaviorMethodsKit
* @param {boolean} [thisfulMethods]
* @param {Record<string, InterfaceGuard>} [interfaceGuardKit]
*/
export const defendPrototypeKit = (
tag,
contextMapKit,
contextProviderKit,
behaviorMethodsKit,
thisfulMethods = false,
interfaceGuardKit = undefined,
Expand All @@ -255,7 +259,7 @@ export const defendPrototypeKit = (
extraFacetNames.length === 0 ||
Fail`Facets ${q(extraFacetNames)} of ${q(tag)} not guarded by interfaces`;
}
const contextMapNames = ownKeys(contextMapKit);
const contextMapNames = ownKeys(contextProviderKit);
const extraContextNames = listDifference(facetNames, contextMapNames);
extraContextNames.length === 0 ||
Fail`Contexts ${q(extraContextNames)} not implemented by ${q(tag)}`;
Expand All @@ -265,7 +269,7 @@ export const defendPrototypeKit = (
return objectMap(behaviorMethodsKit, (behaviorMethods, facetName) =>
defendPrototype(
`${tag} ${facetName}`,
contextMapKit[facetName],
contextProviderKit[facetName],
behaviorMethods,
thisfulMethods,
interfaceGuardKit && interfaceGuardKit[facetName],
Expand Down
9 changes: 7 additions & 2 deletions packages/swingset-liveslots/src/virtualObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,19 @@ export function makeVirtualObjectManager(
};

const facetiousness = assessFacetiousness(behavior);
const getContextKit = objectMap(
behavior,
(_v, name) => facet => contextMapTemplate[name].get(facet),
);

switch (facetiousness) {
case 'one': {
assert(!multifaceted);
facetNames = undefined;
contextMapTemplate = new WeakMap();
prototypeTemplate = defendPrototype(
tag,
contextMapTemplate,
self => contextMapTemplate.get(self),
behavior,
thisfulMethods,
interfaceGuard,
Expand All @@ -652,7 +657,7 @@ export function makeVirtualObjectManager(
contextMapTemplate = objectMap(behavior, () => new WeakMap());
prototypeTemplate = defendPrototypeKit(
tag,
contextMapTemplate,
getContextKit,
behavior,
thisfulMethods,
interfaceGuard,
Expand Down

0 comments on commit 6ee9369

Please sign in to comment.