Skip to content

Commit

Permalink
fix: symbols no longer passable
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Mar 6, 2020
1 parent 6acbde7 commit 7290a90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 30 deletions.
10 changes: 5 additions & 5 deletions packages/SwingSet/test/test-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ test('serialize static data', t => {
body: '{"@qclass":"-Infinity"}',
slots: [],
});
t.deepEqual(ser(Symbol.for('sym1')), {
body: '{"@qclass":"symbol","key":"sym1"}',
slots: [],
});
// t.deepEqual(ser(Symbol.for('sym1')), {
// body: '{"@qclass":"symbol","key":"sym1"}',
// slots: [],
// });
let bn;
try {
bn = BigInt(4);
Expand Down Expand Up @@ -91,7 +91,7 @@ test('unserialize static data', t => {
t.ok(Object.is(uns('{"@qclass":"NaN"}'), NaN));
t.deepEqual(uns('{"@qclass":"Infinity"}'), Infinity);
t.deepEqual(uns('{"@qclass":"-Infinity"}'), -Infinity);
t.deepEqual(uns('{"@qclass":"symbol", "key":"sym1"}'), Symbol.for('sym1'));
// t.deepEqual(uns('{"@qclass":"symbol", "key":"sym1"}'), Symbol.for('sym1'));

// Normal json reviver cannot make properties with undefined values
t.deepEqual(uns('[{"@qclass":"undefined"}]'), [undefined]);
Expand Down
22 changes: 2 additions & 20 deletions packages/marshal/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function sameValueZero(x, y) {

// How would val be passed? For primitive values, the answer is
// * 'null' for null
// * throwing an error for an unregistered symbol
// * throwing an error for a symbol, whether registered or not.
// * that value's typeof string for all other primitive values
// For frozen objects, the possible answers
// * 'copyRecord' for non-empty records with only data properties
Expand Down Expand Up @@ -225,10 +225,7 @@ export function passStyleOf(val) {
return typestr;
}
case 'symbol': {
if (Symbol.keyFor(val) === undefined) {
throw new TypeError('Cannot pass unregistered symbols');
}
return typestr;
throw new TypeError('Cannot pass symbols');
}
default: {
throw new TypeError(`unrecognized typeof ${typestr}`);
Expand Down Expand Up @@ -364,13 +361,6 @@ export function makeMarshal(
}
return val;
}
case 'symbol': {
const key = Symbol.keyFor(val);
return harden({
[QCLASS]: 'symbol',
key,
});
}
case 'bigint': {
return harden({
[QCLASS]: 'bigint',
Expand Down Expand Up @@ -498,14 +488,6 @@ export function makeMarshal(
case '-Infinity': {
return -Infinity;
}
case 'symbol': {
if (typeof rawTree.key !== 'string') {
throw new TypeError(
`invalid symbol key typeof ${typeof rawTree.key}`,
);
}
return Symbol.for(rawTree.key);
}
case 'bigint': {
if (typeof rawTree.digits !== 'string') {
throw new TypeError(
Expand Down
10 changes: 5 additions & 5 deletions packages/marshal/test/test-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ test('serialize static data', t => {
body: '{"@qclass":"-Infinity"}',
slots: [],
});
t.deepEqual(ser(Symbol.for('sym1')), {
body: '{"@qclass":"symbol","key":"sym1"}',
slots: [],
});
// t.deepEqual(ser(Symbol.for('sym1')), {
// body: '{"@qclass":"symbol","key":"sym1"}',
// slots: [],
// });
let bn;
try {
bn = BigInt(4);
Expand Down Expand Up @@ -80,7 +80,7 @@ test('unserialize static data', t => {
t.ok(Object.is(uns('{"@qclass":"NaN"}'), NaN));
t.deepEqual(uns('{"@qclass":"Infinity"}'), Infinity);
t.deepEqual(uns('{"@qclass":"-Infinity"}'), -Infinity);
t.deepEqual(uns('{"@qclass":"symbol", "key":"sym1"}'), Symbol.for('sym1'));
// t.deepEqual(uns('{"@qclass":"symbol", "key":"sym1"}'), Symbol.for('sym1'));

// Normal json reviver cannot make properties with undefined values
t.deepEqual(uns('[{"@qclass":"undefined"}]'), [undefined]);
Expand Down

0 comments on commit 7290a90

Please sign in to comment.