Skip to content

Commit

Permalink
chore: switch to E.when for promise-space onResolve hook
Browse files Browse the repository at this point in the history
This is more defensive against sneaky promises, at the cost of
delaying storage by a turn for non-promises.
  • Loading branch information
warner committed May 12, 2023
1 parent ec7cea6 commit 9d57c66
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/vats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@agoric/vat-data": "^0.4.3",
"@agoric/zoe": "^0.25.3",
"@agoric/zone": "^0.1.0",
"@endo/eventual-send": "^0.17.2",
"@endo/far": "^0.2.18",
"@endo/import-bundle": "^0.3.4",
"@endo/init": "^0.5.56",
Expand Down
9 changes: 3 additions & 6 deletions packages/vats/src/core/promise-space.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @ts-check
import { E } from '@endo/eventual-send';
import { assertKey } from '@agoric/store';
import { canBeDurable } from '@agoric/vat-data';
import { isPromise, makePromiseKit } from '@endo/promise-kit';
import { makePromiseKit } from '@endo/promise-kit';

/**
* @typedef {{
Expand Down Expand Up @@ -59,11 +60,7 @@ export const makeStoreHooks = (store, log = noop) => {
return harden({
...logHooks,
onResolve: (name, valueP) => {
if (isPromise(valueP)) {
void valueP.then(value => save(name, value));
} else {
save(name, valueP);
}
void E.when(valueP, value => save(name, value));
},
onReset: name => {
if (store.has(name)) {
Expand Down
1 change: 1 addition & 0 deletions packages/vats/test/test-promise-space.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ test('makePromiseSpace copied into store', async t => {
produce.chocolate.resolve(doesNotResolve);
const nonPassable = harden(() => {});
produce.strawberry.resolve(nonPassable);
await null;
const actual = Object.fromEntries(store.entries());
t.deepEqual(
actual,
Expand Down

0 comments on commit 9d57c66

Please sign in to comment.