Skip to content

Commit 91f9fb9

Browse files
warnerdckc
authored andcommitted
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
1 parent 3714ed9 commit 91f9fb9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

packages/SwingSet/src/kernel/vatManager/supervisor-subprocess-xsnap.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ function abbreviateReplacer(_, arg) {
108108
return arg;
109109
}
110110

111+
function bigIntReplacer(_, arg) {
112+
if (typeof arg === 'bigint') {
113+
return Number(arg);
114+
}
115+
return arg;
116+
}
117+
111118
/**
112119
* @param { ReturnType<typeof managerPort> } port
113120
*/
@@ -122,8 +129,10 @@ function makeWorker(port) {
122129
* @param { string } tag
123130
*/
124131
function makeConsole(tag) {
125-
const log = level => (...args) =>
126-
port.send(['console', level, tag, ...args]);
132+
const log = level => (...args) => {
133+
const jsonSafeArgs = JSON.parse(JSON.stringify(args, bigIntReplacer));
134+
port.send(['console', level, tag, ...jsonSafeArgs]);
135+
};
127136
const cons = {
128137
debug: log('debug'),
129138
log: log('log'),

packages/SwingSet/test/workers/vat-target.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function ignore(p) {
1515

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

0 commit comments

Comments
 (0)