Skip to content

Commit

Permalink
feat(marshal): Data({}) is pass-by-copy
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Feb 23, 2021
1 parent d7b190f commit 03d7b5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ function isPassByCopyRecord(val) {
);
}

if (descKeys.length === 1) {
if (ignorePassStyle(descKeys[0])) {
// the only key is the Data() marker, therefore this is pass-by-data
return true;
}
}

for (const descKey of descKeys) {
// we tolerate and ignore a non-enumerable PASS_STYLE symbol-named key, the Data marker
if (ignorePassStyle(descKey)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/marshal/test/test-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ test('records', t => {
}),
slots: ['slot'],
};
// const emptyData = { body: JSON.stringify({}), slots: [] };
const emptyData = { body: JSON.stringify({}), slots: [] };

// For objects with Symbol-named properties
const symEnumData = Symbol.for('symEnumData');
Expand Down Expand Up @@ -532,7 +532,7 @@ test('records', t => {
// interim1: pass-by-copy without warning
// interim2: pass-by-copy without warning
// final: not applicable, Data() removed
// t.deepEqual(build('data'), emptyData); // interim 1+2
t.deepEqual(ser(build('data')), emptyData); // interim 1+2

// Far('iface', {})
// all cases: pass-by-ref
Expand Down

0 comments on commit 03d7b5e

Please sign in to comment.