Skip to content

Commit

Permalink
Merge pull request #4767 from Agoric/mfig-xsnap-logging
Browse files Browse the repository at this point in the history
Rework `xsnap/src/object-inspect.js`
  • Loading branch information
mergify[bot] authored Apr 9, 2022
2 parents f31c8bd + e075ea0 commit fa068d1
Show file tree
Hide file tree
Showing 12 changed files with 707 additions and 587 deletions.
4 changes: 2 additions & 2 deletions packages/SwingSet/test/snapshots/test-xsnap-store.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Generated by [AVA](https://avajs.dev).

> after SES boot - sensitive to SES-shim, XS, and supervisor
'e71b8f4b7b749dea1a295da4b66c6b7bef8b2eb812bba5ccf0a3d91c408ce43f'
'e728d42dcfad5a32fbce4767ede358a833a52e3d4f3e6e998651280a947d576c'

> after use of harden() - sensitive to SES-shim, XS, and supervisor
'7ddd8102ddb1f626ecf3833796d16abfd29cf74a8be3f55a1a13038092f73140'
'8ef12286ec4b89aad9679480c79f35e3198a7e6e6ad687b76f37fdf303599483'
Binary file modified packages/SwingSet/test/snapshots/test-xsnap-store.js.snap
Binary file not shown.
24 changes: 24 additions & 0 deletions packages/xsnap/lib/confined-object-inspect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import objectInspectSources from '../dist/src-object-inspect.js';

// Ensure the object inspector is confined.
const c = new Compartment();
harden(c.globalThis);

// Transform the imported inspector module source string into an evaluable
// string. We could have played more games with bundlers to do something less
// fragile, but even so, SES should fail-safe if this replacement doesn't match.
//
// The goal (presuming the file ends with a single export default statement):
// `...\n export default harden(inspect0);`
// becomes:
// `...\n /* export default */ harden(inspect0);`
// and we can evaluate it to obtain the completion value as the object inspector.
const src = objectInspectSources.replace(
/(^|\s)(export\s+default)(\s+)/g,
'$1/* $2 */$3',
);
const objectInspect = c.evaluate(
`${src}\n//# sourceURL=xsnap/src/object-inspect.js\n`,
);

export default objectInspect;
8 changes: 7 additions & 1 deletion packages/xsnap/lib/console-shim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* global globalThis, print */

import inspect from './object-inspect.js';
// Default implementation just stringifies.
let inspect = String;

// Allow the importer to override the inspect function.
export const setObjectInspector = objectInspector => {
inspect = objectInspector;
};

const printAll = (...args) => {
// Though xsnap doesn't have a whole console, it does have print().
Expand Down
Loading

0 comments on commit fa068d1

Please sign in to comment.