Skip to content

Commit 3dc6638

Browse files
authored
fix: settle REMOTE_STYLE name (#2900)
Change all uses of `REMOTE_STYLE` to `'remotable'`. The old value of `REMOTE_STYLE` was `'presence'` so this change does have a possible compat hazard. But because this name is never sent as part of a protocol, the hazard is small.
1 parent 43cc292 commit 3dc6638

File tree

12 files changed

+32
-65
lines changed

12 files changed

+32
-65
lines changed

packages/ERTP/src/displayInfo.js

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
// @ts-check
22

33
import { assert, details as X, q } from '@agoric/assert';
4-
import {
5-
pureCopy,
6-
passStyleOf,
7-
REMOTE_STYLE,
8-
getInterfaceOf,
9-
} from '@agoric/marshal';
4+
import { pureCopy, passStyleOf } from '@agoric/marshal';
105

116
// TODO: assertSubset and assertKeysAllowed are copied from Zoe. Move
127
// this code to a location where it can be used by ERTP and Zoe
@@ -45,26 +40,15 @@ export const assertDisplayInfo = allegedDisplayInfo => {
4540
if (allegedDisplayInfo === undefined) {
4641
return;
4742
}
43+
assert(
44+
passStyleOf(allegedDisplayInfo) === 'copyRecord',
45+
X`A displayInfo can only be a pass-by-copy record: ${allegedDisplayInfo}`,
46+
);
4847
const displayInfoKeys = harden(['decimalPlaces']);
4948
assertKeysAllowed(displayInfoKeys, allegedDisplayInfo);
5049
};
5150

5251
export const coerceDisplayInfo = allegedDisplayInfo => {
53-
if (passStyleOf(allegedDisplayInfo) === REMOTE_STYLE) {
54-
// These condition together try to ensure that `allegedDisplayInfo`
55-
// is a plain empty object. It will accept all plain empty objects
56-
// that it should. It will reject most things we want to reject including
57-
// remotables that are explicitly declared `Remotable`. But a normal
58-
// HandledPromise presence not explicitly declared `Remotable` will
59-
// be mistaken for a plain empty object. Even in this case, the copy
60-
// has a new identity, so the only danger is that we didn't reject
61-
// with a diagnostic, potentially masking a programmer error.
62-
assert(Object.isFrozen(allegedDisplayInfo));
63-
assert.equal(Reflect.ownKeys(allegedDisplayInfo).length, 0);
64-
assert.equal(Object.getPrototypeOf(allegedDisplayInfo), Object.prototype);
65-
assert.equal(getInterfaceOf(allegedDisplayInfo), undefined);
66-
return harden({});
67-
}
6852
allegedDisplayInfo = pureCopy(allegedDisplayInfo);
6953
assertDisplayInfo(allegedDisplayInfo);
7054
return allegedDisplayInfo;

packages/ERTP/src/mathHelpers/setMathHelpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const hashBadly = thing => {
2929
if (allowableNonObjectValues.includes(type)) {
3030
return thing;
3131
}
32-
if (passStyleOf(thing) === 'presence') {
32+
if (passStyleOf(thing) === 'remotable') {
3333
return thing;
3434
}
3535
if (passStyleOf(thing) === 'copyRecord') {

packages/ERTP/src/typeGuards.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isNat } from '@agoric/nat';
2-
import { passStyleOf, REMOTE_STYLE } from '@agoric/marshal';
2+
import { passStyleOf } from '@agoric/marshal';
33

44
const { isFrozen } = Object;
55

@@ -61,4 +61,4 @@ export const looksLikeValue = value =>
6161
* @returns {brand is Brand}
6262
*/
6363
export const looksLikeBrand = brand =>
64-
isFrozen(brand) && passStyleOf(brand) === REMOTE_STYLE;
64+
isFrozen(brand) && passStyleOf(brand) === 'remotable';

packages/SwingSet/src/kernel/deviceSlots.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
Remotable,
3-
passStyleOf,
4-
REMOTE_STYLE,
5-
makeMarshal,
6-
} from '@agoric/marshal';
1+
import { Remotable, passStyleOf, makeMarshal } from '@agoric/marshal';
72
import { assert, details as X } from '@agoric/assert';
83
import { insistVatType, makeVatSlot, parseVatSlot } from '../parseVatSlots';
94
import { insistCapData } from '../capdata';
@@ -72,7 +67,7 @@ export function makeDeviceSlots(
7267
if (!valToSlot.has(val)) {
7368
// must be a new export
7469
// lsdebug('must be a new export', JSON.stringify(val));
75-
assert.equal(passStyleOf(val), REMOTE_STYLE);
70+
assert.equal(passStyleOf(val), 'remotable');
7671
const slot = exportPassByPresence();
7772
parseVatSlot(slot); // assertion
7873
valToSlot.set(val, slot);
@@ -175,7 +170,7 @@ export function makeDeviceSlots(
175170
deviceParameters,
176171
serialize: m.serialize, // We deliberately do not provide m.deserialize
177172
});
178-
assert.equal(passStyleOf(rootObject), REMOTE_STYLE);
173+
assert.equal(passStyleOf(rootObject), 'remotable');
179174

180175
const rootSlot = makeVatSlot('device', true, 0n);
181176
valToSlot.set(rootObject, rootSlot);

packages/SwingSet/src/kernel/liveSlots.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
/* global HandledPromise */
22

3-
import {
4-
Remotable,
5-
passStyleOf,
6-
REMOTE_STYLE,
7-
makeMarshal,
8-
} from '@agoric/marshal';
3+
import { Remotable, passStyleOf, makeMarshal } from '@agoric/marshal';
94
import { assert, details as X } from '@agoric/assert';
105
import { isPromise } from '@agoric/promise-kit';
116
import { insistVatType, makeVatSlot, parseVatSlot } from '../parseVatSlots';
@@ -379,7 +374,7 @@ function build(
379374
exitVatWithFailure(disavowalError);
380375
throw disavowalError; // cannot reference a disavowed object
381376
}
382-
assert.equal(passStyleOf(val), REMOTE_STYLE);
377+
assert.equal(passStyleOf(val), 'remotable');
383378
slot = exportPassByPresence();
384379
}
385380
parseVatSlot(slot); // assertion
@@ -798,7 +793,7 @@ function build(
798793

799794
// here we finally invoke the vat code, and get back the root object
800795
const rootObject = buildRootObject(harden(vpow), harden(vatParameters));
801-
assert.equal(passStyleOf(rootObject), REMOTE_STYLE);
796+
assert.equal(passStyleOf(rootObject), 'remotable');
802797

803798
const rootSlot = makeVatSlot('object', true, BigInt(0));
804799
valToSlot.set(rootObject, rootSlot);

packages/deploy-script-support/src/startInstance.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const makeStartInstance = (
6565
console.log(`-- Registering Contract Instance: ${instancePetname}`);
6666
await E(instanceManager).add(instancePetname, instance);
6767

68-
if (passStyleOf(creatorInvitation) === 'presence') {
68+
if (passStyleOf(creatorInvitation) === 'remotable') {
6969
assert(
7070
creatorInvitation,
7171
`creatorInvitation must be defined to be deposited`,

packages/marshal/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export {
2-
REMOTE_STYLE,
32
getInterfaceOf,
43
getErrorConstructor,
54
passStyleOf,

packages/marshal/src/marshal.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { assert, details as X, q } from '@agoric/assert';
88
import { makeReplacerIbidTable, makeReviverIbidTable } from './ibidTables';
99
import {
1010
PASS_STYLE,
11-
REMOTE_STYLE,
1211
passStyleOf,
1312
getInterfaceOf,
1413
getErrorConstructor,
@@ -98,7 +97,7 @@ function pureCopy(val, already = new WeakMap()) {
9897
return /** @type {T} */ (unk2);
9998
}
10099

101-
case REMOTE_STYLE: {
100+
case 'remotable': {
102101
assert.fail(
103102
X`Input value ${q(
104103
passStyle,
@@ -130,7 +129,7 @@ const makeRemotableProto = (oldProto, allegedName) => {
130129
const toString = () => `[${allegedName}]`;
131130
return harden(
132131
create(oldProto, {
133-
[PASS_STYLE]: { value: REMOTE_STYLE },
132+
[PASS_STYLE]: { value: 'remotable' },
134133
toString: { value: toString },
135134
[Symbol.toStringTag]: { value: allegedName },
136135
}),
@@ -252,7 +251,7 @@ ${q(body2)}
252251
slotMap.set(val, slotIndex);
253252

254253
/*
255-
if (iface === undefined && passStyleOf(val) === REMOTE_STYLE) {
254+
if (iface === undefined && passStyleOf(val) === 'remotable') {
256255
// iface = `Alleged: remotable at slot ${slotIndex}`;
257256
if (
258257
getPrototypeOf(val) === objectPrototype &&
@@ -425,7 +424,7 @@ ${q(body2)}
425424
});
426425
}
427426
}
428-
case REMOTE_STYLE: {
427+
case 'remotable': {
429428
ibidTable.leaf(val);
430429
const iface = getInterfaceOf(val);
431430
// console.log(`serializeSlot: ${val}`);

packages/marshal/src/passStyleOf.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ const {
1717

1818
const { ownKeys } = Reflect;
1919

20-
// TODO: Use just 'remote' when we're willing to make a breaking change.
21-
export const REMOTE_STYLE = 'presence';
22-
2320
export const PASS_STYLE = Symbol.for('passStyle');
2421

2522
/** @type {MarshalGetInterfaceOf} */
2623
export function getInterfaceOf(val) {
2724
if (typeof val !== 'object' || val === null) {
2825
return undefined;
2926
}
30-
if (val[PASS_STYLE] !== REMOTE_STYLE) {
27+
if (val[PASS_STYLE] !== 'remotable') {
3128
return undefined;
3229
}
3330
assert(isFrozen(val), X`Remotable ${val} must be frozen`, TypeError);
@@ -225,8 +222,8 @@ const assertRemotableProto = val => {
225222
X`Unexpect properties on Remotable Proto ${ownKeys(rest)}`,
226223
);
227224
assert(
228-
passStyleValue === REMOTE_STYLE,
229-
X`Expected ${q(REMOTE_STYLE)}, not ${q(passStyleValue)}`,
225+
passStyleValue === 'remotable',
226+
X`Expected 'remotable', not ${q(passStyleValue)}`,
230227
);
231228
assert.typeof(toStringValue, 'function', X`toString must be a function`);
232229
assert.typeof(toStringTagValue, 'string', X`@@toStringTag must be a string`);
@@ -306,7 +303,7 @@ function assertRemotable(val) {
306303
* * 'copyRecord' for non-empty records with only data properties
307304
* * 'copyArray' for arrays with only data properties
308305
* * 'copyError' for instances of Error with only data properties
309-
* * REMOTE_STYLE for non-array objects with only method properties
306+
* * 'remotable' for non-array objects with only method properties
310307
* * 'promise' for genuine promises only
311308
* * throwing an error on anything else, including thenables.
312309
* We export passStyleOf so other algorithms can use this module's
@@ -320,7 +317,7 @@ export function passStyleOf(val) {
320317
switch (typestr) {
321318
case 'object': {
322319
if (getInterfaceOf(val)) {
323-
return REMOTE_STYLE;
320+
return 'remotable';
324321
}
325322
if (val === null) {
326323
return 'null';
@@ -348,7 +345,7 @@ export function passStyleOf(val) {
348345
assertRemotable(val);
349346
// console.log(`--- @@marshal: pass-by-ref object without Far/Remotable`);
350347
// assert.fail(X`pass-by-ref object without Far/Remotable`);
351-
return REMOTE_STYLE;
348+
return 'remotable';
352349
}
353350
case 'function': {
354351
assert.fail(X`Bare functions like ${val} are disabled for now`);

packages/marshal/src/types.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
/// <reference path="extra-types.d.ts" />
33

44
/**
5-
* @typedef { "bigint" | "boolean" | "null" | "number" | "string" | "symbol" | "undefined" | "copyArray" | "copyRecord" | "copyError" | "promise" | "presence" } PassStyle
6-
* TODO "presence" above should indirect through REMOTE_STYLE to prepare
7-
* for changing it to "remotable"
5+
* @typedef { "bigint" | "boolean" | "null" | "number" | "string" | "symbol" | "undefined" | "copyArray" | "copyRecord" | "copyError" | "promise" | "remotable" } PassStyle
86
*/
97

108
// TODO declare more precise types throughout this file, so the type system

packages/same-structure/src/sameStructure.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22

3-
import { passStyleOf, REMOTE_STYLE } from '@agoric/marshal';
3+
import { passStyleOf } from '@agoric/marshal';
44
import { assert, details as X, q } from '@agoric/assert';
55

66
const {
@@ -89,7 +89,7 @@ function allComparable(passable) {
8989
case 'boolean':
9090
case 'number':
9191
case 'bigint':
92-
case REMOTE_STYLE:
92+
case 'remotable':
9393
case 'copyError': {
9494
return passable;
9595
}
@@ -149,7 +149,7 @@ function sameStructure(left, right) {
149149
case 'boolean':
150150
case 'number':
151151
case 'bigint':
152-
case REMOTE_STYLE: {
152+
case 'remotable': {
153153
return sameValueZero(left, right);
154154
}
155155
case 'copyRecord':
@@ -227,7 +227,7 @@ function mustBeSameStructureInternal(left, right, message, path) {
227227
case 'boolean':
228228
case 'number':
229229
case 'bigint':
230-
case REMOTE_STYLE: {
230+
case 'remotable': {
231231
if (!sameValueZero(left, right)) {
232232
complain('different');
233233
}

packages/zoe/test/unitTests/test-zoe.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava';
55

66
import { E } from '@agoric/eventual-send';
77
import { makePromiseKit } from '@agoric/promise-kit';
8-
import { passStyleOf, REMOTE_STYLE } from '@agoric/marshal';
8+
import { passStyleOf } from '@agoric/marshal';
99

1010
// eslint-disable-next-line import/no-extraneous-dependencies
1111
import bundleSource from '@agoric/bundle-source';
@@ -60,7 +60,7 @@ test(`zoe.startInstance bad installation`, async t => {
6060
});
6161

6262
function isEmptyFacet(t, facet) {
63-
t.is(passStyleOf(facet), REMOTE_STYLE);
63+
t.is(passStyleOf(facet), 'remotable');
6464
t.deepEqual(Object.getOwnPropertyNames(facet), []);
6565
}
6666

0 commit comments

Comments
 (0)