Skip to content

Commit fffd37e

Browse files
committed
fix(sharing-service): add Far to all pass-by-reference objects
refs #2018
1 parent d4fa4f1 commit fffd37e

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
lines changed

packages/sharing-service/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
},
3131
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
3232
"dependencies": {
33-
"@agoric/assert": "^0.2.2"
33+
"@agoric/assert": "^0.2.2",
34+
"@agoric/marshal": "^0.3.2"
3435
},
3536
"devDependencies": {
3637
"@agoric/eventual-send": "^0.13.2",

packages/sharing-service/src/sharedMap.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Copyright (C) 2019 Agoric, under Apache License 2.0
22

33
import { assert, details as X } from '@agoric/assert';
4+
import { Far } from '@agoric/marshal';
45

56
// Allows multiple parties to store values for retrieval by others.
67
function makeSharedMap(name) {
78
const namedEntries = new Map();
89
const orderedEntries = [];
910

10-
return harden({
11+
return Far('sharedMap', {
1112
lookup(propertyName) {
1213
if (!namedEntries.has(propertyName)) {
1314
return undefined;

packages/sharing-service/src/sharing.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (C) 2019 Agoric, under Apache License 2.0
22

33
import { assert, details as X } from '@agoric/assert';
4+
import { Far } from '@agoric/marshal';
45
import { makeSharedMap } from './sharedMap';
56

67
function makeSharingService() {
@@ -9,7 +10,7 @@ function makeSharingService() {
910
const brand = new WeakSet();
1011
const tombstone = [];
1112

12-
const sharingService = harden({
13+
const sharingService = Far('sharingService', {
1314
// retrieve and remove from the map.
1415
grabSharedMap(key) {
1516
if (!sharedMaps.has(key)) {

packages/sharing-service/test/swingsetTests/sharingService/bootstrap.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { E } from '@agoric/eventual-send';
44
import { assert, details as X } from '@agoric/assert';
5+
import { Far } from '@agoric/marshal';
56
import { makeSharedMap } from '../../../src/sharedMap';
67
import { makeSharingService } from '../../../src/sharing';
78

@@ -40,7 +41,7 @@ export function buildRootObject(vatPowers, vatParameters) {
4041
log('expected sharedMap to validate');
4142
}
4243

43-
const fakeSharedMap = harden({
44+
const fakeSharedMap = Far('fakeSharedMap', {
4445
lookup(propertyName) {
4546
return `${propertyName}: value`;
4647
},
@@ -80,7 +81,7 @@ export function buildRootObject(vatPowers, vatParameters) {
8081
});
8182
}
8283

83-
const obj0 = {
84+
return Far('root', {
8485
async bootstrap(vats) {
8586
switch (vatParameters.argv[0]) {
8687
case 'sharedMap': {
@@ -100,6 +101,5 @@ export function buildRootObject(vatPowers, vatParameters) {
100101
}
101102
}
102103
},
103-
};
104-
return harden(obj0);
104+
});
105105
}

packages/sharing-service/test/swingsetTests/sharingService/vat-alice.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Copyright (C) 2019 Agoric, under Apache License 2.0
22

33
import { E } from '@agoric/eventual-send';
4+
import { Far } from '@agoric/marshal';
45

56
function makeAliceMaker() {
6-
return harden({
7+
return Far('aliceMaker', {
78
make(sharingServiceP) {
8-
const alice = harden({
9+
const alice = Far('alice', {
910
shareSomething(someKey) {
1011
return E(sharingServiceP)
1112
.createSharedMap(someKey)
@@ -18,9 +19,9 @@ function makeAliceMaker() {
1819
}
1920

2021
export function buildRootObject(_vatPowers) {
21-
return harden({
22+
return Far('root', {
2223
makeAliceMaker(_host) {
23-
return harden(makeAliceMaker());
24+
return makeAliceMaker();
2425
},
2526
});
2627
}

packages/sharing-service/test/swingsetTests/sharingService/vat-bob.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// Copyright (C) 2019 Agoric, under Apache License 2.0
22

33
import { E } from '@agoric/eventual-send';
4+
import { Far } from '@agoric/marshal';
45

56
function makeBobMaker() {
6-
return harden({
7+
return Far('bobMaker', {
78
make(sharingServiceP) {
8-
const bob = harden({
9+
const bob = Far('bob', {
910
findSomething(key) {
1011
return E(sharingServiceP)
1112
.grabSharedMap(key)
@@ -20,9 +21,9 @@ function makeBobMaker() {
2021
}
2122

2223
export function buildRootObject(_vatPowers) {
23-
return harden({
24+
return Far('root', {
2425
makeBobMaker(_host) {
25-
return harden(makeBobMaker());
26+
return makeBobMaker();
2627
},
2728
});
2829
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright (C) 2019 Agoric, under Apache License 2.0
22

3+
import { Far } from '@agoric/marshal';
34
import { makeSharingService } from '../../../src/sharing';
45

56
export function buildRootObject(_vatPowers) {
6-
return harden({ makeSharingService });
7+
return Far('root', { makeSharingService });
78
}

0 commit comments

Comments
 (0)