Skip to content

Commit

Permalink
fix(swingset): supervisor-xs: tolerate console.log(BigInt) (#2967)
Browse files Browse the repository at this point in the history
* 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

* chore(xs-worker): use assert.q replacer to handle bigint etc.

* test(swingset): console.log doesn't harden args

Co-authored-by: Brian Warner <[email protected]>
  • Loading branch information
dckc and warner authored Apr 27, 2021
1 parent b4f4f45 commit cddd949
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global globalThis WeakRef FinalizationRegistry */
// @ts-check
import { assert, details as X } from '@agoric/assert';
import { assert, details as X, q } from '@agoric/assert';
import { importBundle } from '@agoric/import-bundle';
import { makeMarshal } from '@agoric/marshal';
import '../../types';
Expand Down Expand Up @@ -122,8 +122,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(`${q(args)}`);
port.send(['console', level, tag, ...jsonSafeArgs]);
};
const cons = {
debug: log('debug'),
log: log('log'),
Expand Down
5 changes: 5 additions & 0 deletions packages/SwingSet/test/workers/vat-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ 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
const mutable = [];
console.log('list:', mutable); // make sure console.log doesn't harden args
mutable.push(1);
console.log('list+1:', mutable);
// note: XS doesn't appear to print console.log unless an exception happens
vatPowers.testLog('testLog works');

Expand Down

0 comments on commit cddd949

Please sign in to comment.