Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cosmic-swingset): repl.js imports getInterfaceOf/etc #2638

Merged
merged 2 commits into from
Mar 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions packages/cosmic-swingset/lib/ag-solo/vats/repl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isPromise } from '@agoric/promise-kit';
import { E } from '@agoric/eventual-send';
import { getInterfaceOf, Remotable, Far } from '@agoric/marshal';

import { Nat } from '@agoric/nat';
import makeUIAgentMakers from './ui-agent';
Expand All @@ -8,7 +9,7 @@ import makeUIAgentMakers from './ui-agent';
export function stringify(
value,
spaces,
getInterfaceOf,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make an incompatible change to the API? Just rename the argument to avoid the shadowing, and default its value as in:

  gio = getInterfaceOf,

and then use gio within the stringify function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye. I generally like to delete code when it's no longer needed, but I agree it's quicker and only slightly ugly to leave this argument in place.

gio = getInterfaceOf,
inProgress = new WeakSet(),
depth = 0,
) {
Expand Down Expand Up @@ -41,7 +42,7 @@ export function stringify(

let ret = '';
const spcs = spaces === undefined ? '' : ' '.repeat(spaces);
if (getInterfaceOf && getInterfaceOf(value) !== undefined) {
if (gio && gio(value) !== undefined) {
ret += `${value}`;
} else if (Array.isArray(value)) {
ret += `[`;
Expand All @@ -52,7 +53,7 @@ export function stringify(
if (spcs !== '') {
ret += `\n${spcs.repeat(depth + 1)}`;
}
ret += stringify(value[i], spaces, getInterfaceOf, inProgress, depth + 1);
ret += stringify(value[i], spaces, gio, inProgress, depth + 1);
sep = ',';
}
if (sep !== '' && spcs !== '') {
Expand All @@ -70,7 +71,7 @@ export function stringify(
ret += `\n${spcs.repeat(depth + 1)}`;
}
ret += `${JSON.stringify(key)}:${spaces > 0 ? ' ' : ''}`;
ret += stringify(value[key], spaces, getInterfaceOf, inProgress, depth + 1);
ret += stringify(value[key], spaces, gio, inProgress, depth + 1);
sep = ',';
}
if (sep !== '' && spcs !== '') {
Expand All @@ -82,10 +83,10 @@ export function stringify(
}

export function getReplHandler(replObjects, send, vatPowers) {
// We use getInterfaceOf locally, and transformTildot is baked into the
// Compartment we use to evaluate REPL inputs. We provide getInterfaceOf
// and Remotable to REPL input code.
const { getInterfaceOf, Remotable, Far, transformTildot } = vatPowers;
// transformTildot is baked into the Compartment we use to evaluate REPL
// inputs. We provide getInterfaceOf and Remotable to REPL input code., but
// import them from @agoric/marshal directly
const { transformTildot } = vatPowers;
let highestHistory = -1;
const commands = {
[highestHistory]: '',
Expand Down