Skip to content

Commit

Permalink
fix(demo): make demos robust against bigints in JSON.stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Mar 10, 2021
1 parent a0ec399 commit c289502
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/swingset-runner/demo/exchangeBenchmark/printLog.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
function bigintReplacer(_, arg) {
if (typeof arg === 'bigint') {
return Number(arg);
}
return arg;
}

export function makePrintLog() {
return function printLog(...args) {
const rendered = args.map(arg =>
typeof arg === 'string' ? arg : JSON.stringify(arg),
typeof arg === 'string' ? arg : JSON.stringify(arg, bigintReplacer),
);
console.log(rendered.join(''));
};
Expand Down
9 changes: 8 additions & 1 deletion packages/swingset-runner/demo/swapBenchmark/printLog.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
function bigintReplacer(_, arg) {
if (typeof arg === 'bigint') {
return Number(arg);
}
return arg;
}

export function makePrintLog() {
return function printLog(...args) {
const rendered = args.map(arg =>
typeof arg === 'string' ? arg : JSON.stringify(arg),
typeof arg === 'string' ? arg : JSON.stringify(arg, bigintReplacer),
);
console.log(rendered.join(''));
};
Expand Down
9 changes: 8 additions & 1 deletion packages/swingset-runner/demo/zoeTests/printLog.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
function bigintReplacer(_, arg) {
if (typeof arg === 'bigint') {
return Number(arg);
}
return arg;
}

export function makePrintLog() {
return function printLog(...args) {
const rendered = args.map(arg =>
typeof arg === 'string' ? arg : JSON.stringify(arg),
typeof arg === 'string' ? arg : JSON.stringify(arg, bigintReplacer),
);
console.log(rendered.join(''));
};
Expand Down

0 comments on commit c289502

Please sign in to comment.