Skip to content

Commit

Permalink
restore PassableCap
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 9, 2024
1 parent 75605a1 commit 3d927c3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/captp/src/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ export const makeCapTP = (

const IS_REMOTE_PUMPKIN = harden({});
/**
* @type {import('@endo/marshal').ConvertSlotToVal<import('./types.js').CapTPSlot>}
* @type {import('@endo/marshal').ConvertValToSlot<import('./types.js').CapTPSlot>}
*/
// @ts-expect-error intentional hack
const assertValIsLocal = val => {
const slot = valToSlot.get(val);
if (slot && slot[1] === '-') {
Expand Down Expand Up @@ -499,6 +500,7 @@ export const makeCapTP = (
}

// If we imported this slot, mark it as one our peer exported.
// @ts-expect-error map lacks value type
return slotToImported.get(recvSlot.add(slot));
}

Expand Down
8 changes: 4 additions & 4 deletions packages/marshal/src/encodeToCapData.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {

/** @typedef {import('@endo/pass-style').Passable} Passable */
/** @typedef {import('./types.js').Encoding} Encoding */
/** @typedef {import('@endo/pass-style').Remotable} Remotable */
/** @typedef {import('@endo/pass-style').RemotableObject} RemotableObject */
/** @typedef {import('./types.js').EncodingUnion} EncodingUnion */

const { ownKeys } = Reflect;
Expand Down Expand Up @@ -62,7 +62,7 @@ const qclassMatches = (encoded, qclass) =>
/**
* @typedef {object} EncodeToCapDataOptions
* @property {(
* remotable: Remotable,
* remotable: RemotableObject,
* encodeRecur: (p: Passable) => Encoding
* ) => Encoding} [encodeRemotableToCapData]
* @property {(
Expand Down Expand Up @@ -269,11 +269,11 @@ harden(makeEncodeToCapData);
* @property {(
* encodedRemotable: Encoding,
* decodeRecur: (e: Encoding) => Passable
* ) => (Promise|Remotable)} [decodeRemotableFromCapData]
* ) => (Promise|RemotableObject)} [decodeRemotableFromCapData]
* @property {(
* encodedPromise: Encoding,
* decodeRecur: (e: Encoding) => Passable
* ) => (Promise|Remotable)} [decodePromiseFromCapData]
* ) => (Promise|RemotableObject)} [decodePromiseFromCapData]
* @property {(
* encodedError: Encoding,
* decodeRecur: (e: Encoding) => Passable
Expand Down
8 changes: 5 additions & 3 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const makeMarshal = (
const slotMap = new Map();

/**
* @param {Passable} passable
* @param {import('@endo/pass-style').PassableCap} passable
* @returns {{index: number, repeat: boolean}}
*/
const encodeSlotCommon = passable => {
Expand Down Expand Up @@ -134,7 +134,7 @@ export const makeMarshal = (

if (serializeBodyFormat === 'capdata') {
/**
* @param {Passable} passable
* @param {import('@endo/pass-style').PassableCap} passable
* @param {InterfaceSpec} [iface]
* @returns {Encoding}
*/
Expand All @@ -148,9 +148,11 @@ export const makeMarshal = (
}
};

/** @type {(promise: import('@endo/pass-style').RemotableObject, encodeRecur: (p: Passable) => Encoding) => Encoding} */
const encodeRemotableToCapData = (val, _encodeRecur) =>
encodeSlotToCapData(val, getInterfaceOf(val));

/** @type {(promise: Promise, encodeRecur: (p: Passable) => Encoding) => Encoding} */
const encodePromiseToCapData = (promise, _encodeRecur) =>
encodeSlotToCapData(promise);

Expand Down Expand Up @@ -184,7 +186,7 @@ export const makeMarshal = (
} else if (serializeBodyFormat === 'smallcaps') {
/**
* @param {string} prefix
* @param {Passable} passable
* @param {import('@endo/pass-style').PassableCap} passable
* @param {InterfaceSpec} [iface]
* @returns {string}
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/marshal/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export {};
/**
* @template Slot
* @callback ConvertValToSlot
* @param {any} val a PassableCap
* @param {import("@endo/pass-style").PassableCap} val
* @returns {Slot}
*/

Expand All @@ -13,7 +13,7 @@ export {};
* @callback ConvertSlotToVal
* @param {Slot} slot
* @param {string} [iface]
* @returns {any} a PassableCap
* @returns {import("@endo/pass-style").PassableCap}
*/

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/marshal/test/test-marshal-capdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ test('records', t => {
const fauxPresence = harden({});
const { serialize: ser, unserialize: unser } = makeMarshal(
_val => 'slot',
// @ts-expect-error mock
_slot => fauxPresence,
{
errorTagging: 'off',
Expand Down Expand Up @@ -401,6 +402,7 @@ test('capdata proto problems', t => {
test('capdata slot leniency', t => {
const { unserialize: fromCapData } = makeMarshal(
undefined,
// @ts-expect-error mock
_slot => ({
name: 'I should not be in a slot',
}),
Expand Down
1 change: 1 addition & 0 deletions packages/marshal/test/test-marshal-smallcaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ test('smallcaps records', t => {
const fauxPresence = harden({});
const { serialize: ser, unserialize: unser } = makeMarshal(
_val => 'slot',
// @ts-expect-error mock
_slot => fauxPresence,
{
errorTagging: 'off',
Expand Down

0 comments on commit 3d927c3

Please sign in to comment.