Skip to content

Commit

Permalink
fix: missing Far on some iterables
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jan 10, 2022
1 parent c95d80d commit 063614b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/store/src/keys/copyMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import {
assertChecker,
Far,
getTag,
makeTagged,
passStyleOf,
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions packages/store/src/stores/store-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check

import { Far } from '@agoric/marshal';

const { details: X, quote: q } = assert;

/**
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions packages/store/test/test-copyMap.js
Original file line number Diff line number Diff line change
@@ -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');
});
13 changes: 13 additions & 0 deletions packages/store/test/test-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 063614b

Please sign in to comment.