@@ -46,10 +46,21 @@ export const makeRunUtils = controller => {
46
46
} ;
47
47
48
48
/**
49
- * @typedef {import('@endo/eventual-send').EProxy & {
50
- * sendOnly: (presence: unknown) => Record<string, (...args: any) => void>;
51
- * vat: (name: string) => Record<string, (...args: any) => Promise<any>>;
52
- * }} EVProxy
49
+ * @typedef {object } EVProxyMethods Given a presence, return a "methods proxy"
50
+ * for which every requested property manifests as a method that forwards
51
+ * its invocation through the controller to the presence as an invocation of
52
+ * an identically-named method with identical arguments (modulo passable
53
+ * translation).
54
+ * So e.g. `EV(x).m(0)` becomes `controller.queueToVatObject(x, 'm', [0])`.
55
+ * @property {(presence: unknown) => Record<string, (...args: any) => void> } sendOnly
56
+ * Returns a "methods proxy" for the presence that ignores the result.
57
+ * @property {(name: string) => Record<string, (...args: any) => Promise<any>> } vat
58
+ * Returns a "methods proxy" for the root object of the specified vat.
59
+ * So e.g. `EV.vat('foo').m(0)` becomes
60
+ * `controller.queueToVatRoot('foo', 'm', [0])`.
61
+ */
62
+ /**
63
+ * @typedef {import('@endo/eventual-send').EProxy & EVProxyMethods } EVProxy
53
64
*/
54
65
55
66
// IMPORTANT WARNING TO USERS OF `EV`
@@ -96,50 +107,27 @@ export const makeRunUtils = controller => {
96
107
// promise that can remain pending indefinitely, possibly to be settled by a
97
108
// future message delivery.
98
109
110
+ const makeMethodsProxy = ( invoker , target , voidResult = false ) =>
111
+ new Proxy ( harden ( { } ) , {
112
+ get : ( _t , method , _rx ) => {
113
+ const boundMethod = ( ...args ) =>
114
+ queueAndRun ( ( ) => invoker ( target , method , args ) , voidResult ) ;
115
+ return harden ( boundMethod ) ;
116
+ } ,
117
+ } ) ;
118
+
99
119
/** @type {EVProxy } */
100
120
// @ts -expect-error cast, approximate
101
121
const EV = Object . assign (
102
- presence =>
103
- new Proxy ( harden ( { } ) , {
104
- get : ( _t , method , _rx ) => {
105
- const boundMethod = ( ...args ) =>
106
- queueAndRun ( ( ) =>
107
- controller . queueToVatObject ( presence , method , args ) ,
108
- ) ;
109
- return harden ( boundMethod ) ;
110
- } ,
111
- } ) ,
122
+ presence => makeMethodsProxy ( controller . queueToVatObject , presence ) ,
112
123
{
113
- vat : vatName =>
114
- new Proxy ( harden ( { } ) , {
115
- get : ( _t , method , _rx ) => {
116
- const boundMethod = ( ...args ) =>
117
- queueAndRun ( ( ) =>
118
- controller . queueToVatRoot ( vatName , method , args ) ,
119
- ) ;
120
- return harden ( boundMethod ) ;
121
- } ,
122
- } ) ,
124
+ vat : vatName => makeMethodsProxy ( controller . queueToVatRoot , vatName ) ,
123
125
sendOnly : presence =>
124
- new Proxy ( harden ( { } ) , {
125
- get : ( _t , method , _rx ) => {
126
- const boundMethod = ( ...args ) =>
127
- queueAndRun (
128
- ( ) => controller . queueToVatObject ( presence , method , args ) ,
129
- true ,
130
- ) ;
131
- return harden ( boundMethod ) ;
132
- } ,
133
- } ) ,
126
+ makeMethodsProxy ( controller . queueToVatObject , presence , true ) ,
134
127
get : presence =>
135
128
new Proxy ( harden ( { } ) , {
136
- get : ( _t , pathElement , _rx ) =>
137
- queueAndRun ( ( ) =>
138
- controller . queueToVatRoot ( 'bootstrap' , 'awaitVatObject' , [
139
- presence ,
140
- [ pathElement ] ,
141
- ] ) ,
142
- ) ,
129
+ get : ( _t , key , _rx ) =>
130
+ EV . vat ( 'bootstrap' ) . awaitVatObject ( presence , [ key ] ) ,
143
131
} ) ,
144
132
} ,
145
133
) ;
0 commit comments