Skip to content

Commit 93c8933

Browse files
committed
fix: allow local Presences to receive deliveries as well
Closes #1719
1 parent d12f22b commit 93c8933

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

packages/SwingSet/src/kernel/liveSlots.js

+10-18
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,6 @@ function build(
222222
if (isPromise(val)) {
223223
slot = exportPromise(val);
224224
} else {
225-
const iface = getInterfaceOf(val);
226-
// TODO unimplemented
227-
assert(
228-
iface === undefined,
229-
details`cannot forward ${iface}; synthetic presences not implemented`,
230-
);
231225
mustPassByPresence(val);
232226
slot = exportPassByPresence();
233227
}
@@ -380,19 +374,17 @@ function build(
380374
// the kernel. deliver() does not report such exceptions to the kernel.
381375

382376
try {
383-
if (!(method in t)) {
384-
const names = Object.getOwnPropertyNames(t);
385-
throw new TypeError(`target[${method}] does not exist, has ${names}`);
386-
}
387-
if (!(t[method] instanceof Function)) {
388-
const ftype = typeof t[method];
389-
const names = Object.getOwnPropertyNames(t);
390-
throw new TypeError(
391-
`target[${method}] is not a function, typeof is ${ftype}, has ${names}`,
392-
);
377+
// We have a presence, so forward to it.
378+
let res;
379+
if (args) {
380+
// It has arguments, must be a method application.
381+
res = HandledPromise.applyMethod(t, method, args);
382+
} else {
383+
// TODO: untested, but in principle sound.
384+
// Just a getter.
385+
res = HandledPromise.get(t, method);
393386
}
394-
const res = t[method](...args);
395-
Promise.resolve(res).then(notifySuccess, notifyFailure);
387+
res.then(notifySuccess, notifyFailure);
396388
} catch (err) {
397389
notifyFailure(err);
398390
}

packages/eventual-send/src/index.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,26 @@ export function makeHandledPromise() {
355355
// eslint-disable-next-line prefer-const
356356
forwardingHandler = {
357357
get: makeForwarder('get', (o, key) => o[key]),
358-
applyMethod: makeForwarder('applyMethod', (o, optKey, args) => {
359-
if (optKey === undefined || optKey === null) {
360-
return o(...args);
358+
applyMethod: makeForwarder('applyMethod', (t, method, args) => {
359+
if (method === undefined || method === null) {
360+
if (!(t instanceof Function)) {
361+
const ftype = typeof t;
362+
throw new TypeError(`target is not a function, typeof is ${ftype}`);
363+
}
364+
return t(...args);
365+
}
366+
if (!(method in t)) {
367+
const names = Object.getOwnPropertyNames(t).sort();
368+
throw new TypeError(`target[${method}] does not exist, has ${names}`);
361369
}
362-
// console.log(`sending`, optKey, o[optKey], o);
363-
if (typeof o[optKey] !== 'function') {
364-
throw TypeError(`o[${JSON.stringify(optKey)}] is not a function`);
370+
if (!(t[method] instanceof Function)) {
371+
const ftype = typeof t[method];
372+
const names = Object.getOwnPropertyNames(t).sort();
373+
throw new TypeError(
374+
`target[${method}] is not a function, typeof is ${ftype}, has ${names}`,
375+
);
365376
}
366-
return o[optKey](...args);
377+
return t[method](...args);
367378
}),
368379
};
369380

0 commit comments

Comments
 (0)