Skip to content

Commit

Permalink
fix: endow with original unstructured assert
Browse files Browse the repository at this point in the history
  • Loading branch information
erights committed Jun 15, 2024
1 parent 0850f10 commit 963ba73
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 16 deletions.
5 changes: 4 additions & 1 deletion packages/SwingSet/src/controller/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ export async function makeSwingsetController(
filePrefix: 'kernel/...',
endowments: {
console: makeConsole(`${debugPrefix}SwingSet:kernel`),
assert,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
require: kernelRequire,
URL: globalThis.Base64, // Unavailable only on XSnap
Base64: globalThis.Base64, // Available only on XSnap
Expand Down
11 changes: 10 additions & 1 deletion packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global globalThis */

import { assert, Fail } from '@agoric/assert';
import { isNat } from '@endo/nat';
import { importBundle } from '@endo/import-bundle';
Expand Down Expand Up @@ -1644,7 +1646,14 @@ export default function buildKernel(
assert(bundle);
const NS = await importBundle(bundle, {
filePrefix: `dev-${name}/...`,
endowments: harden({ ...vatEndowments, console: devConsole, assert }),
endowments: harden({
...vatEndowments,
console: devConsole,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
}),
});

if (deviceEndowments[name] || unendowed) {
Expand Down
5 changes: 4 additions & 1 deletion packages/SwingSet/src/kernel/vat-loader/manager-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export function makeLocalVatManagerFactory({
const workerEndowments = harden({
...vatEndowments,
console: makeVatConsole(makeLogMaker('vat')),
assert,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
TextEncoder,
TextDecoder,
Base64: globalThis.Base64, // Available only on XSnap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global WeakRef, FinalizationRegistry */
/* global globalThis, WeakRef, FinalizationRegistry */

// this file is loaded at the start of a new subprocess
import '@endo/init';
Expand Down Expand Up @@ -139,7 +139,10 @@ function handleSetBundle(margs) {
// Enable or disable the console accordingly.
const workerEndowments = {
console: makeVatConsole(makeLogMaker(`SwingSet:vat:${vatID}`)),
assert,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
};

async function buildVatNamespace(lsEndowments, inescapableGlobalProperties) {
Expand Down
12 changes: 9 additions & 3 deletions packages/SwingSet/test/zcf-ish-upgrade/pseudo-zcf.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// @ts-nocheck
/* global VatData */
/* global globalThis, VatData */
/* eslint-disable no-unused-vars */

import { Far } from '@endo/far';
import { importBundle } from '@endo/import-bundle';
import { defineDurableKind } from '@agoric/vat-data';
import { assert } from '@agoric/assert';
import {
provideHandle,
provideBaggageSubset as provideBaggageSubTree,
Expand All @@ -24,7 +23,14 @@ export const buildRootObject = async (vatPowers, vatParameters, baggage) => {
const { D } = vatPowers;
const { contractBundleCap } = vatParameters;
const contractBundle = D(contractBundleCap).getBundle();
const endowments = { console, assert, VatData };
const endowments = {
console,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
VatData,
};
const contractNS = await importBundle(contractBundle, { endowments });
const { setupInstallation, setup: _ } = contractNS;
if (!setupInstallation) {
Expand Down
7 changes: 6 additions & 1 deletion packages/cosmic-swingset/scripts/clean-core-eval.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env node
/* global globalThis */

import '@endo/init/debug.js';
import * as farExports from '@endo/far';
import { isEntrypoint } from '../src/helpers/is-entrypoint.js';
Expand All @@ -12,7 +14,10 @@ export const compartmentEvaluate = code => {
const globals = harden({
...modules,
...farExports,
assert,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
console: {
// Ensure we don't pollute stdout.
debug: console.warn,
Expand Down
5 changes: 4 additions & 1 deletion packages/spawner/src/vat-spawned.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { Far } from '@endo/marshal';
const endowments = {
VatData,
console,
assert,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
Base64: globalThis.Base64, // Present only on XSnap
URL: globalThis.URL, // Absent only on XSnap
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ function makeWorker(port) {

const workerEndowments = {
console: makeVatConsole(makeLogMaker('vat')),
assert,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
// bootstrap provides HandledPromise
HandledPromise: globalThis.HandledPromise,
TextEncoder,
Expand Down
5 changes: 4 additions & 1 deletion packages/vats/src/core/chain-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export const bridgeCoreEval = async allPowers => {
const endowments = {
VatData: globalThis.VatData,
console,
assert,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
Base64: globalThis.Base64, // Present only on XSnap
URL: globalThis.URL, // Absent only on XSnap
};
Expand Down
7 changes: 6 additions & 1 deletion packages/vats/src/repl.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global globalThis */

import { isPromise } from '@endo/promise-kit';
import { Far } from '@endo/far';
import { V as E } from '@agoric/vow/vat.js';
Expand Down Expand Up @@ -194,7 +196,10 @@ export function getReplHandler(replObjects, send) {
...farExports,
...vowExports,
E,
assert,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
console: replConsole,
commands,
history,
Expand Down
2 changes: 1 addition & 1 deletion packages/xsnap/src/avaAssertXS.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function makeTester(htest, out) {
fail(message) {
assert(false, message);
},
assert,
assert, // Not the SES assert
truthy,
/**
* @param {unknown} value
Expand Down
6 changes: 4 additions & 2 deletions packages/zoe/src/contractFacet/evalContractCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/* global globalThis */

import { importBundle } from '@endo/import-bundle';
import { assert } from '@agoric/assert';
import { handlePWarning } from '../handleWarning.js';

const evalContractBundle = (bundle, additionalEndowments = {}) => {
Expand All @@ -16,7 +15,10 @@ const evalContractBundle = (bundle, additionalEndowments = {}) => {

const defaultEndowments = {
console: louderConsole,
assert,
// This is the underlying unstructured assert that @endo/errors
// uses to build the structured assert that it exports. So we
// cannot use the assert imported from @endo/errors here.
assert: globalThis.assert,
VatData: globalThis.VatData,
};

Expand Down

0 comments on commit 963ba73

Please sign in to comment.