fix: decodeToJustin accepts slot backrefs
MODIFY
packages/marshal/index.js
packages/marshal/index.js
@@ -24,8 +24,8 @@ export { Remotable, Far, ToFarFunction } from './src/make-far.js';
export { QCLASS, makeMarshal } from './src/marshal.js';
export { stringify, parse } from './src/marshal-stringify.js';
-// Works, but not yet used
-// export { decodeToJustin } from './src/marshal-justin.js';
+
+export { decodeToJustin } from './src/marshal-justin.js';
export {
assertRecord,

MODIFY
packages/marshal/src/marshal-justin.js
packages/marshal/src/marshal-justin.js
@@ -182,7 +182,9 @@ const decodeToJustin = (encoding, shouldIndent = false) => {
const { index, iface } = rawTree;
assert.typeof(index, 'number');
Nat(index);
+ if (iface !== undefined) {
assert.typeof(iface, 'string');
+ }
return;
}
case 'hilbert': {
@@ -356,8 +358,12 @@ const decodeToJustin = (encoding, shouldIndent = false) => {
case 'slot': {
let { index, iface } = rawTree;
index = Number(Nat(index));
+ if (iface === undefined) {
+ return out.next(`slot(${index})`);
+ } else {
iface = quote(iface);
- return out.next(`getSlotVal(${index},${iface})`);
+ return out.next(`slot(${index},${iface})`);
+ }
}
case 'hilbert': {

MODIFY
packages/marshal/test/test-marshal-justin.js
packages/marshal/test/test-marshal-justin.js
@@ -71,14 +71,28 @@ export const jsonPairs = harden([
// Slots
[
'[{"@qclass":"slot","iface":"Alleged: for testing Justin","index":0}]',
- '[getSlotVal(0,"Alleged: for testing Justin")]',
+ '[slot(0,"Alleged: for testing Justin")]',
+ ],
+ // Tests https://github.com/endojs/endo/issues/1185 fix
+ [
+ '[{"@qclass":"slot","iface":"Alleged: for testing Justin","index":0},{"@qclass":"slot","index":0}]',
+ '[slot(0,"Alleged: for testing Justin"),slot(0)]',
],
]);
const fakeJustinCompartment = () => {
- const getSlotVal = (index, iface) =>
- Remotable(iface, undefined, { getIndex: () => index });
- return new Compartment({ getSlotVal, makeTagged });
+ const slots = [];
+ const slot = (index, iface = undefined) => {
+ if (slots[index] !== undefined) {
+ assert(iface === undefined); // Assumes backrefs omit iface
+ return slots[index];
+ }
+ assert.typeof(iface, 'string'); // Assumes not optional the first time
+ const r = Remotable(iface, undefined, { getIndex: () => index });
+ slots[index] = r;
+ return r;
+ };
+ return new Compartment({ slot, makeTagged });
};
test('serialize decodeToJustin eval round trip pairs', t => {

fix: decodeToJustin accepts slot backrefs (#1186)