Skip to content

Commit

Permalink
fix: seal payload used for quoted details (#1610)
Browse files Browse the repository at this point in the history
  • Loading branch information
erights authored Aug 26, 2020
1 parent 5ceb471 commit 1acd5ba
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/assert/src/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function cycleTolerantStringify(payload) {
return JSON.stringify(payload, replacer);
}

const declassifiers = new WeakSet();
const declassifiers = new WeakMap();

/**
* To "declassify" and quote a substitution value used in a
Expand All @@ -72,7 +72,6 @@ const declassifiers = new WeakSet();
* ```
*
* @typedef {Object} StringablePayload
* @property {*} payload The original payload
* @property {() => string} toString How to print the payload
*
* @param {*} payload What to declassify
Expand All @@ -81,10 +80,9 @@ const declassifiers = new WeakSet();
function q(payload) {
// Don't harden the payload
const result = Object.freeze({
payload,
toString: Object.freeze(() => cycleTolerantStringify(payload)),
});
declassifiers.add(result);
declassifiers.set(result, payload);
return result;
}
harden(q);
Expand Down Expand Up @@ -138,7 +136,7 @@ function details(template, ...args) {
let argStr;
if (declassifiers.has(arg)) {
argStr = `${arg}`;
arg = arg.payload;
arg = declassifiers.get(arg);
} else {
argStr = `(${an(typeof arg)})`;
}
Expand Down

0 comments on commit 1acd5ba

Please sign in to comment.