Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 9, 2024
1 parent b1c806d commit a0c1e63
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion packages/far/test/test-marshal-far-obj.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ test('Remotable/getInterfaceOf', t => {
const GOOD_PASS_STYLE = Symbol.for('passStyle');
const BAD_PASS_STYLE = Symbol('passStyle');

/** @type {() => import('@endo/pass-style').RemotableObject<'Good remotable proto'>} */
const testRecord = ({
styleSymbol = GOOD_PASS_STYLE,
styleString = 'remotable',
Expand All @@ -67,6 +66,7 @@ const testRecord = ({
}),
);

/** @type {import('@endo/pass-style').PassStyled<'remotable'>} */
const goodRemotableProto = testRecord();

// @ts-ignore We're testing bad things anyway
Expand Down Expand Up @@ -130,6 +130,7 @@ test('passStyleOf validation of remotables', t => {
t.throws(() => passStyleOf(badRemotableProto3), NON_METHOD);
t.throws(() => passStyleOf(badRemotableProto4), NON_METHOD);

// @ts-expect-error UNTIL https://github.com/microsoft/TypeScript/issues/38385
t.is(passStyleOf(sub(goodRemotableProto)), 'remotable');

t.throws(() => passStyleOf(sub(badRemotableProto1)), EXPECTED_PASS_STYLE);
Expand Down
2 changes: 1 addition & 1 deletion packages/marshal/src/deeplyFulfilled.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const deeplyFulfilled = async val => {
case 'copyRecord': {
// @ts-expect-error FIXME narrowed
const names = ownKeys(val);
// @ts-expect-error FIXME narrowed
const valPs = names.map(name => deeplyFulfilled(val[name]));
return E.when(Promise.all(valPs), vals =>
harden(fromEntries(vals.map((c, i) => [names[i], c]))),
Expand All @@ -65,6 +64,7 @@ export const deeplyFulfilled = async val => {
return E.when(Promise.all(valPs), vals => harden(vals));
}
case 'tagged': {
// @ts-expect-error FIXME narrowed
const tag = getTag(val);
// @ts-expect-error FIXME narrowed
return E.when(deeplyFulfilled(val.payload), payload =>
Expand Down
1 change: 0 additions & 1 deletion packages/marshal/src/encodePassable.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ export const makeEncodePassable = (encodeOptions = {}) => {
encodeError = (err, _) => Fail`error unexpected: ${err}`,
} = encodeOptions;

/** @param {Passable} passable */
const encodePassable = passable => {
if (isErrorLike(passable)) {
return encodeError(passable, encodePassable);
Expand Down
2 changes: 1 addition & 1 deletion packages/marshal/src/encodeToCapData.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const makeEncodeToCapData = (encodeOptions = {}) => {
* Readers must not care about this order anyway. We impose this requirement
* mainly to reduce non-determinism exposed outside a vat.
*
* @param {Passable} passable
* @param {any} passable
* @returns {Encoding} except that `encodeToCapData` does not generally
* `harden` this result before returning. Rather, `encodeToCapData` is not
* directly exposed.
Expand Down
8 changes: 4 additions & 4 deletions packages/marshal/src/encodeToSmallcaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '@endo/pass-style';

/** @typedef {import('@endo/pass-style').Passable} Passable */
/** @typedef {import('@endo/pass-style').Remotable} Remotable */
/** @typedef {import('@endo/pass-style').RemotableObject} RemotableObject */
// @typedef {import('./types.js').SmallcapsEncoding} SmallcapsEncoding */
// @typedef {import('./types.js').SmallcapsEncodingUnion} SmallcapsEncodingUnion */
/** @typedef {any} SmallcapsEncoding */
Expand Down Expand Up @@ -89,7 +89,7 @@ const startsSpecial = encodedStr => {
/**
* @typedef {object} EncodeToSmallcapsOptions
* @property {(
* remotable: Remotable,
* remotable: RemotableObject,
* encodeRecur: (p: Passable) => SmallcapsEncoding
* ) => SmallcapsEncoding} [encodeRemotableToSmallcaps]
* @property {(
Expand Down Expand Up @@ -161,7 +161,7 @@ export const makeEncodeToSmallcaps = (encodeOptions = {}) => {
* Readers must not care about this order anyway. We impose this requirement
* mainly to reduce non-determinism exposed outside a vat.
*
* @param {Passable} passable
* @param {any} passable
* @returns {SmallcapsEncoding} except that `encodeToSmallcaps` does not generally
* `harden` this result before returning. Rather, `encodeToSmallcaps` is not
* directly exposed.
Expand Down Expand Up @@ -299,7 +299,7 @@ harden(makeEncodeToSmallcaps);
* @property {(
* encodedRemotable: SmallcapsEncoding,
* decodeRecur: (e :SmallcapsEncoding) => Passable
* ) => Remotable} [decodeRemotableFromSmallcaps]
* ) => RemotableObject} [decodeRemotableFromSmallcaps]
* @property {(
* encodedPromise: SmallcapsEncoding,
* decodeRecur: (e :SmallcapsEncoding) => Passable
Expand Down
11 changes: 8 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 {Remotable | Promise} passable
* @param {Passable} passable
* @returns {{index: number, repeat: boolean}}
*/
const encodeSlotCommon = passable => {
Expand Down Expand Up @@ -236,7 +236,7 @@ export const makeMarshal = (

/**
* @param {{iface?: string, index: number}} slotData
* @returns {Remotable | Promise}
* @returns {Passable}
*/
const decodeSlotCommon = slotData => {
const { iface = undefined, index, ...rest } = slotData;
Expand All @@ -255,7 +255,7 @@ export const makeMarshal = (

/**
* @param {{errorId?: string, message: string, name: string}} errData
* @param {(e: unknown) => Passable} decodeRecur
* @param {(e: unknown) => string} decodeRecur
* @returns {Error}
*/
const decodeErrorCommon = (errData, decodeRecur) => {
Expand Down Expand Up @@ -298,7 +298,9 @@ export const makeMarshal = (
};

const reviveFromCapData = makeDecodeFromCapData({
// @ts-expect-error FIXME
decodeRemotableFromCapData: decodeRemotableOrPromiseFromCapData,
// @ts-expect-error FIXME
decodePromiseFromCapData: decodeRemotableOrPromiseFromCapData,
decodeErrorFromCapData,
});
Expand All @@ -316,6 +318,7 @@ export const makeMarshal = (
const index = Number(stringEncoding.slice(1, i < 0 ? undefined : i));
// i < 0 means there was no iface included.
const iface = i < 0 ? undefined : stringEncoding.slice(i + 1);
// @ts-expect-error FIXME
return decodeSlotCommon({ iface, index });
};
};
Expand All @@ -330,7 +333,9 @@ export const makeMarshal = (
};

const reviveFromSmallcaps = makeDecodeFromSmallcaps({
// @ts-expect-error FIXME
decodeRemotableFromSmallcaps,
// @ts-expect-error FIXME
decodePromiseFromSmallcaps,
decodeErrorFromSmallcaps,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/pass-style/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export {};
* (p: Iterator): 'remotable';
* <T extends PassStyled<any>>(p: T): ExtractStyle<T>
* (p: {[key: string]: any}): 'copyRecord';
* (p: any): never;
* (p: any): unknown;
* }} PassStyleOf
*/

Expand Down

0 comments on commit a0c1e63

Please sign in to comment.