ses 0.18.1 → 0.18.2
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 +5 -0
- package/README.md +9 -4
- package/SECURITY.md +1 -1
- package/dist/lockdown.cjs +171 -146
- package/dist/lockdown.mjs +171 -146
- package/dist/lockdown.umd.js +171 -146
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +171 -146
- package/dist/ses.mjs +171 -146
- package/dist/ses.umd.js +171 -146
- package/dist/ses.umd.min.js +1 -1
- package/index.js +1 -0
- package/package.json +13 -11
- package/src/commons.js +2 -0
- package/src/compartment-shim.js +3 -3
- package/src/enablements.js +12 -0
- package/src/environment-options.js +10 -19
- package/src/error/assert.js +24 -16
- package/src/error/internal-types.js +3 -3
- package/src/error/types.js +51 -70
- package/src/get-anonymous-intrinsics.js +2 -2
- package/src/get-source-url.js +3 -0
- package/src/global-object.js +9 -9
- package/src/intrinsics.js +1 -1
- package/src/lockdown-shim.js +7 -4
- package/src/make-hardener.js +1 -1
- package/src/make-safe-evaluator.js +4 -4
- package/src/module-instance.js +11 -5
- package/src/module-load.js +1 -1
- package/src/scope-constants.js +2 -2
- package/src/sloppy-globals-scope-terminator.js +1 -0
- package/src/tame-domains.js +1 -0
- package/src/tame-locale-methods.js +2 -2
- package/src/transforms.js +15 -0
- package/src/whitelist-intrinsics.js +2 -2
- package/tools.js +25 -0
- /package/{index.d.ts → types.d.ts} +0 -0
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.2",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"main": "./dist/ses.cjs",
|
|
33
33
|
"module": "./index.js",
|
|
34
34
|
"unpkg": "./dist/ses.umd.js",
|
|
35
|
-
"types": "./
|
|
35
|
+
"types": "./types.d.ts",
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
38
|
"import": "./index.js",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"import": "./index.js",
|
|
43
43
|
"require": "./dist/ses.cjs"
|
|
44
44
|
},
|
|
45
|
+
"./tools.js": "./tools.js",
|
|
45
46
|
"./package.json": "./package.json"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
@@ -59,32 +60,33 @@
|
|
|
59
60
|
"test:platform-compatibility": "node test/package/test.cjs"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
|
-
"@endo/compartment-mapper": "^0.8.
|
|
63
|
-
"@endo/eslint-config": "^0.5.
|
|
64
|
-
"@endo/static-module-record": "^0.7.
|
|
65
|
-
"@endo/test262-runner": "^0.1.
|
|
66
|
-
"ava": "^5.
|
|
63
|
+
"@endo/compartment-mapper": "^0.8.2",
|
|
64
|
+
"@endo/eslint-config": "^0.5.3",
|
|
65
|
+
"@endo/static-module-record": "^0.7.17",
|
|
66
|
+
"@endo/test262-runner": "^0.1.30",
|
|
67
|
+
"ava": "^5.2.0",
|
|
67
68
|
"babel-eslint": "^10.0.3",
|
|
68
69
|
"c8": "^7.7.3",
|
|
69
70
|
"eslint": "^7.32.0",
|
|
70
71
|
"eslint-config-airbnb-base": "^14.0.0",
|
|
71
72
|
"eslint-config-prettier": "^6.9.0",
|
|
72
73
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
73
|
-
"eslint-plugin-import": "^2.
|
|
74
|
+
"eslint-plugin-import": "^2.27.5",
|
|
74
75
|
"eslint-plugin-prettier": "^3.4.1",
|
|
75
76
|
"prettier": "^2.8.0",
|
|
76
77
|
"sinon": "8.0.4",
|
|
77
78
|
"terser": "^4.8.0",
|
|
78
79
|
"tsd": "^0.24.1",
|
|
79
|
-
"typescript": "~4.
|
|
80
|
+
"typescript": "~4.9.5"
|
|
80
81
|
},
|
|
81
82
|
"files": [
|
|
82
83
|
"LICENSE*",
|
|
83
84
|
"NEWS*",
|
|
84
85
|
"SECURITY*",
|
|
85
86
|
"dist",
|
|
86
|
-
"
|
|
87
|
+
"types.d.ts",
|
|
87
88
|
"index.js",
|
|
89
|
+
"tools.js",
|
|
88
90
|
"src"
|
|
89
91
|
],
|
|
90
92
|
"private": false,
|
|
@@ -180,5 +182,5 @@
|
|
|
180
182
|
],
|
|
181
183
|
"timeout": "2m"
|
|
182
184
|
},
|
|
183
|
-
"gitHead": "
|
|
185
|
+
"gitHead": "0053227a37ee76ee8a3dce6059dd55140ed0ce6d"
|
|
184
186
|
}
|
package/src/commons.js
CHANGED
|
@@ -97,6 +97,7 @@ export const defineProperty = (object, prop, descriptor) => {
|
|
|
97
97
|
// Instead, to workaround the Safari bug
|
|
98
98
|
const result = originalDefineProperty(object, prop, descriptor);
|
|
99
99
|
if (result !== object) {
|
|
100
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DEFINE_PROPERTY_FAILED_SILENTLY.md
|
|
100
101
|
throw TypeError(
|
|
101
102
|
`Please report that the original defineProperty silently failed to set ${stringifyJson(
|
|
102
103
|
String(prop),
|
|
@@ -279,6 +280,7 @@ export const FERAL_EVAL = eval;
|
|
|
279
280
|
export const FERAL_FUNCTION = Function;
|
|
280
281
|
|
|
281
282
|
export const noEvalEvaluate = () => {
|
|
283
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
|
|
282
284
|
throw new TypeError(
|
|
283
285
|
'Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)',
|
|
284
286
|
);
|
package/src/compartment-shim.js
CHANGED
|
@@ -96,10 +96,10 @@ export const CompartmentPrototype = {
|
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* @param {string} source is a JavaScript program grammar construction.
|
|
99
|
-
* @param {
|
|
99
|
+
* @param {object} [options]
|
|
100
100
|
* @param {Array<Transform>} [options.transforms]
|
|
101
101
|
* @param {boolean} [options.sloppyGlobalsMode]
|
|
102
|
-
* @param {
|
|
102
|
+
* @param {object} [options.__moduleShimLexicals__]
|
|
103
103
|
* @param {boolean} [options.__evadeHtmlCommentTest__]
|
|
104
104
|
* @param {boolean} [options.__evadeImportExpressionTest__]
|
|
105
105
|
* @param {boolean} [options.__rejectSomeDirectEvalExpressions__]
|
|
@@ -180,7 +180,7 @@ defineProperties(InertCompartment, {
|
|
|
180
180
|
* @callback MakeCompartmentConstructor
|
|
181
181
|
* @param {MakeCompartmentConstructor} targetMakeCompartmentConstructor
|
|
182
182
|
* @param {Record<string, any>} intrinsics
|
|
183
|
-
* @param {(object:
|
|
183
|
+
* @param {(object: object) => void} markVirtualizedNativeFunction
|
|
184
184
|
* @returns {Compartment['constructor']}
|
|
185
185
|
*/
|
|
186
186
|
|
package/src/enablements.js
CHANGED
|
@@ -206,4 +206,16 @@ export const severeEnablements = {
|
|
|
206
206
|
* enablements just enable them all.
|
|
207
207
|
*/
|
|
208
208
|
'%TypedArrayPrototype%': '*',
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Needed to work with Immer before https://github.com/immerjs/immer/pull/914
|
|
212
|
+
* is accepted.
|
|
213
|
+
*/
|
|
214
|
+
'%MapPrototype%': '*',
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Needed to work with Immer before https://github.com/immerjs/immer/pull/914
|
|
218
|
+
* is accepted.
|
|
219
|
+
*/
|
|
220
|
+
'%SetPrototype%': '*',
|
|
209
221
|
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { arrayPush, freeze } from './commons.js';
|
|
6
6
|
import { assert } from './error/assert.js';
|
|
7
7
|
|
|
8
|
-
const {
|
|
8
|
+
const { Fail, quote: q } = assert;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* JavaScript module semantics resists attempts to parameterize a module's
|
|
@@ -55,7 +55,7 @@ const { details: X, Fail, quote: q } = assert;
|
|
|
55
55
|
* variables, if they are needed, and a way to catalog the names of all
|
|
56
56
|
* the environment variables that were captured.
|
|
57
57
|
*
|
|
58
|
-
* @param {
|
|
58
|
+
* @param {object} aGlobal
|
|
59
59
|
*/
|
|
60
60
|
export const makeEnvironmentCaptor = aGlobal => {
|
|
61
61
|
const capturedEnvironmentOptionNames = [];
|
|
@@ -70,19 +70,13 @@ export const makeEnvironmentCaptor = aGlobal => {
|
|
|
70
70
|
*/
|
|
71
71
|
const getEnvironmentOption = (optionName, defaultSetting) => {
|
|
72
72
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
73
|
-
|
|
74
|
-
optionName
|
|
75
|
-
'string',
|
|
76
|
-
X`Environment option name ${q(optionName)} must be a string.`,
|
|
77
|
-
);
|
|
73
|
+
typeof optionName === 'string' ||
|
|
74
|
+
Fail`Environment option name ${q(optionName)} must be a string.`;
|
|
78
75
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
'string',
|
|
82
|
-
X`Environment option default setting ${q(
|
|
76
|
+
typeof defaultSetting === 'string' ||
|
|
77
|
+
Fail`Environment option default setting ${q(
|
|
83
78
|
defaultSetting,
|
|
84
|
-
)} must be a string
|
|
85
|
-
);
|
|
79
|
+
)} must be a string.`;
|
|
86
80
|
|
|
87
81
|
/** @type {string} */
|
|
88
82
|
let setting = defaultSetting;
|
|
@@ -94,15 +88,12 @@ export const makeEnvironmentCaptor = aGlobal => {
|
|
|
94
88
|
arrayPush(capturedEnvironmentOptionNames, optionName);
|
|
95
89
|
const optionValue = globalEnv[optionName];
|
|
96
90
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
'string',
|
|
100
|
-
X`Environment option named ${q(
|
|
91
|
+
typeof optionValue === 'string' ||
|
|
92
|
+
Fail`Environment option named ${q(
|
|
101
93
|
optionName,
|
|
102
94
|
)}, if present, must have a corresponding string value, got ${q(
|
|
103
95
|
optionValue,
|
|
104
|
-
)}
|
|
105
|
-
);
|
|
96
|
+
)}`;
|
|
106
97
|
setting = optionValue;
|
|
107
98
|
}
|
|
108
99
|
}
|
package/src/error/assert.js
CHANGED
|
@@ -58,7 +58,7 @@ freeze(quote);
|
|
|
58
58
|
// /////////////////////////////////////////////////////////////////////////////
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* @typedef {
|
|
61
|
+
* @typedef {object} HiddenDetails
|
|
62
62
|
*
|
|
63
63
|
* Captures the arguments passed to the `details` template string tag.
|
|
64
64
|
*
|
|
@@ -362,9 +362,11 @@ export { loggedErrorHandler };
|
|
|
362
362
|
*/
|
|
363
363
|
const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
364
364
|
const details = unredacted ? unredactedDetails : redactedDetails;
|
|
365
|
+
const assertFailedDetails = details`Check failed`;
|
|
366
|
+
|
|
365
367
|
/** @type {AssertFail} */
|
|
366
368
|
const fail = (
|
|
367
|
-
optDetails =
|
|
369
|
+
optDetails = assertFailedDetails,
|
|
368
370
|
ErrorConstructor = globalThis.Error,
|
|
369
371
|
) => {
|
|
370
372
|
const reason = makeError(optDetails, ErrorConstructor);
|
|
@@ -384,31 +386,37 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
384
386
|
/** @type {BaseAssert} */
|
|
385
387
|
function baseAssert(
|
|
386
388
|
flag,
|
|
387
|
-
optDetails =
|
|
388
|
-
ErrorConstructor =
|
|
389
|
+
optDetails = undefined,
|
|
390
|
+
ErrorConstructor = undefined,
|
|
389
391
|
) {
|
|
390
|
-
|
|
391
|
-
throw fail(optDetails, ErrorConstructor);
|
|
392
|
-
}
|
|
392
|
+
flag || fail(optDetails, ErrorConstructor);
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
/** @type {AssertEqual} */
|
|
396
396
|
const equal = (
|
|
397
397
|
actual,
|
|
398
398
|
expected,
|
|
399
|
-
optDetails =
|
|
400
|
-
ErrorConstructor =
|
|
399
|
+
optDetails = undefined,
|
|
400
|
+
ErrorConstructor = undefined,
|
|
401
401
|
) => {
|
|
402
|
-
|
|
402
|
+
is(actual, expected) ||
|
|
403
|
+
fail(
|
|
404
|
+
optDetails || details`Expected ${actual} is same as ${expected}`,
|
|
405
|
+
ErrorConstructor || RangeError,
|
|
406
|
+
);
|
|
403
407
|
};
|
|
404
408
|
freeze(equal);
|
|
405
409
|
|
|
406
410
|
/** @type {AssertTypeof} */
|
|
407
411
|
const assertTypeof = (specimen, typename, optDetails) => {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
)
|
|
412
|
+
// This will safely fall through if typename is not a string,
|
|
413
|
+
// which is what we want.
|
|
414
|
+
// eslint-disable-next-line valid-typeof
|
|
415
|
+
if (typeof specimen === typename) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
typeof typename === 'string' || Fail`${quote(typename)} must be a string`;
|
|
419
|
+
|
|
412
420
|
if (optDetails === undefined) {
|
|
413
421
|
// Like
|
|
414
422
|
// ```js
|
|
@@ -418,12 +426,12 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
418
426
|
// so it doesn't get quoted.
|
|
419
427
|
optDetails = details(['', ` must be ${an(typename)}`], specimen);
|
|
420
428
|
}
|
|
421
|
-
|
|
429
|
+
fail(optDetails, TypeError);
|
|
422
430
|
};
|
|
423
431
|
freeze(assertTypeof);
|
|
424
432
|
|
|
425
433
|
/** @type {AssertString} */
|
|
426
|
-
const assertString = (specimen, optDetails) =>
|
|
434
|
+
const assertString = (specimen, optDetails = undefined) =>
|
|
427
435
|
assertTypeof(specimen, 'string', optDetails);
|
|
428
436
|
|
|
429
437
|
// Note that "assert === baseAssert"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* @typedef {
|
|
28
|
+
* @typedef {object} LoggedErrorHandler
|
|
29
29
|
*
|
|
30
30
|
* Used to parameterize `makeCausalConsole` to give it access to potentially
|
|
31
31
|
* hidden information to augment the logging of errors.
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* @typedef {
|
|
48
|
+
* @typedef {object} LoggingConsoleKit
|
|
49
49
|
* @property {VirtualConsole} loggingConsole
|
|
50
50
|
* @property {() => readonly LogRecord[]} takeLog
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* @typedef {
|
|
54
|
+
* @typedef {object} MakeLoggingConsoleKitOptions
|
|
55
55
|
* @property {boolean=} shouldResetForDebugging
|
|
56
56
|
*/
|
|
57
57
|
|
package/src/error/types.js
CHANGED
|
@@ -34,8 +34,9 @@
|
|
|
34
34
|
*
|
|
35
35
|
* The `assert.fail` method.
|
|
36
36
|
*
|
|
37
|
-
* Fail an assertion, recording details to the console and
|
|
38
|
-
* raising an exception with
|
|
37
|
+
* Fail an assertion, recording full details to the console and
|
|
38
|
+
* raising an exception with a message in which `details` substitution values
|
|
39
|
+
* have been redacted.
|
|
39
40
|
*
|
|
40
41
|
* The optional `optDetails` can be a string for backwards compatibility
|
|
41
42
|
* with the nodejs assertion library.
|
|
@@ -141,14 +142,15 @@
|
|
|
141
142
|
* Assert an expected typeof result.
|
|
142
143
|
* @param {any} specimen The value to get the typeof
|
|
143
144
|
* @param {Details=} optDetails The details to throw
|
|
145
|
+
* @returns {asserts specimen is string}
|
|
144
146
|
*/
|
|
145
147
|
|
|
146
148
|
/**
|
|
147
149
|
* @callback AssertNote
|
|
148
150
|
* The `assert.note` method.
|
|
149
151
|
*
|
|
150
|
-
* Annotate
|
|
151
|
-
* augmented console
|
|
152
|
+
* Annotate an error with details, potentially to be used by an
|
|
153
|
+
* augmented console such as the causal console of `console.js`, to
|
|
152
154
|
* provide extra information associated with logged errors.
|
|
153
155
|
*
|
|
154
156
|
* @param {Error} error
|
|
@@ -178,38 +180,24 @@
|
|
|
178
180
|
|
|
179
181
|
/**
|
|
180
182
|
* To "declassify" and quote a substitution value used in a
|
|
181
|
-
* details`...` template literal, enclose that substitution expression
|
|
182
|
-
* in a call to `quote`. This
|
|
183
|
-
* (as if with `JSON.stringify`)
|
|
183
|
+
* ``` details`...` ``` template literal, enclose that substitution expression
|
|
184
|
+
* in a call to `quote`. This makes the value appear quoted
|
|
185
|
+
* (as if with `JSON.stringify`) in the message of the thrown error. The
|
|
184
186
|
* payload itself is still passed unquoted to the console as it would be
|
|
185
187
|
* without `quote`.
|
|
186
188
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* want to reveal the sky's actual color, but we do want the thrown error's
|
|
190
|
-
* message to reveal what color the sky was supposed to be:
|
|
189
|
+
* For example, the following will reveal the expected sky color, but not the
|
|
190
|
+
* actual incorrect sky color, in the thrown error's message:
|
|
191
191
|
* ```js
|
|
192
|
-
*
|
|
193
|
-
* sky.color,
|
|
194
|
-
* color,
|
|
195
|
-
* details`${sky.color} should be ${quote(color)}`,
|
|
196
|
-
* );
|
|
192
|
+
* sky.color === expectedColor || Fail`${sky.color} should be ${quote(expectedColor)}`;
|
|
197
193
|
* ```
|
|
198
194
|
*
|
|
199
195
|
* // TODO Update SES-shim to new convention, where `details` is
|
|
200
196
|
* // renamed to `X` rather than `d`.
|
|
201
|
-
* The normal convention is to locally rename `quote` to `q`
|
|
202
|
-
* `details
|
|
203
|
-
* ```js
|
|
204
|
-
* const { details: d, quote: q } = assert;
|
|
205
|
-
* ```
|
|
206
|
-
* so the above example would then be
|
|
197
|
+
* The normal convention is to locally rename `details` to `d` and `quote` to `q`
|
|
198
|
+
* like `const { details: d, quote: q } = assert;`, so the above example would then be
|
|
207
199
|
* ```js
|
|
208
|
-
*
|
|
209
|
-
* sky.color,
|
|
210
|
-
* color,
|
|
211
|
-
* d`${sky.color} should be ${q(color)}`,
|
|
212
|
-
* );
|
|
200
|
+
* sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;
|
|
213
201
|
* ```
|
|
214
202
|
*
|
|
215
203
|
* @callback AssertQuote
|
|
@@ -261,75 +249,68 @@
|
|
|
261
249
|
* ```js
|
|
262
250
|
* assert(sky.isBlue(), details`${sky.color} should be "blue"`);
|
|
263
251
|
* ```
|
|
252
|
+
* // TODO Update SES-shim to new convention, where `details` is
|
|
253
|
+
* // renamed to `X` rather than `d`.
|
|
254
|
+
* or following the normal convention to locally rename `details` to `d`
|
|
255
|
+
* and `quote` to `q` like `const { details: d, quote: q } = assert;`:
|
|
256
|
+
* ```js
|
|
257
|
+
* assert(sky.isBlue(), d`${sky.color} should be "blue"`);
|
|
258
|
+
* ```
|
|
259
|
+
* However, note that in most cases it is preferable to instead use the `Fail`
|
|
260
|
+
* template literal tag (which has the same input signature as `details`
|
|
261
|
+
* but automatically creates and throws an error):
|
|
262
|
+
* ```js
|
|
263
|
+
* sky.isBlue() || Fail`${sky.color} should be "blue"`;
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
264
266
|
* The details template tag returns a `DetailsToken` object that can print
|
|
265
267
|
* itself with the formatted message in two ways.
|
|
266
|
-
* It will report
|
|
267
|
-
*
|
|
268
|
+
* It will report full details to the console, but
|
|
269
|
+
* mask embedded substitution values with their typeof information in the thrown error
|
|
268
270
|
* to prevent revealing secrets up the exceptional path. In the example
|
|
269
271
|
* above, the thrown error may reveal only that `sky.color` is a string,
|
|
270
272
|
* whereas the same diagnostic printed to the console reveals that the
|
|
271
|
-
* sky was green.
|
|
273
|
+
* sky was green. This masking can be disabled for an individual substitution value
|
|
274
|
+
* using `quote`.
|
|
272
275
|
*
|
|
273
|
-
* The `raw`
|
|
274
|
-
*
|
|
276
|
+
* The `raw` property of an input template array is ignored, so a simple
|
|
277
|
+
* array of strings may be provided directly.
|
|
275
278
|
*/
|
|
276
279
|
|
|
277
280
|
/**
|
|
278
281
|
* @typedef {(template: TemplateStringsArray | string[], ...args: any) => never} FailTag
|
|
279
|
-
* The `Fail` tamplate tag supports replacing patterns like
|
|
280
|
-
* ```js
|
|
281
|
-
* assert(cond, X`...complaint...`);
|
|
282
|
-
* ```
|
|
283
|
-
* or
|
|
284
|
-
* ```js
|
|
285
|
-
* cond || assert.fail(X`...complaint...`);
|
|
286
|
-
* ```
|
|
287
|
-
* with patterns like
|
|
288
|
-
* ```js
|
|
289
|
-
* cond || Fail`...complaint...`;
|
|
290
|
-
* ```
|
|
291
282
|
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* patterns are not as powerful as the `assert(...)` call at enabling static
|
|
295
|
-
* reasoning. Of the `||`, again due to weaknesses in current TypeScript,
|
|
296
|
-
* the
|
|
297
|
-
* ```js
|
|
298
|
-
* cond || Fail`...complaint...`
|
|
299
|
-
* ```
|
|
300
|
-
* pattern is not as powerful as the
|
|
283
|
+
* Use the `Fail` function as a template literal tag to efficiently
|
|
284
|
+
* create and throw a `details`-style error only when a condition is not satisfied.
|
|
301
285
|
* ```js
|
|
302
|
-
*
|
|
286
|
+
* condition || Fail`...complaint...`;
|
|
303
287
|
* ```
|
|
304
|
-
*
|
|
305
|
-
* return to the
|
|
288
|
+
* This avoids the overhead of creating usually-unnecessary errors like
|
|
306
289
|
* ```js
|
|
307
|
-
* assert(
|
|
290
|
+
* assert(condition, details`...complaint...`);
|
|
308
291
|
* ```
|
|
309
|
-
*
|
|
310
|
-
* evaluating the `X` template in the typical `true` case where it is not
|
|
311
|
-
* needed. And we do not want to return to the
|
|
292
|
+
* while improving readability over alternatives like
|
|
312
293
|
* ```js
|
|
313
|
-
* assert.fail(
|
|
294
|
+
* condition || assert.fail(details`...complaint...`);
|
|
314
295
|
* ```
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
296
|
+
*
|
|
297
|
+
* However, due to current weakness in TypeScript, static reasoning
|
|
298
|
+
* is less powerful with the `||` patterns than with an `assert` call.
|
|
299
|
+
* Until/unless https://github.com/microsoft/TypeScript/issues/51426 is fixed,
|
|
300
|
+
* for `||`-style assertions where this loss of static reasoning is a problem,
|
|
318
301
|
* instead express the assertion as
|
|
319
302
|
* ```js
|
|
320
|
-
* if (!
|
|
303
|
+
* if (!condition) {
|
|
321
304
|
* Fail`...complaint...`;
|
|
322
305
|
* }
|
|
323
306
|
* ```
|
|
324
307
|
* or, if needed,
|
|
325
308
|
* ```js
|
|
326
|
-
* if (!
|
|
327
|
-
* // `throw` is noop since `Fail` throws
|
|
309
|
+
* if (!condition) {
|
|
310
|
+
* // `throw` is noop since `Fail` throws, but it improves static analysis
|
|
328
311
|
* throw Fail`...complaint...`;
|
|
329
312
|
* }
|
|
330
313
|
* ```
|
|
331
|
-
* This avoid the TypeScript bugs that cause the loss of static reasoning,
|
|
332
|
-
* but with no loss of efficiency and little loss of readability.
|
|
333
314
|
*/
|
|
334
315
|
|
|
335
316
|
/**
|
|
@@ -367,7 +348,7 @@
|
|
|
367
348
|
// /////////////////////////////////////////////////////////////////////////////
|
|
368
349
|
|
|
369
350
|
/**
|
|
370
|
-
* @typedef {
|
|
351
|
+
* @typedef {object} VirtualConsole
|
|
371
352
|
* @property {Console['debug']} debug
|
|
372
353
|
* @property {Console['log']} log
|
|
373
354
|
* @property {Console['info']} info
|
|
@@ -20,7 +20,7 @@ import { InertCompartment } from './compartment-shim.js';
|
|
|
20
20
|
* Object.getConstructorOf()
|
|
21
21
|
* Helper function to improve readability, similar to Object.getPrototypeOf().
|
|
22
22
|
*
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {object} obj
|
|
24
24
|
*/
|
|
25
25
|
function getConstructorOf(obj) {
|
|
26
26
|
return getPrototypeOf(obj).constructor;
|
|
@@ -38,7 +38,7 @@ function makeArguments() {
|
|
|
38
38
|
* Get the intrinsics not otherwise reachable by named own property
|
|
39
39
|
* traversal from the global object.
|
|
40
40
|
*
|
|
41
|
-
* @returns {
|
|
41
|
+
* @returns {object}
|
|
42
42
|
*/
|
|
43
43
|
export const getAnonymousIntrinsics = () => {
|
|
44
44
|
const InertFunction = FERAL_FUNCTION.prototype.constructor;
|
package/src/get-source-url.js
CHANGED
package/src/global-object.js
CHANGED
|
@@ -22,7 +22,7 @@ import { constantProperties, universalPropertyNames } from './whitelist.js';
|
|
|
22
22
|
* But, we can install this setter to prevent a program from proceding on
|
|
23
23
|
* this false assumption.
|
|
24
24
|
*
|
|
25
|
-
* @param {
|
|
25
|
+
* @param {object} globalObject
|
|
26
26
|
*/
|
|
27
27
|
export const setGlobalObjectSymbolUnscopables = globalObject => {
|
|
28
28
|
defineProperty(
|
|
@@ -48,7 +48,7 @@ export const setGlobalObjectSymbolUnscopables = globalObject => {
|
|
|
48
48
|
* (SetDefaultGlobalBindings). This process is split between this function and
|
|
49
49
|
* `setGlobalObjectMutableProperties`.
|
|
50
50
|
*
|
|
51
|
-
* @param {
|
|
51
|
+
* @param {object} globalObject
|
|
52
52
|
*/
|
|
53
53
|
export const setGlobalObjectConstantProperties = globalObject => {
|
|
54
54
|
for (const [name, constant] of entries(constantProperties)) {
|
|
@@ -68,12 +68,12 @@ export const setGlobalObjectConstantProperties = globalObject => {
|
|
|
68
68
|
* `newGlobalPropertyNames` should be either `initialGlobalPropertyNames` or
|
|
69
69
|
* `sharedGlobalPropertyNames`.
|
|
70
70
|
*
|
|
71
|
-
* @param {
|
|
72
|
-
* @param {
|
|
73
|
-
* @param {
|
|
74
|
-
* @param {
|
|
71
|
+
* @param {object} globalObject
|
|
72
|
+
* @param {object} param1
|
|
73
|
+
* @param {object} param1.intrinsics
|
|
74
|
+
* @param {object} param1.newGlobalPropertyNames
|
|
75
75
|
* @param {Function} param1.makeCompartmentConstructor
|
|
76
|
-
* @param {(
|
|
76
|
+
* @param {(object) => void} param1.markVirtualizedNativeFunction
|
|
77
77
|
*/
|
|
78
78
|
export const setGlobalObjectMutableProperties = (
|
|
79
79
|
globalObject,
|
|
@@ -135,9 +135,9 @@ export const setGlobalObjectMutableProperties = (
|
|
|
135
135
|
* setGlobalObjectEvaluators()
|
|
136
136
|
* Set the eval and the Function evaluator on the global object with given evalTaming policy.
|
|
137
137
|
*
|
|
138
|
-
* @param {
|
|
138
|
+
* @param {object} globalObject
|
|
139
139
|
* @param {Function} evaluator
|
|
140
|
-
* @param {(
|
|
140
|
+
* @param {(object) => void} markVirtualizedNativeFunction
|
|
141
141
|
*/
|
|
142
142
|
export const setGlobalObjectEvaluators = (
|
|
143
143
|
globalObject,
|
package/src/intrinsics.js
CHANGED
|
@@ -160,7 +160,7 @@ export const makeIntrinsicsCollector = () => {
|
|
|
160
160
|
* If run before lockdown, the returned intrinsics record will carry the
|
|
161
161
|
* *original* unsafe (feral, untamed) bindings of these global variables.
|
|
162
162
|
*
|
|
163
|
-
* @param {
|
|
163
|
+
* @param {object} globalObject
|
|
164
164
|
*/
|
|
165
165
|
export const getGlobalIntrinsics = globalObject => {
|
|
166
166
|
const { addIntrinsics, finalIntrinsics } = makeIntrinsicsCollector();
|
package/src/lockdown-shim.js
CHANGED
|
@@ -53,7 +53,7 @@ import { makeEnvironmentCaptor } from './environment-options.js';
|
|
|
53
53
|
import { getAnonymousIntrinsics } from './get-anonymous-intrinsics.js';
|
|
54
54
|
import { makeCompartmentConstructor } from './compartment-shim.js';
|
|
55
55
|
|
|
56
|
-
/** @typedef {import('../
|
|
56
|
+
/** @typedef {import('../types.js').LockdownOptions} LockdownOptions */
|
|
57
57
|
|
|
58
58
|
const { Fail, details: d, quote: q } = assert;
|
|
59
59
|
|
|
@@ -77,9 +77,9 @@ const harden = makeHardener();
|
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* @callback CompartmentConstructor
|
|
80
|
-
* @param {
|
|
81
|
-
* @param {
|
|
82
|
-
* @param {
|
|
80
|
+
* @param {object} endowments
|
|
81
|
+
* @param {object} moduleMap
|
|
82
|
+
* @param {object} [options]
|
|
83
83
|
* @param {Array<Transform>} [options.transforms]
|
|
84
84
|
* @param {Array<Transform>} [options.__shimTransforms__]
|
|
85
85
|
*/
|
|
@@ -115,6 +115,7 @@ const assertDirectEvalAvailable = () => {
|
|
|
115
115
|
allowed = true;
|
|
116
116
|
}
|
|
117
117
|
if (!allowed) {
|
|
118
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
|
|
118
119
|
throw new TypeError(
|
|
119
120
|
`SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`,
|
|
120
121
|
);
|
|
@@ -206,6 +207,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
206
207
|
d`Already locked down at ${priorLockdown} (SES_ALREADY_LOCKED_DOWN)`,
|
|
207
208
|
TypeError,
|
|
208
209
|
);
|
|
210
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_ALREADY_LOCKED_DOWN.md
|
|
209
211
|
priorLockdown = new TypeError('Prior lockdown (SES_ALREADY_LOCKED_DOWN)');
|
|
210
212
|
// Tease V8 to generate the stack string and release the closures the stack
|
|
211
213
|
// trace retained:
|
|
@@ -247,6 +249,7 @@ export const repairIntrinsics = (options = {}) => {
|
|
|
247
249
|
};
|
|
248
250
|
|
|
249
251
|
if (seemsToBeLockedDown()) {
|
|
252
|
+
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_MULTIPLE_INSTANCES.md
|
|
250
253
|
throw new TypeError(
|
|
251
254
|
`Already locked down but not by this SES instance (SES_MULTIPLE_INSTANCES)`,
|
|
252
255
|
);
|
package/src/make-hardener.js
CHANGED
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
import { assert } from './error/assert.js';
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* @typedef {import('../
|
|
55
|
+
* @typedef {import('../types.js').Harden} Harden
|
|
56
56
|
*/
|
|
57
57
|
|
|
58
58
|
// Obtain the string tag accessor of of TypedArray so we can indirectly use the
|