Skip to content

Commit

Permalink
fix: protect testLog against BigInts
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Feb 18, 2021
1 parent 4fa4daf commit 60c4684
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import { makeVatLoader } from './loadVat';
import { makeVatTranslators } from './vatTranslator';
import { makeDeviceTranslators } from './deviceTranslator';

function abbreviateReviver(_, arg) {
function abbreviateReplacer(_, arg) {
if (typeof arg === 'bigint') {
return Number(arg);
}
if (typeof arg === 'string' && arg.length >= 40) {
// truncate long strings
return `${arg.slice(0, 15)}...${arg.slice(arg.length - 15)}`;
Expand Down Expand Up @@ -138,7 +141,7 @@ export default function buildKernel(
// 'result' value returned by c.queueToExport()
function testLog(...args) {
const rendered = args.map(arg =>
typeof arg === 'string' ? arg : JSON.stringify(arg, abbreviateReviver),
typeof arg === 'string' ? arg : JSON.stringify(arg, abbreviateReplacer),
);
ephemeral.log.push(rendered.join(''));
}
Expand Down

0 comments on commit 60c4684

Please sign in to comment.