feat(eventual-send): harden things where possible under SES
MODIFY
packages/eventual-send/src/E.js
packages/eventual-send/src/E.js
@@ -30,15 +30,10 @@ function EProxyHandler(x, HandledPromise) {
return harden({
...baseFreezableProxyHandler,
get(_target, p, _receiver) {
- // Harden this Promise because it's our only opportunity to ensure
- // p1=E(x).foo() is hardened. The Handled Promise API does not (yet)
- // allow the handler to synchronously influence the promise returned
- // by the handled methods, so we must freeze it from the outside. See
- // #95 for details.
- return (...args) => harden(HandledPromise.applyMethod(x, p, args));
+ return harden((...args) => HandledPromise.applyMethod(x, p, args));
},
apply(_target, _thisArg, argArray = []) {
- return harden(HandledPromise.applyFunction(x, argArray));
+ return HandledPromise.applyFunction(x, argArray);
},
has(_target, _p) {
// We just pretend everything exists.
@@ -88,7 +83,7 @@ export default function makeE(HandledPromise) {
return true;
},
get(_target, prop) {
- return harden(HandledPromise.get(x, prop));
+ return HandledPromise.get(x, prop);
},
});

MODIFY
packages/eventual-send/src/handled-promise.js
packages/eventual-send/src/handled-promise.js
@@ -63,6 +63,7 @@ const coerceToObjectProperty = specimen => {
*/
export const makeHandledPromise = () => {
const presenceToHandler = new WeakMap();
+ /** @type {WeakMap<any, any>} */
const presenceToPromise = new WeakMap();
const promiseToPendingHandler = new WeakMap();
const promiseToPresence = new WeakMap();
@@ -477,7 +478,11 @@ export const makeHandledPromise = () => {
applyMethodSendOnly: makeForwarder('applyMethodSendOnly', localApplyMethod),
};
- handle = (p, operation, opArgs, ...dispatchArgs) => {
+ handle = (...handleArgs) => {
+ // We're in SES mode, so we should harden.
+ harden(handleArgs);
+ const [_p, operation, opArgs, ...dispatchArgs] = handleArgs;
+ let [p] = handleArgs;
const doDispatch = (handlerName, handler, o) =>
dispatchToHandler(
handlerName,
@@ -541,13 +546,14 @@ export const makeHandledPromise = () => {
.catch(lose);
});
- // Workaround for Node.js: silence "Unhandled Rejection" by default when
- // using the static methods.
- returnedP.catch(_ => {});
+ // Harden the fulfillment and rejection, as well as a workaround for
+ // Node.js: silence "Unhandled Rejection" by default when using the static
+ // methods.
+ returnedP.then(harden, harden);
// We return a handled promise with the default pending handler. This
// prevents a race between the above Promise.resolves and pipelining.
- return returnedP;
+ return harden(returnedP);
};
// Add everything needed on the constructor.

feat(eventual-send): harden things where possible under SES