Skip to content

Commit

Permalink
Merge pull request #2632 from Agoric/2018-remove-Data
Browse files Browse the repository at this point in the history
remove Data from marshal and all packages that used it
  • Loading branch information
warner authored Mar 17, 2021
2 parents 3fd04c1 + 81dd9a4 commit e7efb11
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 159 deletions.
3 changes: 1 addition & 2 deletions packages/ERTP/src/displayInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
passStyleOf,
REMOTE_STYLE,
getInterfaceOf,
Data,
} from '@agoric/marshal';

// TODO: assertSubset and assertKeysAllowed are copied from Zoe. Move
Expand Down Expand Up @@ -64,7 +63,7 @@ export const coerceDisplayInfo = allegedDisplayInfo => {
assert.equal(Reflect.ownKeys(allegedDisplayInfo).length, 0);
assert.equal(Object.getPrototypeOf(allegedDisplayInfo), Object.prototype);
assert.equal(getInterfaceOf(allegedDisplayInfo), undefined);
return Data({});
return harden({});
}
allegedDisplayInfo = pureCopy(allegedDisplayInfo);
assertDisplayInfo(allegedDisplayInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import '@agoric/swingset-vat/tools/prepare-test-env';
// eslint-disable-next-line import/no-extraneous-dependencies
import test from 'ava';

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

import { amountMath as m, MathKind } from '../../../src';
import { mockBrand } from './mockBrand';
Expand Down Expand Up @@ -118,7 +118,7 @@ const runSetMathHelpersTests = (t, [a, b, c], a2 = undefined) => {
`m.isEmpty([]) is true`,
);
t.throws(
() => m.isEmpty({ brand: mockBrand, value: Data({}) }),
() => m.isEmpty({ brand: mockBrand, value: harden({}) }),
{ message: `value (an object) must be a Nat or an array` },
`m.isEmpty({}) throws`,
);
Expand Down
3 changes: 1 addition & 2 deletions packages/ERTP/test/unitTests/test-issuerObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import '@agoric/swingset-vat/tools/prepare-test-env';
// eslint-disable-next-line import/no-extraneous-dependencies
import test from 'ava';
import { E } from '@agoric/eventual-send';
import { Data } from '@agoric/marshal';
import { MathKind, makeIssuerKit, amountMath } from '../../src';

test('issuer.getBrand, brand.isMyIssuer', t => {
Expand Down Expand Up @@ -51,7 +50,7 @@ test('bad display info', t => {
});

test('empty display info', t => {
const displayInfo = Data({});
const displayInfo = harden({});
const { brand } = makeIssuerKit('fungible', MathKind.NAT, displayInfo);
t.deepEqual(brand.getDisplayInfo(), displayInfo);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/SwingSet/src/kernel/initializeKernel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-use-before-define */

import { makeMarshal, Far, Data } from '@agoric/marshal';
import { makeMarshal, Far } from '@agoric/marshal';
import { assert, details as X } from '@agoric/assert';
import { assertKnownOptions } from '../assertOptions';
import { insistVatID } from './id';
Expand Down Expand Up @@ -169,7 +169,7 @@ export function initializeKernel(config, hostStorage, verbose = false) {
const m = makeMarshal(convertValToSlot, undefined, {
marshalName: 'kernel:bootstrap',
});
const args = harden([Data(vatObj0s), Data(deviceObj0s)]);
const args = harden([vatObj0s, deviceObj0s]);
// queueToExport() takes kernel-refs (ko+NN, kd+NN) in s.slots
const rootSlot = makeVatRootObjectSlot();
const resultKpid = doQueueToExport(
Expand Down
3 changes: 1 addition & 2 deletions packages/cosmic-swingset/lib/ag-solo/vats/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// in its own makeHardener, etc.
import { makeCapTP } from '@agoric/captp/lib/captp';
import { E } from '@agoric/eventual-send';
import { Data } from '@agoric/marshal';

export const getCapTPHandler = (
send,
Expand All @@ -12,7 +11,7 @@ export const getCapTPHandler = (
const chans = new Map();
const doFallback = async (method, ...args) => {
if (!fallback) {
return Data({});
return harden({});
}
return E(fallback)[method](...args);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function buildRootObject(vatPowers) {
...decentralObjects, // TODO: Remove; replaced by .agoric
...privateObjects, // TODO: Remove; replaced by .local
...handyObjects,
agoric: { ...decentralObjects }, // TODO: maybe needs Data()???
agoric: { ...decentralObjects },
local: { ...privateObjects },
};

Expand Down
12 changes: 6 additions & 6 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { makeIssuerTable } from '@agoric/zoe/src/issuerTable';

import { E } from '@agoric/eventual-send';

import { makeMarshal, passStyleOf, Far, Data } from '@agoric/marshal';
import { makeMarshal, passStyleOf, Far } from '@agoric/marshal';
import { makeNotifierKit, observeNotifier } from '@agoric/notifier';
import { makePromiseKit } from '@agoric/promise-kit';

Expand Down Expand Up @@ -470,7 +470,7 @@ export function makeWallet({
// Payments are made for the keywords in proposal.give.
const keywords = [];

const paymentPs = Object.entries(proposal.give || Data({})).map(
const paymentPs = Object.entries(proposal.give || harden({})).map(
([keyword, amount]) => {
const purse = purseKeywordRecord[keyword];
assert(
Expand All @@ -491,7 +491,7 @@ export function makeWallet({
// for the offer.
const payments = await Promise.all(paymentPs);

const paymentKeywordRecord = Data(
const paymentKeywordRecord = harden(
Object.fromEntries(keywords.map((keyword, i) => [keyword, payments[i]])),
);

Expand Down Expand Up @@ -691,15 +691,15 @@ export function makeWallet({

const compileProposal = proposalTemplate => {
const {
want = Data({}),
give = Data({}),
want = harden({}),
give = harden({}),
exit = { onDemand: null },
} = proposalTemplate;

const purseKeywordRecord = {};

const compile = amountKeywordRecord => {
return Data(
return harden(
Object.fromEntries(
Object.entries(amountKeywordRecord).map(
([keyword, { pursePetname, value }]) => {
Expand Down
7 changes: 3 additions & 4 deletions packages/dapp-svelte-wallet/api/test/test-lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import test from 'ava';
// eslint-disable-next-line import/no-extraneous-dependencies
import bundleSource from '@agoric/bundle-source';
import { makeIssuerKit, makeLocalAmountMath } from '@agoric/ertp';
import { Data } from '@agoric/marshal';

import { makeZoe } from '@agoric/zoe';
import fakeVatAdmin from '@agoric/zoe/src/contractFacet/fakeVatAdmin';
Expand Down Expand Up @@ -276,7 +275,7 @@ test('lib-wallet dapp suggests issuer, instance, installation petnames', async t

inviteHandleBoardId,

proposalTemplate: Data({}),
proposalTemplate: {},
});

const rawId = '1588645041696';
Expand Down Expand Up @@ -1201,7 +1200,7 @@ test('addOffer makeContinuingInvitation', async t => {
instance,
description: 'FirstThing',
},
proposalTemplate: Data({}),
proposalTemplate: harden({}),
};

await wallet.addOffer(offer);
Expand All @@ -1224,7 +1223,7 @@ test('addOffer makeContinuingInvitation', async t => {
priorOfferId: rawId,
description: 'SecondThing',
},
proposalTemplate: Data({}),
proposalTemplate: harden({}),
};

await wallet.addOffer(offer2);
Expand Down
1 change: 0 additions & 1 deletion packages/marshal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export {
makeMarshal,
Remotable,
Far,
Data,
} from './src/marshal';

export { stringify, parse } from './src/marshal-stringify';
84 changes: 9 additions & 75 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,42 +248,13 @@ function isPassByCopyArray(val) {
return true;
}

/**
* Everything having to do with a `dataProto` is a temporary kludge until
* we're on the other side of #2018. TODO remove.
*/
const dataProto = harden(
create(objectPrototype, {
[PASS_STYLE]: { value: 'copyRecord' },
}),
);

const isDataProto = proto => {
if (!isFrozen(proto)) {
return false;
}
if (getPrototypeOf(proto) !== objectPrototype) {
return false;
}
const {
// @ts-ignore
[PASS_STYLE]: passStyleDesc,
...rest
} = getOwnPropertyDescriptors(proto);
return (
passStyleDesc &&
passStyleDesc.value === 'copyRecord' &&
ownKeys(rest).length === 0
);
};

/**
* @param {Passable} val
* @returns {boolean}
*/
function isPassByCopyRecord(val) {
const proto = getPrototypeOf(val);
if (proto !== objectPrototype && !isDataProto(proto)) {
if (proto !== objectPrototype) {
return false;
}
const descs = getOwnPropertyDescriptors(val);
Expand Down Expand Up @@ -948,20 +919,14 @@ export function makeMarshal(
}
return ibidTable.finish(result);
} else {
let result = ibidTable.start({});
const names = ownKeys(rawTree);
if (names.length === 0) {
// eslint-disable-next-line no-use-before-define
result = Data(result);
} else {
for (const name of names) {
assert.typeof(
name,
'string',
X`Property ${name} of ${rawTree} must be a string`,
);
result[name] = fullRevive(rawTree[name]);
}
const result = ibidTable.start({});
for (const name of ownKeys(rawTree)) {
assert.typeof(
name,
'string',
X`Property ${name} of ${rawTree} must be a string`,
);
result[name] = fullRevive(rawTree[name]);
}
return ibidTable.finish(result);
}
Expand Down Expand Up @@ -1088,34 +1053,3 @@ const Far = (farName, remotable = {}) =>

harden(Far);
export { Far };

/**
* Everything having to do with `Data` is a temporary kludge until
* we're on the other side of #2018. TODO remove.
*
* @param {Object} record
*/
const Data = record => {
// Ensure that the record isn't already marked.
assert(
!(PASS_STYLE in record),
X`Record ${record} is already marked as a ${q(record[PASS_STYLE])}`,
);
// Ensure that the record isn't already frozen.
assert(!isFrozen(record), X`Record ${record} is already frozen`);
assert(
getPrototypeOf(record) === objectPrototype,
X`A record ${record} must initially inherit from Object.prototype`,
);

setPrototypeOf(record, dataProto);
harden(record);
assert(
isPassByCopyRecord(record),
X`Data() can only be applied to otherwise pass-by-copy records`,
);
return record;
};

harden(Data);
export { Data };
22 changes: 0 additions & 22 deletions packages/marshal/test/test-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import test from 'ava';
import {
Remotable,
Far,
Data,
getInterfaceOf,
makeMarshal,
passStyleOf,
Expand Down Expand Up @@ -467,18 +466,13 @@ test('records', t => {
props[symNonenumFunc] = { enumerable: false, value: () => 0 };
} else if (opt === 'nonenumSymbolGetFunc') {
props[symNonenumGetFunc] = { enumerable: false, get: () => () => 0 };
} else if (opt === 'data') {
mark = 'data';
} else if (opt === 'far') {
mark = 'far';
} else {
throw Error(`unknown option ${opt}`);
}
}
const o = create(objectPrototype, props);
if (mark === 'data') {
return Data(o);
}
if (mark === 'far') {
return Far('iface', o);
}
Expand All @@ -492,7 +486,6 @@ test('records', t => {
const NOACC = /Records must not contain accessors/;
const RECENUM = /Record fields must be enumerable/;
const NOMETH = /cannot serialize objects with non-methods/;
const NODATA = /Data\(\) can only be applied to otherwise pass-by-copy records/;

// empty objects

Expand All @@ -506,12 +499,7 @@ test('records', t => {
// harden({})
t.deepEqual(ser(build()), emptyData);

// Data({key1: 'data'})
// old: not applicable, Data() not yet added
// interim1: pass-by-copy without warning, but Data() is not necessary
// final: not applicable, Data() removed
const key1Data = { body: JSON.stringify({ key1: 'data' }), slots: [] };
t.deepEqual(ser(build('enumStringData', 'data')), key1Data);

// Serialized data should roundtrip properly
t.deepEqual(unser(ser(harden({}))), {});
Expand All @@ -521,13 +509,6 @@ test('records', t => {
t.deepEqual(ser(unser(emptyData)), emptyData);
t.deepEqual(ser(unser(key1Data)), key1Data);

// Data({})
// old: not applicable, Data() not yet added
// interim1: pass-by-copy without warning
// interim2: pass-by-copy without warning
// final: not applicable, Data() removed
t.deepEqual(ser(build('data')), emptyData); // interim 1+2

// Far('iface', {})
// all cases: pass-by-ref
t.deepEqual(ser(build('far')), yesIface);
Expand Down Expand Up @@ -556,9 +537,6 @@ test('records', t => {
t.deepEqual(ser(build('nonenumStringFunc')), noIface);
t.deepEqual(ser(build('nonenumSymbolFunc')), noIface);

// Data({ key: data, key: func }) : rejected
shouldThrow(['data', 'enumStringData', 'enumStringFunc'], NODATA);

// Far('iface', { key: data, key: func }) : rejected
// (some day this might add auxilliary data, but not now
shouldThrow(['far', 'enumStringData', 'enumStringFunc'], CSO);
Expand Down
6 changes: 3 additions & 3 deletions packages/swingset-runner/src/vat-launcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { E } from '@agoric/eventual-send';
import { Far, Data } from '@agoric/marshal';
import { Far } from '@agoric/marshal';

/*
* Vat to launch other vats.
Expand Down Expand Up @@ -41,14 +41,14 @@ export function buildRootObject(_vatPowers, vatParameters) {
// eslint-disable-next-line no-await-in-loop
const vat = await E(vatMaker).createVatByName(
bundleName,
{ metered: vatParameters.metered, vatParameters: Data(subvatParameters) },
{ metered: vatParameters.metered, vatParameters: harden(subvatParameters) },
);
vatRoots[vatName] = vat.root;
}
vatRoots.vatAdmin = vats.vatAdmin;
bootstrapRoot = vatRoots[vatParameters.config.bootstrap];
// prettier-ignore
return E(bootstrapRoot).bootstrap(Data(vatRoots), devices);
return E(bootstrapRoot).bootstrap(harden(vatRoots), devices);
},
runBenchmarkRound() {
return E(bootstrapRoot).runBenchmarkRound();
Expand Down
Loading

0 comments on commit e7efb11

Please sign in to comment.