ses 1.1.0 → 1.3.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/NEWS.md +27 -0
- package/README.md +1 -1
- package/dist/lockdown.cjs +525 -341
- package/dist/lockdown.mjs +525 -341
- package/dist/lockdown.umd.js +525 -341
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +525 -341
- package/dist/ses.mjs +525 -341
- package/dist/ses.umd.js +525 -341
- package/dist/ses.umd.min.js +1 -1
- package/package.json +13 -8
- package/src/commons.js +1 -0
- package/src/compartment.js +13 -4
- package/src/enablements.js +9 -1
- package/src/error/assert.js +37 -9
- package/src/error/console.js +10 -0
- package/src/error/internal-types.js +6 -1
- package/src/error/note-log-args.js +1 -205
- package/src/error/types.js +45 -27
- package/src/make-lru-cachemap.js +221 -0
- package/src/permits.js +78 -9
- package/types.d.ts +16 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"homepage": "https://github.com/Agoric/SES-shim/tree/master/packages/ses#readme",
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/endojs/endo.git"
|
|
26
|
+
"url": "git+https://github.com/endojs/endo.git",
|
|
27
|
+
"directory": "packages/ses"
|
|
27
28
|
},
|
|
28
29
|
"bugs": {
|
|
29
30
|
"url": "https://github.com/endojs/endo/issues"
|
|
@@ -45,6 +46,9 @@
|
|
|
45
46
|
"require": "./dist/ses.cjs"
|
|
46
47
|
},
|
|
47
48
|
"./tools.js": "./tools.js",
|
|
49
|
+
"./assert-shim.js": "./assert-shim.js",
|
|
50
|
+
"./lockdown-shim.js": "./lockdown-shim.js",
|
|
51
|
+
"./compartment-shim.js": "./compartment-shim.js",
|
|
48
52
|
"./package.json": "./package.json"
|
|
49
53
|
},
|
|
50
54
|
"scripts": {
|
|
@@ -62,12 +66,12 @@
|
|
|
62
66
|
"test:platform-compatibility": "node test/package/test.cjs"
|
|
63
67
|
},
|
|
64
68
|
"dependencies": {
|
|
65
|
-
"@endo/env-options": "^1.1.
|
|
69
|
+
"@endo/env-options": "^1.1.1"
|
|
66
70
|
},
|
|
67
71
|
"devDependencies": {
|
|
68
|
-
"@endo/compartment-mapper": "^1.1.
|
|
69
|
-
"@endo/static-module-record": "^1.0.
|
|
70
|
-
"@endo/test262-runner": "^0.1.
|
|
72
|
+
"@endo/compartment-mapper": "^1.1.2",
|
|
73
|
+
"@endo/static-module-record": "^1.0.4",
|
|
74
|
+
"@endo/test262-runner": "^0.1.34",
|
|
71
75
|
"ava": "^5.3.0",
|
|
72
76
|
"babel-eslint": "^10.0.3",
|
|
73
77
|
"c8": "^7.14.0",
|
|
@@ -157,7 +161,8 @@
|
|
|
157
161
|
"isNaN",
|
|
158
162
|
"parseFloat",
|
|
159
163
|
"parseInt",
|
|
160
|
-
"unescape"
|
|
164
|
+
"unescape",
|
|
165
|
+
"AggregateError"
|
|
161
166
|
],
|
|
162
167
|
"@endo/no-polymorphic-call": "error"
|
|
163
168
|
},
|
|
@@ -184,5 +189,5 @@
|
|
|
184
189
|
"typeCoverage": {
|
|
185
190
|
"atLeast": 81.17
|
|
186
191
|
},
|
|
187
|
-
"gitHead": "
|
|
192
|
+
"gitHead": "297fed572fedec0e1ae3ce34cf409f9d45233d43"
|
|
188
193
|
}
|
package/src/commons.js
CHANGED
package/src/compartment.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
defineProperties,
|
|
12
12
|
entries,
|
|
13
13
|
promiseThen,
|
|
14
|
+
toStringTagSymbol,
|
|
14
15
|
weakmapGet,
|
|
15
16
|
weakmapSet,
|
|
16
17
|
} from './commons.js';
|
|
@@ -105,10 +106,6 @@ export const CompartmentPrototype = {
|
|
|
105
106
|
return compartmentEvaluate(compartmentFields, source, options);
|
|
106
107
|
},
|
|
107
108
|
|
|
108
|
-
toString() {
|
|
109
|
-
return '[object Compartment]';
|
|
110
|
-
},
|
|
111
|
-
|
|
112
109
|
module(specifier) {
|
|
113
110
|
if (typeof specifier !== 'string') {
|
|
114
111
|
throw TypeError('first argument of module() must be a string');
|
|
@@ -168,6 +165,18 @@ export const CompartmentPrototype = {
|
|
|
168
165
|
},
|
|
169
166
|
};
|
|
170
167
|
|
|
168
|
+
// This causes `String(new Compartment())` to evaluate to `[object Compartment]`.
|
|
169
|
+
// The descriptor follows the conventions of other globals with @@toStringTag
|
|
170
|
+
// properties, e.g. Math.
|
|
171
|
+
defineProperties(CompartmentPrototype, {
|
|
172
|
+
[toStringTagSymbol]: {
|
|
173
|
+
value: 'Compartment',
|
|
174
|
+
writable: false,
|
|
175
|
+
enumerable: false,
|
|
176
|
+
configurable: true,
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
171
180
|
defineProperties(InertCompartment, {
|
|
172
181
|
prototype: { value: CompartmentPrototype },
|
|
173
182
|
});
|
package/src/enablements.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toStringTagSymbol } from './commons.js';
|
|
1
|
+
import { toStringTagSymbol, iteratorSymbol } from './commons.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file Exports {@code enablements}, a recursively defined
|
|
@@ -97,6 +97,8 @@ export const moderateEnablements = {
|
|
|
97
97
|
'%ArrayPrototype%': {
|
|
98
98
|
toString: true,
|
|
99
99
|
push: true, // set by "Google Analytics"
|
|
100
|
+
concat: true, // set by mobx generated code (old TS compiler?)
|
|
101
|
+
[iteratorSymbol]: true, // set by mobx generated code (old TS compiler?)
|
|
100
102
|
},
|
|
101
103
|
|
|
102
104
|
// Function.prototype has no 'prototype' property to enable.
|
|
@@ -147,6 +149,12 @@ export const moderateEnablements = {
|
|
|
147
149
|
name: true, // set by "node 14"
|
|
148
150
|
},
|
|
149
151
|
|
|
152
|
+
// https://github.com/endojs/endo/issues/550
|
|
153
|
+
'%AggregateErrorPrototype%': {
|
|
154
|
+
message: true, // to match TypeErrorPrototype.message
|
|
155
|
+
name: true, // set by "node 14"?
|
|
156
|
+
},
|
|
157
|
+
|
|
150
158
|
'%PromisePrototype%': {
|
|
151
159
|
constructor: true, // set by "core-js"
|
|
152
160
|
},
|
package/src/error/assert.js
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
arrayPush,
|
|
22
22
|
assign,
|
|
23
23
|
freeze,
|
|
24
|
+
defineProperty,
|
|
24
25
|
globalThis,
|
|
25
26
|
is,
|
|
26
27
|
isError,
|
|
@@ -33,6 +34,7 @@ import {
|
|
|
33
34
|
weakmapGet,
|
|
34
35
|
weakmapHas,
|
|
35
36
|
weakmapSet,
|
|
37
|
+
AggregateError,
|
|
36
38
|
} from '../commons.js';
|
|
37
39
|
import { an, bestEffortStringify } from './stringify-utils.js';
|
|
38
40
|
import './types.js';
|
|
@@ -257,8 +259,8 @@ const tagError = (err, optErrorName = err.name) => {
|
|
|
257
259
|
*/
|
|
258
260
|
const makeError = (
|
|
259
261
|
optDetails = redactedDetails`Assert failed`,
|
|
260
|
-
|
|
261
|
-
{ errorName = undefined } = {},
|
|
262
|
+
errConstructor = globalThis.Error,
|
|
263
|
+
{ errorName = undefined, cause = undefined, errors = undefined } = {},
|
|
262
264
|
) => {
|
|
263
265
|
if (typeof optDetails === 'string') {
|
|
264
266
|
// If it is a string, use it as the literal part of the template so
|
|
@@ -270,7 +272,29 @@ const makeError = (
|
|
|
270
272
|
throw TypeError(`unrecognized details ${quote(optDetails)}`);
|
|
271
273
|
}
|
|
272
274
|
const messageString = getMessageString(hiddenDetails);
|
|
273
|
-
const
|
|
275
|
+
const opts = cause && { cause };
|
|
276
|
+
let error;
|
|
277
|
+
if (
|
|
278
|
+
typeof AggregateError !== 'undefined' &&
|
|
279
|
+
errConstructor === AggregateError
|
|
280
|
+
) {
|
|
281
|
+
error = AggregateError(errors || [], messageString, opts);
|
|
282
|
+
} else {
|
|
283
|
+
error = /** @type {ErrorConstructor} */ (errConstructor)(
|
|
284
|
+
messageString,
|
|
285
|
+
opts,
|
|
286
|
+
);
|
|
287
|
+
if (errors !== undefined) {
|
|
288
|
+
// Since we need to tolerate `errors` on an AggregateError, may as
|
|
289
|
+
// well tolerate it on all errors.
|
|
290
|
+
defineProperty(error, 'errors', {
|
|
291
|
+
value: errors,
|
|
292
|
+
writable: true,
|
|
293
|
+
enumerable: false,
|
|
294
|
+
configurable: true,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
274
298
|
weakmapSet(hiddenMessageLogArgs, error, getLogArgs(hiddenDetails));
|
|
275
299
|
if (errorName !== undefined) {
|
|
276
300
|
tagError(error, errorName);
|
|
@@ -382,9 +406,10 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
382
406
|
/** @type {AssertFail} */
|
|
383
407
|
const fail = (
|
|
384
408
|
optDetails = assertFailedDetails,
|
|
385
|
-
|
|
409
|
+
errConstructor = undefined,
|
|
410
|
+
options = undefined,
|
|
386
411
|
) => {
|
|
387
|
-
const reason = makeError(optDetails,
|
|
412
|
+
const reason = makeError(optDetails, errConstructor, options);
|
|
388
413
|
if (optRaise !== undefined) {
|
|
389
414
|
optRaise(reason);
|
|
390
415
|
}
|
|
@@ -402,9 +427,10 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
402
427
|
function baseAssert(
|
|
403
428
|
flag,
|
|
404
429
|
optDetails = undefined,
|
|
405
|
-
|
|
430
|
+
errConstructor = undefined,
|
|
431
|
+
options = undefined,
|
|
406
432
|
) {
|
|
407
|
-
flag || fail(optDetails,
|
|
433
|
+
flag || fail(optDetails, errConstructor, options);
|
|
408
434
|
}
|
|
409
435
|
|
|
410
436
|
/** @type {AssertEqual} */
|
|
@@ -412,12 +438,14 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
412
438
|
actual,
|
|
413
439
|
expected,
|
|
414
440
|
optDetails = undefined,
|
|
415
|
-
|
|
441
|
+
errConstructor = undefined,
|
|
442
|
+
options = undefined,
|
|
416
443
|
) => {
|
|
417
444
|
is(actual, expected) ||
|
|
418
445
|
fail(
|
|
419
446
|
optDetails || details`Expected ${actual} is same as ${expected}`,
|
|
420
|
-
|
|
447
|
+
errConstructor || RangeError,
|
|
448
|
+
options,
|
|
421
449
|
);
|
|
422
450
|
};
|
|
423
451
|
freeze(equal);
|
package/src/error/console.js
CHANGED
|
@@ -169,6 +169,8 @@ export { makeLoggingConsoleKit };
|
|
|
169
169
|
const ErrorInfo = {
|
|
170
170
|
NOTE: 'ERROR_NOTE:',
|
|
171
171
|
MESSAGE: 'ERROR_MESSAGE:',
|
|
172
|
+
CAUSE: 'cause:',
|
|
173
|
+
ERRORS: 'errors:',
|
|
172
174
|
};
|
|
173
175
|
freeze(ErrorInfo);
|
|
174
176
|
|
|
@@ -308,6 +310,14 @@ const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
|
|
|
308
310
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
309
311
|
baseConsole[severity](stackString);
|
|
310
312
|
// Show the other annotations on error
|
|
313
|
+
if (error.cause) {
|
|
314
|
+
logErrorInfo(severity, error, ErrorInfo.CAUSE, [error.cause], subErrors);
|
|
315
|
+
}
|
|
316
|
+
// @ts-expect-error AggregateError has an `errors` property.
|
|
317
|
+
if (error.errors) {
|
|
318
|
+
// @ts-expect-error AggregateError has an `errors` property.
|
|
319
|
+
logErrorInfo(severity, error, ErrorInfo.ERRORS, error.errors, subErrors);
|
|
320
|
+
}
|
|
311
321
|
for (const noteLogArgs of noteLogArgsArray) {
|
|
312
322
|
logErrorInfo(severity, error, ErrorInfo.NOTE, noteLogArgs, subErrors);
|
|
313
323
|
}
|
|
@@ -2,216 +2,12 @@
|
|
|
2
2
|
/* eslint-disable @endo/no-polymorphic-call */
|
|
3
3
|
/* eslint-disable no-restricted-globals */
|
|
4
4
|
|
|
5
|
+
import { makeLRUCacheMap } from '../make-lru-cachemap.js';
|
|
5
6
|
import './internal-types.js';
|
|
6
7
|
|
|
7
8
|
const { freeze } = Object;
|
|
8
9
|
const { isSafeInteger } = Number;
|
|
9
10
|
|
|
10
|
-
/**
|
|
11
|
-
* @template Data
|
|
12
|
-
* @typedef {object} DoublyLinkedCell
|
|
13
|
-
* A cell of a doubly-linked ring, i.e., a doubly-linked circular list.
|
|
14
|
-
* DoublyLinkedCells are not frozen, and so should be closely encapsulated by
|
|
15
|
-
* any abstraction that uses them.
|
|
16
|
-
* @property {DoublyLinkedCell<Data>} next
|
|
17
|
-
* @property {DoublyLinkedCell<Data>} prev
|
|
18
|
-
* @property {Data} data
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Makes a new self-linked cell. There are two reasons to do so:
|
|
23
|
-
* * To make the head sigil of a new initially-empty doubly-linked ring.
|
|
24
|
-
* * To make a non-sigil cell to be `spliceAfter`ed.
|
|
25
|
-
*
|
|
26
|
-
* @template Data
|
|
27
|
-
* @param {Data} data
|
|
28
|
-
* @returns {DoublyLinkedCell<Data>}
|
|
29
|
-
*/
|
|
30
|
-
const makeSelfCell = data => {
|
|
31
|
-
/** @type {Partial<DoublyLinkedCell<Data>>} */
|
|
32
|
-
const incompleteCell = {
|
|
33
|
-
next: undefined,
|
|
34
|
-
prev: undefined,
|
|
35
|
-
data,
|
|
36
|
-
};
|
|
37
|
-
const selfCell = /** @type {DoublyLinkedCell<Data>} */ (incompleteCell);
|
|
38
|
-
selfCell.next = selfCell;
|
|
39
|
-
selfCell.prev = selfCell;
|
|
40
|
-
// Not frozen!
|
|
41
|
-
return selfCell;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Splices a self-linked non-sigil cell into a ring after `prev`.
|
|
46
|
-
* `prev` could be the head sigil, or it could be some other non-sigil
|
|
47
|
-
* cell within a ring.
|
|
48
|
-
*
|
|
49
|
-
* @template Data
|
|
50
|
-
* @param {DoublyLinkedCell<Data>} prev
|
|
51
|
-
* @param {DoublyLinkedCell<Data>} selfCell
|
|
52
|
-
*/
|
|
53
|
-
const spliceAfter = (prev, selfCell) => {
|
|
54
|
-
if (prev === selfCell) {
|
|
55
|
-
throw TypeError('Cannot splice a cell into itself');
|
|
56
|
-
}
|
|
57
|
-
if (selfCell.next !== selfCell || selfCell.prev !== selfCell) {
|
|
58
|
-
throw TypeError('Expected self-linked cell');
|
|
59
|
-
}
|
|
60
|
-
const cell = selfCell;
|
|
61
|
-
// rename variable cause it isn't self-linked after this point.
|
|
62
|
-
|
|
63
|
-
const next = prev.next;
|
|
64
|
-
cell.prev = prev;
|
|
65
|
-
cell.next = next;
|
|
66
|
-
prev.next = cell;
|
|
67
|
-
next.prev = cell;
|
|
68
|
-
// Not frozen!
|
|
69
|
-
return cell;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @template Data
|
|
74
|
-
* @param {DoublyLinkedCell<Data>} cell
|
|
75
|
-
* No-op if the cell is self-linked.
|
|
76
|
-
*/
|
|
77
|
-
const spliceOut = cell => {
|
|
78
|
-
const { prev, next } = cell;
|
|
79
|
-
prev.next = next;
|
|
80
|
-
next.prev = prev;
|
|
81
|
-
cell.prev = cell;
|
|
82
|
-
cell.next = cell;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* The LRUCacheMap is used within the implementation of `assert` and so
|
|
87
|
-
* at a layer below SES or harden. Thus, we give it a `WeakMap`-like interface
|
|
88
|
-
* rather than a `WeakMapStore`-like interface. To work before `lockdown`,
|
|
89
|
-
* the implementation must use `freeze` manually, but still exhaustively.
|
|
90
|
-
*
|
|
91
|
-
* It implements the WeakMap interface, and holds its keys weakly. Cached
|
|
92
|
-
* values are only held while the key is held by the user and the key/value
|
|
93
|
-
* bookkeeping cell has not been pushed off the end of the cache by `budget`
|
|
94
|
-
* number of more recently referenced cells. If the key is dropped by the user,
|
|
95
|
-
* the value will no longer be held by the cache, but the bookkeeping cell
|
|
96
|
-
* itself will stay in memory.
|
|
97
|
-
*
|
|
98
|
-
* @template {{}} K
|
|
99
|
-
* @template {unknown} V
|
|
100
|
-
* @param {number} keysBudget
|
|
101
|
-
* @returns {WeakMap<K,V>}
|
|
102
|
-
*/
|
|
103
|
-
export const makeLRUCacheMap = keysBudget => {
|
|
104
|
-
if (!isSafeInteger(keysBudget) || keysBudget < 0) {
|
|
105
|
-
throw TypeError('keysBudget must be a safe non-negative integer number');
|
|
106
|
-
}
|
|
107
|
-
/** @typedef {DoublyLinkedCell<WeakMap<K, V> | undefined>} LRUCacheCell */
|
|
108
|
-
/** @type {WeakMap<K, LRUCacheCell>} */
|
|
109
|
-
const keyToCell = new WeakMap();
|
|
110
|
-
let size = 0; // `size` must remain <= `keysBudget`
|
|
111
|
-
// As a sigil, `head` uniquely is not in the `keyToCell` map.
|
|
112
|
-
/** @type {LRUCacheCell} */
|
|
113
|
-
const head = makeSelfCell(undefined);
|
|
114
|
-
|
|
115
|
-
const touchCell = key => {
|
|
116
|
-
const cell = keyToCell.get(key);
|
|
117
|
-
if (cell === undefined || cell.data === undefined) {
|
|
118
|
-
// Either the key was GCed, or the cell was condemned.
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
// Becomes most recently used
|
|
122
|
-
spliceOut(cell);
|
|
123
|
-
spliceAfter(head, cell);
|
|
124
|
-
return cell;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @param {K} key
|
|
129
|
-
*/
|
|
130
|
-
const has = key => touchCell(key) !== undefined;
|
|
131
|
-
freeze(has);
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @param {K} key
|
|
135
|
-
*/
|
|
136
|
-
// UNTIL https://github.com/endojs/endo/issues/1514
|
|
137
|
-
// Prefer: const get = key => touchCell(key)?.data?.get(key);
|
|
138
|
-
const get = key => {
|
|
139
|
-
const cell = touchCell(key);
|
|
140
|
-
return cell && cell.data && cell.data.get(key);
|
|
141
|
-
};
|
|
142
|
-
freeze(get);
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* @param {K} key
|
|
146
|
-
* @param {V} value
|
|
147
|
-
*/
|
|
148
|
-
const set = (key, value) => {
|
|
149
|
-
if (keysBudget < 1) {
|
|
150
|
-
// eslint-disable-next-line no-use-before-define
|
|
151
|
-
return lruCacheMap; // Implements WeakMap.set
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
let cell = touchCell(key);
|
|
155
|
-
if (cell === undefined) {
|
|
156
|
-
cell = makeSelfCell(undefined);
|
|
157
|
-
spliceAfter(head, cell); // start most recently used
|
|
158
|
-
}
|
|
159
|
-
if (!cell.data) {
|
|
160
|
-
// Either a fresh cell or a reused condemned cell.
|
|
161
|
-
size += 1;
|
|
162
|
-
// Add its data.
|
|
163
|
-
cell.data = new WeakMap();
|
|
164
|
-
// Advertise the cell for this key.
|
|
165
|
-
keyToCell.set(key, cell);
|
|
166
|
-
while (size > keysBudget) {
|
|
167
|
-
const condemned = head.prev;
|
|
168
|
-
spliceOut(condemned); // Drop least recently used
|
|
169
|
-
condemned.data = undefined;
|
|
170
|
-
size -= 1;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Update the data.
|
|
175
|
-
cell.data.set(key, value);
|
|
176
|
-
|
|
177
|
-
// eslint-disable-next-line no-use-before-define
|
|
178
|
-
return lruCacheMap; // Implements WeakMap.set
|
|
179
|
-
};
|
|
180
|
-
freeze(set);
|
|
181
|
-
|
|
182
|
-
// "delete" is a keyword.
|
|
183
|
-
/**
|
|
184
|
-
* @param {K} key
|
|
185
|
-
*/
|
|
186
|
-
const deleteIt = key => {
|
|
187
|
-
const cell = keyToCell.get(key);
|
|
188
|
-
if (cell === undefined) {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
spliceOut(cell);
|
|
192
|
-
keyToCell.delete(key);
|
|
193
|
-
if (cell.data === undefined) {
|
|
194
|
-
// Already condemned.
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
cell.data = undefined;
|
|
199
|
-
size -= 1;
|
|
200
|
-
return true;
|
|
201
|
-
};
|
|
202
|
-
freeze(deleteIt);
|
|
203
|
-
|
|
204
|
-
const lruCacheMap = freeze({
|
|
205
|
-
has,
|
|
206
|
-
get,
|
|
207
|
-
set,
|
|
208
|
-
delete: deleteIt,
|
|
209
|
-
[Symbol.toStringTag]: 'LRUCacheMap',
|
|
210
|
-
});
|
|
211
|
-
return lruCacheMap;
|
|
212
|
-
};
|
|
213
|
-
freeze(makeLRUCacheMap);
|
|
214
|
-
|
|
215
11
|
const defaultLoggedErrorsBudget = 1000;
|
|
216
12
|
const defaultArgsPerErrorBudget = 100;
|
|
217
13
|
|
package/src/error/types.js
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript does not treat `AggregateErrorConstructor` as a subtype of
|
|
5
|
+
* `ErrorConstructor`, which makes sense because their constructors
|
|
6
|
+
* have incompatible signatures. However, we want to parameterize some
|
|
7
|
+
* operations by any error constructor, including possible `AggregateError`.
|
|
8
|
+
* So we introduce `GenericErrorConstructor` as a common supertype. Any call
|
|
9
|
+
* to it to make an instance must therefore first case split on whether the
|
|
10
|
+
* constructor is an AggregateErrorConstructor or a normal ErrorConstructor.
|
|
11
|
+
*
|
|
12
|
+
* @typedef {ErrorConstructor | AggregateErrorConstructor} GenericErrorConstructor
|
|
13
|
+
*/
|
|
14
|
+
|
|
3
15
|
/**
|
|
4
16
|
* @callback BaseAssert
|
|
5
17
|
* The `assert` function itself.
|
|
6
18
|
*
|
|
7
19
|
* @param {any} flag The truthy/falsy value
|
|
8
|
-
* @param {Details
|
|
9
|
-
* @param {
|
|
10
|
-
* constructor to use.
|
|
20
|
+
* @param {Details} [optDetails] The details to throw
|
|
21
|
+
* @param {GenericErrorConstructor} [errConstructor]
|
|
22
|
+
* An optional alternate error constructor to use.
|
|
23
|
+
* @param {AssertMakeErrorOptions} [options]
|
|
11
24
|
* @returns {asserts flag}
|
|
12
25
|
*/
|
|
13
26
|
|
|
14
27
|
/**
|
|
15
28
|
* @typedef {object} AssertMakeErrorOptions
|
|
16
|
-
* @property {string
|
|
29
|
+
* @property {string} [errorName]
|
|
30
|
+
* @property {Error} [cause]
|
|
31
|
+
* @property {Error[]} [errors]
|
|
32
|
+
* Normally only used when the ErrorConstuctor is `AggregateError`
|
|
17
33
|
*/
|
|
18
34
|
|
|
19
35
|
/**
|
|
@@ -22,10 +38,10 @@
|
|
|
22
38
|
* The `assert.error` method, recording details for the console.
|
|
23
39
|
*
|
|
24
40
|
* The optional `optDetails` can be a string.
|
|
25
|
-
* @param {Details
|
|
26
|
-
* @param {
|
|
27
|
-
* constructor to use.
|
|
28
|
-
* @param {AssertMakeErrorOptions
|
|
41
|
+
* @param {Details} [optDetails] The details of what was asserted
|
|
42
|
+
* @param {GenericErrorConstructor} [errConstructor]
|
|
43
|
+
* An optional alternate error constructor to use.
|
|
44
|
+
* @param {AssertMakeErrorOptions} [options]
|
|
29
45
|
* @returns {Error}
|
|
30
46
|
*/
|
|
31
47
|
|
|
@@ -40,9 +56,10 @@
|
|
|
40
56
|
*
|
|
41
57
|
* The optional `optDetails` can be a string for backwards compatibility
|
|
42
58
|
* with the nodejs assertion library.
|
|
43
|
-
* @param {Details
|
|
44
|
-
* @param {
|
|
45
|
-
* constructor to use.
|
|
59
|
+
* @param {Details} [optDetails] The details of what was asserted
|
|
60
|
+
* @param {GenericErrorConstructor} [errConstructor]
|
|
61
|
+
* An optional alternate error constructor to use.
|
|
62
|
+
* @param {AssertMakeErrorOptions} [options]
|
|
46
63
|
* @returns {never}
|
|
47
64
|
*/
|
|
48
65
|
|
|
@@ -53,9 +70,10 @@
|
|
|
53
70
|
* Assert that two values must be `Object.is`.
|
|
54
71
|
* @param {any} actual The value we received
|
|
55
72
|
* @param {any} expected What we wanted
|
|
56
|
-
* @param {Details
|
|
57
|
-
* @param {
|
|
58
|
-
* constructor to use.
|
|
73
|
+
* @param {Details} [optDetails] The details to throw
|
|
74
|
+
* @param {GenericErrorConstructor} [errConstructor]
|
|
75
|
+
* An optional alternate error constructor to use.
|
|
76
|
+
* @param {AssertMakeErrorOptions} [options]
|
|
59
77
|
* @returns {void}
|
|
60
78
|
*/
|
|
61
79
|
|
|
@@ -66,7 +84,7 @@
|
|
|
66
84
|
* @callback AssertTypeofBigint
|
|
67
85
|
* @param {any} specimen
|
|
68
86
|
* @param {'bigint'} typename
|
|
69
|
-
* @param {Details
|
|
87
|
+
* @param {Details} [optDetails]
|
|
70
88
|
* @returns {asserts specimen is bigint}
|
|
71
89
|
*/
|
|
72
90
|
|
|
@@ -74,7 +92,7 @@
|
|
|
74
92
|
* @callback AssertTypeofBoolean
|
|
75
93
|
* @param {any} specimen
|
|
76
94
|
* @param {'boolean'} typename
|
|
77
|
-
* @param {Details
|
|
95
|
+
* @param {Details} [optDetails]
|
|
78
96
|
* @returns {asserts specimen is boolean}
|
|
79
97
|
*/
|
|
80
98
|
|
|
@@ -82,7 +100,7 @@
|
|
|
82
100
|
* @callback AssertTypeofFunction
|
|
83
101
|
* @param {any} specimen
|
|
84
102
|
* @param {'function'} typename
|
|
85
|
-
* @param {Details
|
|
103
|
+
* @param {Details} [optDetails]
|
|
86
104
|
* @returns {asserts specimen is Function}
|
|
87
105
|
*/
|
|
88
106
|
|
|
@@ -90,7 +108,7 @@
|
|
|
90
108
|
* @callback AssertTypeofNumber
|
|
91
109
|
* @param {any} specimen
|
|
92
110
|
* @param {'number'} typename
|
|
93
|
-
* @param {Details
|
|
111
|
+
* @param {Details} [optDetails]
|
|
94
112
|
* @returns {asserts specimen is number}
|
|
95
113
|
*/
|
|
96
114
|
|
|
@@ -98,7 +116,7 @@
|
|
|
98
116
|
* @callback AssertTypeofObject
|
|
99
117
|
* @param {any} specimen
|
|
100
118
|
* @param {'object'} typename
|
|
101
|
-
* @param {Details
|
|
119
|
+
* @param {Details} [optDetails]
|
|
102
120
|
* @returns {asserts specimen is Record<any, any> | null}
|
|
103
121
|
*/
|
|
104
122
|
|
|
@@ -106,7 +124,7 @@
|
|
|
106
124
|
* @callback AssertTypeofString
|
|
107
125
|
* @param {any} specimen
|
|
108
126
|
* @param {'string'} typename
|
|
109
|
-
* @param {Details
|
|
127
|
+
* @param {Details} [optDetails]
|
|
110
128
|
* @returns {asserts specimen is string}
|
|
111
129
|
*/
|
|
112
130
|
|
|
@@ -114,7 +132,7 @@
|
|
|
114
132
|
* @callback AssertTypeofSymbol
|
|
115
133
|
* @param {any} specimen
|
|
116
134
|
* @param {'symbol'} typename
|
|
117
|
-
* @param {Details
|
|
135
|
+
* @param {Details} [optDetails]
|
|
118
136
|
* @returns {asserts specimen is symbol}
|
|
119
137
|
*/
|
|
120
138
|
|
|
@@ -122,7 +140,7 @@
|
|
|
122
140
|
* @callback AssertTypeofUndefined
|
|
123
141
|
* @param {any} specimen
|
|
124
142
|
* @param {'undefined'} typename
|
|
125
|
-
* @param {Details
|
|
143
|
+
* @param {Details} [optDetails]
|
|
126
144
|
* @returns {asserts specimen is undefined}
|
|
127
145
|
*/
|
|
128
146
|
|
|
@@ -141,7 +159,7 @@
|
|
|
141
159
|
*
|
|
142
160
|
* Assert an expected typeof result.
|
|
143
161
|
* @param {any} specimen The value to get the typeof
|
|
144
|
-
* @param {Details
|
|
162
|
+
* @param {Details} [optDetails] The details to throw
|
|
145
163
|
* @returns {asserts specimen is string}
|
|
146
164
|
*/
|
|
147
165
|
|
|
@@ -202,7 +220,7 @@
|
|
|
202
220
|
*
|
|
203
221
|
* @callback AssertQuote
|
|
204
222
|
* @param {any} payload What to declassify
|
|
205
|
-
* @param {(string|number)
|
|
223
|
+
* @param {(string|number)} [spaces]
|
|
206
224
|
* @returns {StringablePayload} The declassified payload
|
|
207
225
|
*/
|
|
208
226
|
|
|
@@ -235,8 +253,8 @@
|
|
|
235
253
|
* `optRaise` returns normally, which would be unusual, the throw following
|
|
236
254
|
* `optRaise(reason)` would still happen.
|
|
237
255
|
*
|
|
238
|
-
* @param {Raise
|
|
239
|
-
* @param {boolean
|
|
256
|
+
* @param {Raise} [optRaise]
|
|
257
|
+
* @param {boolean} [unredacted]
|
|
240
258
|
* @returns {Assert}
|
|
241
259
|
*/
|
|
242
260
|
|
|
@@ -400,6 +418,6 @@
|
|
|
400
418
|
* @callback FilterConsole
|
|
401
419
|
* @param {VirtualConsole} baseConsole
|
|
402
420
|
* @param {ConsoleFilter} filter
|
|
403
|
-
* @param {string
|
|
421
|
+
* @param {string} [topic]
|
|
404
422
|
* @returns {VirtualConsole}
|
|
405
423
|
*/
|