Skip to content

Commit

Permalink
fix(swingset): supervisor-xs: tolerate console.log(BigInt)
Browse files Browse the repository at this point in the history
We serialize console.log arguments (to send over the pipe to the kernel
process) with JSON.stringify, which doesn't tolerate BigInt. Use a simple
replacer to turn them into Numbers first; we can tolerate the loss of
fidelity for console.log.

closes #2936
  • Loading branch information
warner authored and dckc committed Jun 9, 2021
1 parent 5b177db commit bcbf9cf
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ function abbreviateReplacer(_, arg) {
return arg;
}

function bigIntReplacer(_, arg) {
if (typeof arg === 'bigint') {
return Number(arg);
}
return arg;
}

/**
* @param { ReturnType<typeof managerPort> } port
*/
Expand All @@ -124,7 +131,7 @@ function makeWorker(port) {
*/
function makeConsole(tag) {
const log = level => (...args) => {
const jsonSafeArgs = JSON.parse(`${q(args)}`);
const jsonSafeArgs = JSON.parse(JSON.stringify(args, bigIntReplacer));
port.send(['console', level, tag, ...jsonSafeArgs]);
};
const cons = {
Expand Down

0 comments on commit bcbf9cf

Please sign in to comment.