From 94389ad75ed5a0ede88b0a7cd862ab29f870feb3 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Wed, 1 Nov 2023 18:15:54 -0700 Subject: [PATCH] fix: review suggestions --- packages/exo/src/exo-tools.js | 10 ++++++++-- packages/exo/src/get-interface.js | 7 ++++--- packages/exo/test/test-exo-class-js-class.js | 2 -- packages/exo/test/test-heap-classes.js | 4 +--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/exo/src/exo-tools.js b/packages/exo/src/exo-tools.js index 7358ca083a..427f4f672b 100644 --- a/packages/exo/src/exo-tools.js +++ b/packages/exo/src/exo-tools.js @@ -426,9 +426,10 @@ export const defendPrototype = ( ); } - if (interfaceGuard) { + if (!hasOwnPropertyOf(prototype, GET_INTERFACE_GUARD)) { const getInterfaceGuardMethod = { [GET_INTERFACE_GUARD]() { + // Note: May be `undefined` return interfaceGuard; }, }[GET_INTERFACE_GUARD]; @@ -441,7 +442,12 @@ export const defendPrototype = ( ); } - return Far(tag, /** @type {T} */ (prototype)); + return Far( + tag, + /** @type {T & import('./get-interface.js').GetInterfaceGuard} */ ( + prototype + ), + ); }; harden(defendPrototype); diff --git a/packages/exo/src/get-interface.js b/packages/exo/src/get-interface.js index 9fd4baf9d0..1d1d894d36 100644 --- a/packages/exo/src/get-interface.js +++ b/packages/exo/src/get-interface.js @@ -15,8 +15,9 @@ export const GET_INTERFACE_GUARD = Symbol.for('getInterfaceGuard'); /** * @template {Record} M * @typedef {{ - * [GET_INTERFACE_GUARD]: () => import('@endo/patterns').InterfaceGuard<{ - * [K in keyof M]: import('@endo/patterns').MethodGuard - * }> + * [GET_INTERFACE_GUARD]: () => + * import('@endo/patterns').InterfaceGuard<{ + * [K in keyof M]: import('@endo/patterns').MethodGuard + * }> | undefined * }} GetInterfaceGuard */ diff --git a/packages/exo/test/test-exo-class-js-class.js b/packages/exo/test/test-exo-class-js-class.js index 697ece1922..8cc19eae56 100644 --- a/packages/exo/test/test-exo-class-js-class.js +++ b/packages/exo/test/test-exo-class-js-class.js @@ -4,8 +4,6 @@ import { test } from './prepare-test-env-ava.js'; import { passStyleOf } from '@endo/pass-style'; -// import { M, getInterfaceGuardPayload } from '@endo/patterns'; -// import { defineExoClass, makeExo } from '../src/exo-makers.js'; import { M, getInterfaceGuardPayload } from '@endo/patterns'; import { makeExo, defineExoClass } from '../src/exo-makers.js'; diff --git a/packages/exo/test/test-heap-classes.js b/packages/exo/test/test-heap-classes.js index a5ef1346a5..91ff0a1ee3 100644 --- a/packages/exo/test/test-heap-classes.js +++ b/packages/exo/test/test-heap-classes.js @@ -172,9 +172,7 @@ test('missing interface', t => { message: 'In "makeSayHello" method of (greeterMaker): result: "[Symbol(passStyle)]" property expected: "[Function ]"', }); - t.throws(() => greeterMaker[GET_INTERFACE_GUARD](), { - message: 'greeterMaker[GET_INTERFACE_GUARD] is not a function', - }); + t.is(greeterMaker[GET_INTERFACE_GUARD](), undefined); }); const SloppyGreeterI = M.interface('greeter', {}, { sloppy: true });