diff --git a/packages/captp/lib/captp.js b/packages/captp/lib/captp.js index 4fb711299a7..817aa5bab73 100644 --- a/packages/captp/lib/captp.js +++ b/packages/captp/lib/captp.js @@ -9,8 +9,14 @@ import { isPromise } from '@agoric/produce-promise'; export { E, HandledPromise, Nat }; -export function makeCapTP(ourId, send, bootstrapObj = undefined) { +export function makeCapTP(ourId, rawSend, bootstrapObj = undefined) { let unplug = false; + function send(...args) { + if (unplug) { + throw unplug; + } + return rawSend(...args); + } // convertValToSlot and convertSlotToVal both perform side effects, // populating the c-lists (imports/exports/questions/answers) upon @@ -253,7 +259,6 @@ export function makeCapTP(ourId, send, bootstrapObj = undefined) { // Pull the plug! CTP_ABORT(obj) { const { exception } = obj; - unplug = true; for (const pr of questions.values()) { pr.rej(exception); } @@ -261,6 +266,7 @@ export function makeCapTP(ourId, send, bootstrapObj = undefined) { pr.rej(exception); } send(obj); + unplug = exception; }, }; diff --git a/packages/captp/lib/index.js b/packages/captp/lib/index.js new file mode 100644 index 00000000000..dc204a3e951 --- /dev/null +++ b/packages/captp/lib/index.js @@ -0,0 +1,8 @@ +import harden from '@agoric/harden'; +import Nat from '@agoric/nat'; + +export * from '@agoric/eventual-send'; +export * from '@agoric/marshal'; + +export * from './captp'; +export { harden, Nat }; diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/captp.js b/packages/cosmic-swingset/lib/ag-solo/vats/captp.js index f906f0881f9..dcce6f3a7b4 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/captp.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/captp.js @@ -4,7 +4,7 @@ // in its own makeHardener, etc. import { makeCapTP } from '@agoric/captp/lib/captp'; -export const getCapTPHandler = (E, send, getBootstrapObject) => { +export const getCapTPHandler = (send, getBootstrapObject, powers) => { const chans = new Map(); const handler = harden({ onOpen(_obj, meta) { @@ -17,6 +17,7 @@ export const getCapTPHandler = (E, send, getBootstrapObject) => { origin, sendObj, getBootstrapObject, + { harden, ...powers }, ); chans.set(channelHandle, [dispatch, abort]); }, diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js b/packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js index 8237d81a736..c3f7d7f93b1 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js @@ -74,9 +74,11 @@ export function buildRootObject(vatPowers) { // Assign the captp handler. // TODO: Break this out into a separate vat. - const captpHandler = getCapTPHandler(E, send, () => + const captpHandler = getCapTPHandler( + send, // Harden only our exported objects. - harden(exportedToCapTP), + () => harden(exportedToCapTP), + { E, harden, ...vatPowers }, ); registerURLHandler(captpHandler, '/private/captp'); }