Skip to content

Commit 5015441

Browse files
authored
Merge pull request #1961 from endojs/revert-1933-1488-Passable
Revert "1488 Passable"
2 parents 3fae760 + aada61a commit 5015441

37 files changed

Lines changed: 249 additions & 443 deletions

packages/captp/src/captp.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,8 @@ export const makeCapTP = (
326326

327327
const IS_REMOTE_PUMPKIN = harden({});
328328
/**
329-
* @type {import('@endo/marshal').ConvertValToSlot<import('./types.js').CapTPSlot>}
329+
* @type {import('@endo/marshal').ConvertSlotToVal<import('./types.js').CapTPSlot>}
330330
*/
331-
// @ts-expect-error intentional hack
332331
const assertValIsLocal = val => {
333332
const slot = valToSlot.get(val);
334333
if (slot && slot[1] === '-') {
@@ -500,7 +499,6 @@ export const makeCapTP = (
500499
}
501500

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

packages/exo/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.eslint-base.json",
33
"compilerOptions": {
4-
"maxNodeModuleJsDepth": 2
4+
"maxNodeModuleJsDepth": 1
55
},
66
"include": [
77
"*.js",

packages/far/test/test-marshal-far-obj.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const testRecord = ({
6666
}),
6767
);
6868

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

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

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

136134
t.throws(() => passStyleOf(sub(badRemotableProto1)), EXPECTED_PASS_STYLE);

packages/marshal/src/deeplyFulfilled.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,18 @@ export const deeplyFulfilled = async val => {
5151
const passStyle = passStyleOf(val);
5252
switch (passStyle) {
5353
case 'copyRecord': {
54-
// @ts-expect-error FIXME narrowed
5554
const names = ownKeys(val);
5655
const valPs = names.map(name => deeplyFulfilled(val[name]));
5756
return E.when(Promise.all(valPs), vals =>
5857
harden(fromEntries(vals.map((c, i) => [names[i], c]))),
5958
);
6059
}
6160
case 'copyArray': {
62-
// @ts-expect-error FIXME narrowed
6361
const valPs = val.map(p => deeplyFulfilled(p));
6462
return E.when(Promise.all(valPs), vals => harden(vals));
6563
}
6664
case 'tagged': {
67-
// @ts-expect-error FIXME narrowed
6865
const tag = getTag(val);
69-
// @ts-expect-error FIXME narrowed
7066
return E.when(deeplyFulfilled(val.payload), payload =>
7167
makeTagged(tag, payload),
7268
);

packages/marshal/src/encodePassable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const { ownKeys } = Reflect;
2727
* string-named own properties. `recordNames` returns those name *reverse*
2828
* sorted, because that's how records are compared, encoded, and sorted.
2929
*
30-
* @template {Passable} T
30+
* @template T
3131
* @param {CopyRecord<T>} record
3232
* @returns {string[]}
3333
*/
@@ -44,7 +44,7 @@ harden(recordNames);
4444
* Assuming that `record` is a CopyRecord and `names` is `recordNames(record)`,
4545
* return the corresponding array of property values.
4646
*
47-
* @template {Passable} T
47+
* @template T
4848
* @param {CopyRecord<T>} record
4949
* @param {string[]} names
5050
* @returns {T[]}

packages/marshal/src/encodeToCapData.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020

2121
/** @typedef {import('@endo/pass-style').Passable} Passable */
2222
/** @typedef {import('./types.js').Encoding} Encoding */
23-
/** @typedef {import('@endo/pass-style').RemotableObject} RemotableObject */
23+
/** @typedef {import('@endo/pass-style').Remotable} Remotable */
2424
/** @typedef {import('./types.js').EncodingUnion} EncodingUnion */
2525

2626
const { ownKeys } = Reflect;
@@ -62,7 +62,7 @@ const qclassMatches = (encoded, qclass) =>
6262
/**
6363
* @typedef {object} EncodeToCapDataOptions
6464
* @property {(
65-
* remotable: RemotableObject,
65+
* remotable: Remotable,
6666
* encodeRecur: (p: Passable) => Encoding
6767
* ) => Encoding} [encodeRemotableToCapData]
6868
* @property {(
@@ -117,7 +117,7 @@ export const makeEncodeToCapData = (encodeOptions = {}) => {
117117
* Readers must not care about this order anyway. We impose this requirement
118118
* mainly to reduce non-determinism exposed outside a vat.
119119
*
120-
* @param {any} passable
120+
* @param {Passable} passable
121121
* @returns {Encoding} except that `encodeToCapData` does not generally
122122
* `harden` this result before returning. Rather, `encodeToCapData` is not
123123
* directly exposed.
@@ -269,11 +269,11 @@ harden(makeEncodeToCapData);
269269
* @property {(
270270
* encodedRemotable: Encoding,
271271
* decodeRecur: (e: Encoding) => Passable
272-
* ) => (Promise|RemotableObject)} [decodeRemotableFromCapData]
272+
* ) => (Promise|Remotable)} [decodeRemotableFromCapData]
273273
* @property {(
274274
* encodedPromise: Encoding,
275275
* decodeRecur: (e: Encoding) => Passable
276-
* ) => (Promise|RemotableObject)} [decodePromiseFromCapData]
276+
* ) => (Promise|Remotable)} [decodePromiseFromCapData]
277277
* @property {(
278278
* encodedError: Encoding,
279279
* decodeRecur: (e: Encoding) => Passable

packages/marshal/src/encodeToSmallcaps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '@endo/pass-style';
1919

2020
/** @typedef {import('@endo/pass-style').Passable} Passable */
21-
/** @typedef {import('@endo/pass-style').RemotableObject} Remotable */
21+
/** @typedef {import('@endo/pass-style').Remotable} Remotable */
2222
// @typedef {import('./types.js').SmallcapsEncoding} SmallcapsEncoding */
2323
// @typedef {import('./types.js').SmallcapsEncodingUnion} SmallcapsEncodingUnion */
2424
/** @typedef {any} SmallcapsEncoding */
@@ -161,7 +161,7 @@ export const makeEncodeToSmallcaps = (encodeOptions = {}) => {
161161
* Readers must not care about this order anyway. We impose this requirement
162162
* mainly to reduce non-determinism exposed outside a vat.
163163
*
164-
* @param {any} passable
164+
* @param {Passable} passable
165165
* @returns {SmallcapsEncoding} except that `encodeToSmallcaps` does not generally
166166
* `harden` this result before returning. Rather, `encodeToSmallcaps` is not
167167
* directly exposed.

packages/marshal/src/marshal.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export const makeMarshal = (
7979
const slotMap = new Map();
8080

8181
/**
82-
* @param {import('@endo/pass-style').PassableCap} passable
82+
* @param {Remotable | Promise} passable
8383
* @returns {{index: number, repeat: boolean}}
8484
*/
8585
const encodeSlotCommon = passable => {
@@ -134,7 +134,7 @@ export const makeMarshal = (
134134

135135
if (serializeBodyFormat === 'capdata') {
136136
/**
137-
* @param {import('@endo/pass-style').PassableCap} passable
137+
* @param {Passable} passable
138138
* @param {InterfaceSpec} [iface]
139139
* @returns {Encoding}
140140
*/
@@ -148,11 +148,9 @@ export const makeMarshal = (
148148
}
149149
};
150150

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

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

@@ -186,7 +184,7 @@ export const makeMarshal = (
186184
} else if (serializeBodyFormat === 'smallcaps') {
187185
/**
188186
* @param {string} prefix
189-
* @param {import('@endo/pass-style').PassableCap} passable
187+
* @param {Passable} passable
190188
* @param {InterfaceSpec} [iface]
191189
* @returns {string}
192190
*/
@@ -233,7 +231,7 @@ export const makeMarshal = (
233231
};
234232

235233
const makeFullRevive = slots => {
236-
/** @type {Map<number, Remotable | Promise>} */
234+
/** @type {Map<number, Passable>} */
237235
const valMap = new Map();
238236

239237
/**
@@ -244,9 +242,8 @@ export const makeMarshal = (
244242
const { iface = undefined, index, ...rest } = slotData;
245243
ownKeys(rest).length === 0 ||
246244
Fail`unexpected encoded slot properties ${q(ownKeys(rest))}`;
247-
const extant = valMap.get(index);
248-
if (extant) {
249-
return extant;
245+
if (valMap.has(index)) {
246+
return valMap.get(index);
250247
}
251248
// TODO SECURITY HAZARD: must enfoce that remotable vs promise
252249
// is according to the encoded string.
@@ -270,12 +267,11 @@ export const makeMarshal = (
270267
// are for reuse by other encodings that do, such as smallcaps.
271268
const dName = decodeRecur(name);
272269
const dMessage = decodeRecur(message);
273-
const dErrorId = /** @type {string} */ (errorId && decodeRecur(errorId));
270+
const dErrorId = errorId && decodeRecur(errorId);
274271
typeof dName === 'string' ||
275272
Fail`invalid error name typeof ${q(typeof dName)}`;
276-
if (typeof dMessage !== 'string') {
277-
throw Fail`invalid error message typeof ${q(typeof dMessage)}`;
278-
}
273+
typeof dMessage === 'string' ||
274+
Fail`invalid error message typeof ${q(typeof dMessage)}`;
279275
const EC = getErrorConstructor(dName) || Error;
280276
// errorId is a late addition so be tolerant of its absence.
281277
const errorName =
@@ -334,9 +330,7 @@ export const makeMarshal = (
334330
};
335331

336332
const reviveFromSmallcaps = makeDecodeFromSmallcaps({
337-
// @ts-expect-error FIXME
338333
decodeRemotableFromSmallcaps,
339-
// @ts-expect-error FIXME
340334
decodePromiseFromSmallcaps,
341335
decodeErrorFromSmallcaps,
342336
});

packages/marshal/src/rankOrder.js

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,16 @@ export const makeComparatorKit = (compareRemotables = (_x, _y) => 0) => {
144144
case 'string': {
145145
// Within each of these passStyles, the rank ordering agrees with
146146
// JavaScript's relational operators `<` and `>`.
147-
// @ts-expect-error FIXME narrowed
148147
if (left < right) {
149148
return -1;
150149
} else {
151-
// @ts-expect-error FIXME narrowed
152150
assert(left > right);
153151
return 1;
154152
}
155153
}
156154
case 'symbol': {
157155
return comparator(
158-
// @ts-expect-error FIXME narrowed
159156
nameForPassableSymbol(left),
160-
// @ts-expect-error FIXME narrowed
161157
nameForPassableSymbol(right),
162158
);
163159
}
@@ -171,11 +167,9 @@ export const makeComparatorKit = (compareRemotables = (_x, _y) => 0) => {
171167
}
172168
// The rank ordering of non-NaN numbers agrees with JavaScript's
173169
// relational operators '<' and '>'.
174-
// @ts-expect-error FIXME narrowed
175170
if (left < right) {
176171
return -1;
177172
} else {
178-
// @ts-expect-error FIXME narrowed
179173
assert(left > right);
180174
return 1;
181175
}
@@ -192,46 +186,37 @@ export const makeComparatorKit = (compareRemotables = (_x, _y) => 0) => {
192186
// of these names, which we then compare lexicographically. This ensures
193187
// that if the names of record X are a subset of the names of record Y,
194188
// then record X will have an earlier rank and sort to the left of Y.
195-
// @ts-expect-error FIXME narrowed
196189
const leftNames = recordNames(left);
197-
// @ts-expect-error FIXME narrowed
198190
const rightNames = recordNames(right);
199191

200192
const result = comparator(leftNames, rightNames);
201193
if (result !== 0) {
202194
return result;
203195
}
204196
return comparator(
205-
// @ts-expect-error FIXME narrowed
206197
recordValues(left, leftNames),
207-
// @ts-expect-error FIXME narrowed
208198
recordValues(right, rightNames),
209199
);
210200
}
211201
case 'copyArray': {
212202
// Lexicographic
213-
// @ts-expect-error FIXME narrowed
214203
const len = Math.min(left.length, right.length);
215204
for (let i = 0; i < len; i += 1) {
216-
// @ts-expect-error FIXME narrowed
217205
const result = comparator(left[i], right[i]);
218206
if (result !== 0) {
219207
return result;
220208
}
221209
}
222210
// If all matching elements were tied, then according to their lengths.
223211
// If array X is a prefix of array Y, then X has an earlier rank than Y.
224-
// @ts-expect-error FIXME narrowed
225212
return comparator(left.length, right.length);
226213
}
227214
case 'tagged': {
228215
// Lexicographic by `[Symbol.toStringTag]` then `.payload`.
229-
// @ts-expect-error FIXME narrowed
230216
const labelComp = comparator(getTag(left), getTag(right));
231217
if (labelComp !== 0) {
232218
return labelComp;
233219
}
234-
// @ts-expect-error FIXME narrowed
235220
return comparator(left.payload, right.payload);
236221
}
237222
default: {
@@ -301,10 +286,9 @@ harden(assertRankSorted);
301286
* function. This is a genuine bug for us NOW because sometimes we sort
302287
* in reverse order by passing a reversed rank comparison function.
303288
*
304-
* @template {Passable} T
305-
* @param {Iterable<T>} passables
289+
* @param {Iterable<Passable>} passables
306290
* @param {RankCompare} compare
307-
* @returns {T[]}
291+
* @returns {Passable[]}
308292
*/
309293
export const sortByRank = (passables, compare) => {
310294
if (Array.isArray(passables)) {
@@ -398,20 +382,18 @@ export const coveredEntries = (sorted, [leftIndex, rightIndex]) => {
398382
harden(coveredEntries);
399383

400384
/**
401-
* @template {Passable} T
402385
* @param {RankCompare} compare
403-
* @param {T} a
404-
* @param {T} b
405-
* @returns {T}
386+
* @param {Passable} a
387+
* @param {Passable} b
388+
* @returns {Passable}
406389
*/
407390
const maxRank = (compare, a, b) => (compare(a, b) >= 0 ? a : b);
408391

409392
/**
410-
* @template {Passable} T
411393
* @param {RankCompare} compare
412-
* @param {T} a
413-
* @param {T} b
414-
* @returns {T}
394+
* @param {Passable} a
395+
* @param {Passable} b
396+
* @returns {Passable}
415397
*/
416398
const minRank = (compare, a, b) => (compare(a, b) <= 0 ? a : b);
417399

packages/marshal/src/types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ export {};
172172
* ordering would also compare magnitudes, and so agree with the rank ordering
173173
* of all values other than `NaN`. An array sorted by rank would enable range
174174
* queries by magnitude.
175-
* @param {import("@endo/pass-style").Passable} left
176-
* @param {import("@endo/pass-style").Passable} right
175+
* @param {any} left a Passable
176+
* @param {any} right a Passable
177177
* @returns {RankComparison}
178178
*/
179179

0 commit comments

Comments
 (0)