From 540d917b20ae74e44752210524f6ffcb27708892 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 12 Mar 2021 17:35:09 -0800 Subject: [PATCH 1/2] fix: remove use of Data() from all packages Now that `harden({})` is pass-by-copy, we no longer need the Data() marker. refs #2018 --- packages/ERTP/src/displayInfo.js | 3 +-- .../unitTests/mathHelpers/test-setMathHelpers.js | 4 ++-- packages/ERTP/test/unitTests/test-issuerObj.js | 3 +-- packages/SwingSet/src/kernel/initializeKernel.js | 4 ++-- packages/cosmic-swingset/lib/ag-solo/vats/captp.js | 3 +-- .../cosmic-swingset/lib/ag-solo/vats/vat-http.js | 2 +- packages/dapp-svelte-wallet/api/src/lib-wallet.js | 12 ++++++------ .../dapp-svelte-wallet/api/test/test-lib-wallet.js | 7 +++---- packages/swingset-runner/src/vat-launcher.js | 6 +++--- packages/zoe/src/cleanProposal.js | 3 +-- packages/zoe/src/contractFacet/contractFacet.js | 10 +++++----- packages/zoe/src/contractFacet/seat.js | 6 +++--- packages/zoe/src/contractSupport/zoeHelpers.js | 3 +-- packages/zoe/src/contracts/otcDesk.js | 4 ++-- packages/zoe/src/objArrayConversion.js | 5 ++--- packages/zoe/src/zoeService/zoe.js | 12 ++++++------ .../test/unitTests/contractSupport/test-offerTo.js | 3 +-- .../unitTests/contractSupport/test-zoeHelpers.js | 4 ++-- .../test/unitTests/contracts/loan/test-liquidate.js | 9 ++++----- packages/zoe/test/unitTests/test-cleanProposal.js | 9 ++++----- 20 files changed, 51 insertions(+), 61 deletions(-) diff --git a/packages/ERTP/src/displayInfo.js b/packages/ERTP/src/displayInfo.js index e13578e4d54..e669a9d456d 100644 --- a/packages/ERTP/src/displayInfo.js +++ b/packages/ERTP/src/displayInfo.js @@ -6,7 +6,6 @@ import { passStyleOf, REMOTE_STYLE, getInterfaceOf, - Data, } from '@agoric/marshal'; // TODO: assertSubset and assertKeysAllowed are copied from Zoe. Move @@ -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); diff --git a/packages/ERTP/test/unitTests/mathHelpers/test-setMathHelpers.js b/packages/ERTP/test/unitTests/mathHelpers/test-setMathHelpers.js index a02cf7314db..2791b4e97f8 100644 --- a/packages/ERTP/test/unitTests/mathHelpers/test-setMathHelpers.js +++ b/packages/ERTP/test/unitTests/mathHelpers/test-setMathHelpers.js @@ -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'; @@ -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`, ); diff --git a/packages/ERTP/test/unitTests/test-issuerObj.js b/packages/ERTP/test/unitTests/test-issuerObj.js index 8113147cdae..fd0a3781ee9 100644 --- a/packages/ERTP/test/unitTests/test-issuerObj.js +++ b/packages/ERTP/test/unitTests/test-issuerObj.js @@ -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 => { @@ -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); }); diff --git a/packages/SwingSet/src/kernel/initializeKernel.js b/packages/SwingSet/src/kernel/initializeKernel.js index 4bc4b72ca97..dd4ea4125ac 100644 --- a/packages/SwingSet/src/kernel/initializeKernel.js +++ b/packages/SwingSet/src/kernel/initializeKernel.js @@ -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'; @@ -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( diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/captp.js b/packages/cosmic-swingset/lib/ag-solo/vats/captp.js index 3c2ed577d8e..abb775b04d0 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/captp.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/captp.js @@ -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, @@ -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); }; diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js b/packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js index b55437dee9a..37ef5910213 100644 --- a/packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js +++ b/packages/cosmic-swingset/lib/ag-solo/vats/vat-http.js @@ -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 }, }; diff --git a/packages/dapp-svelte-wallet/api/src/lib-wallet.js b/packages/dapp-svelte-wallet/api/src/lib-wallet.js index 417ab60fee9..e63f2e6f07e 100644 --- a/packages/dapp-svelte-wallet/api/src/lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/src/lib-wallet.js @@ -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'; @@ -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( @@ -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]])), ); @@ -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 }]) => { diff --git a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js index 004ef63b0c0..51ccd03e25c 100644 --- a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js @@ -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'; @@ -276,7 +275,7 @@ test('lib-wallet dapp suggests issuer, instance, installation petnames', async t inviteHandleBoardId, - proposalTemplate: Data({}), + proposalTemplate: {}, }); const rawId = '1588645041696'; @@ -1201,7 +1200,7 @@ test('addOffer makeContinuingInvitation', async t => { instance, description: 'FirstThing', }, - proposalTemplate: Data({}), + proposalTemplate: harden({}), }; await wallet.addOffer(offer); @@ -1224,7 +1223,7 @@ test('addOffer makeContinuingInvitation', async t => { priorOfferId: rawId, description: 'SecondThing', }, - proposalTemplate: Data({}), + proposalTemplate: harden({}), }; await wallet.addOffer(offer2); diff --git a/packages/swingset-runner/src/vat-launcher.js b/packages/swingset-runner/src/vat-launcher.js index f0905f191eb..6d3f2c5e35a 100644 --- a/packages/swingset-runner/src/vat-launcher.js +++ b/packages/swingset-runner/src/vat-launcher.js @@ -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. @@ -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(); diff --git a/packages/zoe/src/cleanProposal.js b/packages/zoe/src/cleanProposal.js index 982bb100eae..1bbcc24f570 100644 --- a/packages/zoe/src/cleanProposal.js +++ b/packages/zoe/src/cleanProposal.js @@ -1,7 +1,6 @@ import { assert, details as X, q } from '@agoric/assert'; import { mustBeComparable } from '@agoric/same-structure'; import { isNat } from '@agoric/nat'; -import { Data } from '@agoric/marshal'; import '../exported'; import './internal-types'; @@ -111,7 +110,7 @@ export const cleanProposal = (getAmountMath, proposal) => { assertKeysAllowed(rootKeysAllowed, proposal); // We fill in the default values if the keys are undefined. - let { want = Data({}), give = Data({}) } = proposal; + let { want = harden({}), give = harden({}) } = proposal; const { exit = harden({ onDemand: null }) } = proposal; want = coerceAmountKeywordRecord(getAmountMath, want); diff --git a/packages/zoe/src/contractFacet/contractFacet.js b/packages/zoe/src/contractFacet/contractFacet.js index 4b309d766fb..b68735b3632 100644 --- a/packages/zoe/src/contractFacet/contractFacet.js +++ b/packages/zoe/src/contractFacet/contractFacet.js @@ -12,7 +12,7 @@ import { assert, details as X, q, makeAssert } from '@agoric/assert'; import { E } from '@agoric/eventual-send'; import { makeStore } from '@agoric/store'; -import { Far, Data } from '@agoric/marshal'; +import { Far } from '@agoric/marshal'; import { makeAmountMath, MathKind } from '@agoric/ertp'; import { makeNotifierKit, observeNotifier } from '@agoric/notifier'; @@ -150,7 +150,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { }; const makeEmptySeatKit = (exit = undefined) => { - const initialAllocation = Data({}); + const initialAllocation = harden({}); const proposal = cleanProposal(getAmountMath, harden({ exit })); const { notifier, updater } = makeNotifierKit(); /** @type {PromiseRecord} */ @@ -254,7 +254,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { : amountToAdd; return [seatKeyword, newAmount]; }); - const newAllocation = Data({ + const newAllocation = harden({ ...oldAllocation, ...updates, }); @@ -293,7 +293,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { return [seatKeyword, newAmount]; }, ); - const newAllocation = Data({ + const newAllocation = harden({ ...oldAllocation, ...updates, }); @@ -370,7 +370,7 @@ export function buildRootObject(powers, _params, testJigSetter = undefined) { makeInvitation: ( offerHandler = () => {}, description, - customProperties = Data({}), + customProperties = harden({}), ) => { assert.typeof( description, diff --git a/packages/zoe/src/contractFacet/seat.js b/packages/zoe/src/contractFacet/seat.js index 9ad34dfe2ed..31481ac04d3 100644 --- a/packages/zoe/src/contractFacet/seat.js +++ b/packages/zoe/src/contractFacet/seat.js @@ -2,7 +2,7 @@ import { E } from '@agoric/eventual-send'; import { assert, details as X } from '@agoric/assert'; -import { Data, Far } from '@agoric/marshal'; +import { Far } from '@agoric/marshal'; import { isOfferSafe } from './offerSafety'; @@ -88,7 +88,7 @@ export const makeZcfSeatAdminKit = ( }, isOfferSafe: newAllocation => { assertExitedFalse(); - const reallocation = Data({ + const reallocation = harden({ ...currentAllocation, ...newAllocation, }); @@ -98,7 +98,7 @@ export const makeZcfSeatAdminKit = ( stage: newAllocation => { assertExitedFalse(); // Check offer safety. - const allocation = Data({ + const allocation = harden({ ...currentAllocation, ...newAllocation, }); diff --git a/packages/zoe/src/contractSupport/zoeHelpers.js b/packages/zoe/src/contractSupport/zoeHelpers.js index 61e0eb08924..60ebd67718b 100644 --- a/packages/zoe/src/contractSupport/zoeHelpers.js +++ b/packages/zoe/src/contractSupport/zoeHelpers.js @@ -7,7 +7,6 @@ import { E } from '@agoric/eventual-send'; import { makePromiseKit } from '@agoric/promise-kit'; import { MathKind } from '@agoric/ertp'; -import { Data } from '@agoric/marshal'; import { satisfiesWant } from '../contractFacet/offerSafety'; import { objectMap } from '../objArrayConversion'; @@ -409,7 +408,7 @@ export async function withdrawFromSeat(zcf, seat, amounts) { * @param {IssuerKeywordRecord} issuerKeywordRecord Issuers to save to * ZCF */ -export async function saveAllIssuers(zcf, issuerKeywordRecord = Data({})) { +export async function saveAllIssuers(zcf, issuerKeywordRecord = harden({})) { const { issuers } = zcf.getTerms(); const issuersPSaved = Object.entries(issuerKeywordRecord).map( ([keyword, issuer]) => { diff --git a/packages/zoe/src/contracts/otcDesk.js b/packages/zoe/src/contracts/otcDesk.js index f8935544708..315a0c4d69c 100644 --- a/packages/zoe/src/contracts/otcDesk.js +++ b/packages/zoe/src/contracts/otcDesk.js @@ -2,7 +2,7 @@ import { E } from '@agoric/eventual-send'; import { assert } from '@agoric/assert'; -import { Data, Far } from '@agoric/marshal'; +import { Far } from '@agoric/marshal'; import { trade, offerTo, @@ -125,7 +125,7 @@ const start = zcf => { * @param {IssuerKeywordRecord=} issuerKeywordRecord * @returns {Promise} */ - makeAddInventoryInvitation: async (issuerKeywordRecord = Data({})) => { + makeAddInventoryInvitation: async (issuerKeywordRecord = harden({})) => { await saveAllIssuers(zcf, issuerKeywordRecord); return zcf.makeInvitation(addInventory, 'addInventory'); }, diff --git a/packages/zoe/src/objArrayConversion.js b/packages/zoe/src/objArrayConversion.js index 14da64d04a4..b88bd71646d 100644 --- a/packages/zoe/src/objArrayConversion.js +++ b/packages/zoe/src/objArrayConversion.js @@ -1,6 +1,5 @@ // @ts-check -import { Data } from '@agoric/marshal'; import { assert, details as X, q } from '@agoric/assert'; /** @@ -23,7 +22,7 @@ export const arrayToObj = (array, keys) => { /** @type {Record} */ ({}); keys.forEach((key, i) => (obj[key] = array[i])); - return Data(obj); + return harden(obj); }; /** @@ -88,5 +87,5 @@ export const assertSubset = (whole, part) => { export const objectMap = (original, mapPairFn) => { const ents = /** @type {[K, T][]} */ (Object.entries(original)); const mapEnts = ents.map(ent => mapPairFn(ent)); - return /** @type {Record} */ (Data(Object.fromEntries(mapEnts))); + return /** @type {Record} */ (harden(Object.fromEntries(mapEnts))); }; diff --git a/packages/zoe/src/zoeService/zoe.js b/packages/zoe/src/zoeService/zoe.js index 9d17cce6b11..7912c422319 100644 --- a/packages/zoe/src/zoeService/zoe.js +++ b/packages/zoe/src/zoeService/zoe.js @@ -14,7 +14,7 @@ import { makeIssuerKit, MathKind } from '@agoric/ertp'; import '../../exported'; import '../internal-types'; -import { Data, Far } from '@agoric/marshal'; +import { Far } from '@agoric/marshal'; import { makeIssuerTable } from '../issuerTable'; import { makeZoeSeatAdminKit } from './zoeSeat'; import zcfContractBundle from '../../bundles/bundle-contractFacet'; @@ -97,8 +97,8 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) { }, startInstance: async ( installationP, - uncleanIssuerKeywordRecord = Data({}), - customTerms = Data({}), + uncleanIssuerKeywordRecord = harden({}), + customTerms = harden({}), ) => { /** @param {Issuer[]} issuers */ const initIssuers = issuers => @@ -356,7 +356,7 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) { zoeService, invitationIssuer, zoeInstanceAdminForZcf, - Data({ ...instanceRecord }), + harden({ ...instanceRecord }), ); addSeatObjPromiseKit.resolve(addSeatObj); @@ -395,8 +395,8 @@ function makeZoe(vatAdminSvc, zcfBundleName = undefined) { }, offer: async ( invitation, - uncleanProposal = Data({}), - paymentKeywordRecord = Data({}), + uncleanProposal = harden({}), + paymentKeywordRecord = harden({}), ) => { return invitationKit.issuer.burn(invitation).then( invitationAmount => { diff --git a/packages/zoe/test/unitTests/contractSupport/test-offerTo.js b/packages/zoe/test/unitTests/contractSupport/test-offerTo.js index 17304dd6cf4..2c771a94501 100644 --- a/packages/zoe/test/unitTests/contractSupport/test-offerTo.js +++ b/packages/zoe/test/unitTests/contractSupport/test-offerTo.js @@ -7,7 +7,6 @@ import '@agoric/zoe/tools/prepare-test-env'; import test from 'ava'; import { E } from '@agoric/eventual-send'; -import { Data } from '@agoric/marshal'; import bundleSource from '@agoric/bundle-source'; import { setup } from '../setupBasicMints'; @@ -98,7 +97,7 @@ test(`offerTo - basic usage`, async t => { const { zcfSeat: fromSeatContractA } = await makeOffer( zoe, zcfA, - harden({ want: Data({}), give: { TokenK: bucks(5) } }), + harden({ want: harden({}), give: { TokenK: bucks(5) } }), harden({ TokenK: bucksMint.mintPayment(bucks(5)) }), ); diff --git a/packages/zoe/test/unitTests/contractSupport/test-zoeHelpers.js b/packages/zoe/test/unitTests/contractSupport/test-zoeHelpers.js index 2ca95eba244..bcbbbc430d8 100644 --- a/packages/zoe/test/unitTests/contractSupport/test-zoeHelpers.js +++ b/packages/zoe/test/unitTests/contractSupport/test-zoeHelpers.js @@ -2,7 +2,7 @@ import '@agoric/zoe/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 makeStore from '@agoric/store'; import { setup } from '../setupBasicMints'; @@ -48,7 +48,7 @@ test('ZoeHelpers satisfies blank proposal', t => { const { moolaR, moola } = setup(); const fakeZcfSeat = Far('fakeZcfSeat', { getCurrentAllocation: () => harden({ Asset: moola(10) }), - getProposal: () => Data({}), + getProposal: () => harden({}), }); const mockZCFBuilder = makeMockTradingZcfBuilder(); mockZCFBuilder.addBrand(moolaR); diff --git a/packages/zoe/test/unitTests/contracts/loan/test-liquidate.js b/packages/zoe/test/unitTests/contracts/loan/test-liquidate.js index 33f4cfa2f89..02a5e74b775 100644 --- a/packages/zoe/test/unitTests/contracts/loan/test-liquidate.js +++ b/packages/zoe/test/unitTests/contracts/loan/test-liquidate.js @@ -7,7 +7,6 @@ import '@agoric/zoe/tools/prepare-test-env'; // eslint-disable-next-line import/no-extraneous-dependencies import test from 'ava'; -import { Data } from '@agoric/marshal'; import { doLiquidation } from '../../../../src/contracts/loan/liquidate'; import { @@ -24,8 +23,8 @@ test('test doLiquidation with mocked autoswap', async t => { // Set up the lender seat. At this point the lender has nothing. const { zcfSeat: lenderSeat, userSeat: lenderUserSeat } = await makeSeatKit( zcf, - { give: Data({}) }, - Data({}), + { give: harden({}) }, + harden({}), ); const collateral = collateralKit.amountMath.make(10); @@ -113,8 +112,8 @@ test('test with malfunctioning autoswap', async t => { // Set up the lender seat. At this point the lender has nothing. const { zcfSeat: lenderSeat, userSeat: lenderUserSeat } = await makeSeatKit( zcf, - { give: Data({}) }, - Data({}), + { give: harden({}) }, + harden({}), ); const collateral = collateralKit.amountMath.make(10); diff --git a/packages/zoe/test/unitTests/test-cleanProposal.js b/packages/zoe/test/unitTests/test-cleanProposal.js index 5c336390e72..ba7db960e71 100644 --- a/packages/zoe/test/unitTests/test-cleanProposal.js +++ b/packages/zoe/test/unitTests/test-cleanProposal.js @@ -3,7 +3,6 @@ import '@agoric/zoe/tools/prepare-test-env'; // eslint-disable-next-line import/no-extraneous-dependencies import test from 'ava'; import { makeWeakStore } from '@agoric/store'; -import { Data } from '@agoric/marshal'; import { cleanProposal } from '../../src/cleanProposal'; import { setup } from './setupBasicMints'; import buildManualTimer from '../../tools/manualTimer'; @@ -45,14 +44,14 @@ test('cleanProposal - all empty', t => { const getAmountMathForBrand = brandToAmountMath.get; const proposal = harden({ - give: Data({}), - want: Data({}), + give: harden({}), + want: harden({}), exit: { waived: null }, }); const expected = harden({ - give: Data({}), - want: Data({}), + give: harden({}), + want: harden({}), exit: { waived: null }, }); From 81dd9a492bd70f63e71647a29356eb890063641d Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 12 Mar 2021 17:35:44 -0800 Subject: [PATCH 2/2] fix(marshal): remove Data refs #2018 --- packages/marshal/index.js | 1 - packages/marshal/src/marshal.js | 84 +++------------------------ packages/marshal/test/test-marshal.js | 22 ------- 3 files changed, 9 insertions(+), 98 deletions(-) diff --git a/packages/marshal/index.js b/packages/marshal/index.js index 530c1fa7739..4b35ed66d24 100644 --- a/packages/marshal/index.js +++ b/packages/marshal/index.js @@ -9,7 +9,6 @@ export { makeMarshal, Remotable, Far, - Data, } from './src/marshal'; export { stringify, parse } from './src/marshal-stringify'; diff --git a/packages/marshal/src/marshal.js b/packages/marshal/src/marshal.js index 4647b6c9445..65807af3fc1 100644 --- a/packages/marshal/src/marshal.js +++ b/packages/marshal/src/marshal.js @@ -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); @@ -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); } @@ -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 }; diff --git a/packages/marshal/test/test-marshal.js b/packages/marshal/test/test-marshal.js index cac78689fab..a417ea7ceee 100644 --- a/packages/marshal/test/test-marshal.js +++ b/packages/marshal/test/test-marshal.js @@ -3,7 +3,6 @@ import test from 'ava'; import { Remotable, Far, - Data, getInterfaceOf, makeMarshal, passStyleOf, @@ -467,8 +466,6 @@ 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 { @@ -476,9 +473,6 @@ test('records', t => { } } const o = create(objectPrototype, props); - if (mark === 'data') { - return Data(o); - } if (mark === 'far') { return Far('iface', o); } @@ -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 @@ -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({}))), {}); @@ -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); @@ -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);