ses 1.2.0 → 1.4.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 +20 -0
- package/dist/lockdown.cjs +397 -91
- package/dist/lockdown.mjs +397 -91
- package/dist/lockdown.umd.js +397 -91
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +397 -91
- package/dist/ses.mjs +397 -91
- package/dist/ses.umd.js +397 -91
- package/dist/ses.umd.min.js +1 -1
- package/index.js +1 -0
- package/package.json +10 -9
- package/src/commons.js +4 -0
- package/src/console-shim.js +50 -0
- package/src/enablements.js +6 -0
- package/src/error/README.md +9 -1
- package/src/error/assert.js +37 -9
- package/src/error/console.js +156 -17
- package/src/error/internal-types.js +6 -1
- package/src/error/tame-console.js +8 -8
- package/src/error/types.js +45 -27
- package/src/make-eval-function.js +1 -1
- package/src/permits.js +25 -7
- package/src/tame-regexp-constructor.js +13 -6
- package/types.d.ts +16 -4
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
|
*/
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @param {Function} safeEvaluate
|
|
7
7
|
*/
|
|
8
8
|
export const makeEvalFunction = safeEvaluate => {
|
|
9
|
-
// We use the
|
|
9
|
+
// We use the concise method syntax to create an eval without a
|
|
10
10
|
// [[Construct]] behavior (such that the invocation "new eval()" throws
|
|
11
11
|
// TypeError: eval is not a constructor"), but which still accepts a
|
|
12
12
|
// 'this' binding.
|
package/src/permits.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/* eslint-disable no-restricted-globals */
|
|
2
|
+
/* eslint max-lines: 0 */
|
|
3
|
+
|
|
4
|
+
import { arrayPush } from './commons.js';
|
|
5
|
+
|
|
2
6
|
/**
|
|
3
7
|
* @file Exports {@code whitelist}, a recursively defined
|
|
4
8
|
* JSON record enumerating all intrinsics and their properties
|
|
@@ -8,8 +12,6 @@
|
|
|
8
12
|
* @author Mark S. Miller
|
|
9
13
|
*/
|
|
10
14
|
|
|
11
|
-
/* eslint max-lines: 0 */
|
|
12
|
-
|
|
13
15
|
/**
|
|
14
16
|
* constantProperties
|
|
15
17
|
* non-configurable, non-writable data properties of all global objects.
|
|
@@ -82,6 +84,8 @@ export const universalPropertyNames = {
|
|
|
82
84
|
Iterator: 'Iterator',
|
|
83
85
|
// https://github.com/tc39/proposal-async-iterator-helpers
|
|
84
86
|
AsyncIterator: 'AsyncIterator',
|
|
87
|
+
// https://github.com/endojs/endo/issues/550
|
|
88
|
+
AggregateError: 'AggregateError',
|
|
85
89
|
|
|
86
90
|
// *** Other Properties of the Global Object
|
|
87
91
|
|
|
@@ -185,16 +189,27 @@ export const uniqueGlobalPropertyNames = {
|
|
|
185
189
|
|
|
186
190
|
// All the "subclasses" of Error. These are collectively represented in the
|
|
187
191
|
// ECMAScript spec by the meta variable NativeError.
|
|
188
|
-
|
|
189
|
-
|
|
192
|
+
/** @type {GenericErrorConstructor[]} */
|
|
193
|
+
const NativeErrors = [
|
|
190
194
|
EvalError,
|
|
191
195
|
RangeError,
|
|
192
196
|
ReferenceError,
|
|
193
197
|
SyntaxError,
|
|
194
198
|
TypeError,
|
|
195
199
|
URIError,
|
|
200
|
+
// https://github.com/endojs/endo/issues/550
|
|
201
|
+
// Commented out to accommodate platforms prior to AggregateError.
|
|
202
|
+
// Instead, conditional push below.
|
|
203
|
+
// AggregateError,
|
|
196
204
|
];
|
|
197
205
|
|
|
206
|
+
if (typeof AggregateError !== 'undefined') {
|
|
207
|
+
// Conditional, to accommodate platforms prior to AggregateError
|
|
208
|
+
arrayPush(NativeErrors, AggregateError);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export { NativeErrors };
|
|
212
|
+
|
|
198
213
|
/**
|
|
199
214
|
* <p>Each JSON record enumerates the disposition of the properties on
|
|
200
215
|
* some corresponding intrinsic object.
|
|
@@ -599,6 +614,8 @@ export const permitted = {
|
|
|
599
614
|
SyntaxError: NativeError('%SyntaxErrorPrototype%'),
|
|
600
615
|
TypeError: NativeError('%TypeErrorPrototype%'),
|
|
601
616
|
URIError: NativeError('%URIErrorPrototype%'),
|
|
617
|
+
// https://github.com/endojs/endo/issues/550
|
|
618
|
+
AggregateError: NativeError('%AggregateErrorPrototype%'),
|
|
602
619
|
|
|
603
620
|
'%EvalErrorPrototype%': NativeErrorPrototype('EvalError'),
|
|
604
621
|
'%RangeErrorPrototype%': NativeErrorPrototype('RangeError'),
|
|
@@ -606,6 +623,8 @@ export const permitted = {
|
|
|
606
623
|
'%SyntaxErrorPrototype%': NativeErrorPrototype('SyntaxError'),
|
|
607
624
|
'%TypeErrorPrototype%': NativeErrorPrototype('TypeError'),
|
|
608
625
|
'%URIErrorPrototype%': NativeErrorPrototype('URIError'),
|
|
626
|
+
// https://github.com/endojs/endo/issues/550
|
|
627
|
+
'%AggregateErrorPrototype%': NativeErrorPrototype('AggregateError'),
|
|
609
628
|
|
|
610
629
|
// *** Numbers and Dates
|
|
611
630
|
|
|
@@ -1473,9 +1492,8 @@ export const permitted = {
|
|
|
1473
1492
|
'[[Proto]]': '%FunctionPrototype%',
|
|
1474
1493
|
all: fn,
|
|
1475
1494
|
allSettled: fn,
|
|
1476
|
-
//
|
|
1477
|
-
|
|
1478
|
-
any: false, // ES2021
|
|
1495
|
+
// https://github.com/Agoric/SES-shim/issues/550
|
|
1496
|
+
any: fn,
|
|
1479
1497
|
prototype: '%PromisePrototype%',
|
|
1480
1498
|
race: fn,
|
|
1481
1499
|
reject: fn,
|
|
@@ -25,11 +25,6 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
|
|
|
25
25
|
return construct(FERAL_REG_EXP, rest, new.target);
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const speciesDesc = getOwnPropertyDescriptor(FERAL_REG_EXP, speciesSymbol);
|
|
29
|
-
if (!speciesDesc) {
|
|
30
|
-
throw TypeError('no RegExp[Symbol.species] descriptor');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
28
|
defineProperties(ResultRegExp, {
|
|
34
29
|
length: { value: 2 },
|
|
35
30
|
prototype: {
|
|
@@ -38,8 +33,20 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
|
|
|
38
33
|
enumerable: false,
|
|
39
34
|
configurable: false,
|
|
40
35
|
},
|
|
41
|
-
[speciesSymbol]: speciesDesc,
|
|
42
36
|
});
|
|
37
|
+
// Hermes does not have `Symbol.species`. We should support such platforms.
|
|
38
|
+
if (speciesSymbol) {
|
|
39
|
+
const speciesDesc = getOwnPropertyDescriptor(
|
|
40
|
+
FERAL_REG_EXP,
|
|
41
|
+
speciesSymbol,
|
|
42
|
+
);
|
|
43
|
+
if (!speciesDesc) {
|
|
44
|
+
throw TypeError('no RegExp[Symbol.species] descriptor');
|
|
45
|
+
}
|
|
46
|
+
defineProperties(ResultRegExp, {
|
|
47
|
+
[speciesSymbol]: speciesDesc,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
43
50
|
return ResultRegExp;
|
|
44
51
|
};
|
|
45
52
|
|
package/types.d.ts
CHANGED
|
@@ -119,6 +119,8 @@ export type Details = string | DetailsToken;
|
|
|
119
119
|
|
|
120
120
|
export interface AssertMakeErrorOptions {
|
|
121
121
|
errorName?: string;
|
|
122
|
+
cause?: Error;
|
|
123
|
+
errors?: Error[];
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
type AssertTypeofBigint = (
|
|
@@ -175,6 +177,10 @@ interface ToStringable {
|
|
|
175
177
|
toString(): string;
|
|
176
178
|
}
|
|
177
179
|
|
|
180
|
+
export type GenericErrorConstructor =
|
|
181
|
+
| ErrorConstructor
|
|
182
|
+
| AggregateErrorConstructor;
|
|
183
|
+
|
|
178
184
|
export type Raise = (reason: Error) => void;
|
|
179
185
|
// Behold: recursion.
|
|
180
186
|
// eslint-disable-next-line no-use-before-define
|
|
@@ -184,23 +190,29 @@ export interface AssertionFunctions {
|
|
|
184
190
|
(
|
|
185
191
|
value: any,
|
|
186
192
|
details?: Details,
|
|
187
|
-
|
|
193
|
+
errConstructor?: GenericErrorConstructor,
|
|
194
|
+
options?: AssertMakeErrorOptions,
|
|
188
195
|
): asserts value;
|
|
189
196
|
typeof: AssertTypeof;
|
|
190
197
|
equal(
|
|
191
198
|
left: any,
|
|
192
199
|
right: any,
|
|
193
200
|
details?: Details,
|
|
194
|
-
|
|
201
|
+
errConstructor?: GenericErrorConstructor,
|
|
202
|
+
options?: AssertMakeErrorOptions,
|
|
195
203
|
): void;
|
|
196
204
|
string(specimen: any, details?: Details): asserts specimen is string;
|
|
197
|
-
fail(
|
|
205
|
+
fail(
|
|
206
|
+
details?: Details,
|
|
207
|
+
errConstructor?: GenericErrorConstructor,
|
|
208
|
+
options?: AssertMakeErrorOptions,
|
|
209
|
+
): never;
|
|
198
210
|
}
|
|
199
211
|
|
|
200
212
|
export interface AssertionUtilities {
|
|
201
213
|
error(
|
|
202
214
|
details?: Details,
|
|
203
|
-
|
|
215
|
+
errConstructor?: GenericErrorConstructor,
|
|
204
216
|
options?: AssertMakeErrorOptions,
|
|
205
217
|
): Error;
|
|
206
218
|
note(error: Error, details: Details): void;
|