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 May 13, 2021
1 parent f533f76 commit c798e1a
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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 @@ -123,7 +130,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 c798e1a

Please sign in to comment.