ses 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -89,7 +89,6 @@ export type ImportHook = (moduleSpecifier: string) => Promise<StaticModuleType>;
89
89
  export interface CompartmentOptions {
90
90
  name?: string;
91
91
  transforms?: Array<Transform>;
92
- globalLexicals?: Record<string, any>;
93
92
  moduleMapHook?: ModuleMapHook;
94
93
  importHook?: ImportHook;
95
94
  resolveHook?: ResolveHook;
@@ -196,6 +195,7 @@ export interface Assert {
196
195
  template: TemplateStringsArray | string[],
197
196
  ...args: any
198
197
  ): DetailsToken;
198
+ Fail(template: TemplateStringsArray | string[], ...args: any): never;
199
199
  quote(payload: any, spaces?: string | number): ToStringable;
200
200
  makeAssert: MakeAssert;
201
201
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -59,9 +59,9 @@
59
59
  "test:platform-compatibility": "node test/package/test.cjs"
60
60
  },
61
61
  "devDependencies": {
62
- "@endo/compartment-mapper": "^0.7.15",
62
+ "@endo/compartment-mapper": "^0.8.0",
63
63
  "@endo/eslint-config": "^0.5.1",
64
- "@endo/static-module-record": "^0.7.14",
64
+ "@endo/static-module-record": "^0.7.15",
65
65
  "@endo/test262-runner": "^0.1.28",
66
66
  "ava": "^3.12.1",
67
67
  "babel-eslint": "^10.0.3",
@@ -75,8 +75,8 @@
75
75
  "prettier": "^1.19.1",
76
76
  "sinon": "8.0.4",
77
77
  "terser": "^4.8.0",
78
- "tsd": "^0.19.1",
79
- "typescript": "~4.6.2"
78
+ "tsd": "^0.24.1",
79
+ "typescript": "~4.8.4"
80
80
  },
81
81
  "files": [
82
82
  "LICENSE*",
@@ -179,5 +179,5 @@
179
179
  ],
180
180
  "timeout": "2m"
181
181
  },
182
- "gitHead": "8fb324d8f13a0c6939dc0c1feb831f72298f1853"
182
+ "gitHead": "da16a94856482e36296b7cae16d715aa63344928"
183
183
  }
@@ -3,7 +3,6 @@ import {
3
3
  TypeError,
4
4
  arrayPush,
5
5
  create,
6
- defineProperties,
7
6
  getOwnPropertyDescriptors,
8
7
  } from './commons.js';
