Skip to content

Commit

Permalink
refactor(exo): break GET_INTERFACE_GUARD loop
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Oct 27, 2023
1 parent aceca1a commit 263254a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/exo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export {
makeExo,
} from './src/exo-makers.js';

export { GET_INTERFACE_GUARD } from './src/exo-tools.js';
export { GET_INTERFACE_GUARD } from './src/get-interface.js';
18 changes: 2 additions & 16 deletions packages/exo/src/exo-makers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
import { makeEnvironmentCaptor } from '@endo/env-options';
import { objectMap } from '@endo/patterns';

import {
GET_INTERFACE_GUARD,
defendPrototype,
defendPrototypeKit,
} from './exo-tools.js';

// Used in typing.
GET_INTERFACE_GUARD;
import { defendPrototype, defendPrototypeKit } from './exo-tools.js';

const { create, seal, freeze, defineProperty, values } = Object;

Expand Down Expand Up @@ -102,14 +95,7 @@ export const initEmpty = () => emptyRecord;

/**
* @template {Methods} M
* @typedef {{
* [GET_INTERFACE_GUARD]: () => InterfaceGuard<{ [K in keyof M]: MethodGuard }>
* }} GetInterfaceGuard
*/

/**
* @template {Methods} M
* @typedef {Farable<M & GetInterfaceGuard<M>>} Facet
* @typedef {Farable<M & import('./get-interface.js').GetInterfaceGuard<M>>} Facet
*/

/**
Expand Down
18 changes: 4 additions & 14 deletions packages/exo/src/exo-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
getCopyMapEntries,
} from '@endo/patterns';

import { GET_INTERFACE_GUARD } from './get-interface.js';

/** @typedef {import('@endo/patterns').Method} Method */
/** @typedef {import('@endo/patterns').MethodGuard} MethodGuard */
/** @typedef {import('@endo/patterns').MethodGuardPayload} MethodGuardPayload */
Expand Down Expand Up @@ -348,24 +350,12 @@ const bindMethod = (
return method;
};

/**
* The name of the automatically added default meta-method for
* obtaining an exo's interface, if it has one.
*
* TODO Name to be bikeshed. Perhaps even whether it is a
* string or symbol to be bikeshed.
*
* TODO Beware that an exo's interface can change across an upgrade,
* so remotes that cache it can become stale.
*/
export const GET_INTERFACE_GUARD = Symbol.for('getInterfaceGuard');

/**
*
* @template {Record<PropertyKey, CallableFunction>} T
* @param {T} behaviorMethods
* @param {InterfaceGuard<{ [M in keyof T]: MethodGuard }>} interfaceGuard
* @returns {T & { [GET_INTERFACE_GUARD]: () => InterfaceGuard<{ [M in keyof T]: MethodGuard }> }}
* @returns {T & import('./get-interface.js').GetInterfaceGuard<T>}
*/
const withGetInterfaceGuardMethod = (behaviorMethods, interfaceGuard) =>
harden({
Expand Down Expand Up @@ -448,7 +438,7 @@ export const defendPrototype = (

return Far(
tag,
/** @type {T & { [GET_INTERFACE_GUARD]: () => InterfaceGuard<{ [M in keyof T]: MethodGuard }>}} */ (
/** @type {T & import('./get-interface.js').GetInterfaceGuard<T>} */ (
prototype
),
);
Expand Down
22 changes: 22 additions & 0 deletions packages/exo/src/get-interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @ts-check

/**
* The name of the automatically added default meta-method for
* obtaining an exo's interface, if it has one.
*
* TODO Name to be bikeshed. Perhaps even whether it is a
* string or symbol to be bikeshed.
*
* TODO Beware that an exo's interface can change across an upgrade,
* so remotes that cache it can become stale.
*/
export const GET_INTERFACE_GUARD = Symbol.for('getInterfaceGuard');

/**
* @template {Record<PropertyKey, CallableFunction>} M
* @typedef {{
* [GET_INTERFACE_GUARD]: () => import('@endo/patterns').InterfaceGuard<{
* [K in keyof M]: import('@endo/patterns').MethodGuard
* }>
* }} GetInterfaceGuard
*/
4 changes: 2 additions & 2 deletions packages/exo/test/test-heap-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { test } from './prepare-test-env-ava.js';
// eslint-disable-next-line import/order
import { getInterfaceMethodKeys, M } from '@endo/patterns';
import {
GET_INTERFACE_GUARD,
defineExoClass,
defineExoClassKit,
makeExo,
} from '../src/exo-makers.js';
import { GET_INTERFACE_GUARD } from '../src/exo-tools.js';
} from '../index.js';

const NoExtraI = M.interface('NoExtra', {
foo: M.call().returns(),
Expand Down

0 comments on commit 263254a

Please sign in to comment.