ses 0.18.3 → 0.18.5
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 +16 -0
- package/README.md +105 -47
- package/dist/lockdown.cjs +6779 -6508
- package/dist/lockdown.mjs +6779 -6508
- package/dist/lockdown.umd.js +6779 -6508
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +6779 -6508
- package/dist/ses.mjs +6779 -6508
- package/dist/ses.umd.js +6779 -6508
- package/dist/ses.umd.min.js +1 -1
- package/index.js +1 -1
- package/package.json +17 -13
- package/src/commons.js +14 -11
- package/src/compartment-evaluate.js +1 -1
- package/src/compartment-shim.js +10 -14
- package/src/enable-property-overrides.js +4 -4
- package/src/error/assert.js +36 -9
- package/src/error/note-log-args.js +2 -4
- package/src/error/tame-console.js +1 -1
- package/src/error/tame-error-constructor.js +3 -3
- package/src/error/tame-v8-error-constructor.js +1 -1
- package/src/error/types.js +1 -0
- package/src/eval-scope.js +4 -2
- package/src/get-anonymous-intrinsics.js +25 -4
- package/src/global-object.js +2 -2
- package/src/intrinsics.js +14 -11
- package/src/lockdown-shim.js +13 -26
- package/src/make-hardener.js +8 -1
- package/src/make-safe-evaluator.js +6 -5
- package/src/module-instance.js +8 -11
- package/src/module-link.js +2 -2
- package/src/module-load.js +5 -7
- package/src/module-proxy.js +12 -12
- package/src/{whitelist-intrinsics.js → permits-intrinsics.js} +24 -20
- package/src/{whitelist.js → permits.js} +135 -8
- package/src/scope-constants.js +1 -0
- package/src/strict-scope-terminator.js +10 -4
- package/src/tame-date-constructor.js +1 -1
- package/src/tame-domains.js +2 -2
- package/src/tame-function-constructors.js +2 -2
- package/src/tame-function-tostring.js +1 -1
- package/src/tame-harden.js +7 -1
- package/src/tame-locale-methods.js +2 -2
- package/src/tame-math-object.js +1 -1
- package/src/tame-regexp-constructor.js +11 -2
- package/src/tame-symbol-constructor.js +65 -0
- package/src/transforms.js +3 -3
- package/types.d.ts +1 -0
- package/src/environment-options.js +0 -117
package/index.js
CHANGED
|
@@ -27,7 +27,7 @@ function getThis() {
|
|
|
27
27
|
|
|
28
28
|
if (getThis()) {
|
|
29
29
|
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_SLOPPY.md
|
|
30
|
-
throw
|
|
30
|
+
throw TypeError(`SES failed to initialize, sloppy mode (SES_NO_SLOPPY)`);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const markVirtualizedNativeFunction = tameFunctionToString();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.5",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -59,23 +59,27 @@
|
|
|
59
59
|
"test": "tsd && ava",
|
|
60
60
|
"test:platform-compatibility": "node test/package/test.cjs"
|
|
61
61
|
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@endo/env-options": "^0.1.1"
|
|
64
|
+
},
|
|
62
65
|
"devDependencies": {
|
|
63
|
-
"@endo/compartment-mapper": "^0.8.
|
|
64
|
-
"@endo/static-module-record": "^0.7.
|
|
65
|
-
"@endo/test262-runner": "^0.1.
|
|
66
|
-
"ava": "^5.
|
|
66
|
+
"@endo/compartment-mapper": "^0.8.5",
|
|
67
|
+
"@endo/static-module-record": "^0.7.20",
|
|
68
|
+
"@endo/test262-runner": "^0.1.32",
|
|
69
|
+
"ava": "^5.3.0",
|
|
67
70
|
"babel-eslint": "^10.0.3",
|
|
68
|
-
"c8": "^7.
|
|
69
|
-
"
|
|
70
|
-
"eslint
|
|
71
|
+
"c8": "^7.14.0",
|
|
72
|
+
"core-js": "^3.31.0",
|
|
73
|
+
"eslint": "^8.44.0",
|
|
74
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
71
75
|
"eslint-config-prettier": "^8.8.0",
|
|
72
76
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
73
77
|
"eslint-plugin-import": "^2.27.5",
|
|
74
|
-
"prettier": "^
|
|
75
|
-
"sinon": "
|
|
78
|
+
"prettier": "^3.0.0",
|
|
79
|
+
"sinon": "^15.1.0",
|
|
76
80
|
"terser": "^5.16.6",
|
|
77
|
-
"tsd": "^0.
|
|
78
|
-
"typescript": "~
|
|
81
|
+
"tsd": "^0.28.1",
|
|
82
|
+
"typescript": "~5.1.3"
|
|
79
83
|
},
|
|
80
84
|
"files": [
|
|
81
85
|
"LICENSE*",
|
|
@@ -175,5 +179,5 @@
|
|
|
175
179
|
],
|
|
176
180
|
"timeout": "2m"
|
|
177
181
|
},
|
|
178
|
-
"gitHead": "
|
|
182
|
+
"gitHead": "106da55b8bcea3067f70c29c357806f3f2e55c52"
|
|
179
183
|
}
|
package/src/commons.js
CHANGED
|
@@ -33,6 +33,7 @@ export const {
|
|
|
33
33
|
RegExp: FERAL_REG_EXP,
|
|
34
34
|
Set,
|
|
35
35
|
String,
|
|
36
|
+
Symbol,
|
|
36
37
|
WeakMap,
|
|
37
38
|
WeakSet,
|
|
38
39
|
} = globalThis;
|
|
@@ -135,6 +136,7 @@ export const { prototype: promisePrototype } = Promise;
|
|
|
135
136
|
export const typedArrayPrototype = getPrototypeOf(Uint8Array.prototype);
|
|
136
137
|
|
|
137
138
|
const { bind } = functionPrototype;
|
|
139
|
+
|
|
138
140
|
/**
|
|
139
141
|
* uncurryThis()
|
|
140
142
|
* Equivalent of: fn => (thisArg, ...args) => apply(fn, thisArg, args)
|
|
@@ -154,8 +156,8 @@ export const arrayFilter = uncurryThis(arrayPrototype.filter);
|
|
|
154
156
|
export const arrayForEach = uncurryThis(arrayPrototype.forEach);
|
|
155
157
|
export const arrayIncludes = uncurryThis(arrayPrototype.includes);
|
|
156
158
|
export const arrayJoin = uncurryThis(arrayPrototype.join);
|
|
157
|
-
/** @type {<T, U>(thisArg: readonly T[], callbackfn: (value: T, index: number, array: T[]) => U,
|
|
158
|
-
export const arrayMap = uncurryThis(arrayPrototype.map);
|
|
159
|
+
/** @type {<T, U>(thisArg: readonly T[], callbackfn: (value: T, index: number, array: T[]) => U, cbThisArg?: any) => U[]} */
|
|
160
|
+
export const arrayMap = /** @type {any} */ (uncurryThis(arrayPrototype.map));
|
|
159
161
|
export const arrayPop = uncurryThis(arrayPrototype.pop);
|
|
160
162
|
/** @type {<T>(thisArg: T[], ...items: T[]) => number} */
|
|
161
163
|
export const arrayPush = uncurryThis(arrayPrototype.push);
|
|
@@ -186,12 +188,14 @@ export const stringIncludes = uncurryThis(stringPrototype.includes);
|
|
|
186
188
|
export const stringIndexOf = uncurryThis(stringPrototype.indexOf);
|
|
187
189
|
export const stringMatch = uncurryThis(stringPrototype.match);
|
|
188
190
|
/**
|
|
189
|
-
* @type {
|
|
190
|
-
* ((thisArg: string, searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string) => string)
|
|
191
|
+
* @type { &
|
|
192
|
+
* ((thisArg: string, searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string) => string) &
|
|
191
193
|
* ((thisArg: string, searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string) => string)
|
|
192
194
|
* }
|
|
193
195
|
*/
|
|
194
|
-
export const stringReplace =
|
|
196
|
+
export const stringReplace = /** @type {any} */ (
|
|
197
|
+
uncurryThis(stringPrototype.replace)
|
|
198
|
+
);
|
|
195
199
|
export const stringSearch = uncurryThis(stringPrototype.search);
|
|
196
200
|
export const stringSlice = uncurryThis(stringPrototype.slice);
|
|
197
201
|
/** @type {(thisArg: string, splitter: string | RegExp | { [Symbol.split](string: string, limit?: number): string[]; }, limit?: number) => string[]} */
|
|
@@ -200,13 +204,12 @@ export const stringStartsWith = uncurryThis(stringPrototype.startsWith);
|
|
|
200
204
|
export const iterateString = uncurryThis(stringPrototype[iteratorSymbol]);
|
|
201
205
|
//
|
|
202
206
|
export const weakmapDelete = uncurryThis(weakmapPrototype.delete);
|
|
203
|
-
/** @type {<K, V>(thisArg: WeakMap<K, V>, ...args: Parameters<WeakMap<K,V>['get']>) => ReturnType<WeakMap<K,V>['get']>} */
|
|
207
|
+
/** @type {<K extends {}, V>(thisArg: WeakMap<K, V>, ...args: Parameters<WeakMap<K,V>['get']>) => ReturnType<WeakMap<K,V>['get']>} */
|
|
204
208
|
export const weakmapGet = uncurryThis(weakmapPrototype.get);
|
|
205
209
|
export const weakmapHas = uncurryThis(weakmapPrototype.has);
|
|
206
210
|
export const weakmapSet = uncurryThis(weakmapPrototype.set);
|
|
207
211
|
//
|
|
208
212
|
export const weaksetAdd = uncurryThis(weaksetPrototype.add);
|
|
209
|
-
export const weaksetGet = uncurryThis(weaksetPrototype.get);
|
|
210
213
|
export const weaksetHas = uncurryThis(weaksetPrototype.has);
|
|
211
214
|
//
|
|
212
215
|
export const functionToString = uncurryThis(functionPrototype.toString);
|
|
@@ -215,7 +218,9 @@ const { all } = Promise;
|
|
|
215
218
|
export const promiseAll = promises => apply(all, Promise, [promises]);
|
|
216
219
|
export const promiseCatch = uncurryThis(promisePrototype.catch);
|
|
217
220
|
/** @type {<T, TResult1 = T, TResult2 = never>(thisArg: T, onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null) => Promise<TResult1 | TResult2>} */
|
|
218
|
-
export const promiseThen =
|
|
221
|
+
export const promiseThen = /** @type {any} */ (
|
|
222
|
+
uncurryThis(promisePrototype.then)
|
|
223
|
+
);
|
|
219
224
|
//
|
|
220
225
|
export const finalizationRegistryRegister =
|
|
221
226
|
FinalizationRegistry && uncurryThis(FinalizationRegistry.prototype.register);
|
|
@@ -283,7 +288,5 @@ export const FERAL_FUNCTION = Function;
|
|
|
283
288
|
|
|
284
289
|
export const noEvalEvaluate = () => {
|
|
285
290
|
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
|
|
286
|
-
throw
|
|
287
|
-
'Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)',
|
|
288
|
-
);
|
|
291
|
+
throw TypeError('Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)');
|
|
289
292
|
};
|
|
@@ -61,7 +61,7 @@ export const compartmentEvaluate = (compartmentFields, source, options) => {
|
|
|
61
61
|
// TODO Maybe relax string check and coerce instead:
|
|
62
62
|
// https://github.com/tc39/proposal-dynamic-code-brand-checks
|
|
63
63
|
if (typeof source !== 'string') {
|
|
64
|
-
throw
|
|
64
|
+
throw TypeError('first argument of evaluate() must be a string');
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// Extract options, and shallow-clone transforms.
|
package/src/compartment-shim.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
setGlobalObjectMutableProperties,
|
|
21
21
|
setGlobalObjectEvaluators,
|
|
22
22
|
} from './global-object.js';
|
|
23
|
-
import { sharedGlobalPropertyNames } from './
|
|
23
|
+
import { sharedGlobalPropertyNames } from './permits.js';
|
|
24
24
|
import { load } from './module-load.js';
|
|
25
25
|
import { link } from './module-link.js';
|
|
26
26
|
import { getDeferredExports } from './module-proxy.js';
|
|
@@ -41,10 +41,6 @@ const moduleAliases = new WeakMap();
|
|
|
41
41
|
// privateFields captures the private state for each compartment.
|
|
42
42
|
const privateFields = new WeakMap();
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* @typedef {(source: string) => string} Transform
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
44
|
// Compartments do not need an importHook or resolveHook to be useful
|
|
49
45
|
// as a vessel for evaluating programs.
|
|
50
46
|
// However, any method that operates the module system will throw an exception
|
|
@@ -52,7 +48,7 @@ const privateFields = new WeakMap();
|
|
|
52
48
|
const assertModuleHooks = compartment => {
|
|
53
49
|
const { importHook, resolveHook } = weakmapGet(privateFields, compartment);
|
|
54
50
|
if (typeof importHook !== 'function' || typeof resolveHook !== 'function') {
|
|
55
|
-
throw
|
|
51
|
+
throw TypeError(
|
|
56
52
|
'Compartment must be constructed with an importHook and a resolveHook for it to be able to load modules',
|
|
57
53
|
);
|
|
58
54
|
}
|
|
@@ -63,7 +59,7 @@ export const InertCompartment = function Compartment(
|
|
|
63
59
|
_modules = {},
|
|
64
60
|
_options = {},
|
|
65
61
|
) {
|
|
66
|
-
throw
|
|
62
|
+
throw TypeError(
|
|
67
63
|
'Compartment.prototype.constructor is not a valid constructor.',
|
|
68
64
|
);
|
|
69
65
|
};
|
|
@@ -97,7 +93,7 @@ export const CompartmentPrototype = {
|
|
|
97
93
|
/**
|
|
98
94
|
* @param {string} source is a JavaScript program grammar construction.
|
|
99
95
|
* @param {object} [options]
|
|
100
|
-
* @param {Array<Transform>} [options.transforms]
|
|
96
|
+
* @param {Array<import('./lockdown-shim').Transform>} [options.transforms]
|
|
101
97
|
* @param {boolean} [options.sloppyGlobalsMode]
|
|
102
98
|
* @param {object} [options.__moduleShimLexicals__]
|
|
103
99
|
* @param {boolean} [options.__evadeHtmlCommentTest__]
|
|
@@ -115,7 +111,7 @@ export const CompartmentPrototype = {
|
|
|
115
111
|
|
|
116
112
|
module(specifier) {
|
|
117
113
|
if (typeof specifier !== 'string') {
|
|
118
|
-
throw
|
|
114
|
+
throw TypeError('first argument of module() must be a string');
|
|
119
115
|
}
|
|
120
116
|
|
|
121
117
|
assertModuleHooks(this);
|
|
@@ -132,7 +128,7 @@ export const CompartmentPrototype = {
|
|
|
132
128
|
|
|
133
129
|
async import(specifier) {
|
|
134
130
|
if (typeof specifier !== 'string') {
|
|
135
|
-
throw
|
|
131
|
+
throw TypeError('first argument of import() must be a string');
|
|
136
132
|
}
|
|
137
133
|
|
|
138
134
|
assertModuleHooks(this);
|
|
@@ -153,7 +149,7 @@ export const CompartmentPrototype = {
|
|
|
153
149
|
|
|
154
150
|
async load(specifier) {
|
|
155
151
|
if (typeof specifier !== 'string') {
|
|
156
|
-
throw
|
|
152
|
+
throw TypeError('first argument of load() must be a string');
|
|
157
153
|
}
|
|
158
154
|
|
|
159
155
|
assertModuleHooks(this);
|
|
@@ -163,7 +159,7 @@ export const CompartmentPrototype = {
|
|
|
163
159
|
|
|
164
160
|
importNow(specifier) {
|
|
165
161
|
if (typeof specifier !== 'string') {
|
|
166
|
-
throw
|
|
162
|
+
throw TypeError('first argument of importNow() must be a string');
|
|
167
163
|
}
|
|
168
164
|
|
|
169
165
|
assertModuleHooks(this);
|
|
@@ -192,7 +188,7 @@ export const makeCompartmentConstructor = (
|
|
|
192
188
|
) => {
|
|
193
189
|
function Compartment(endowments = {}, moduleMap = {}, options = {}) {
|
|
194
190
|
if (new.target === undefined) {
|
|
195
|
-
throw
|
|
191
|
+
throw TypeError(
|
|
196
192
|
"Class constructor Compartment cannot be invoked without 'new'",
|
|
197
193
|
);
|
|
198
194
|
}
|
|
@@ -224,7 +220,7 @@ export const makeCompartmentConstructor = (
|
|
|
224
220
|
for (const [specifier, aliasNamespace] of entries(moduleMap || {})) {
|
|
225
221
|
if (typeof aliasNamespace === 'string') {
|
|
226
222
|
// TODO implement parent module record retrieval.
|
|
227
|
-
throw
|
|
223
|
+
throw TypeError(
|
|
228
224
|
`Cannot map module ${q(specifier)} to ${q(
|
|
229
225
|
aliasNamespace,
|
|
230
226
|
)} in parent compartment`,
|
|
@@ -102,7 +102,7 @@ export default function enablePropertyOverrides(
|
|
|
102
102
|
|
|
103
103
|
function setter(newValue) {
|
|
104
104
|
if (obj === this) {
|
|
105
|
-
throw
|
|
105
|
+
throw TypeError(
|
|
106
106
|
`Cannot assign to read only property '${String(
|
|
107
107
|
prop,
|
|
108
108
|
)}' of '${path}'`,
|
|
@@ -113,7 +113,7 @@ export default function enablePropertyOverrides(
|
|
|
113
113
|
} else {
|
|
114
114
|
if (isDebug) {
|
|
115
115
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
116
|
-
console.error(
|
|
116
|
+
console.error(TypeError(`Override property ${prop}`));
|
|
117
117
|
}
|
|
118
118
|
defineProperty(this, prop, {
|
|
119
119
|
value: newValue,
|
|
@@ -175,7 +175,7 @@ export default function enablePropertyOverrides(
|
|
|
175
175
|
} else if (isObject(subPlan)) {
|
|
176
176
|
enableProperties(subPath, desc.value, subPlan);
|
|
177
177
|
} else {
|
|
178
|
-
throw
|
|
178
|
+
throw TypeError(`Unexpected override enablement plan ${subPath}`);
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -195,7 +195,7 @@ export default function enablePropertyOverrides(
|
|
|
195
195
|
break;
|
|
196
196
|
}
|
|
197
197
|
default: {
|
|
198
|
-
throw
|
|
198
|
+
throw TypeError(`unrecognized overrideTaming ${overrideTaming}`);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
package/src/error/assert.js
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
globalThis,
|
|
25
25
|
is,
|
|
26
26
|
isError,
|
|
27
|
+
regexpTest,
|
|
27
28
|
stringIndexOf,
|
|
28
29
|
stringReplace,
|
|
29
30
|
stringSlice,
|
|
@@ -56,6 +57,35 @@ const quote = (payload, spaces = undefined) => {
|
|
|
56
57
|
};
|
|
57
58
|
freeze(quote);
|
|
58
59
|
|
|
60
|
+
const canBeBare = freeze(/^[\w:-]( ?[\w:-])*$/);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Embed a string directly into error details without wrapping punctuation.
|
|
64
|
+
* To avoid injection attacks that exploit quoting confusion, this must NEVER
|
|
65
|
+
* be used with data that is possibly attacker-controlled.
|
|
66
|
+
* As a further safeguard, we fall back to quoting any input that is not a
|
|
67
|
+
* string of sufficiently word-like parts separated by isolated spaces (rather
|
|
68
|
+
* than throwing an exception, which could hide the original problem for which
|
|
69
|
+
* explanatory details are being constructed---i.e., ``` assert.details`...` ```
|
|
70
|
+
* should never be the source of a new exception, nor should an attempt to
|
|
71
|
+
* render its output, although we _could_ instead decide to handle the latter
|
|
72
|
+
* by inline replacement similar to that of `bestEffortStringify` for producing
|
|
73
|
+
* rendered messages like `(an object) was tagged "[Unsafe bare string]"`).
|
|
74
|
+
*
|
|
75
|
+
* @type {AssertQuote}
|
|
76
|
+
*/
|
|
77
|
+
const bare = (payload, spaces = undefined) => {
|
|
78
|
+
if (typeof payload !== 'string' || !regexpTest(canBeBare, payload)) {
|
|
79
|
+
return quote(payload, spaces);
|
|
80
|
+
}
|
|
81
|
+
const result = freeze({
|
|
82
|
+
toString: freeze(() => payload),
|
|
83
|
+
});
|
|
84
|
+
weakmapSet(declassifiers, result, payload);
|
|
85
|
+
return result;
|
|
86
|
+
};
|
|
87
|
+
freeze(bare);
|
|
88
|
+
|
|
59
89
|
// /////////////////////////////////////////////////////////////////////////////
|
|
60
90
|
|
|
61
91
|
/**
|
|
@@ -237,7 +267,7 @@ const makeError = (
|
|
|
237
267
|
}
|
|
238
268
|
const hiddenDetails = weakmapGet(hiddenDetailsMap, optDetails);
|
|
239
269
|
if (hiddenDetails === undefined) {
|
|
240
|
-
throw
|
|
270
|
+
throw TypeError(`unrecognized details ${quote(optDetails)}`);
|
|
241
271
|
}
|
|
242
272
|
const messageString = getMessageString(hiddenDetails);
|
|
243
273
|
const error = new ErrorConstructor(messageString);
|
|
@@ -277,7 +307,7 @@ const note = (error, detailsNote) => {
|
|
|
277
307
|
}
|
|
278
308
|
const hiddenDetails = weakmapGet(hiddenDetailsMap, detailsNote);
|
|
279
309
|
if (hiddenDetails === undefined) {
|
|
280
|
-
throw
|
|
310
|
+
throw TypeError(`unrecognized details ${quote(detailsNote)}`);
|
|
281
311
|
}
|
|
282
312
|
const logArgs = getLogArgs(hiddenDetails);
|
|
283
313
|
const callbacks = weakmapGet(hiddenNoteCallbackArrays, error);
|
|
@@ -403,13 +433,9 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
403
433
|
typeof typename === 'string' || Fail`${quote(typename)} must be a string`;
|
|
404
434
|
|
|
405
435
|
if (optDetails === undefined) {
|
|
406
|
-
//
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
// ```
|
|
410
|
-
// except it puts the typename into the literal part of the template
|
|
411
|
-
// so it doesn't get quoted.
|
|
412
|
-
optDetails = details(['', ` must be ${an(typename)}`], specimen);
|
|
436
|
+
// Embed the type phrase without quotes.
|
|
437
|
+
const typeWithDeterminer = an(typename);
|
|
438
|
+
optDetails = details`${specimen} must be ${bare(typeWithDeterminer)}`;
|
|
413
439
|
}
|
|
414
440
|
fail(optDetails, TypeError);
|
|
415
441
|
};
|
|
@@ -431,6 +457,7 @@ const makeAssert = (optRaise = undefined, unredacted = false) => {
|
|
|
431
457
|
details,
|
|
432
458
|
Fail,
|
|
433
459
|
quote,
|
|
460
|
+
bare,
|
|
434
461
|
makeAssert,
|
|
435
462
|
});
|
|
436
463
|
return freeze(assert);
|
|
@@ -102,9 +102,7 @@ const spliceOut = cell => {
|
|
|
102
102
|
*/
|
|
103
103
|
export const makeLRUCacheMap = keysBudget => {
|
|
104
104
|
if (!isSafeInteger(keysBudget) || keysBudget < 0) {
|
|
105
|
-
throw
|
|
106
|
-
'keysBudget must be a safe non-negative integer number',
|
|
107
|
-
);
|
|
105
|
+
throw TypeError('keysBudget must be a safe non-negative integer number');
|
|
108
106
|
}
|
|
109
107
|
/** @typedef {DoublyLinkedCell<WeakMap<K, V> | undefined>} LRUCacheCell */
|
|
110
108
|
/** @type {WeakMap<K, LRUCacheCell>} */
|
|
@@ -227,7 +225,7 @@ export const makeNoteLogArgsArrayKit = (
|
|
|
227
225
|
argsPerErrorBudget = defaultArgsPerErrorBudget,
|
|
228
226
|
) => {
|
|
229
227
|
if (!isSafeInteger(argsPerErrorBudget) || argsPerErrorBudget < 1) {
|
|
230
|
-
throw
|
|
228
|
+
throw TypeError(
|
|
231
229
|
'argsPerErrorBudget must be a safe positive integer number',
|
|
232
230
|
);
|
|
233
231
|
}
|
|
@@ -28,7 +28,7 @@ export const tameConsole = (
|
|
|
28
28
|
optGetStackString = undefined,
|
|
29
29
|
) => {
|
|
30
30
|
if (consoleTaming !== 'safe' && consoleTaming !== 'unsafe') {
|
|
31
|
-
throw
|
|
31
|
+
throw TypeError(`unrecognized consoleTaming ${consoleTaming}`);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
let loggedErrorHandler;
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
getOwnPropertyDescriptor,
|
|
9
9
|
defineProperty,
|
|
10
10
|
} from '../commons.js';
|
|
11
|
-
import { NativeErrors } from '../
|
|
11
|
+
import { NativeErrors } from '../permits.js';
|
|
12
12
|
import { tameV8ErrorConstructor } from './tame-v8-error-constructor.js';
|
|
13
13
|
|
|
14
14
|
// Present on at least FF and XS. Proposed by Error-proposal. The original
|
|
@@ -35,10 +35,10 @@ export default function tameErrorConstructor(
|
|
|
35
35
|
stackFiltering = 'concise',
|
|
36
36
|
) {
|
|
37
37
|
if (errorTaming !== 'safe' && errorTaming !== 'unsafe') {
|
|
38
|
-
throw
|
|
38
|
+
throw TypeError(`unrecognized errorTaming ${errorTaming}`);
|
|
39
39
|
}
|
|
40
40
|
if (stackFiltering !== 'concise' && stackFiltering !== 'verbose') {
|
|
41
|
-
throw
|
|
41
|
+
throw TypeError(`unrecognized stackFiltering ${stackFiltering}`);
|
|
42
42
|
}
|
|
43
43
|
const ErrorPrototype = FERAL_ERROR.prototype;
|
|
44
44
|
|
|
@@ -207,7 +207,7 @@ export const tameV8ErrorConstructor = (
|
|
|
207
207
|
// Mapping from error instance to the stack for that instance.
|
|
208
208
|
// The stack info is either the structured stack trace
|
|
209
209
|
// or the generated tamed stack string
|
|
210
|
-
/** @type {WeakMap<Error, ParsedStackInfo | StructuredStackInfo} */
|
|
210
|
+
/** @type {WeakMap<Error, ParsedStackInfo | StructuredStackInfo>} */
|
|
211
211
|
const stackInfos = new WeakMap();
|
|
212
212
|
|
|
213
213
|
// Use concise methods to obtain named functions without constructors.
|
package/src/error/types.js
CHANGED
package/src/eval-scope.js
CHANGED
|
@@ -72,14 +72,16 @@ export const makeEvalScopeKit = () => {
|
|
|
72
72
|
const evalScopeKit = {
|
|
73
73
|
evalScope,
|
|
74
74
|
allowNextEvalToBeUnsafe() {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
const { revoked } = evalScopeKit;
|
|
76
|
+
if (revoked !== null) {
|
|
77
|
+
Fail`a handler did not reset allowNextEvalToBeUnsafe ${revoked.err}`;
|
|
77
78
|
}
|
|
78
79
|
// Allow next reference to eval produce the unsafe FERAL_EVAL.
|
|
79
80
|
// We avoid defineProperty because it consumes an extra stack frame taming
|
|
80
81
|
// its return value.
|
|
81
82
|
defineProperties(evalScope, oneTimeEvalProperties);
|
|
82
83
|
},
|
|
84
|
+
/** @type {null | { err: any }} */
|
|
83
85
|
revoked: null,
|
|
84
86
|
};
|
|
85
87
|
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
matchAllRegExp,
|
|
14
14
|
matchAllSymbol,
|
|
15
15
|
regexpPrototype,
|
|
16
|
+
globalThis,
|
|
16
17
|
} from './commons.js';
|
|
17
18
|
import { InertCompartment } from './compartment-shim.js';
|
|
18
19
|
|
|
@@ -45,10 +46,8 @@ export const getAnonymousIntrinsics = () => {
|
|
|
45
46
|
|
|
46
47
|
// 9.2.4.1 %ThrowTypeError%
|
|
47
48
|
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
'callee',
|
|
51
|
-
).get;
|
|
49
|
+
const argsCalleeDesc = getOwnPropertyDescriptor(makeArguments(), 'callee');
|
|
50
|
+
const ThrowTypeError = argsCalleeDesc && argsCalleeDesc.get;
|
|
52
51
|
|
|
53
52
|
// 21.1.5.2 The %StringIteratorPrototype% Object
|
|
54
53
|
|
|
@@ -136,5 +135,27 @@ export const getAnonymousIntrinsics = () => {
|
|
|
136
135
|
'%InertCompartment%': InertCompartment,
|
|
137
136
|
};
|
|
138
137
|
|
|
138
|
+
if (globalThis.Iterator) {
|
|
139
|
+
intrinsics['%IteratorHelperPrototype%'] = getPrototypeOf(
|
|
140
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
141
|
+
globalThis.Iterator.from([]).take(0),
|
|
142
|
+
);
|
|
143
|
+
intrinsics['%WrapForValidIteratorPrototype%'] = getPrototypeOf(
|
|
144
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
145
|
+
globalThis.Iterator.from({ next() {} }),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (globalThis.AsyncIterator) {
|
|
150
|
+
intrinsics['%AsyncIteratorHelperPrototype%'] = getPrototypeOf(
|
|
151
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
152
|
+
globalThis.AsyncIterator.from([]).take(0),
|
|
153
|
+
);
|
|
154
|
+
intrinsics['%WrapForValidAsyncIteratorPrototype%'] = getPrototypeOf(
|
|
155
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
156
|
+
globalThis.AsyncIterator.from({ next() {} }),
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
139
160
|
return intrinsics;
|
|
140
161
|
};
|
package/src/global-object.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from './commons.js';
|
|
11
11
|
import { makeEvalFunction } from './make-eval-function.js';
|
|
12
12
|
import { makeFunctionConstructor } from './make-function-constructor.js';
|
|
13
|
-
import { constantProperties, universalPropertyNames } from './
|
|
13
|
+
import { constantProperties, universalPropertyNames } from './permits.js';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The host's ordinary global object is not provided by a `with` block, so
|
|
@@ -31,7 +31,7 @@ export const setGlobalObjectSymbolUnscopables = globalObject => {
|
|
|
31
31
|
freeze(
|
|
32
32
|
assign(create(null), {
|
|
33
33
|
set: freeze(() => {
|
|
34
|
-
throw
|
|
34
|
+
throw TypeError(
|
|
35
35
|
`Cannot set Symbol.unscopables of a Compartment's globalThis`,
|
|
36
36
|
);
|
|
37
37
|
}),
|
package/src/intrinsics.js
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
TypeError,
|
|
3
3
|
WeakSet,
|
|
4
4
|
arrayFilter,
|
|
5
|
+
create,
|
|
5
6
|
defineProperty,
|
|
6
7
|
entries,
|
|
7
8
|
freeze,
|
|
@@ -19,8 +20,8 @@ import {
|
|
|
19
20
|
constantProperties,
|
|
20
21
|
sharedGlobalPropertyNames,
|
|
21
22
|
universalPropertyNames,
|
|
22
|
-
|
|
23
|
-
} from './
|
|
23
|
+
permitted,
|
|
24
|
+
} from './permits.js';
|
|
24
25
|
|
|
25
26
|
const isFunction = obj => typeof obj === 'function';
|
|
26
27
|
|
|
@@ -34,6 +35,7 @@ function initProperty(obj, name, desc) {
|
|
|
34
35
|
if (objectHasOwnProperty(obj, name)) {
|
|
35
36
|
const preDesc = getOwnPropertyDescriptor(obj, name);
|
|
36
37
|
if (
|
|
38
|
+
!preDesc ||
|
|
37
39
|
!is(preDesc.value, desc.value) ||
|
|
38
40
|
preDesc.get !== desc.get ||
|
|
39
41
|
preDesc.set !== desc.set ||
|
|
@@ -41,7 +43,7 @@ function initProperty(obj, name, desc) {
|
|
|
41
43
|
preDesc.enumerable !== desc.enumerable ||
|
|
42
44
|
preDesc.configurable !== desc.configurable
|
|
43
45
|
) {
|
|
44
|
-
throw
|
|
46
|
+
throw TypeError(`Conflicting definitions of ${name}`);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
defineProperty(obj, name, desc);
|
|
@@ -70,7 +72,8 @@ function sampleGlobals(globalObject, newPropertyNames) {
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
export const makeIntrinsicsCollector = () => {
|
|
73
|
-
|
|
75
|
+
/** @type {Record<any, any>} */
|
|
76
|
+
const intrinsics = create(null);
|
|
74
77
|
let pseudoNatives;
|
|
75
78
|
|
|
76
79
|
const addIntrinsics = newIntrinsics => {
|
|
@@ -91,24 +94,24 @@ export const makeIntrinsicsCollector = () => {
|
|
|
91
94
|
// eslint-disable-next-line no-continue
|
|
92
95
|
continue;
|
|
93
96
|
}
|
|
94
|
-
const permit =
|
|
97
|
+
const permit = permitted[name];
|
|
95
98
|
if (typeof permit !== 'object') {
|
|
96
|
-
throw
|
|
99
|
+
throw TypeError(`Expected permit object at whitelist.${name}`);
|
|
97
100
|
}
|
|
98
101
|
const namePrototype = permit.prototype;
|
|
99
102
|
if (!namePrototype) {
|
|
100
|
-
throw
|
|
103
|
+
throw TypeError(`${name}.prototype property not whitelisted`);
|
|
101
104
|
}
|
|
102
105
|
if (
|
|
103
106
|
typeof namePrototype !== 'string' ||
|
|
104
|
-
!objectHasOwnProperty(
|
|
107
|
+
!objectHasOwnProperty(permitted, namePrototype)
|
|
105
108
|
) {
|
|
106
|
-
throw
|
|
109
|
+
throw TypeError(`Unrecognized ${name}.prototype whitelist entry`);
|
|
107
110
|
}
|
|
108
111
|
const intrinsicPrototype = intrinsic.prototype;
|
|
109
112
|
if (objectHasOwnProperty(intrinsics, namePrototype)) {
|
|
110
113
|
if (intrinsics[namePrototype] !== intrinsicPrototype) {
|
|
111
|
-
throw
|
|
114
|
+
throw TypeError(`Conflicting bindings of ${namePrototype}`);
|
|
112
115
|
}
|
|
113
116
|
// eslint-disable-next-line no-continue
|
|
114
117
|
continue;
|
|
@@ -127,7 +130,7 @@ export const makeIntrinsicsCollector = () => {
|
|
|
127
130
|
|
|
128
131
|
const isPseudoNative = obj => {
|
|
129
132
|
if (!pseudoNatives) {
|
|
130
|
-
throw
|
|
133
|
+
throw TypeError(
|
|
131
134
|
'isPseudoNative can only be called after finalIntrinsics',
|
|
132
135
|
);
|
|
133
136
|
}
|