Skip to content

Commit

Permalink
fix(xsnap): use object-inspect to render print output better
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jan 25, 2022
1 parent d563783 commit 3c3a353
Show file tree
Hide file tree
Showing 8 changed files with 556 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ function makeWorker(port) {
const makeLogMaker = dst => {
/** @param {string} level */
const makeLog = level => {
// Capture the `console.log`, etc.'s `printAll` function.
const printAll = console[level];
assert.typeof(printAll, 'function');
const portSendingPrinter = (...args) => {
Expand Down
20 changes: 5 additions & 15 deletions packages/xsnap/lib/console-shim.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* global globalThis, print */

// We use setQuote() below to break the cycle
// where SES requires console and console is
// implemented using assert.quote from SES.
let quote = _v => '[?]';
import inspect from './object-inspect.js';

const printAll = (...args) => {
// Though xsnap doesn't have a whole console, it does have print().
//
// We use inspect to render non-string arguments to strings.
//
// eslint-disable-next-line no-restricted-globals
print(...args.map(v => (typeof v === 'string' ? v : quote(v))));
print(...args.map(v => (typeof v === 'string' ? v : inspect(v))));
};

const noop = _ => {};
Expand Down Expand Up @@ -50,14 +50,4 @@ const console = {
timeStamp: noop,
};

let quoteSet = false;

export function setQuote(f) {
if (quoteSet) {
throw TypeError('quote already set');
}
quote = f;
quoteSet = true;
}

globalThis.console = console;
Loading

0 comments on commit 3c3a353

Please sign in to comment.