9
8
  import {
@@ -28,9 +27,9 @@ export const provideCompartmentEvaluator = (compartmentFields, options) => {
28
27
  // shared evaluator so we need to build a new one
29
28
 
30
29
  let { globalTransforms } = compartmentFields;
31
- const { globalObject, globalLexicals } = compartmentFields;
30
+ const { globalObject } = compartmentFields;
32
31
 
33
- let localObject = globalLexicals;
32
+ let moduleLexicals;
34
33
  if (__moduleShimLexicals__ !== undefined) {
35
34
  // When using `evaluate` for ESM modules, as should only occur from the
36
35
  // module-shim's module-instance.js, we do not reveal the SES-shim's
@@ -42,16 +41,15 @@ export const provideCompartmentEvaluator = (compartmentFields, options) => {
42
41
  // and `import`, at the expense of being tightly coupled to SES-shim.
43
42
  globalTransforms = undefined;
44
43
 
45
- localObject = create(null, getOwnPropertyDescriptors(globalLexicals));
46
- defineProperties(
47
- localObject,
44
+ moduleLexicals = create(
45
+ null,
48
46
  getOwnPropertyDescriptors(__moduleShimLexicals__),
49
47
  );
50
48
  }
51
49
 
52
50
  ({ safeEvaluate } = makeSafeEvaluator({
53
51
  globalObject,
54
- globalLexicals: localObject,
52
+ moduleLexicals,
55
53
  globalTransforms,
56
54
  sloppyGlobalsMode,
57
55
  }));
@@ -7,13 +7,9 @@ import {
7
7
  ReferenceError,
8
8
  TypeError,
9
9
  WeakMap,
10
- arrayFilter,
11
- arrayJoin,
12
10
  assign,
13
11
  defineProperties,
14
12
  entries,
15
- freeze,
16
- getOwnPropertyNames,
17
13
  promiseThen,
18
14
  weakmapGet,
19
15
  weakmapSet,
@@ -24,7 +20,6 @@ import {
24
20
  setGlobalObjectMutableProperties,
25
21
  setGlobalObjectEvaluators,
26
22
  } from './global-object.js';
27
- import { isValidIdentifierName } from './scope-constants.js';
28
23
  import { sharedGlobalPropertyNames } from './whitelist.js';
29
24
  import { load } from './module-load.js';
30
25
  import { link } from './module-link.js';
@@ -207,7 +202,6 @@ export const makeCompartmentConstructor = (
207
202
  name = '<unknown>',
208
203
  transforms = [],
209
204
  __shimTransforms__ = [],
210
- globalLexicals: globalLexicalsOption = {},
211
205
  resolveHook,
212
206
  importHook,
213
207
  moduleMapHook,
@@ -246,28 +240,6 @@ export const makeCompartmentConstructor = (
246
240
  }
247
241
  }
248
242
 
249
- const invalidNames = arrayFilter(
250
- getOwnPropertyNames(globalLexicalsOption),
251
- identifier => !isValidIdentifierName(identifier),
252
- );
253
- if (invalidNames.length) {
254
- throw new TypeError(
255
- `Cannot create compartment with invalid names for global lexicals: ${arrayJoin(
256
- invalidNames,
257
- ', ',
258
- )}; these names would not be lexically mentionable`,
259
- );
260
- }
261
- // The caller continues to own the globalLexicals object they passed to
262
- // the compartment constructor, but the compartment only respects the
263
- // original values and they are constants in the scope of evaluated
264
- // programs and executed modules.
265
- // This shallow copy captures only the values of enumerable own
266
- // properties, erasing accessors.
267
- // The snapshot is frozen to ensure that the properties are immutable
268
- // when transferred-by-property-descriptor onto local scope objects.
269
- const globalLexicals = freeze({ ...globalLexicalsOption });
270
-
271
243
  const globalObject = {};
272
244
 
273
245
  setGlobalObjectSymbolUnscopables(globalObject);
@@ -281,7 +253,6 @@ export const makeCompartmentConstructor = (
281
253
 
282
254
  const { safeEvaluate } = makeSafeEvaluator({
283
255
  globalObject,
284
- globalLexicals,
285
256
  globalTransforms,
286
257
  sloppyGlobalsMode: false,
287
258
  });
@@ -306,7 +277,6 @@ export const makeCompartmentConstructor = (
306
277
  name: `${name}`,
307
278
  globalTransforms,
308
279
  globalObject,
309
- globalLexicals,
310
280
  safeEvaluate,
311
281
  resolveHook,
312
282
  importHook,
@@ -5,7 +5,7 @@
5
5
  import { arrayPush, freeze } from './commons.js';
6
6
  import { assert } from './error/assert.js';
7
7
 
8
- const { details: X, quote: q } = assert;
8
+ const { details: X, Fail, quote: q } = assert;
9
9
 
10
10
  /**
11
11
  * JavaScript module semantics resists attempts to parameterize a module's
@@ -109,12 +109,9 @@ export const makeEnvironmentCaptor = aGlobal => {
109
109
  }
110
110
  setting === undefined ||
111
111
  typeof setting === 'string' ||
112
- // eslint-disable-next-line @endo/no-polymorphic-call
113
- assert.fail(
114
- X`Environment option value ${q(
115
- setting,
116
- )}, if present, must be a string.`,
117
- );
112
+ Fail`Environment option value ${q(
113
+ setting,
114
+ )}, if present, must be a string.`;
118
115
  return setting;
119
116
  };
120
117
  freeze(getEnvironmentOption);
@@ -375,6 +375,9 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
375
375
  };
376
376
  freeze(fail);
377
377
 
378
+ /** @type {FailTag} */
379
+ const Fail = (template, ...args) => fail(details(template, ...args));
380
+
378
381
  // Don't freeze or export `baseAssert` until we add methods.
379
382
  // TODO If I change this from a `function` function to an arrow
380
383
  // function, I seem to get type errors from TypeScript. Why?
@@ -433,6 +436,7 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
433
436
  string: assertString,
434
437
  note,
435
438
  details,
439
+ Fail,
436
440
  quote,
437
441
  makeAssert,
438
442
  });
@@ -260,6 +260,64 @@
260
260
  * `string[]` can also be used as a template.
261
261
  */
262
262
 
263
+ /**
264
+ * @typedef {(template: TemplateStringsArray | string[], ...args: any) => never} FailTag
265
+ * The `Fail` tamplate tag supports replacing patterns like
266
+ * ```js
267
+ * assert(cond, X`...complaint...`);
268
+ * ```
269
+ * or
270
+ * ```js
271
+ * cond || assert.fail(X`...complaint...`);
272
+ * ```
273
+ * with patterns like
274
+ * ```js
275
+ * cond || Fail`...complaint...`;
276
+ * ```
277
+ *
278
+ * However, due to [weakness in current
279
+ * TypeScript](https://github.com/microsoft/TypeScript/issues/51426), the `||`
280
+ * patterns are not as powerful as the `assert(...)` call at enabling static
281
+ * reasoning. Of the `||`, again due to weaknesses in current TypeScript,
282
+ * the
283
+ * ```js
284
+ * cond || Fail`...complaint...`
285
+ * ```
286
+ * pattern is not as powerful as the
287
+ * ```js
288
+ * cond || assert.fail(X`...complaint...`);
289
+ * ```
290
+ * at enabling static resoning. Despite these problems, we do not want to
291
+ * return to the
292
+ * ```js
293
+ * assert(cond, X`...complaint...`)
294
+ * ```
295
+ * style because of the substantial overhead in
296
+ * evaluating the `X` template in the typical `true` case where it is not
297
+ * needed. And we do not want to return to the
298
+ * ```js
299
+ * assert.fail(X`...complaint...`)`
300
+ * ```
301
+ * because of the verbosity and loss of readability. Instead, until/unless
302
+ * https://github.com/microsoft/TypeScript/issues/51426 is fixed, for those
303
+ * new-style assertions where this loss of static reasoning is a problem,
304
+ * instead express the assertion as
305
+ * ```js
306
+ * if (!cond) {
307
+ * Fail`...complaint...`;
308
+ * }
309
+ * ```
310
+ * or, if needed,
311
+ * ```js
312
+ * if (!cond) {
313
+ * // `throw` is noop since `Fail` throws. But linter confused
314
+ * throw Fail`...complaint...`;
315
+ * }
316
+ * ```
317
+ * This avoid the TypeScript bugs that cause the loss of static reasoning,
318
+ * but with no loss of efficiency and little loss of readability.
319
+ */
320
+
263
321
  /**
264
322
  * assert that expr is truthy, with an optional details to describe
265
323
  * the assertion. It is a tagged template literal like
@@ -286,6 +344,7 @@
286
344
  * string: AssertString,
287
345
  * note: AssertNote,
288
346
  * details: DetailsTag,
347
+ * Fail: FailTag,
289
348
  * quote: AssertQuote,
290
349
  * makeAssert: MakeAssert,
291
350
  * } } Assert
package/src/eval-scope.js CHANGED
@@ -2,7 +2,7 @@ import { FERAL_EVAL, create, defineProperties, freeze } from './commons.js';
2
2
 
3
3
  import { assert } from './error/assert.js';
4
4
 
5
- const { details: d } = assert;
5
+ const { Fail } = assert;
6
6
 
7
7
  // We attempt to frustrate stack bumping attacks on the safe evaluator
8
8
  // (`make-safe-evaluator.js`).
@@ -73,10 +73,7 @@ export const makeEvalScopeKit = () => {
73
73
  evalScope,
74
74
  allowNextEvalToBeUnsafe() {
75
75
  if (evalScopeKit.revoked !== null) {
76
- // eslint-disable-next-line @endo/no-polymorphic-call
77
- assert.fail(
78
- d`a handler did not reset allowNextEvalToBeUnsafe ${this.revoked.err}`,
79
- );
76
+ Fail`a handler did not reset allowNextEvalToBeUnsafe ${this.revoked.err}`;
80
77
  }
81
78
  // Allow next reference to eval produce the unsafe FERAL_EVAL.
82
79
  // We avoid defineProperty because it consumes an extra stack frame taming
@@ -55,7 +55,7 @@ import { makeCompartmentConstructor } from './compartment-shim.js';
55
55
 
56
56
  /** @typedef {import('../index.js').LockdownOptions} LockdownOptions */
57
57
 
58
- const { details: d, quote: q } = assert;
58
+ const { Fail, details: d, quote: q } = assert;
59
59
 
60
60
  /** @type {Error=} */
61
61
  let priorLockdown;
@@ -82,7 +82,6 @@ const harden = makeHardener();
82
82
  * @param {Object} [options]
83
83
  * @param {Array<Transform>} [options.transforms]
84
84
  * @param {Array<Transform>} [options.__shimTransforms__]
85
- * @param {Object} [options.globalLexicals]
86
85
  */
87
86
 
88
87
  // TODO https://github.com/endojs/endo/issues/814
@@ -192,26 +191,23 @@ export const repairIntrinsics = (options = {}) => {
192
191
  );
193
192
  }
194
193
 
195
- assert(
196
- evalTaming === 'unsafeEval' ||
197
- evalTaming === 'safeEval' ||
198
- evalTaming === 'noEval',
199
- d`lockdown(): non supported option evalTaming: ${q(evalTaming)}`,
200
- );
194
+ evalTaming === 'unsafeEval' ||
195
+ evalTaming === 'safeEval' ||
196
+ evalTaming === 'noEval' ||
197
+ Fail`lockdown(): non supported option evalTaming: ${q(evalTaming)}`;
201
198
 
202
199
  // Assert that only supported options were passed.
203
200
  // Use Reflect.ownKeys to reject symbol-named properties as well.
204
201
  const extraOptionsNames = ownKeys(extraOptions);
205
- assert(
206
- extraOptionsNames.length === 0,
207
- d`lockdown(): non supported option ${q(extraOptionsNames)}`,
208
- );
202
+ extraOptionsNames.length === 0 ||
203
+ Fail`lockdown(): non supported option ${q(extraOptionsNames)}`;
209
204
 
210
- assert(
211
- priorLockdown === undefined,
212
- `Already locked down at ${priorLockdown} (SES_ALREADY_LOCKED_DOWN)`,
213
- TypeError,
214
- );
205
+ priorLockdown === undefined ||
206
+ // eslint-disable-next-line @endo/no-polymorphic-call
207
+ assert.fail(
208
+ d`Already locked down at ${priorLockdown} (SES_ALREADY_LOCKED_DOWN)`,
209
+ TypeError,
210
+ );
215
211
  priorLockdown = new TypeError('Prior lockdown (SES_ALREADY_LOCKED_DOWN)');
216
212
  // Tease V8 to generate the stack string and release the closures the stack
217
213
  // trace retained:
@@ -253,7 +249,6 @@ export const repairIntrinsics = (options = {}) => {
253
249
  };
254
250
 
255
251
  if (seemsToBeLockedDown()) {
256
- // eslint-disable-next-line @endo/no-polymorphic-call
257
252
  throw new TypeError(
258
253
  `Already locked down but not by this SES instance (SES_MULTIPLE_INSTANCES)`,
259
254
  );
@@ -26,22 +26,22 @@ function buildOptimizer(constants, name) {
26
26
  *
27
27
  * @param {object} context
28
28
  * @param {object} context.evalScope
29
- * @param {object} context.globalLexicals
29
+ * @param {object} context.moduleLexicals
30
30
  * @param {object} context.globalObject
31
31
  * @param {object} context.scopeTerminator
32
32
  */
33
33
  export const makeEvaluate = context => {
34
- const { globalObjectConstants, globalLexicalConstants } = getScopeConstants(
34
+ const { globalObjectConstants, moduleLexicalConstants } = getScopeConstants(
35
35
  context.globalObject,
36
- context.globalLexicals,
36
+ context.moduleLexicals,
37
37
  );
38
38
  const globalObjectOptimizer = buildOptimizer(
39
39
  globalObjectConstants,
40
40
  'globalObject',
41
41
  );
42
- const globalLexicalOptimizer = buildOptimizer(
43
- globalLexicalConstants,
44
- 'globalLexicals',
42
+ const moduleLexicalOptimizer = buildOptimizer(
43
+ moduleLexicalConstants,
44
+ 'moduleLexicals',
45
45
  );
46
46
 
47
47
  // Create a function in sloppy mode, so that we can use 'with'. It returns
@@ -57,7 +57,7 @@ export const makeEvaluate = context => {
57
57
  // trigger direct eval. The direct eval semantics is what allows the
58
58
  // evaluated code to lookup free variable names on the other scope
59
59
  // objects and not in global scope.
60
- // b) `globalLexicals` which provide a way to introduce free variables
60
+ // b) `moduleLexicals` which provide a way to introduce free variables
61
61
  // that are not available on the globalObject.
62
62
  // c) `globalObject` is the global scope object of the evaluator, aka the
63
63
  // Compartment's `globalThis`.
@@ -71,7 +71,7 @@ export const makeEvaluate = context => {
71
71
 
72
72
  // Notes:
73
73
  // - The `optimizer` strings only lookup values on the `globalObject` and
74
- // `globalLexicals` objects by construct. Keywords like 'function' are
74
+ // `moduleLexicals` objects by construct. Keywords like 'function' are
75
75
  // reserved and cannot be used as a variable, so they are excluded from the
76
76
  // optimizer. Furthermore to prevent shadowing 'eval', while a valid
77
77
  // identifier, that name is also explicitly excluded.
@@ -92,10 +92,10 @@ export const makeEvaluate = context => {
92
92
  const evaluateFactory = FERAL_FUNCTION(`
93
93
  with (this.scopeTerminator) {
94
94
  with (this.globalObject) {
95
- with (this.globalLexicals) {
95
+ with (this.moduleLexicals) {
96
96
  with (this.evalScope) {
97
97
  ${globalObjectOptimizer}
98
- ${globalLexicalOptimizer}
98
+ ${moduleLexicalOptimizer}
99
99
  return function() {
100
100
  'use strict';
101
101
  return eval(arguments[0]);
@@ -7,6 +7,8 @@ import {
7
7
  } from './commons.js';
8
8
  import { assert } from './error/assert.js';
9
9
 
10
+ const { Fail } = assert;
11
+
10
12
  /*
11
13
  * makeFunctionConstructor()
12
14
  * A safe version of the native Function which relies on
@@ -67,14 +69,10 @@ export const makeFunctionConstructor = safeEvaluate => {
67
69
  });
68
70
 
69
71
  // Assert identity of Function.__proto__ accross all compartments
70
- assert(
71
- getPrototypeOf(FERAL_FUNCTION) === FERAL_FUNCTION.prototype,
72
- 'Function prototype is the same accross compartments',
73
- );
74
- assert(
75
- getPrototypeOf(newFunction) === FERAL_FUNCTION.prototype,
76
- 'Function constructor prototype is the same accross compartments',
77
- );
72
+ getPrototypeOf(FERAL_FUNCTION) === FERAL_FUNCTION.prototype ||
73
+ Fail`Function prototype is the same accross compartments`;
74
+ getPrototypeOf(newFunction) === FERAL_FUNCTION.prototype ||
75
+ Fail`Function constructor prototype is the same accross compartments`;
78
76
 
79
77
  return newFunction;
80
78
  };
@@ -9,7 +9,7 @@ import { applyTransforms, mandatoryTransforms } from './transforms.js';
9
9
  import { makeEvaluate } from './make-evaluate.js';
10
10
  import { assert } from './error/assert.js';
11
11
 
12
- const { details: d } = assert;
12
+ const { Fail } = assert;
13
13
 
14
14
  /**
15
15
  * makeSafeEvaluator()
@@ -18,13 +18,13 @@ const { details: d } = assert;
18
18
  *
19
19
  * @param {Object} options
20
20
  * @param {Object} options.globalObject
21
- * @param {Object} [options.globalLexicals]
21
+ * @param {Object} [options.moduleLexicals]
22
22
  * @param {Array<Transform>} [options.globalTransforms]
23
23
  * @param {bool} [options.sloppyGlobalsMode]
24
24
  */
25
25
  export const makeSafeEvaluator = ({
26
26
  globalObject,
27
- globalLexicals = {},
27
+ moduleLexicals = {},
28
28
  globalTransforms = [],
29
29
  sloppyGlobalsMode = false,
30
30
  } = {}) => {
@@ -36,7 +36,7 @@ export const makeSafeEvaluator = ({
36
36
 
37
37
  const evaluateContext = freeze({
38
38
  evalScope,
39
- globalLexicals,
39
+ moduleLexicals,
40
40
  globalObject,
41
41
  scopeTerminator,
42
42
  });
@@ -100,8 +100,7 @@ export const makeSafeEvaluator = ({
100
100
  evalScopeKit.revoked = { err };
101
101
  // TODO A GOOD PLACE TO PANIC(), i.e., kill the vat incarnation.
102
102
  // See https://github.com/Agoric/SES-shim/issues/490
103
- // eslint-disable-next-line @endo/no-polymorphic-call
104
- assert.fail(d`handler did not reset allowNextEvalToBeUnsafe ${err}`);
103
+ Fail`handler did not reset allowNextEvalToBeUnsafe ${err}`;
105
104
  }
106
105
  }
107
106
  };
@@ -152,10 +152,10 @@ export const makeModuleInstance = (
152
152
  // object (eventually proxied).
153
153
  const exportsProps = create(null);
154
154
 
155
- // {_localName_: accessor} proxy traps for globalLexicals and live bindings.
156
- // The globalLexicals object is frozen and the corresponding properties of
157
- // localLexicals must be immutable, so we copy the descriptors.
158
- const localLexicals = create(null);
155
+ // {_localName_: accessor} proxy traps for moduleLexicals and live bindings.
156
+ // The moduleLexicals object is frozen and the corresponding properties of
157
+ // moduleLexicals must be immutable, so we copy the descriptors.
158
+ const moduleLexicals = create(null);
159
159
 
160
160
  // {_localName_: init(initValue) -> initValue} used by the
161
161
  // rewritten code to initialize exported fixed bindings.
@@ -321,7 +321,7 @@ export const makeModuleInstance = (
321
321
 
322
322
  localGetNotify[localName] = liveGetNotify;
323
323
  if (setProxyTrap) {
324
- defineProperty(localLexicals, localName, {
324
+ defineProperty(moduleLexicals, localName, {
325
325
  get,
326
326
  set,
327
327
  enumerable: true,
@@ -437,7 +437,7 @@ export const makeModuleInstance = (
437
437
  let optFunctor = compartmentEvaluate(compartmentFields, functorSource, {
438
438
  globalObject: compartment.globalThis,
439
439
  transforms: __shimTransforms__,
440
- __moduleShimLexicals__: localLexicals,
440
+ __moduleShimLexicals__: moduleLexicals,
441
441
  });
442
442
  let didThrow = false;
443
443
  let thrownError;
@@ -26,7 +26,7 @@ import {
26
26
  weakmapGet,
27
27
  } from './commons.js';
28
28
 
29
- const { quote: q } = assert;
29
+ const { Fail, quote: q } = assert;
30
30
 
31
31
  // `link` creates `ModuleInstances` and `ModuleNamespaces` for a module and its
32
32
  // transitive dependencies and connects their imports and exports.
@@ -70,18 +70,14 @@ function validatePrecompiledStaticModuleRecord(
70
70
  moduleSpecifier,
71
71
  ) {
72
72
  const { __fixedExportMap__, __liveExportMap__ } = staticModuleRecord;
73
- assert(
74
- isObject(__fixedExportMap__),
75
- `Property '__fixedExportMap__' of a precompiled module record must be an object, got ${q(
73
+ isObject(__fixedExportMap__) ||
74
+ Fail`Property '__fixedExportMap__' of a precompiled module record must be an object, got ${q(
76
75
  __fixedExportMap__,
77
- )}, for module ${q(moduleSpecifier)}`,
78
- );
79
- assert(
80
- isObject(__liveExportMap__),
81
- `Property '__liveExportMap__' of a precompiled module record must be an object, got ${q(
76
+ )}, for module ${q(moduleSpecifier)}`;
77
+ isObject(__liveExportMap__) ||
78
+ Fail`Property '__liveExportMap__' of a precompiled module record must be an object, got ${q(
82
79
  __liveExportMap__,
83
- )}, for module ${q(moduleSpecifier)}`,
84
- );
80
+ )}, for module ${q(moduleSpecifier)}`;
85
81
  }
86
82
 
87
83
  function isThirdParty(staticModuleRecord) {
@@ -93,40 +89,30 @@ function validateThirdPartyStaticModuleRecord(
93
89
  moduleSpecifier,
94
90
  ) {
95
91
  const { exports } = staticModuleRecord;
96
- assert(
97
- isArray(exports),
98
- `Property 'exports' of a third-party static module record must be an array, got ${q(
92
+ isArray(exports) ||
93
+ Fail`Property 'exports' of a third-party static module record must be an array, got ${q(
99
94
  exports,
100
- )}, for module ${q(moduleSpecifier)}`,
101
- );
95
+ )}, for module ${q(moduleSpecifier)}`;
102
96
  }
103
97
 
104
98
  function validateStaticModuleRecord(staticModuleRecord, moduleSpecifier) {
105
- assert(
106
- isObject(staticModuleRecord),
107
- `Static module records must be of type object, got ${q(
99
+ isObject(staticModuleRecord) ||
100
+ Fail`Static module records must be of type object, got ${q(
108
101
  staticModuleRecord,
109
- )}, for module ${q(moduleSpecifier)}`,
110
- );
102
+ )}, for module ${q(moduleSpecifier)}`;
111
103
  const { imports, exports, reexports = [] } = staticModuleRecord;
112
- assert(
113
- isArray(imports),
114
- `Property 'imports' of a static module record must be an array, got ${q(
104
+ isArray(imports) ||
105
+ Fail`Property 'imports' of a static module record must be an array, got ${q(
115
106
  imports,
116
- )}, for module ${q(moduleSpecifier)}`,
117
- );
118
- assert(
119
- isArray(exports),
120
- `Property 'exports' of a precompiled module record must be an array, got ${q(
107
+ )}, for module ${q(moduleSpecifier)}`;
108
+ isArray(exports) ||
109
+ Fail`Property 'exports' of a precompiled module record must be an array, got ${q(
121
110
  exports,
122
- )}, for module ${q(moduleSpecifier)}`,
123
- );
124
- assert(
125
- isArray(reexports),
126
- `Property 'reexports' of a precompiled module record must be an array if present, got ${q(
111
+ )}, for module ${q(moduleSpecifier)}`;
112
+ isArray(reexports) ||
113
+ Fail`Property 'reexports' of a precompiled module record must be an array if present, got ${q(
127
114
  reexports,
128
- )}, for module ${q(moduleSpecifier)}`,
129
- );
115
+ )}, for module ${q(moduleSpecifier)}`;
130
116
  }
131
117
 
132
118
  export const instantiate = (
@@ -27,7 +27,7 @@ import {
27
27
  } from './commons.js';
28
28
  import { assert } from './error/assert.js';
29
29
 
30
- const { details: d, quote: q } = assert;
30
+ const { Fail, details: d, quote: q } = assert;
31
31
 
32
32
  const noop = () => {};
33
33
 
@@ -170,12 +170,9 @@ const loadWithoutErrorAnnotation = async (
170
170
  const staticModuleRecord = await importHook(moduleSpecifier);
171
171
 
172
172
  if (staticModuleRecord === null || typeof staticModuleRecord !== 'object') {
173
- // eslint-disable-next-line @endo/no-polymorphic-call
174
- assert.fail(
175
- d`importHook must return a promise for an object, for module ${q(
176
- moduleSpecifier,
177
- )} in compartment ${q(compartment.name)}`,
178
- );
173
+ Fail`importHook must return a promise for an object, for module ${q(
174
+ moduleSpecifier,
175
+ )} in compartment ${q(compartment.name)}`;
179
176
  }
180
177
 
181
178
  if (staticModuleRecord.record !== undefined) {