Skip to content

Commit 81dd9a4

Browse files
committed
fix(marshal): remove Data
refs #2018
1 parent 540d917 commit 81dd9a4

File tree

3 files changed

+9
-98
lines changed

3 files changed

+9
-98
lines changed

packages/marshal/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export {
99
makeMarshal,
1010
Remotable,
1111
Far,
12-
Data,
1312
} from './src/marshal';
1413

1514
export { stringify, parse } from './src/marshal-stringify';

packages/marshal/src/marshal.js

+9-75
Original file line numberDiff line numberDiff line change
@@ -248,42 +248,13 @@ function isPassByCopyArray(val) {
248248
return true;
249249
}
250250

251-
/**
252-
* Everything having to do with a `dataProto` is a temporary kludge until
253-
* we're on the other side of #2018. TODO remove.
254-
*/
255-
const dataProto = harden(
256-
create(objectPrototype, {
257-
[PASS_STYLE]: { value: 'copyRecord' },
258-
}),
259-
);
260-
261-
const isDataProto = proto => {
262-
if (!isFrozen(proto)) {
263-
return false;
264-
}
265-
if (getPrototypeOf(proto) !== objectPrototype) {
266-
return false;
267-
}
268-
const {
269-
// @ts-ignore
270-
[PASS_STYLE]: passStyleDesc,
271-
...rest
272-
} = getOwnPropertyDescriptors(proto);
273-
return (
274-
passStyleDesc &&
275-
passStyleDesc.value === 'copyRecord' &&
276-
ownKeys(rest).length === 0
277-
);
278-
};
279-
280251
/**
281252
* @param {Passable} val
282253
* @returns {boolean}
283254
*/
284255
function isPassByCopyRecord(val) {
285256
const proto = getPrototypeOf(val);
286-
if (proto !== objectPrototype && !isDataProto(proto)) {
257+
if (proto !== objectPrototype) {
287258
return false;
288259
}
289260
const descs = getOwnPropertyDescriptors(val);
@@ -948,20 +919,14 @@ export function makeMarshal(
948919
}
949920
return ibidTable.finish(result);
950921
} else {
951-
let result = ibidTable.start({});
952-
const names = ownKeys(rawTree);
953-
if (names.length === 0) {
954-
// eslint-disable-next-line no-use-before-define
955-
result = Data(result);
956-
} else {
957-
for (const name of names) {
958-
assert.typeof(
959-
name,
960-
'string',
961-
X`Property ${name} of ${rawTree} must be a string`,
962-
);
963-
result[name] = fullRevive(rawTree[name]);
964-
}
922+
const result = ibidTable.start({});
923+
for (const name of ownKeys(rawTree)) {
924+
assert.typeof(
925+
name,
926+
'string',
927+
X`Property ${name} of ${rawTree} must be a string`,
928+
);
929+
result[name] = fullRevive(rawTree[name]);
965930
}
966931
return ibidTable.finish(result);
967932
}
@@ -1088,34 +1053,3 @@ const Far = (farName, remotable = {}) =>
10881053

10891054
harden(Far);
10901055
export { Far };
1091-
1092-
/**
1093-
* Everything having to do with `Data` is a temporary kludge until
1094-
* we're on the other side of #2018. TODO remove.
1095-
*
1096-
* @param {Object} record
1097-
*/
1098-
const Data = record => {
1099-
// Ensure that the record isn't already marked.
1100-
assert(
1101-
!(PASS_STYLE in record),
1102-
X`Record ${record} is already marked as a ${q(record[PASS_STYLE])}`,
1103-
);
1104-
// Ensure that the record isn't already frozen.
1105-
assert(!isFrozen(record), X`Record ${record} is already frozen`);
1106-
assert(
1107-
getPrototypeOf(record) === objectPrototype,
1108-
X`A record ${record} must initially inherit from Object.prototype`,
1109-
);
1110-
1111-
setPrototypeOf(record, dataProto);
1112-
harden(record);
1113-
assert(
1114-
isPassByCopyRecord(record),
1115-
X`Data() can only be applied to otherwise pass-by-copy records`,
1116-
);
1117-
return record;
1118-
};
1119-
1120-
harden(Data);
1121-
export { Data };

packages/marshal/test/test-marshal.js

-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import test from 'ava';
33
import {
44
Remotable,
55
Far,
6-
Data,
76
getInterfaceOf,
87
makeMarshal,
98
passStyleOf,
@@ -467,18 +466,13 @@ test('records', t => {
467466
props[symNonenumFunc] = { enumerable: false, value: () => 0 };
468467
} else if (opt === 'nonenumSymbolGetFunc') {
469468
props[symNonenumGetFunc] = { enumerable: false, get: () => () => 0 };
470-
} else if (opt === 'data') {
471-
mark = 'data';
472469
} else if (opt === 'far') {
473470
mark = 'far';
474471
} else {
475472
throw Error(`unknown option ${opt}`);
476473
}
477474
}
478475
const o = create(objectPrototype, props);
479-
if (mark === 'data') {
480-
return Data(o);
481-
}
482476
if (mark === 'far') {
483477
return Far('iface', o);
484478
}
@@ -492,7 +486,6 @@ test('records', t => {
492486
const NOACC = /Records must not contain accessors/;
493487
const RECENUM = /Record fields must be enumerable/;
494488
const NOMETH = /cannot serialize objects with non-methods/;
495-
const NODATA = /Data\(\) can only be applied to otherwise pass-by-copy records/;
496489

497490
// empty objects
498491

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

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

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

524-
// Data({})
525-
// old: not applicable, Data() not yet added
526-
// interim1: pass-by-copy without warning
527-
// interim2: pass-by-copy without warning
528-
// final: not applicable, Data() removed
529-
t.deepEqual(ser(build('data')), emptyData); // interim 1+2
530-
531512
// Far('iface', {})
532513
// all cases: pass-by-ref
533514
t.deepEqual(ser(build('far')), yesIface);
@@ -556,9 +537,6 @@ test('records', t => {
556537
t.deepEqual(ser(build('nonenumStringFunc')), noIface);
557538
t.deepEqual(ser(build('nonenumSymbolFunc')), noIface);
558539

559-
// Data({ key: data, key: func }) : rejected
560-
shouldThrow(['data', 'enumStringData', 'enumStringFunc'], NODATA);
561-
562540
// Far('iface', { key: data, key: func }) : rejected
563541
// (some day this might add auxilliary data, but not now
564542
shouldThrow(['far', 'enumStringData', 'enumStringFunc'], CSO);

0 commit comments

Comments
 (0)