From 063614b59fc38d28421e30e96a91b7c0315d3276 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Thu, 6 Jan 2022 22:48:52 -0800 Subject: [PATCH] fix: missing Far on some iterables --- packages/store/src/keys/copyMap.js | 5 +++-- packages/store/src/stores/store-utils.js | 6 ++++-- packages/store/test/test-copyMap.js | 22 ++++++++++++++++++++++ packages/store/test/test-store.js | 13 +++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 packages/store/test/test-copyMap.js diff --git a/packages/store/src/keys/copyMap.js b/packages/store/src/keys/copyMap.js index 04b7b4f422be..f626a32a25b2 100644 --- a/packages/store/src/keys/copyMap.js +++ b/packages/store/src/keys/copyMap.js @@ -2,6 +2,7 @@ import { assertChecker, + Far, getTag, makeTagged, passStyleOf, @@ -111,10 +112,10 @@ export const getCopyMapEntries = m => { payload: { keys, values }, } = m; const { length } = keys; - return harden({ + return Far('CopyMap entries iterable', { [Symbol.iterator]: () => { let i = 0; - return harden({ + return Far('CopyMap entries iterator', { next: () => { /** @type {IteratorResult<[K,V],void>} */ let result; diff --git a/packages/store/src/stores/store-utils.js b/packages/store/src/stores/store-utils.js index de6190990c32..8cf9ca40cfb0 100644 --- a/packages/store/src/stores/store-utils.js +++ b/packages/store/src/stores/store-utils.js @@ -1,5 +1,7 @@ // @ts-check +import { Far } from '@agoric/marshal'; + const { details: X, quote: q } = assert; /** @@ -54,13 +56,13 @@ export const makeCurrentKeysKit = ( return sortedKeysMemo; }; - const iterableKeys = harden({ + const iterableKeys = Far('Iterable of keys', { [Symbol.iterator]: () => { const generation = updateCount; getSortedKeys(); const len = sortedKeysMemo.length; let i = 0; - return harden({ + return Far('Iterator of keys', { next: () => { assert.equal( generation, diff --git a/packages/store/test/test-copyMap.js b/packages/store/test/test-copyMap.js new file mode 100644 index 000000000000..3b3ad41736f1 --- /dev/null +++ b/packages/store/test/test-copyMap.js @@ -0,0 +1,22 @@ +// @ts-check + +import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava.js'; +import { getTag, passStyleOf } from '@agoric/marshal'; +import { getCopyMapEntries, makeCopyMap } from '../src/keys/copyMap.js'; +import '../src/types.js'; + +test('copyMap - iters are passable', t => { + // See test 'passability of store iters' + const m = makeCopyMap([ + ['x', 8], + ['y', 7], + ]); + t.is(passStyleOf(m), 'tagged'); + t.is(getTag(m), 'copyMap'); + const i = getCopyMapEntries(m); + t.is(passStyleOf(i), 'remotable'); + const iter = i[Symbol.iterator](); + t.is(passStyleOf(iter), 'remotable'); + const iterResult = iter.next(); + t.is(passStyleOf(iterResult), 'copyRecord'); +}); diff --git a/packages/store/test/test-store.js b/packages/store/test/test-store.js index a017f859030e..deb4330ceb43 100644 --- a/packages/store/test/test-store.js +++ b/packages/store/test/test-store.js @@ -129,3 +129,16 @@ test('passability of stores', t => { t.throws(() => passStyleOf(makeLegacyWeakMap('foo')), { message: /x/ }); } }); + +test('passability of store iters', t => { + // See test 'copyMap - iters are passable' + const m = makeScalarMapStore('bar'); + m.init('x', 8); + m.init('y', 7); + const keys = m.keys(); + t.is(passStyleOf(keys), 'remotable'); + const iter = keys[Symbol.iterator](); + t.is(passStyleOf(iter), 'remotable'); + const iterResult = iter.next(); + t.is(passStyleOf(iterResult), 'copyRecord'); +});