ses 1.14.0 → 2.0.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.
@@ -25,9 +25,10 @@ import {
25
25
  globalThis,
26
26
  is,
27
27
  isError,
28
- regexpTest,
28
+ regexpExec,
29
+ regexpReplace,
30
+ sealRegexp,
29
31
  stringIndexOf,
30
- stringReplace,
31
32
  stringSlice,
32
33
  stringStartsWith,
33
34
  weakmapDelete,
@@ -47,24 +48,28 @@ import './internal-types.js';
47
48
  import { makeNoteLogArgsArrayKit } from './note-log-args.js';
48
49
 
49
50
  /**
50
- * @import {BaseAssert, Assert, AssertionFunctions, AssertionUtilities, StringablePayload, DetailsToken, MakeAssert} from '../../types.js'
51
- * @import {LogArgs, NoteCallback, LoggedErrorHandler} from "./internal-types.js";
51
+ * @import {BaseAssert, Assert, AssertionFunctions, AssertionUtilities, DeprecatedAssertionUtilities, Stringable, DetailsToken, MakeAssert} from '../../types.js';
52
+ * @import {LogArgs, NoteCallback, LoggedErrorHandler} from './internal-types.js';
52
53
  */
53
54
 
54
- // For our internal debugging purposes, uncomment
55
+ // For internal debugging purposes, uncomment
55
56
  // const internalDebugConsole = console;
56
57
 
57
58
  // /////////////////////////////////////////////////////////////////////////////
58
59
 
59
- /** @type {WeakMap<StringablePayload, any>} */
60
+ /**
61
+ * Maps the result of a `quote` or `bare` call back to its input value.
62
+ *
63
+ * @type {WeakMap<Stringable, any>}
64
+ */
60
65
  const declassifiers = new WeakMap();
61
66
 
62
67
  /** @type {AssertionUtilities['quote']} */
63
- const quote = (payload, spaces = undefined) => {
68
+ const quote = (value, spaces = undefined) => {
64
69
  const result = freeze({
65
- toString: freeze(() => bestEffortStringify(payload, spaces)),
70
+ toString: freeze(() => bestEffortStringify(value, spaces)),
66
71
  });
67
- weakmapSet(declassifiers, result, payload);
72
+ weakmapSet(declassifiers, result, value);
68
73
  return result;
69
74
  };
70
75
  freeze(quote);
@@ -74,14 +79,14 @@ const canBeBare = freeze(/^[\w:-]( ?[\w:-])*$/);
74
79
  /**
75
80
  * @type {AssertionUtilities['bare']}
76
81
  */
77
- const bare = (payload, spaces = undefined) => {
78
- if (typeof payload !== 'string' || !regexpTest(canBeBare, payload)) {
79
- return quote(payload, spaces);
82
+ const bare = (text, spaces = undefined) => {
83
+ if (typeof text !== 'string' || !regexpExec(canBeBare, text)) {
84
+ return quote(text, spaces);
80
85
  }
81
86
  const result = freeze({
82
- toString: freeze(() => payload),
87
+ toString: freeze(() => text),
83
88
  });
84
- weakmapSet(declassifiers, result, payload);
89
+ weakmapSet(declassifiers, result, text);
85
90
  return result;
86
91
  };
87
92
  freeze(bare);
@@ -89,24 +94,28 @@ freeze(bare);
89
94
  // /////////////////////////////////////////////////////////////////////////////
90
95
 
91
96
  /**
92
- * @typedef {object} HiddenDetails
97
+ * @typedef {{ template: TemplateStringsArray | string[], args: any[] }} DetailsParts
93
98
  *
94
- * Captures the arguments passed to the `details` template string tag.
99
+ * The contents of a `details` template literal tag: literal strings (always at
100
+ * least one) and arbitrary substitution values from in between them.
95
101
  *
96
- * @property {TemplateStringsArray | string[]} template
97
- * @property {any[]} args
102
+ * Unquoted substitution values are sensitive (and are redacted in error
103
+ * `message` strings), so a DetailsPart must not leak outside of this file.
98
104
  */
99
105
 
100
106
  /**
101
- * @type {WeakMap<DetailsToken, HiddenDetails>}
107
+ * Maps the result of a `details` tagged template literal back to a record of
108
+ * that template literal's contents.
102
109
  *
103
- * Maps from a details token which a `details` template literal returned
104
- * to a record of the contents of that template literal expression.
110
+ * @type {WeakMap<DetailsToken, DetailsParts>}
105
111
  */
106
112
  const hiddenDetailsMap = new WeakMap();
107
113
 
108
114
  /**
109
- * @param {HiddenDetails} hiddenDetails
115
+ * Construct an error message string from `details` template literal contents,
116
+ * replacing unquoted substitution values with redactions.
117
+ *
118
+ * @param {DetailsParts} hiddenDetails
110
119
  * @returns {string}
111
120
  */
112
121
  const getMessageString = ({ template, args }) => {
@@ -127,16 +136,14 @@ const getMessageString = ({ template, args }) => {
127
136
  };
128
137
 
129
138
  /**
130
- * Give detailsTokens a toString behavior. To minimize the overhead of
131
- * creating new detailsTokens, we do this with an
132
- * inherited `this` sensitive `toString` method, even though we normally
133
- * avoid `this` sensitivity. To protect the method from inappropriate
134
- * `this` application, it does something interesting only for objects
135
- * registered in `redactedDetails`, which should be exactly the detailsTokens.
139
+ * Define `toString` behavior for DetailsToken. To minimize the overhead of
140
+ * creating new instances, we do this with an inherited `this`-sensitive method,
141
+ * even though we normally avoid such sensitivity. To protect the method from
142
+ * inappropriate application, it verifies that `this` is registered in
143
+ * `redactedDetails` before doing interesting work.
136
144
  *
137
- * The printing behavior must not reveal anything redacted, so we just use
138
- * the same `getMessageString` we use to construct the redacted message
139
- * string for a thrown assertion error.
145
+ * The behavior must not reveal anything redacted, so we use `getMessageString`
146
+ * to return the same value as the message for a thrown assertion-failure error.
140
147
  */
141
148
  const DetailsTokenProto = freeze({
142
149
  toString() {
@@ -156,16 +163,15 @@ freeze(DetailsTokenProto.toString);
156
163
  * given to `lockdown`, then `unredactedDetails` is used instead.
157
164
  *
158
165
  * There are some unconditional uses of `redactedDetails` in this module. All
159
- * of them should be uses where the template literal has no redacted
160
- * substitution values. In those cases, the two are equivalent.
166
+ * of them should be uses where the template literal has no redacted (unquoted)
167
+ * substitution values. In those cases, `redactedDetails` is equivalent to
168
+ * `unredactedDetails`.
161
169
  *
162
170
  * @type {AssertionUtilities['details']}
163
171
  */
164
172
  const redactedDetails = (template, ...args) => {
165
- // Keep in mind that the vast majority of calls to `details` creates
166
- // a details token that is never used, so this path must remain as fast as
167
- // possible. Hence we store what we've got with little processing, postponing
168
- // all the work to happen only if needed, for example, if an assertion fails.
173
+ // In case the result of this call is never used, perform as little processing
174
+ // as possible here to keep things fast.
169
175
  const detailsToken = freeze({ __proto__: DetailsTokenProto });
170
176
  weakmapSet(hiddenDetailsMap, detailsToken, { template, args });
171
177
  return /** @type {DetailsToken} */ (/** @type {unknown} */ (detailsToken));
@@ -195,8 +201,15 @@ const unredactedDetails = (template, ...args) => {
195
201
  freeze(unredactedDetails);
196
202
  export { unredactedDetails };
197
203
 
204
+ const leadingSpacePattern = sealRegexp(/^ /);
205
+ const trailingSpacePattern = sealRegexp(/ $/);
206
+
198
207
  /**
199
- * @param {HiddenDetails} hiddenDetails
208
+ * Get arguments suitable for a console logger function (e.g., `console.error`)
209
+ * from `details` template literal contents, unquoting quoted substitution
210
+ * values.
211
+ *
212
+ * @param {DetailsParts} hiddenDetails
200
213
  * @returns {LogArgs}
201
214
  */
202
215
  const getLogArgs = ({ template, args }) => {
@@ -206,14 +219,22 @@ const getLogArgs = ({ template, args }) => {
206
219
  if (weakmapHas(declassifiers, arg)) {
207
220
  arg = weakmapGet(declassifiers, arg);
208
221
  }
209
- // Remove the extra spaces (since console.error puts them
210
- // between each cause).
211
- const priorWithoutSpace = stringReplace(arrayPop(logArgs) || '', / $/, '');
212
- if (priorWithoutSpace !== '') {
213
- arrayPush(logArgs, priorWithoutSpace);
222
+ // Remove substitution-adjacent spaces from template fixed-string parts
223
+ // (since console logging inserts its own argument-separating spaces).
224
+ const prevLiteralPart = regexpReplace(
225
+ trailingSpacePattern,
226
+ arrayPop(logArgs) || '',
227
+ '',
228
+ );
229
+ if (prevLiteralPart !== '') {
230
+ arrayPush(logArgs, prevLiteralPart);
214
231
  }
215
- const nextWithoutSpace = stringReplace(template[i + 1], /^ /, '');
216
- arrayPush(logArgs, arg, nextWithoutSpace);
232
+ const nextLiteralPart = regexpReplace(
233
+ leadingSpacePattern,
234
+ template[i + 1],
235
+ '',
236
+ );
237
+ arrayPush(logArgs, arg, nextLiteralPart);
217
238
  }
218
239
  if (logArgs[logArgs.length - 1] === '') {
219
240
  arrayPop(logArgs);
@@ -222,11 +243,11 @@ const getLogArgs = ({ template, args }) => {
222
243
  };
223
244
 
224
245
  /**
225
- * @type {WeakMap<Error, LogArgs>}
246
+ * Maps from an error object to arguments suitable for a privileged console
247
+ * logger function such as `console.error`, including values that may be
248
+ * redacted in the error's `message`.
226
249
  *
227
- * Maps from an error object to the log args that are a more informative
228
- * alternative message for that error. When logging the error, these
229
- * log args should be preferred to `error.message`.
250
+ * @type {WeakMap<Error, LogArgs>}
230
251
  */
231
252
  const hiddenMessageLogArgs = new WeakMap();
232
253
 
@@ -297,27 +318,24 @@ export const sanitizeError = error => {
297
318
  for (const name of restNames) {
298
319
  delete error[name];
299
320
  }
300
- const droppedNote = create(objectPrototype, restDescs);
321
+ const dropped = create(objectPrototype, restDescs);
322
+ const droppedDetails = redactedDetails`originally with properties ${quote(dropped)}`;
301
323
  // eslint-disable-next-line no-use-before-define
302
- note(
303
- error,
304
- redactedDetails`originally with properties ${quote(droppedNote)}`,
305
- );
324
+ note(error, droppedDetails);
306
325
  }
307
326
  for (const name of ownKeys(error)) {
308
- // @ts-expect-error TS still confused by symbols as property names
327
+ // @ts-expect-error TypeScript is still confused by symbols as property keys
309
328
  const desc = descs[name];
310
329
  if (desc && hasOwn(desc, 'get')) {
311
- defineProperty(error, name, {
312
- value: error[name], // invoke the getter to convert to data property
313
- });
330
+ const value = error[name]; // invokes the getter
331
+ defineProperty(error, name, { value });
314
332
  }
315
333
  }
316
334
  freeze(error);
317
335
  };
318
336
 
319
337
  /**
320
- * @type {AssertionUtilities['error']}
338
+ * @type {AssertionUtilities['makeError']}
321
339
  */
322
340
  const makeError = (
323
341
  optDetails = redactedDetails`Assert failed`,
@@ -329,9 +347,9 @@ const makeError = (
329
347
  sanitize = true,
330
348
  } = {},
331
349
  ) => {
350
+ // Promote string-valued `optDetails` into a minimal DetailsParts
351
+ // consisting of that string as the sole literal part with no substitutions.
332
352
  if (typeof optDetails === 'string') {
333
- // If it is a string, use it as the literal part of the template so
334
- // it doesn't get quoted.
335
353
  optDetails = redactedDetails([optDetails]);
336
354
  }
337
355
  const hiddenDetails = weakmapGet(hiddenDetailsMap, optDetails);
@@ -347,13 +365,11 @@ const makeError = (
347
365
  ) {
348
366
  error = AggregateError(errors || [], messageString, opts);
349
367
  } else {
350
- error = /** @type {ErrorConstructor} */ (errConstructor)(
351
- messageString,
352
- opts,
353
- );
368
+ const ErrorCtor = /** @type {ErrorConstructor} */ (errConstructor);
369
+ error = ErrorCtor(messageString, opts);
370
+ // Since we need to tolerate `errors` on an AggregateError, we may as well
371
+ // tolerate it on all errors.
354
372
  if (errors !== undefined) {
355
- // Since we need to tolerate `errors` on an AggregateError, may as
356
- // well tolerate it on all errors.
357
373
  defineProperty(error, 'errors', {
358
374
  value: errors,
359
375
  writable: true,
@@ -376,11 +392,10 @@ freeze(makeError);
376
392
 
377
393
  // /////////////////////////////////////////////////////////////////////////////
378
394
 
379
- const { addLogArgs, takeLogArgsArray } = makeNoteLogArgsArrayKit();
395
+ const { addLogArgs: addNoteLogArgs, takeLogArgsArray: takeAllNoteLogArgs } =
396
+ makeNoteLogArgsArrayKit();
380
397
 
381
398
  /**
382
- * @type {WeakMap<Error, NoteCallback[]>}
383
- *
384
399
  * An augmented console will normally only take the hidden noteArgs array once,
385
400
  * when it logs the error being annotated. Once that happens, further
386
401
  * annotations of that error should go to the console immediately. We arrange
@@ -389,14 +404,16 @@ const { addLogArgs, takeLogArgsArray } = makeNoteLogArgsArrayKit();
389
404
  * callback per error, but that depends on console behavior which we should not
390
405
  * assume. We make this an array of callbacks so multiple registrations
391
406
  * are independent.
407
+ *
408
+ * @type {WeakMap<Error, NoteCallback[]>}
392
409
  */
393
- const hiddenNoteCallbackArrays = new WeakMap();
410
+ const hiddenNoteCallbacks = new WeakMap();
394
411
 
395
412
  /** @type {AssertionUtilities['note']} */
396
413
  const note = (error, detailsNote) => {
414
+ // Promote string-valued `detailsNote` into a minimal DetailsParts consisting
415
+ // of that string as the sole literal part with no substitutions.
397
416
  if (typeof detailsNote === 'string') {
398
- // If it is a string, use it as the literal part of the template so
399
- // it doesn't get quoted.
400
417
  detailsNote = redactedDetails([detailsNote]);
401
418
  }
402
419
  const hiddenDetails = weakmapGet(hiddenDetailsMap, detailsNote);
@@ -404,13 +421,13 @@ const note = (error, detailsNote) => {
404
421
  throw TypeError(`unrecognized details ${quote(detailsNote)}`);
405
422
  }
406
423
  const logArgs = getLogArgs(hiddenDetails);
407
- const callbacks = weakmapGet(hiddenNoteCallbackArrays, error);
424
+ const callbacks = weakmapGet(hiddenNoteCallbacks, error);
408
425
  if (callbacks !== undefined) {
409
426
  for (const callback of callbacks) {
410
427
  callback(error, logArgs);
411
428
  }
412
429
  } else {
413
- addLogArgs(error, logArgs);
430
+ addNoteLogArgs(error, logArgs);
414
431
  }
415
432
  };
416
433
  freeze(note);
@@ -444,21 +461,21 @@ const loggedErrorHandler = {
444
461
  },
445
462
  getMessageLogArgs: error => weakmapGet(hiddenMessageLogArgs, error),
446
463
  takeMessageLogArgs: error => {
447
- const result = weakmapGet(hiddenMessageLogArgs, error);
464
+ const logArgs = weakmapGet(hiddenMessageLogArgs, error);
448
465
  weakmapDelete(hiddenMessageLogArgs, error);
449
- return result;
466
+ return logArgs;
450
467
  },
451
468
  takeNoteLogArgsArray: (error, callback) => {
452
- const result = takeLogArgsArray(error);
469
+ const logArgsArray = takeAllNoteLogArgs(error);
453
470
  if (callback !== undefined) {
454
- const callbacks = weakmapGet(hiddenNoteCallbackArrays, error);
471
+ const callbacks = weakmapGet(hiddenNoteCallbacks, error);
455
472
  if (callbacks) {
456
473
  arrayPush(callbacks, callback);
457
474
  } else {
458
- weakmapSet(hiddenNoteCallbackArrays, error, [callback]);
475
+ weakmapSet(hiddenNoteCallbacks, error, [callback]);
459
476
  }
460
477
  }
461
- return result || [];
478
+ return logArgsArray || [];
462
479
  },
463
480
  };
464
481
  freeze(loggedErrorHandler);
@@ -469,7 +486,7 @@ export { loggedErrorHandler };
469
486
  /**
470
487
  * @type {MakeAssert}
471
488
  */
472
- const makeAssert = (optRaise = undefined, unredacted = false) => {
489
+ export const makeAssert = (optRaise = undefined, unredacted = false) => {
473
490
  const details = unredacted ? unredactedDetails : redactedDetails;
474
491
  const assertFailedDetails = details`Check failed`;
475
492
 
@@ -481,7 +498,6 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
481
498
  ) => {
482
499
  const reason = makeError(optDetails, errConstructor, options);
483
500
  if (optRaise !== undefined) {
484
- // @ts-ignore returns `never` doesn't mean it isn't callable
485
501
  optRaise(reason);
486
502
  }
487
503
  throw reason;
@@ -491,18 +507,16 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
491
507
  /** @type {AssertionUtilities['Fail']} */
492
508
  const Fail = (template, ...args) => fail(details(template, ...args));
493
509
 
494
- // Don't freeze or export `baseAssert` until we add methods.
495
- // TODO If I change this from a `function` function to an arrow
496
- // function, I seem to get type errors from TypeScript. Why?
510
+ // Don't freeze or export `assert` until we add methods.
497
511
  /** @type {BaseAssert} */
498
- function baseAssert(
499
- flag,
512
+ const assert = (
513
+ condition,
500
514
  optDetails = undefined,
501
515
  errConstructor = undefined,
502
516
  options = undefined,
503
- ) {
504
- flag || fail(optDetails, errConstructor, options);
505
- }
517
+ ) => {
518
+ condition || fail(optDetails, errConstructor, options);
519
+ };
506
520
 
507
521
  /** @type {AssertionFunctions['equal']} */
508
522
  const equal = (
@@ -544,25 +558,36 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
544
558
  const assertString = (specimen, optDetails = undefined) =>
545
559
  assertTypeof(specimen, 'string', optDetails);
546
560
 
547
- // Note that "assert === baseAssert"
548
- /** @type {Assert} */
549
- const assert = assign(baseAssert, {
550
- error: makeError,
551
- fail,
561
+ /** @type {Pick<AssertionFunctions, keyof AssertionFunctions>} */
562
+ const assertionFunctions = {
552
563
  equal,
553
564
  typeof: assertTypeof,
554
565
  string: assertString,
566
+ fail,
567
+ };
568
+
569
+ /** @type {AssertionUtilities} */
570
+ const assertionUtilities = {
571
+ makeError,
555
572
  note,
556
573
  details,
557
574
  Fail,
558
575
  quote,
559
576
  bare,
560
- makeAssert,
577
+ };
578
+
579
+ /** @type {DeprecatedAssertionUtilities} */
580
+ const deprecated = { error: makeError, makeAssert };
581
+
582
+ /** @type {Assert} */
583
+ const finishedAssert = assign(assert, {
584
+ ...assertionFunctions,
585
+ ...assertionUtilities,
586
+ ...deprecated,
561
587
  });
562
- return freeze(assert);
588
+ return freeze(finishedAssert);
563
589
  };
564
590
  freeze(makeAssert);
565
- export { makeAssert };
566
591
 
567
592
  /** @type {Assert} */
568
593
  const assert = makeAssert();
@@ -21,12 +21,12 @@ import {
21
21
  toStringTagSymbol,
22
22
  } from '../commons.js';
23
23
 
24
- /** @import {StringablePayload} from '../../types.js' */
24
+ /** @import {Stringable} from '../../types.js' */
25
25
 
26
26
  /**
27
27
  * Joins English terms with commas and an optional conjunction.
28
28
  *
29
- * @param {(string | StringablePayload)[]} terms
29
+ * @param {(string | Stringable)[]} terms
30
30
  * @param {"and" | "or"} conjunction
31
31
  */
32
32
  export const enJoin = (terms, conjunction) => {
@@ -11,7 +11,6 @@ import {
11
11
  fromEntries,
12
12
  reflectSet,
13
13
  regexpExec,
14
- regexpTest,
15
14
  weakmapGet,
16
15
  weakmapSet,
17
16
  weaksetAdd,
@@ -102,12 +101,12 @@ const FILENAME_CENSORS = [
102
101
  // Exported only so it can be unit tested.
103
102
  // TODO Move so that it applies not just to v8.
104
103
  export const filterFileName = fileName => {
105
- if (!fileName) {
106
- // Stack frames with no fileName should appear in concise stack traces.
107
- return true;
104
+ if (fileName === null) {
105
+ // Seems to suppress builtins like `Array.every (<anonymous>)`
106
+ return false;
108
107
  }
109
108
  for (const filter of FILENAME_CENSORS) {
110
- if (regexpTest(filter, fileName)) {
109
+ if (regexpExec(filter, fileName)) {
111
110
  return false;
112
111
  }
113
112
  }
@@ -118,9 +117,9 @@ export const filterFileName = fileName => {
118
117
  // likely url-path prefix, ending in a `/.../` should get dropped.
119
118
  // Anything to the left of the likely path text is kept.
120
119
  // Everything to the right of `/.../` is kept. Thus
121
- // `'Object.bar (/vat-v1/.../eventual-send/test/deep-send.test.js:13:21)'`
120
+ // `'Object.bar (/vat-v1/.../errors/test/deep-send.test.js:13:21)'`
122
121
  // simplifies to
123
- // `'Object.bar (eventual-send/test/deep-send.test.js:13:21)'`.
122
+ // `'Object.bar (errors/test/deep-send.test.js:13:21)'`.
124
123
  //
125
124
  // See thread starting at
126
125
  // https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
@@ -130,9 +129,9 @@ const CALLSITE_ELLIPSIS_PATTERN1 = /^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/;
130
129
  // likely url-path prefix consisting of `.../` should get dropped.
131
130
  // Anything to the left of the likely path text is kept.
132
131
  // Everything to the right of `.../` is kept. Thus
133
- // `'Object.bar (.../eventual-send/test/deep-send.test.js:13:21)'`
132
+ // `'Object.bar (.../errors/test/deep-send.test.js:13:21)'`
134
133
  // simplifies to
135
- // `'Object.bar (eventual-send/test/deep-send.test.js:13:21)'`.
134
+ // `'Object.bar (errors/test/deep-send.test.js:13:21)'`.
136
135
  //
137
136
  // See thread starting at
138
137
  // https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
@@ -143,9 +142,9 @@ const CALLSITE_ELLIPSIS_PATTERN2 = /^((?:.*[( ])?)\.\.\.\/(.+)$/;
143
142
  // dropped.
144
143
  // Anything to the left of the likely path prefix text is kept. `package/` and
145
144
  // everything to its right is kept. Thus
146
- // `'Object.bar (/Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/eventual-send/test/deep-send.test.js:13:21)'`
145
+ // `'Object.bar (/Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/errors/test/deep-send.test.js:13:21)'`
147
146
  // simplifies to
148
- // `'Object.bar (packages/eventual-send/test/deep-send.test.js:13:21)'`.
147
+ // `'Object.bar (packages/errors/test/deep-send.test.js:13:21)'`.
149
148
  // Note that `/packages/` is a convention for monorepos encouraged by
150
149
  // lerna.
151
150
  const CALLSITE_PACKAGES_PATTERN = /^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/;
@@ -155,7 +154,7 @@ const CALLSITE_PACKAGES_PATTERN = /^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/;
155
154
  // dropped.
156
155
  // Anything to the left of the likely path prefix text is kept. Everything to
157
156
  // the right of `file://` is kept. Thus
158
- // `'Object.bar (file:///Users/markmiller/src/ongithub/endojs/endo/packages/eventual-send/test/deep-send.test.js:13:21)'` is unchanged but
157
+ // `'Object.bar (file:///Users/markmiller/src/ongithub/endojs/endo/packages/errors/test/deep-send.test.js:13:21)'` is unchanged but
159
158
  // `'Object.bar (file://test/deep-send.test.js:13:21)'`
160
159
 
161
160
  // simplifies to
@@ -221,6 +220,10 @@ export const tameV8ErrorConstructor = (
221
220
  // const callSiteFilter = _callSite => true;
222
221
  const callSiteFilter = callSite => {
223
222
  if (omitFrames) {
223
+ // eslint-disable-next-line @endo/no-polymorphic-call
224
+ if (callSite.getFunctionName()?.startsWith('__HIDE_')) {
225
+ return false;
226
+ }
224
227
  // eslint-disable-next-line @endo/no-polymorphic-call
225
228
  return filterFileName(callSite.getFileName());
226
229
  }
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
 
3
- /** @import {GenericErrorConstructor, AssertMakeErrorOptions, DetailsToken, StringablePayload} from '../../types.js' */
3
+ /** @import {GenericErrorConstructor, AssertMakeErrorOptions, DetailsToken, Stringable} from '../../types.js' */
4
4
 
5
5
  /**
6
6
  * @typedef {object} VirtualConsole
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  FERAL_FUNCTION,
3
- Float32Array,
3
+ FERAL_FLOAT64_ARRAY,
4
4
  Map,
5
5
  Set,
6
6
  String,
@@ -72,7 +72,7 @@ export const getAnonymousIntrinsics = () => {
72
72
 
73
73
  // 22.2.1 The %TypedArray% Intrinsic Object
74
74
 
75
- const TypedArray = getPrototypeOf(Float32Array);
75
+ const TypedArray = getPrototypeOf(FERAL_FLOAT64_ARRAY);
76
76
 
77
77
  // 23.1.5.2 The %MapIteratorPrototype% Object
78
78
 
@@ -168,7 +168,6 @@ export const getAnonymousIntrinsics = () => {
168
168
  }
169
169
 
170
170
  const ab = new ArrayBuffer(0);
171
- // @ts-expect-error TODO How do I add sliceToImmutable to ArrayBuffer type?
172
171
  // eslint-disable-next-line @endo/no-polymorphic-call
173
172
  const iab = ab.sliceToImmutable();
174
173
  const iabProto = getPrototypeOf(iab);
package/src/lockdown.js CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  is,
26
26
  ownKeys,
27
27
  stringSplit,
28
+ symbolFor,
28
29
  noEvalEvaluate,
29
30
  getOwnPropertyNames,
30
31
  getPrototypeOf,
@@ -35,6 +36,7 @@ import removeUnpermittedIntrinsics from './permits-intrinsics.js';
35
36
  import tameFunctionConstructors from './tame-function-constructors.js';
36
37
  import tameDateConstructor from './tame-date-constructor.js';
37
38
  import tameMathObject from './tame-math-object.js';
39
+ import { tameNaNSideChannel } from './tame-nan-sidechannel.js';
38
40
  import tameRegExpConstructor from './tame-regexp-constructor.js';
39
41
  import enablePropertyOverrides from './enable-property-overrides.js';
40
42
  import tameLocaleMethods from './tame-locale-methods.js';
@@ -352,6 +354,7 @@ export const repairIntrinsics = (options = {}) => {
352
354
  addIntrinsics(tameDateConstructor());
353
355
  addIntrinsics(tameErrorConstructor(errorTaming, stackFiltering));
354
356
  addIntrinsics(tameMathObject());
357
+ tameNaNSideChannel();
355
358
  addIntrinsics(tameRegExpConstructor(regExpTaming));
356
359
  addIntrinsics(tameSymbolConstructor());
357
360
  addIntrinsics(shimArrayBufferTransfer());
@@ -363,6 +366,30 @@ export const repairIntrinsics = (options = {}) => {
363
366
 
364
367
  const intrinsics = finalIntrinsics();
365
368
 
369
+ // Install Object[@harden] or abort.
370
+ const symbolForHarden = symbolFor('harden');
371
+ const priorHarden = intrinsics.Object[symbolForHarden];
372
+ if (priorHarden) {
373
+ // By convention, if a module like @endo/harden gets used before lockdown,
374
+ // it will install itself as a non-configurable, non-writable property over
375
+ // Object[@harden] so that versions of SES predating the introduction of
376
+ // Object[@harden] will fail to lockdown because they cannot remove an
377
+ // unknown intrinsic.
378
+ // All newer versions explicitly check for Object[@harden] (here).
379
+ // The @endo/harden implementation additionally captures a stack trace
380
+ // where harden was first used to assist developers in tracking down the
381
+ // hardened module that was initialized before lockdown.
382
+ if (priorHarden.lockdownError) {
383
+ throw priorHarden.lockdownError;
384
+ }
385
+ // And in the event a library installs Object[@harden] without leaving a
386
+ // hint, we fall back to a generic lockdown error.
387
+ throw new TypeError(
388
+ 'Cannot lockdown (repairIntrinsics) if a prior harden implementation has been used and installed. Check for libraries using @endo/harden before lockdown.',
389
+ );
390
+ }
391
+ intrinsics.Object[symbolForHarden] = tamedHarden;
392
+
366
393
  const hostIntrinsics = { __proto__: null };
367
394
 
368
395
  // The Node.js Buffer is a derived class of Uint8Array, and as such is often
@@ -404,19 +431,16 @@ export const repairIntrinsics = (options = {}) => {
404
431
  );
405
432
  }
406
433
 
434
+ // The default `assert` installed by `assert-shim.js` does not redact errors,
435
+ // leaving `lockdown` or `repairIntrinsics` with the obligation to replace it
436
+ // with a redacting version, unless the caller opts-out with errorTaming set
437
+ // to `unsafe` or `unsafe-debug`.
438
+ // The inverse was true through version 1.13.0, except the configuration
439
+ // was disregarded and the redacting `assert` left in place if lexical
440
+ // `assert` differed from `globalThis.assert`.
407
441
  // @ts-ignore assert is absent on globalThis type def.
408
- if (
409
- (errorTaming === 'unsafe' || errorTaming === 'unsafe-debug') &&
410
- globalThis.assert === assert
411
- ) {
412
- // If errorTaming is 'unsafe' or 'unsafe-debug' we replace the
413
- // global assert with
414
- // one whose `details` template literal tag does not redact
415
- // unmarked substitution values. IOW, it blabs information that
416
- // was supposed to be secret from callers, as an aid to debugging
417
- // at a further cost in safety.
418
- // @ts-ignore assert is absent on globalThis type def.
419
- globalThis.assert = makeAssert(undefined, true);
442
+ if (errorTaming !== 'unsafe' && errorTaming !== 'unsafe-debug') {
443
+ globalThis.assert = makeAssert();
420
444
  }
421
445
 
422
446
  // Replace *Locale* methods with their non-locale equivalents