From d84875412623bd43a12e79c45e8052dfecdf1a03 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Tue, 16 Jan 2024 11:07:37 -0800 Subject: [PATCH] fix(exo): remove receiveRevoker (#1964) --- packages/exo/src/exo-makers.js | 48 +------ .../exo/test/test-amplify-heap-class-kits.js | 19 +-- packages/exo/test/test-revoke-heap-classes.js | 121 ------------------ 3 files changed, 4 insertions(+), 184 deletions(-) delete mode 100644 packages/exo/test/test-revoke-heap-classes.js diff --git a/packages/exo/src/exo-makers.js b/packages/exo/src/exo-makers.js index 6a3e0eff56..ec921790e8 100644 --- a/packages/exo/src/exo-makers.js +++ b/packages/exo/src/exo-makers.js @@ -87,18 +87,6 @@ export const initEmpty = () => emptyRecord; * @typedef {(power: P) => void} ReceivePower */ -/** - * The power to revoke a live instance of the associated exo class, or the - * power to revoke a live facet instance of the associated exo class kit. - * If called with such a live instance, it revokes it and returns true. Once - * revoked, it is no longer live, and calling any of its methods throw - * an informative diagnostic with no further effects. - * - * @callback Revoke - * @param {any} exo - * @returns {boolean} - */ - /** * The power to amplify a live facet instance of the associated exo class kit * into the record of all facets of this facet instance's cohort. @@ -136,15 +124,6 @@ export const initEmpty = () => emptyRecord; * enforce the `stateShape` invariant. The heap exos defined in this * package currently ignore `stateShape`, but will enforce this in the future. * - * @property {ReceivePower} [receiveRevoker] - * If a `receiveRevoker` function is provided, it will be called during - * definition of the exo class or exo class kit with a `Revoke` function. - * A `Revoke` function is a function of one argument. If you call the revoke - * function with a live instance of this exo class, or a live facet instance - * of this exo class kit, then it will "revoke" it and return true. Once - * revoked, this instance is no longer "live": Any attempt to invoke any of - * its methods will fail without further effect. - * * @property {ReceivePower>} [receiveAmplifier] * If a `receiveAmplifier` function is provided, it will be called during * definition of the exo class kit with an `Amplify` function. If called @@ -190,11 +169,7 @@ export const defineExoClass = ( options = {}, ) => { harden(methods); - const { - finish = undefined, - receiveRevoker = undefined, - receiveAmplifier = undefined, - } = options; + const { finish = undefined, receiveAmplifier = undefined } = options; receiveAmplifier === undefined || Fail`Only facets of an exo class kit can be amplified ${q(tag)}`; @@ -227,12 +202,6 @@ export const defineExoClass = ( return self; }; - if (receiveRevoker) { - const revoke = self => contextMap.delete(self); - harden(revoke); - receiveRevoker(revoke); - } - return harden(makeInstance); }; harden(defineExoClass); @@ -260,11 +229,7 @@ export const defineExoClassKit = ( options = {}, ) => { harden(methodsKit); - const { - finish = undefined, - receiveRevoker = undefined, - receiveAmplifier = undefined, - } = options; + const { finish = undefined, receiveAmplifier = undefined } = options; const contextMapKit = objectMap(methodsKit, () => new WeakMap()); const getContextKit = objectMap( contextMapKit, @@ -302,13 +267,6 @@ export const defineExoClassKit = ( return /** @type {GuardedKit} */ (context.facets); }; - if (receiveRevoker) { - const revoke = aFacet => - values(contextMapKit).some(contextMap => contextMap.delete(aFacet)); - harden(revoke); - receiveRevoker(revoke); - } - if (receiveAmplifier) { const amplify = aFacet => { for (const contextMap of values(contextMapKit)) { @@ -317,7 +275,7 @@ export const defineExoClassKit = ( return facets; } } - throw Fail`Must be an unrevoked facet of ${q(tag)}: ${aFacet}`; + throw Fail`Must be a facet of ${q(tag)}: ${aFacet}`; }; harden(amplify); receiveAmplifier(amplify); diff --git a/packages/exo/test/test-amplify-heap-class-kits.js b/packages/exo/test/test-amplify-heap-class-kits.js index 42a6eddf97..a9c018f74c 100644 --- a/packages/exo/test/test-amplify-heap-class-kits.js +++ b/packages/exo/test/test-amplify-heap-class-kits.js @@ -41,7 +41,6 @@ test('test amplify defineExoClass fails', t => { }); test('test amplify defineExoClassKit', t => { - let revoke; let amp; const makeCounterKit = defineExoClassKit( 'Counter', @@ -65,9 +64,6 @@ test('test amplify defineExoClassKit', t => { }, }, { - receiveRevoker(r) { - revoke = r; - }, receiveAmplifier(a) { amp = a; }, @@ -79,21 +75,8 @@ test('test amplify defineExoClassKit', t => { t.is(downCounter.decr(), 7); t.throws(() => amp(harden({})), { - message: 'Must be an unrevoked facet of "Counter": {}', + message: 'Must be a facet of "Counter": {}', }); t.deepEqual(amp(upCounter), counterKit); t.deepEqual(amp(downCounter), counterKit); - - t.is(revoke(upCounter), true); - - t.throws(() => amp(upCounter), { - message: 'Must be an unrevoked facet of "Counter": "[Alleged: Counter up]"', - }); - t.deepEqual(amp(downCounter), counterKit); - t.throws(() => upCounter.incr(3), { - message: - '"In \\"incr\\" method of (Counter up)" may only be applied to a valid instance: "[Alleged: Counter up]"', - }); - t.deepEqual(amp(downCounter), counterKit); - t.is(downCounter.decr(), 6); }); diff --git a/packages/exo/test/test-revoke-heap-classes.js b/packages/exo/test/test-revoke-heap-classes.js deleted file mode 100644 index cc5a0befd7..0000000000 --- a/packages/exo/test/test-revoke-heap-classes.js +++ /dev/null @@ -1,121 +0,0 @@ -// eslint-disable-next-line import/order -import { test } from './prepare-test-env-ava.js'; - -// eslint-disable-next-line import/order -import { M } from '@endo/patterns'; -import { defineExoClass, defineExoClassKit } from '../src/exo-makers.js'; - -const { apply } = Reflect; - -const UpCounterI = M.interface('UpCounter', { - incr: M.call().optional(M.gte(0)).returns(M.number()), -}); - -const DownCounterI = M.interface('DownCounter', { - decr: M.call().optional(M.gte(0)).returns(M.number()), -}); - -test('test revoke defineExoClass', t => { - let revoke; - const makeUpCounter = defineExoClass( - 'UpCounter', - UpCounterI, - /** @param {number} x */ - (x = 0) => ({ x }), - { - incr(y = 1) { - const { state } = this; - state.x += y; - return state.x; - }, - }, - { - receiveRevoker(r) { - revoke = r; - }, - }, - ); - const upCounter = makeUpCounter(3); - t.is(upCounter.incr(5), 8); - t.is(revoke(upCounter), true); - t.throws(() => upCounter.incr(1), { - message: - '"In \\"incr\\" method of (UpCounter)" may only be applied to a valid instance: "[Alleged: UpCounter]"', - }); -}); - -test('test revoke defineExoClassKit', t => { - let revoke; - const makeCounterKit = defineExoClassKit( - 'Counter', - { up: UpCounterI, down: DownCounterI }, - /** @param {number} x */ - (x = 0) => ({ x }), - { - up: { - incr(y = 1) { - const { state } = this; - state.x += y; - return state.x; - }, - }, - down: { - decr(y = 1) { - const { state } = this; - state.x -= y; - return state.x; - }, - }, - }, - { - receiveRevoker(r) { - revoke = r; - }, - }, - ); - const { up: upCounter, down: downCounter } = makeCounterKit(3); - t.is(upCounter.incr(5), 8); - t.is(downCounter.decr(), 7); - t.is(revoke(upCounter), true); - t.is(revoke(upCounter), false); - t.throws(() => upCounter.incr(3), { - message: - '"In \\"incr\\" method of (Counter up)" may only be applied to a valid instance: "[Alleged: Counter up]"', - }); - t.is(revoke(downCounter), true); - t.is(revoke(downCounter), false); - t.throws(() => downCounter.decr(), { - message: - '"In \\"decr\\" method of (Counter down)" may only be applied to a valid instance: "[Alleged: Counter down]"', - }); -}); - -test('test facet cross-talk', t => { - const makeCounterKit = defineExoClassKit( - 'Counter', - { up: UpCounterI, down: DownCounterI }, - /** @param {number} x */ - (x = 0) => ({ x }), - { - up: { - incr(y = 1) { - const { state } = this; - state.x += y; - return state.x; - }, - }, - down: { - decr(y = 1) { - const { state } = this; - state.x -= y; - return state.x; - }, - }, - }, - ); - const { up: upCounter, down: downCounter } = makeCounterKit(3); - t.throws(() => apply(upCounter.incr, downCounter, [2]), { - message: - '"In \\"incr\\" method of (Counter up)" may only be applied to a valid instance: "[Alleged: Counter down]"', - }); -});