Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing Far declarations on some iterables #4250

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});