Skip to content

Commit 8b2bedb

Browse files
authored
fix: endow with original unstructured assert (#2323)
Closes: #XXXX Refs: Agoric/agoric-sdk#9515 Agoric/agoric-sdk#9514 ## Description Addresses Agoric/agoric-sdk#9515 as applied to endo, by doing for endo what Agoric/agoric-sdk#9514 does for agoric-sdk To address Agoric/agoric-sdk#5672 for endo , we should change all applicable uses of `assert` to obtain `assert` by importing it from the `@endo/errors` package. However, attempts to do so ran into the symptoms reported at Agoric/agoric-sdk#9515 for the reasons reported there -- accidentally using the imported `assert` as the endowment for the global `assert` of new Compartments. This PR prepares the ground for these fixes to Agoric/agoric-sdk#5672 for endo by unambiguously endowing with the original unstructured `globalThis.assert`, which will remain the correct endowment even when other uses of `assert` have migrated to the one imported from `@endo/errors`. By itself, this PR, preceding those fixes to Agoric/agoric-sdk#5672 for endo , is not actually fixing a bug in the sense of a behavioral change. Reviewers, let me know if you think this PR should be labeled a "refactor" because of this. ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations anyone gathering endowments for a new compartment should be aware of this issue, and be sure to use `globalThis.assert` as the `assert` endowment. Fortunately, this will only be of concern to advanced developers. ### Testing Considerations Since this PR doesn't actually cause any behavioral change, it cannot be tested in place. Rather, its test will be whether #2324 still passes CI once rebased on this PR. ***Update***: #2324 is now passing CI well enough to consider this PR (#2323) to be adequately tested. ### Compatibility Considerations The point. This PR itself only prepares the ground for the equivalent of Agoric/agoric-sdk#9513 for endo. By itself it has no other effect, and so no other compat issues. ### Upgrade Considerations none
1 parent 8355aba commit 8b2bedb

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed

packages/cli/src/commands/run.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global process */
1+
/* global globalThis, process */
22
import url from 'url';
33
import os from 'os';
44
import { E, Far } from '@endo/far';
@@ -10,7 +10,8 @@ import { withEndoAgent } from '../context.js';
1010
import { parsePetNamePath } from '../pet-name.js';
1111

1212
const endowments = harden({
13-
assert,
13+
// See https://github.com/Agoric/agoric-sdk/issues/9515
14+
assert: globalThis.assert,
1415
E,
1516
Far,
1617
makeExo,

packages/compartment-mapper/test/main.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global globalThis */
2+
13
import 'ses';
24
import test from 'ava';
35
import { loadLocation, importArchive, makeBundle } from '../index.js';
@@ -96,7 +98,8 @@ test('makeBundle / importArchive', async t => {
9698
TextEncoder,
9799
TextDecoder,
98100
URL,
99-
assert,
101+
// See https://github.com/Agoric/agoric-sdk/issues/9515
102+
assert: globalThis.assert,
100103
});
101104
const evasiveArchiverBundle = archiverBundle
102105
.replace(/(?<!\.)\bimport\b(?![:"'])/g, 'IMPORT')

packages/daemon/src/web-page.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-check
2-
/* global window, document */
2+
/* global globalThis, window, document */
33

44
import '@endo/init/debug.js';
55
import { makeCapTP } from '@endo/captp';
@@ -56,7 +56,8 @@ const collectPropsAndBind = target => {
5656
};
5757

5858
const hardenedEndowments = harden({
59-
assert,
59+
// See https://github.com/Agoric/agoric-sdk/issues/9515
60+
assert: globalThis.assert,
6061
E,
6162
Far,
6263
makeExo,

packages/daemon/src/worker.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global globalThis */
12
// @ts-check
23
/// <reference types="ses"/>
34

@@ -12,7 +13,8 @@ import { WorkerFacetForDaemonInterface } from './interfaces.js';
1213
/** @import { EndoReadable, MignonicPowers } from './types.js' */
1314

1415
const endowments = harden({
15-
assert,
16+
// See https://github.com/Agoric/agoric-sdk/issues/9515
17+
assert: globalThis.assert,
1618
console,
1719
E,
1820
Far,

packages/eventual-send/src/track-turns.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {
55
} from '@endo/env-options';
66

77
// NOTE: We can't import these because they're not in scope before lockdown.
8-
// import { assert, details as X, Fail } from '@agoric/assert';
8+
// We also cannot currently import them because it would create a cyclic
9+
// dependency, though this is more easily fixed.
10+
// import { assert, X, Fail } from '@endo/errors';
11+
// See also https://github.com/Agoric/agoric-sdk/issues/9515
912

1013
// WARNING: Global Mutable State!
1114
// This state is communicated to `assert` that makes it available to the
@@ -33,7 +36,7 @@ const ENABLED =
3336

3437
const addRejectionNote = detailsNote => reason => {
3538
if (reason instanceof Error) {
36-
assert.note(reason, detailsNote);
39+
globalThis.assert.note(reason, detailsNote);
3740
}
3841
if (VERBOSE) {
3942
console.log('REJECTED at top of event loop', reason);
@@ -52,7 +55,7 @@ const wrapFunction =
5255
result = func(...args);
5356
} catch (err) {
5457
if (err instanceof Error) {
55-
assert.note(
58+
globalThis.assert.note(
5659
err,
5760
X`Thrown from: ${hiddenPriorError}:${hiddenCurrentTurn}.${hiddenCurrentEvent}`,
5861
);
@@ -90,14 +93,14 @@ export const trackTurns = funcs => {
9093
if (!ENABLED || typeof globalThis === 'undefined' || !globalThis.assert) {
9194
return funcs;
9295
}
93-
const { details: X } = assert;
96+
const { details: X, note: annotateError } = globalThis.assert;
9497

9598
hiddenCurrentEvent += 1;
9699
const sendingError = Error(
97100
`Event: ${hiddenCurrentTurn}.${hiddenCurrentEvent}`,
98101
);
99102
if (hiddenPriorError !== undefined) {
100-
assert.note(sendingError, X`Caused by: ${hiddenPriorError}`);
103+
annotateError(sendingError, X`Caused by: ${hiddenPriorError}`);
101104
}
102105

103106
return /** @type {T} */ (

packages/ses/demos/challenge/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global window, document */
1+
/* global globalThis, window, document */
22
/* eslint-disable no-plusplus */
33

44
// two approaches:
@@ -152,7 +152,8 @@ lockdown();
152152
harden(guess);
153153
const compartment = new Compartment({
154154
console,
155-
assert,
155+
// See https://github.com/Agoric/agoric-sdk/issues/9515
156+
assert: globalThis.assert,
156157
guess,
157158
...dateEndowment,
158159
});

packages/ses/demos/console/main.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals document */
1+
/* globals globalThis, document */
22

33
lockdown();
44
{
@@ -13,7 +13,11 @@ lockdown();
1313

1414
// Under the default `lockdown` settings, it is safe enough
1515
// to endow with the safe `console`.
16-
const compartment = new Compartment({ console, assert });
16+
const compartment = new Compartment({
17+
console,
18+
// See https://github.com/Agoric/agoric-sdk/issues/9515
19+
assert: globalThis.assert,
20+
});
1721

1822
execute.addEventListener('click', () => {
1923
const sourceText = input.value;

0 commit comments

Comments
 (0)