Skip to content

Commit

Permalink
fix: more missing Fars. kill "this" (#3746)
Browse files Browse the repository at this point in the history
  • Loading branch information
erights authored Aug 23, 2021
1 parent bdb4522 commit 7bd027a
Show file tree
Hide file tree
Showing 31 changed files with 135 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function buildRootObject(vatPowers, vatParameters) {
return E(aliceP).testBasicFunctionality();
}

const obj0 = {
const obj0 = Far('root', {
async bootstrap(vats) {
switch (arg0) {
case 'basicFunctionality': {
Expand All @@ -27,6 +27,6 @@ export function buildRootObject(vatPowers, vatParameters) {
}
}
},
};
return Far('root', obj0);
});
return obj0;
}
6 changes: 3 additions & 3 deletions packages/ERTP/test/swingsetTests/splitPayments/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function buildRootObject(vatPowers, vatParameters) {
return E(aliceP).testSplitPayments();
}

const obj0 = {
const obj0 = Far('root', {
async bootstrap(vats) {
switch (arg0) {
case 'splitPayments': {
Expand All @@ -29,6 +29,6 @@ export function buildRootObject(vatPowers, vatParameters) {
}
}
},
};
return Far('root', obj0);
});
return obj0;
}
16 changes: 10 additions & 6 deletions packages/SwingSet/src/kernel/liveSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,18 @@ function build(
},
};

