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 committed Apr 23, 2021
1 parent 51d06e8 commit 668d86b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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 @@ -122,8 +129,10 @@ function makeWorker(port) {
* @param { string } tag
*/
function makeConsole(tag) {
const log = level => (...args) =>
port.send(['console', level, tag, ...args]);
const log = level => (...args) => {
const jsonSafeArgs = JSON.parse(JSON.stringify(args, bigIntReplacer));
port.send(['console', level, tag, ...jsonSafeArgs]);
};
const cons = {
debug: log('debug'),
log: log('log'),
Expand Down
1 change: 1 addition & 0 deletions packages/SwingSet/test/workers/vat-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function ignore(p) {

export function buildRootObject(vatPowers, vatParameters) {
console.log(`vat does buildRootObject`); // make sure console works
console.log(BigInt(0)); // make sure BigInt is tolerated: #2936
// note: XS doesn't appear to print console.log unless an exception happens
vatPowers.testLog('testLog works');

Expand Down

0 comments on commit 668d86b

Please sign in to comment.