diff --git a/packages/SwingSet/tools/run-utils.ts b/packages/SwingSet/tools/run-utils.js similarity index 65% rename from packages/SwingSet/tools/run-utils.ts rename to packages/SwingSet/tools/run-utils.js index 54e283d09f1..40f87d50728 100644 --- a/packages/SwingSet/tools/run-utils.ts +++ b/packages/SwingSet/tools/run-utils.js @@ -1,32 +1,29 @@ -/* eslint-disable @jessie.js/safe-await-separator */ import { Fail, q } from '@agoric/assert'; import { kunser } from '@agoric/kmarshal'; import { makeQueue } from '@endo/stream'; -import type { E } from '@endo/eventual-send'; - -import type { SwingsetController } from '../src/controller/controller.js'; const sink = () => {}; -export const makeRunUtils = ( - controller: SwingsetController, - log = (..._) => {}, -) => { +/** + * @param {import('../src/controller/controller.js').SwingsetController} controller + * @param {(...args: any[]) => void} [log] + */ +export const makeRunUtils = (controller, log = (..._) => {}) => { let cranksRun = 0; const mutex = makeQueue(); mutex.put(controller.run()); - const runThunk = async any>( - thunk: T, - ): Promise> => { - try { - // this promise for the last lock may fail - await mutex.get(); - } catch { - // noop because the result will resolve for the previous runMethod return - } + /** + * @template {() => any} T + * @param {T} thunk + * @returns {Promise>} + */ + const runThunk = async thunk => { + // this promise for the last lock may fail + // sink because the result will resolve for the previous runMethod return + await mutex.get().catch(sink); const thunkResult = await thunk(); @@ -60,10 +57,12 @@ export const makeRunUtils = ( } }; - type EVProxy = typeof E & { - sendOnly: (presence: unknown) => Record void>; - vat: (name: string) => Record Promise>; - }; + /** + * @typedef {import('@endo/eventual-send').EProxy & { + * sendOnly: (presence: unknown) => Record void>; + * vat: (name: string) => Record Promise>; + * }} EVProxy + */ // IMPORTANT WARNING TO USERS OF `EV` // @@ -109,48 +108,56 @@ export const makeRunUtils = ( // promise that can remain pending indefinitely, possibly to be settled by a // future message delivery. + /** @type {EVProxy} */ // @ts-expect-error cast, approximate - const EV: EVProxy = presence => - new Proxy(harden({}), { - get: (_t, method, _rx) => { - const boundMethod = (...args) => - queueAndRun(() => - controller.queueToVatObject(presence, method, args), - ); - return harden(boundMethod); - }, - }); - EV.vat = vatName => - new Proxy(harden({}), { - get: (_t, method, _rx) => { - const boundMethod = (...args) => - queueAndRun(() => controller.queueToVatRoot(vatName, method, args)); - return harden(boundMethod); - }, - }); - // @ts-expect-error xxx - EV.sendOnly = presence => - new Proxy(harden({}), { - get: (_t, method, _rx) => { - const boundMethod = (...args) => - queueAndRun( - () => controller.queueToVatObject(presence, method, args), - true, - ); - return harden(boundMethod); - }, - }); - // @ts-expect-error xxx - EV.get = presence => - new Proxy(harden({}), { - get: (_t, pathElement, _rx) => - queueAndRun(() => - controller.queueToVatRoot('bootstrap', 'awaitVatObject', [ - presence, - [pathElement], - ]), - ), - }); + const EV = Object.assign( + presence => + new Proxy(harden({}), { + get: (_t, method, _rx) => { + const boundMethod = (...args) => + queueAndRun(() => + controller.queueToVatObject(presence, method, args), + ); + return harden(boundMethod); + }, + }), + { + vat: vatName => + new Proxy(harden({}), { + get: (_t, method, _rx) => { + const boundMethod = (...args) => + queueAndRun(() => + controller.queueToVatRoot(vatName, method, args), + ); + return harden(boundMethod); + }, + }), + sendOnly: presence => + new Proxy(harden({}), { + get: (_t, method, _rx) => { + const boundMethod = (...args) => + queueAndRun( + () => controller.queueToVatObject(presence, method, args), + true, + ); + return harden(boundMethod); + }, + }), + get: presence => + new Proxy(harden({}), { + get: (_t, pathElement, _rx) => + queueAndRun(() => + controller.queueToVatRoot('bootstrap', 'awaitVatObject', [ + presence, + [pathElement], + ]), + ), + }), + }, + ); return harden({ runThunk, EV }); }; -export type RunUtils = ReturnType; + +/** + * @typedef {ReturnType} RunUtils + */ diff --git a/packages/boot/test/upgrading/test-upgrade-vats.js b/packages/boot/test/upgrading/test-upgrade-vats.js index 2733bcd6c4b..3f6838b5f8c 100644 --- a/packages/boot/test/upgrading/test-upgrade-vats.js +++ b/packages/boot/test/upgrading/test-upgrade-vats.js @@ -3,7 +3,7 @@ import { test as anyTest } from '@agoric/swingset-vat/tools/prepare-test-env-ava import { BridgeId } from '@agoric/internal'; import { buildVatController } from '@agoric/swingset-vat'; -import { makeRunUtils } from '@agoric/swingset-vat/tools/run-utils.ts'; +import { makeRunUtils } from '@agoric/swingset-vat/tools/run-utils.js'; import { resolve as importMetaResolve } from 'import-meta-resolve'; import { matchAmount, matchIter, matchRef } from '../../tools/supports.ts'; diff --git a/packages/boot/tools/drivers.ts b/packages/boot/tools/drivers.ts index d15e19a293b..b2464856d2d 100644 --- a/packages/boot/tools/drivers.ts +++ b/packages/boot/tools/drivers.ts @@ -22,7 +22,7 @@ import type { WalletFactoryStartResult } from '@agoric/vats/src/core/startWallet import type { OfferSpec } from '@agoric/smart-wallet/src/offers.js'; import type { TimerService } from '@agoric/time'; import type { OfferMaker } from '@agoric/smart-wallet/src/types.js'; -import type { RunUtils } from '@agoric/swingset-vat/tools/run-utils.ts'; +import type { RunUtils } from '@agoric/swingset-vat/tools/run-utils.js'; import type { SwingsetTestKit } from './supports.ts'; export const makeWalletFactoryDriver = async (