From 81dd9a492bd70f63e71647a29356eb890063641d Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 12 Mar 2021 17:35:44 -0800 Subject: [PATCH] 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);