Skip to content

Commit c289502

Browse files
committed
fix(demo): make demos robust against bigints in JSON.stringify
1 parent a0ec399 commit c289502

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

packages/swingset-runner/demo/exchangeBenchmark/printLog.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
function bigintReplacer(_, arg) {
2+
if (typeof arg === 'bigint') {
3+
return Number(arg);
4+
}
5+
return arg;
6+
}
7+
18
export function makePrintLog() {
29
return function printLog(...args) {
310
const rendered = args.map(arg =>
4-
typeof arg === 'string' ? arg : JSON.stringify(arg),
11+
typeof arg === 'string' ? arg : JSON.stringify(arg, bigintReplacer),
512
);
613
console.log(rendered.join(''));
714
};

packages/swingset-runner/demo/swapBenchmark/printLog.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
function bigintReplacer(_, arg) {
2+
if (typeof arg === 'bigint') {
3+
return Number(arg);
4+
}
5+
return arg;
6+
}
7+
18
export function makePrintLog() {
29
return function printLog(...args) {
310
const rendered = args.map(arg =>
4-
typeof arg === 'string' ? arg : JSON.stringify(arg),
11+
typeof arg === 'string' ? arg : JSON.stringify(arg, bigintReplacer),
512
);
613
console.log(rendered.join(''));
714
};

packages/swingset-runner/demo/zoeTests/printLog.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
function bigintReplacer(_, arg) {
2+
if (typeof arg === 'bigint') {
3+
return Number(arg);
4+
}
5+
return arg;
6+
}
7+
18
export function makePrintLog() {
29
return function printLog(...args) {
310
const rendered = args.map(arg =>
4-
typeof arg === 'string' ? arg : JSON.stringify(arg),
11+
typeof arg === 'string' ? arg : JSON.stringify(arg, bigintReplacer),
512
);
613
console.log(rendered.join(''));
714
};

0 commit comments

Comments
 (0)