From 51ac887f355a9ece4ac05d41d6a446b36b331e97 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 21 Apr 2021 19:49:05 -0700 Subject: [PATCH] fix(swingset): supervisor-xs: tolerate console.log(BigInt) 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 --- .../vatManager/supervisor-subprocess-xsnap.js | 13 +++++++++++-- packages/SwingSet/test/workers/vat-target.js | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js b/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js index d4709f4059d4..8a1b7de9f3f0 100644 --- a/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js +++ b/packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js @@ -108,6 +108,13 @@ function abbreviateReplacer(_, arg) { return arg; } +function bigIntReplacer(_, arg) { + if (typeof arg === 'bigint') { + return Number(arg); + } + return arg; +} + /** * @param { ReturnType } port */ @@ -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'), diff --git a/packages/SwingSet/test/workers/vat-target.js b/packages/SwingSet/test/workers/vat-target.js index 20f6629cb95f..187ca9e2a16b 100644 --- a/packages/SwingSet/test/workers/vat-target.js +++ b/packages/SwingSet/test/workers/vat-target.js @@ -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');