let presence;
let remotePresence;
const p = new HandledPromise((_res, _rej, resolveWithPresence) => {
const remote = resolveWithPresence(fulfilledHandler);
presence = Remotable(iface, undefined, remote);
// Use Remotable rather than Far to make a remote from a presence
remotePresence = Remotable(
iface,
undefined,
resolveWithPresence(fulfilledHandler),
);
// remote === presence, actually

// todo: mfig says to swap remote and presence (resolveWithPresence
// gives us a Presence, Remotable gives us a Remote). I think that
// todo: mfig says resolveWithPresence
// gives us a Presence, Remotable gives us a Remote. I think that
// implies we have a lot of renaming to do, 'makeRemote' instead of
// 'makeImportedPresence', etc. I'd like to defer that for a later
// cleanup/renaming pass.
Expand All @@ -297,7 +301,7 @@ function build(
// p.eventualSend('foo', [args]), which uses the fulfilledHandler.

// We harden the presence for the same safety reasons.
return harden(presence);
return harden(remotePresence);
}

function makePipelinablePromise(vpid) {
Expand Down
36 changes: 21 additions & 15 deletions packages/SwingSet/src/vats/plugin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { makeStore } from '@agoric/store';
import { makeCapTP } from '@agoric/captp';
import { makePromiseKit } from '@agoric/promise-kit';
import { E, HandledPromise } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';
import { Remotable, Far } from '@agoric/marshal';

import '@agoric/store/exported.js';

Expand Down Expand Up @@ -173,28 +173,34 @@ export function makePluginManager(pluginDevice, { D, ...vatPowers }) {

const actions = Far('actions', {
/**
* Create a stable identity that just forwards to the current implementation.
* Create a stable identity that just forwards to the current
* implementation.
*
* @type {MakeStableForwarder}
*/
makeStableForwarder(walker = DEFAULT_WALKER) {
let pr;
// eslint-disable-next-line no-new
new HandledPromise((_resolve, _reject, resolveWithPresence) => {
pr = resolveWithPresence({
applyMethod(_p, name, args) {
// console.warn('applying method epoch', currentEpoch);
const targetP = E(walker).walk(pluginRootPK.promise);
return HandledPromise.applyMethod(targetP, name, args);
},
get(_p, name) {
// console.warn('applying get epoch', currentEpoch);
const targetP = E(walker).walk(pluginRootPK.promise);
return HandledPromise.get(targetP, name);
},
});
// Use Remotable rather than Far to make a remote from a presence
pr = Remotable(
'Alleged: stableForwarder',
undefined,
resolveWithPresence({
applyMethod(_p, name, args) {
// console.warn('applying method epoch', currentEpoch);
const targetP = E(walker).walk(pluginRootPK.promise);
return HandledPromise.applyMethod(targetP, name, args);
},
get(_p, name) {
// console.warn('applying get epoch', currentEpoch);
const targetP = E(walker).walk(pluginRootPK.promise);
return HandledPromise.get(targetP, name);
},
}),
);
});
return Far('stableForwarder', pr);
return pr;
},
});

Expand Down
8 changes: 4 additions & 4 deletions packages/SwingSet/src/vats/vat-timerWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function buildRootObject(vatPowers) {

async function createTimerService(timerNode) {
/** @type {TimerService} */
const timerService = {
const timerService = Far('timerService', {
getCurrentTimestamp() {
return Nat(D(timerNode).getLastPolled());
},
Expand All @@ -23,7 +23,7 @@ export function buildRootObject(vatPowers) {
// deprecated in favor of makeRepeater().
// TODO(#2164): remove before Beta
createRepeater(delaySecs, interval) {
return this.makeRepeater(delaySecs, interval);
return timerService.makeRepeater(delaySecs, interval);
},
makeRepeater(delaySecs, interval) {
Nat(delaySecs);
Expand Down Expand Up @@ -62,8 +62,8 @@ export function buildRootObject(vatPowers) {

return notifier;
},
};
return Far('timerService', timerService);
});
return timerService;
}

return Far('root', { createTimerService });
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/test/basedir-controller-3/vat-right.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Far } from '@agoric/marshal';

export function buildRootObject(vatPowers) {
const obj0 = {
const obj0 = Far('root', {
bar(arg2, self) {
vatPowers.testLog(`right.obj0.bar ${arg2} ${self === obj0}`);
return 3;
},
};
return Far('root', obj0);
});
return obj0;
}
2 changes: 1 addition & 1 deletion packages/SwingSet/test/basedir-message-patterns/vat-a.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function buildRootObject(vatPowers) {
const root = Far('root', {
init(bob, bert, carol) {
const { setA, setB, setC, objA } = buildPatterns(vatPowers.testLog);
alice = Far('alice', objA);
alice = objA;
const a = harden({ alice, amy });
setA(a);
setB(harden({ bob, bert }));
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/basedir-message-patterns/vat-b.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function buildRootObject(vatPowers) {
const root = Far('root', {
init() {
const { setB, objB } = buildPatterns(vatPowers.testLog);
const bob = Far('bob', objB);
const bob = objB;
const b = harden({ bob, bert, bill });
setB(b);
return harden({ bob, bert });
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/basedir-message-patterns/vat-c.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function buildRootObject(vatPowers) {
const root = Far('root', {
init() {
const { setC, objC } = buildPatterns(vatPowers.testLog);
const carol = Far('carol', objC);
const carol = objC;
const c = harden({ carol });
setC(c);
return harden({ carol });
Expand Down
6 changes: 3 additions & 3 deletions packages/SwingSet/test/basedir-promises/vat-left.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Far } from '@agoric/marshal';

export function buildRootObject(vatPowers) {
const log = vatPowers.testLog;
const obj0 = {
const obj0 = Far('root', {
callRight(arg1, right) {
log(`left.callRight ${arg1}`);
E(right)
Expand Down Expand Up @@ -44,6 +44,6 @@ export function buildRootObject(vatPowers) {
}),
);
},
};
return Far('root', obj0);
});
return obj0;
}
18 changes: 9 additions & 9 deletions packages/SwingSet/test/message-patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export function buildPatterns(log) {
}

const patterns = new Map();
const objA = { toString: () => 'obj-alice' };
const objB = { toString: () => 'obj-bob' };
const objC = { toString: () => 'obj-carol' };
let objA = { toString: () => 'obj-alice' };
let objB = { toString: () => 'obj-bob' };
let objC = { toString: () => 'obj-carol' };
const out = {};
const outPipelined = {};

Expand Down Expand Up @@ -948,16 +948,16 @@ export function buildPatterns(log) {
}
out.a100 = ['true', 'true'];

objA = Far('alice', objA);
objB = Far('bob', objB);
objC = Far('carol', objC);

// TODO: kernel-allocated promise, either comms or kernel resolves it,
// comms needs to send into kernel again

// TODO: vat-allocated promise, either comms or kernel resolves it, comms
// needs to send into kernel again

// note: we don't harden() this return value because certain callers
// (vat-a/b/c.js) need to Far() the objA/B/C pieces (which isn't convenient
// to do here), and you can't Far() something that's already hardened.
return {
return harden({
setA,
setB,
setC,
Expand All @@ -967,5 +967,5 @@ export function buildPatterns(log) {
objC,
expected: out,
expected_pipelined: outPipelined,
};
});
}
2 changes: 1 addition & 1 deletion packages/SwingSet/test/test-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ test('protocol connection listen', async t => {
const connectionHandler = makeEchoConnectionHandler();
await port2.connect(
'/net/ordered/ordered/some-portname',
harden({
Far('connectionHandlerWithOpen', {
...connectionHandler,
async onOpen(connection, localAddr, remoteAddr, c) {
if (connectionHandler.onOpen) {
Expand Down
6 changes: 3 additions & 3 deletions packages/captp/src/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ export const makeCapTP = (
// Make a new handled promise for the slot.
const pr = makeRemoteKit(slot);
if (slot[0] === 'o' || slot[0] === 't') {
// A new remote presence
const pres = pr.resPres();
if (iface === undefined) {
iface = `Alleged: Presence ${ourId} ${slot}`;
}
val = Remotable(iface, undefined, pres);
// A new remote presence
// Use Remotable rather than Far to make a remote from a presence
val = Remotable(iface, undefined, pr.resPres());
} else {
// A new promise
imports.set(Number(slot.slice(2)), pr);
Expand Down
4 changes: 2 additions & 2 deletions packages/governance/src/committeeRegistrar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const start = zcf => {
};

const makeCommitteeVoterInvitation = index => {
const handler = voterSeat => {
const handler = Far('handler', voterSeat => {
return Far(`voter${index}`, {
castBallot: ballotp => {
E.when(ballotp, ballot => {
Expand All @@ -41,7 +41,7 @@ const start = zcf => {
return E(voter).submitVote(voterSeat, ballot);
},
});
};
});

return zcf.makeInvitation(handler, `Voter${index}`);
};
Expand Down
5 changes: 3 additions & 2 deletions packages/notifier/src/asyncIterableAdaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// <reference types="ses"/>

import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';

import './types.js';

Expand Down Expand Up @@ -36,13 +37,13 @@ import './types.js';
* @returns {AsyncIterable<T>}
*/
export const makeAsyncIterableFromNotifier = notifierP => {
return harden({
return Far('asyncIterableFromNotifier', {
[Symbol.asyncIterator]: () => {
/** @type {UpdateCount} */
let localUpdateCount;
/** @type {Promise<{value: T, done: boolean}> | undefined} */
let myIterationResultP;
return harden({
return Far('asyncIteratorFromNotifier', {
next: () => {
if (!myIterationResultP) {
// In this adaptor, once `next()` is called and returns an
Expand Down
4 changes: 2 additions & 2 deletions packages/notifier/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import './types.js';
export const makeNotifier = baseNotifierP => {
const asyncIterable = makeAsyncIterableFromNotifier(baseNotifierP);

return harden({
return Far('notifier', {
...asyncIterable,
getSharableNotifierInternals: () => baseNotifierP,
});
Expand Down Expand Up @@ -55,7 +55,7 @@ export const makeNotifierKit = (...args) => {

const final = () => currentUpdateCount === undefined;

const baseNotifier = harden({
const baseNotifier = Far('baseNotifier', {
// NaN matches nothing
getUpdateSince(updateCount = NaN) {
if (
Expand Down
4 changes: 2 additions & 2 deletions packages/pegasus/src/pegasus.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ const makePegasus = (zcf, board, namesByAddress) => {
* @type {Set<Peg>}
*/
const pegs = new Set();
return {
return Far('pegConnectionHandler', {
async onOpen(c) {
// Register C with the table of Peg receivers.
connectionToLocalDenomState.init(c, {
Expand Down Expand Up @@ -362,7 +362,7 @@ const makePegasus = (zcf, board, namesByAddress) => {
}
updater.updateState([...pegToConnection.keys()]);
},
};
});
},
/**
* Peg a remote asset over a network connection.
Expand Down
4 changes: 2 additions & 2 deletions packages/pegasus/test/test-peg.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function testRemotePeg(t) {
* @type {import('@agoric/ertp').DepositFacet?}
*/
let localDepositFacet;
const fakeBoard = harden({
const fakeBoard = Far('fakeBoard', {
getValue(id) {
if (id === '0x1234') {
return localDepositFacet;
Expand All @@ -38,7 +38,7 @@ async function testRemotePeg(t) {
throw Error(`unrecognized board id ${id}`);
},
});
const fakeNamesByAddress = harden({
const fakeNamesByAddress = Far('fakeNamesByAddress', {
lookup(...keys) {
t.is(keys[0], 'agoric1234567', 'unrecognized fakeNamesByAddress');
t.is(keys[1], 'depositFacet', 'lookup not for the depositFacet');
Expand Down
Loading

0 comments on commit 7bd027a

Please sign in to comment.