ses 1.12.0 → 1.13.1
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/LICENSE +1 -1
- package/SECURITY.md +2 -2
- package/dist/lockdown.cjs +953 -438
- package/dist/lockdown.mjs +953 -438
- package/dist/lockdown.umd.js +953 -438
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +827 -438
- package/dist/ses.cjs +953 -438
- package/dist/ses.mjs +953 -438
- package/dist/ses.umd.js +953 -438
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +19 -5
- package/package.json +12 -11
- package/src/commons.js +3 -1
- package/src/compartment.js +87 -34
- package/src/enablements.js +3 -1
- package/src/error/tame-console.js +0 -4
- package/src/error/tame-error-constructor.js +0 -11
- package/src/error/tame-v8-error-constructor.js +58 -15
- package/src/get-anonymous-intrinsics.js +11 -0
- package/src/lockdown.js +99 -56
- package/src/make-eval-function.js +5 -4
- package/src/make-function-constructor.js +5 -4
- package/src/module-load.js +47 -24
- package/src/permits.js +32 -1
- package/src/reporting.js +1 -4
- package/src/shim-arraybuffer-transfer.js +0 -1
- package/src/tame-domains.js +0 -4
- package/src/tame-harden.js +1 -5
- package/src/tame-locale-methods.js +0 -3
- package/src/tame-regexp-constructor.js +0 -3
- package/types.d.ts +19 -5
package/dist/types.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Types of the SES environment
|
|
3
|
+
* @module
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
/* eslint-disable no-restricted-globals, vars-on-top, no-var */
|
|
@@ -19,6 +20,10 @@
|
|
|
19
20
|
// version of harden.
|
|
20
21
|
export type Harden = <T>(value: T) => T; // not Hardened<T>;
|
|
21
22
|
|
|
23
|
+
// TODO Somehow remove the redundancy between these type deinitions and the
|
|
24
|
+
// inline casts on each call to `getenv` in `lockdown.js`. Hopefully we can
|
|
25
|
+
// keep the type info in those casts so it is easily comparable by eye to
|
|
26
|
+
// the parameters of that call to `genev`.
|
|
22
27
|
export interface RepairOptions {
|
|
23
28
|
regExpTaming?: 'safe' | 'unsafe';
|
|
24
29
|
localeTaming?: 'safe' | 'unsafe';
|
|
@@ -43,7 +48,7 @@ export interface RepairOptions {
|
|
|
43
48
|
| 'safeEval'
|
|
44
49
|
| 'unsafeEval'
|
|
45
50
|
| 'noEval';
|
|
46
|
-
stackFiltering?: 'concise' | 'verbose';
|
|
51
|
+
stackFiltering?: 'concise' | 'omit-frames' | 'shorten-paths' | 'verbose';
|
|
47
52
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
48
53
|
overrideDebug?: Array<string>;
|
|
49
54
|
domainTaming?: 'safe' | 'unsafe';
|
|
@@ -142,10 +147,12 @@ export type ModuleMapHook = (
|
|
|
142
147
|
moduleSpecifier: string,
|
|
143
148
|
) => ModuleDescriptor | undefined;
|
|
144
149
|
export type ImportHook = (moduleSpecifier: string) => Promise<ModuleDescriptor>;
|
|
145
|
-
export type ImportNowHook = (
|
|
150
|
+
export type ImportNowHook = (
|
|
151
|
+
moduleSpecifier: string,
|
|
152
|
+
) => ModuleDescriptor | undefined;
|
|
146
153
|
export type ImportMetaHook = (
|
|
147
154
|
moduleSpecifier: string,
|
|
148
|
-
importMeta:
|
|
155
|
+
importMeta: ImportMeta,
|
|
149
156
|
) => void;
|
|
150
157
|
|
|
151
158
|
export interface CompartmentOptions {
|
|
@@ -160,6 +167,11 @@ export interface CompartmentOptions {
|
|
|
160
167
|
modules?: Map<string, ModuleDescriptor>;
|
|
161
168
|
__shimTransforms__?: Array<Transform>;
|
|
162
169
|
__noNamespaceBox__?: boolean;
|
|
170
|
+
/** @deprecated */
|
|
171
|
+
loadHook?: (specifier: string) => Promise<ModuleDescriptor>;
|
|
172
|
+
/** @deprecated */
|
|
173
|
+
loadNowHook?: (specifier: string) => ModuleDescriptor;
|
|
174
|
+
__native__?: boolean;
|
|
163
175
|
}
|
|
164
176
|
|
|
165
177
|
export interface EvaluateOptions {
|
|
@@ -576,7 +588,9 @@ declare global {
|
|
|
576
588
|
|
|
577
589
|
evaluate(code: string, options?: CompartmentEvaluateOptions): any;
|
|
578
590
|
|
|
579
|
-
import(
|
|
591
|
+
import(
|
|
592
|
+
specifier: string | null,
|
|
593
|
+
): Promise<{ namespace: ModuleExportsNamespace }>;
|
|
580
594
|
|
|
581
595
|
load(specifier: string): Promise<void>;
|
|
582
596
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -91,34 +91,35 @@
|
|
|
91
91
|
"test": "tsd && ava",
|
|
92
92
|
"test:hermes": "./scripts/hermes-test.sh",
|
|
93
93
|
"test:xs": "xst dist/ses.umd.js test/_lockdown-safe.js && node scripts/generate-test-xs.js && xst tmp/test-xs.js && rm -rf tmp",
|
|
94
|
-
"postpack": "git clean -
|
|
94
|
+
"postpack": "git clean -fX \"*.d.ts*\" \"*.d.cts*\" \"*.d.mts*\" \"*.tsbuildinfo\""
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@endo/env-options": "^1.1.
|
|
97
|
+
"@endo/env-options": "^1.1.10",
|
|
98
|
+
"@endo/immutable-arraybuffer": "^1.1.1"
|
|
98
99
|
},
|
|
99
100
|
"devDependencies": {
|
|
100
101
|
"@babel/generator": "^7.26.3",
|
|
101
102
|
"@babel/parser": "~7.26.2",
|
|
102
103
|
"@babel/traverse": "~7.25.9",
|
|
103
104
|
"@babel/types": "~7.26.0",
|
|
104
|
-
"@endo/compartment-mapper": "^1.6.
|
|
105
|
-
"@endo/module-source": "^1.3.
|
|
106
|
-
"@endo/test262-runner": "^0.1.
|
|
105
|
+
"@endo/compartment-mapper": "^1.6.2",
|
|
106
|
+
"@endo/module-source": "^1.3.2",
|
|
107
|
+
"@endo/test262-runner": "^0.1.47",
|
|
107
108
|
"@types/babel__traverse": "^7.20.5",
|
|
108
109
|
"ava": "^6.1.3",
|
|
109
110
|
"babel-eslint": "^10.1.0",
|
|
110
111
|
"c8": "^7.14.0",
|
|
111
112
|
"core-js": "^3.31.0",
|
|
112
|
-
"eslint": "^8.57.
|
|
113
|
+
"eslint": "^8.57.1",
|
|
113
114
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
114
115
|
"eslint-config-prettier": "^9.1.0",
|
|
115
116
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
116
|
-
"eslint-plugin-import": "^2.
|
|
117
|
+
"eslint-plugin-import": "^2.31.0",
|
|
117
118
|
"hermes-engine-cli": "^0.12.0",
|
|
118
|
-
"prettier": "^3.
|
|
119
|
+
"prettier": "^3.5.3",
|
|
119
120
|
"terser": "^5.16.6",
|
|
120
121
|
"tsd": "^0.31.2",
|
|
121
|
-
"typescript": "~5.
|
|
122
|
+
"typescript": "~5.8.3"
|
|
122
123
|
},
|
|
123
124
|
"files": [
|
|
124
125
|
"./*.d.ts",
|
|
@@ -225,5 +226,5 @@
|
|
|
225
226
|
"typeCoverage": {
|
|
226
227
|
"atLeast": 81.17
|
|
227
228
|
},
|
|
228
|
-
"gitHead": "
|
|
229
|
+
"gitHead": "03b92fc383da5d8bb4ea993b90149a0db5799d0b"
|
|
229
230
|
}
|
package/src/commons.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Captures native intrinsics during initialization, so vetted shims
|
|
3
3
|
* (running between initialization of SES and calling lockdown) are free to
|
|
4
4
|
* modify the environment without compromising the integrity of SES. For
|
|
5
5
|
* example, a vetted shim can modify Object.assign because we capture and
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* This pattern of use is enforced by eslint rules no-restricted-globals and
|
|
10
10
|
* no-polymorphic-call.
|
|
11
11
|
* We maintain the list of restricted globals in ../package.json.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
/* global globalThis */
|
package/src/compartment.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Provides the mechanism to create a Compartment constructor that
|
|
3
3
|
* can provide either shim-specific or native XS features depending on
|
|
4
4
|
* the __native__ constructor option.
|
|
5
5
|
* This is necessary because a native Compartment can handle native ModuleSource
|
|
@@ -33,11 +33,12 @@
|
|
|
33
33
|
* Evaluating ./compartment.js does not have global side-effects.
|
|
34
34
|
* We defer modification of the global environment until the evaluation
|
|
35
35
|
* of ./compartment-shim.js.
|
|
36
|
+
*
|
|
37
|
+
* @module
|
|
36
38
|
*/
|
|
37
39
|
|
|
38
40
|
// @ts-check
|
|
39
41
|
/* eslint-disable no-underscore-dangle */
|
|
40
|
-
/// <reference types="ses">
|
|
41
42
|
|
|
42
43
|
import {
|
|
43
44
|
Map,
|
|
@@ -66,17 +67,49 @@ import { getDeferredExports } from './module-proxy.js';
|
|
|
66
67
|
import { compartmentEvaluate } from './compartment-evaluate.js';
|
|
67
68
|
import { makeSafeEvaluator } from './make-safe-evaluator.js';
|
|
68
69
|
|
|
69
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* @import {ImportHook, ImportMetaHook, ImportNowHook, ModuleDescriptor, ModuleExportsNamespace, ModuleMap, ModuleMapHook, ResolveHook, ModuleSource, CompartmentOptions} from '../types.js'
|
|
72
|
+
* @import {Transform} from './lockdown.js'
|
|
73
|
+
* @import {DeferredExports} from './module-proxy.js'
|
|
74
|
+
*/
|
|
70
75
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Associates every public module exports namespace with its corresponding
|
|
78
|
+
* compartment and specifier so they can be used to link modules across
|
|
79
|
+
* compartments. The mechanism to thread an alias is to use the
|
|
80
|
+
* {@link Compartment.module} function to obtain the exports namespace of a foreign
|
|
81
|
+
* module and pass it into another compartment's `moduleMap` constructor option
|
|
82
|
+
* @type {WeakMap<ModuleExportsNamespace, Compartment>}
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
77
85
|
const moduleAliases = new WeakMap();
|
|
78
86
|
|
|
79
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Private fields for `Compartment` instances
|
|
89
|
+
* @typedef {object} CompartmentFields
|
|
90
|
+
* @property {string} name
|
|
91
|
+
* @property {object} globalObject
|
|
92
|
+
* @property {Array<Transform>} globalTransforms
|
|
93
|
+
* @property {(source: string, options?: {localTransforms?: Array<Transform>}) => void} safeEvaluate
|
|
94
|
+
* @property {ResolveHook} resolveHook
|
|
95
|
+
* @property {ImportHook} importHook
|
|
96
|
+
* @property {ImportNowHook} importNowHook
|
|
97
|
+
* @property {ModuleMap} moduleMap
|
|
98
|
+
* @property {ModuleMapHook} moduleMapHook
|
|
99
|
+
* @property {ImportMetaHook} importMetaHook
|
|
100
|
+
* @property {Map<string, ModuleSource>} moduleRecords
|
|
101
|
+
* @property {Array<Transform>} __shimTransforms__
|
|
102
|
+
* @property {DeferredExports} deferredExports
|
|
103
|
+
* @property {Map<string, ModuleDescriptor>} instances
|
|
104
|
+
* @property {Compartment} [parentCompartment]
|
|
105
|
+
* @property {boolean} noNamespaceBox
|
|
106
|
+
* @property {(fullSpecifier: string) => Promise<ModuleExportsNamespace>} compartmentImport
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Captures the private state for each {@link Compartment}
|
|
111
|
+
* @type {WeakMap<Compartment, CompartmentFields>}
|
|
112
|
+
*/
|
|
80
113
|
const privateFields = new WeakMap();
|
|
81
114
|
|
|
82
115
|
export const InertCompartment = function Compartment(
|
|
@@ -92,6 +125,7 @@ export const InertCompartment = function Compartment(
|
|
|
92
125
|
/**
|
|
93
126
|
* @param {Compartment} compartment
|
|
94
127
|
* @param {string} specifier
|
|
128
|
+
* @returns {{namespace: ModuleExportsNamespace}}
|
|
95
129
|
*/
|
|
96
130
|
const compartmentImportNow = (compartment, specifier) => {
|
|
97
131
|
const { execute, exportsProxy } = link(
|
|
@@ -104,27 +138,20 @@ const compartmentImportNow = (compartment, specifier) => {
|
|
|
104
138
|
return exportsProxy;
|
|
105
139
|
};
|
|
106
140
|
|
|
141
|
+
/** @type {Compartment & {constructor: typeof InertCompartment}} */
|
|
107
142
|
export const CompartmentPrototype = {
|
|
108
143
|
constructor: InertCompartment,
|
|
109
144
|
|
|
110
145
|
get globalThis() {
|
|
111
|
-
return weakmapGet(privateFields, this)
|
|
146
|
+
return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
|
|
147
|
+
.globalObject;
|
|
112
148
|
},
|
|
113
149
|
|
|
114
150
|
get name() {
|
|
115
|
-
return weakmapGet(privateFields, this)
|
|
151
|
+
return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
|
|
152
|
+
.name;
|
|
116
153
|
},
|
|
117
154
|
|
|
118
|
-
/**
|
|
119
|
-
* @param {string} source is a JavaScript program grammar construction.
|
|
120
|
-
* @param {object} [options]
|
|
121
|
-
* @param {Array<import('./lockdown-shim').Transform>} [options.transforms]
|
|
122
|
-
* @param {boolean} [options.sloppyGlobalsMode]
|
|
123
|
-
* @param {object} [options.__moduleShimLexicals__]
|
|
124
|
-
* @param {boolean} [options.__evadeHtmlCommentTest__]
|
|
125
|
-
* @param {boolean} [options.__evadeImportExpressionTest__]
|
|
126
|
-
* @param {boolean} [options.__rejectSomeDirectEvalExpressions__]
|
|
127
|
-
*/
|
|
128
155
|
evaluate(source, options = {}) {
|
|
129
156
|
const compartmentFields = weakmapGet(privateFields, this);
|
|
130
157
|
return compartmentEvaluate(compartmentFields, source, options);
|
|
@@ -146,7 +173,9 @@ export const CompartmentPrototype = {
|
|
|
146
173
|
},
|
|
147
174
|
|
|
148
175
|
async import(specifier) {
|
|
149
|
-
const { noNamespaceBox } =
|
|
176
|
+
const { noNamespaceBox } = /** @type {CompartmentFields} */ (
|
|
177
|
+
weakmapGet(privateFields, this)
|
|
178
|
+
);
|
|
150
179
|
|
|
151
180
|
if (typeof specifier !== 'string') {
|
|
152
181
|
throw TypeError('first argument of import() must be a string');
|
|
@@ -185,7 +214,7 @@ export const CompartmentPrototype = {
|
|
|
185
214
|
}
|
|
186
215
|
|
|
187
216
|
loadNow(privateFields, moduleAliases, this, specifier);
|
|
188
|
-
return compartmentImportNow(
|
|
217
|
+
return compartmentImportNow(this, specifier);
|
|
189
218
|
},
|
|
190
219
|
};
|
|
191
220
|
|
|
@@ -216,15 +245,35 @@ defineProperties(InertCompartment, {
|
|
|
216
245
|
* @returns {Compartment['constructor']}
|
|
217
246
|
*/
|
|
218
247
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
248
|
+
/**
|
|
249
|
+
* "Options bag"-style `Compartment` constructor arguments.
|
|
250
|
+
* @typedef {[options?: CompartmentOptions & { __options__: true }]} CompartmentOptionsArgs
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Legacy `Compartment` constructor arguments.
|
|
255
|
+
*
|
|
256
|
+
* @deprecated
|
|
257
|
+
* @typedef {[globals?: Map<string, any>, modules?: Map<string, ModuleDescriptor>, options?: CompartmentOptions]} LegacyCompartmentOptionsArgs
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* In order to facilitate migration from the deprecated signature of the
|
|
262
|
+
* compartment constructor,
|
|
263
|
+
*
|
|
264
|
+
* `new Compartent(globals?, modules?, options?)`
|
|
265
|
+
*
|
|
266
|
+
* to the new signature:
|
|
267
|
+
*
|
|
268
|
+
* `new Compartment(options?)`
|
|
269
|
+
*
|
|
270
|
+
* ...where globals and modules are expressed in the options bag instead of
|
|
271
|
+
* positional arguments, this function detects the temporary sigil __options__
|
|
272
|
+
* on the first argument and coerces compartments arguments into a single
|
|
273
|
+
* compartments object.
|
|
274
|
+
* @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
|
|
275
|
+
* @returns {CompartmentOptions}
|
|
276
|
+
*/
|
|
228
277
|
export const compartmentOptions = (...args) => {
|
|
229
278
|
if (args.length === 0) {
|
|
230
279
|
return {};
|
|
@@ -246,7 +295,7 @@ export const compartmentOptions = (...args) => {
|
|
|
246
295
|
globals = /** @type {Map<string, any>} */ ({}),
|
|
247
296
|
modules = /** @type {Map<string, ModuleDescriptor>} */ ({}),
|
|
248
297
|
options = {},
|
|
249
|
-
] = args;
|
|
298
|
+
] = /** @type {LegacyCompartmentOptionsArgs} */ (args);
|
|
250
299
|
assertEqual(
|
|
251
300
|
options.modules,
|
|
252
301
|
undefined,
|
|
@@ -272,6 +321,10 @@ export const makeCompartmentConstructor = (
|
|
|
272
321
|
markVirtualizedNativeFunction,
|
|
273
322
|
{ parentCompartment = undefined, enforceNew = false } = {},
|
|
274
323
|
) => {
|
|
324
|
+
/**
|
|
325
|
+
*
|
|
326
|
+
* @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
|
|
327
|
+
*/
|
|
275
328
|
function Compartment(...args) {
|
|
276
329
|
if (enforceNew && new.target === undefined) {
|
|
277
330
|
throw TypeError(
|
package/src/enablements.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { toStringTagSymbol, iteratorSymbol } from './commons.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Exports {@code enablements}, a recursively defined
|
|
5
5
|
* JSON record defining the optimum set of intrinsics properties
|
|
6
6
|
* that need to be "repaired" before hardening is applied on
|
|
7
7
|
* enviromments subject to the override mistake.
|
|
8
8
|
*
|
|
9
9
|
* @author JF Paradis
|
|
10
10
|
* @author Mark S. Miller
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -41,10 +41,6 @@ export const tameConsole = (
|
|
|
41
41
|
unhandledRejectionTrapping = 'report',
|
|
42
42
|
optGetStackString = undefined,
|
|
43
43
|
) => {
|
|
44
|
-
consoleTaming === 'safe' ||
|
|
45
|
-
consoleTaming === 'unsafe' ||
|
|
46
|
-
failFast(`unrecognized consoleTaming ${consoleTaming}`);
|
|
47
|
-
|
|
48
44
|
let loggedErrorHandler;
|
|
49
45
|
if (optGetStackString === undefined) {
|
|
50
46
|
loggedErrorHandler = defaultHandler;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FERAL_ERROR,
|
|
3
|
-
TypeError,
|
|
4
3
|
apply,
|
|
5
4
|
construct,
|
|
6
5
|
defineProperties,
|
|
@@ -36,16 +35,6 @@ export default function tameErrorConstructor(
|
|
|
36
35
|
errorTaming = 'safe',
|
|
37
36
|
stackFiltering = 'concise',
|
|
38
37
|
) {
|
|
39
|
-
if (
|
|
40
|
-
errorTaming !== 'safe' &&
|
|
41
|
-
errorTaming !== 'unsafe' &&
|
|
42
|
-
errorTaming !== 'unsafe-debug'
|
|
43
|
-
) {
|
|
44
|
-
throw TypeError(`unrecognized errorTaming ${errorTaming}`);
|
|
45
|
-
}
|
|
46
|
-
if (stackFiltering !== 'concise' && stackFiltering !== 'verbose') {
|
|
47
|
-
throw TypeError(`unrecognized stackFiltering ${stackFiltering}`);
|
|
48
|
-
}
|
|
49
38
|
const ErrorPrototype = FERAL_ERROR.prototype;
|
|
50
39
|
|
|
51
40
|
const { captureStackTrace: originalCaptureStackTrace } = FERAL_ERROR;
|
|
@@ -71,10 +71,9 @@ const FILENAME_NODE_DEPENDENTS_CENSOR = /\/node_modules\//;
|
|
|
71
71
|
// stack traces.
|
|
72
72
|
const FILENAME_NODE_INTERNALS_CENSOR = /^(?:node:)?internal\//;
|
|
73
73
|
|
|
74
|
-
// Frames within
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
const FILENAME_ASSERT_CENSOR = /\/packages\/ses\/src\/error\/assert.js$/;
|
|
74
|
+
// Frames within SES `assert.js` should be dropped from concise stack traces, as
|
|
75
|
+
// these are just steps towards creating the error object in question.
|
|
76
|
+
const FILENAME_ASSERT_CENSOR = /\/packages\/ses\/src\/error\/assert\.js$/;
|
|
78
77
|
|
|
79
78
|
// Frames within the `eventual-send` shim should be dropped so that concise
|
|
80
79
|
// deep stacks omit the internals of the eventual-sending mechanism causing
|
|
@@ -83,6 +82,10 @@ const FILENAME_ASSERT_CENSOR = /\/packages\/ses\/src\/error\/assert.js$/;
|
|
|
83
82
|
// Endo, so this rule will be of general interest.
|
|
84
83
|
const FILENAME_EVENTUAL_SEND_CENSOR = /\/packages\/eventual-send\/src\//;
|
|
85
84
|
|
|
85
|
+
// Frames within the `ses-ava` package should be dropped from concise stack
|
|
86
|
+
// traces, as they just support exposing error details to AVA.
|
|
87
|
+
const FILENAME_SES_AVA_CENSOR = /\/packages\/ses-ava\/src\/ses-ava-test\.js$/;
|
|
88
|
+
|
|
86
89
|
// Any stack frame whose `fileName` matches any of these censor patterns
|
|
87
90
|
// will be omitted from concise stacks.
|
|
88
91
|
// TODO Enable users to configure FILENAME_CENSORS via `lockdown` options.
|
|
@@ -91,6 +94,7 @@ const FILENAME_CENSORS = [
|
|
|
91
94
|
FILENAME_NODE_INTERNALS_CENSOR,
|
|
92
95
|
FILENAME_ASSERT_CENSOR,
|
|
93
96
|
FILENAME_EVENTUAL_SEND_CENSOR,
|
|
97
|
+
FILENAME_SES_AVA_CENSOR,
|
|
94
98
|
];
|
|
95
99
|
|
|
96
100
|
// Should a stack frame with this as its fileName be included in a concise
|
|
@@ -114,34 +118,64 @@ export const filterFileName = fileName => {
|
|
|
114
118
|
// likely url-path prefix, ending in a `/.../` should get dropped.
|
|
115
119
|
// Anything to the left of the likely path text is kept.
|
|
116
120
|
// Everything to the right of `/.../` is kept. Thus
|
|
117
|
-
// `'Object.bar (/vat-v1/.../eventual-send/test/
|
|
121
|
+
// `'Object.bar (/vat-v1/.../eventual-send/test/deep-send.test.js:13:21)'`
|
|
122
|
+
// simplifies to
|
|
123
|
+
// `'Object.bar (eventual-send/test/deep-send.test.js:13:21)'`.
|
|
124
|
+
//
|
|
125
|
+
// See thread starting at
|
|
126
|
+
// https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
|
|
127
|
+
const CALLSITE_ELLIPSIS_PATTERN1 = /^((?:.*[( ])?)[:/\w_-]*\/\.\.\.\/(.+)$/;
|
|
128
|
+
|
|
129
|
+
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
130
|
+
// likely url-path prefix consisting of `.../` should get dropped.
|
|
131
|
+
// Anything to the left of the likely path text is kept.
|
|
132
|
+
// Everything to the right of `.../` is kept. Thus
|
|
133
|
+
// `'Object.bar (.../eventual-send/test/deep-send.test.js:13:21)'`
|
|
118
134
|
// simplifies to
|
|
119
|
-
// `'Object.bar (eventual-send/test/
|
|
135
|
+
// `'Object.bar (eventual-send/test/deep-send.test.js:13:21)'`.
|
|
120
136
|
//
|
|
121
137
|
// See thread starting at
|
|
122
138
|
// https://github.com/Agoric/agoric-sdk/issues/2326#issuecomment-773020389
|
|
123
|
-
const
|
|
139
|
+
const CALLSITE_ELLIPSIS_PATTERN2 = /^((?:.*[( ])?)\.\.\.\/(.+)$/;
|
|
124
140
|
|
|
125
141
|
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
126
142
|
// likely url-path prefix, ending in a `/` and prior to `package/` should get
|
|
127
143
|
// dropped.
|
|
128
144
|
// Anything to the left of the likely path prefix text is kept. `package/` and
|
|
129
145
|
// everything to its right is kept. Thus
|
|
130
|
-
// `'Object.bar (/Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/eventual-send/test/
|
|
146
|
+
// `'Object.bar (/Users/markmiller/src/ongithub/agoric/agoric-sdk/packages/eventual-send/test/deep-send.test.js:13:21)'`
|
|
131
147
|
// simplifies to
|
|
132
|
-
// `'Object.bar (packages/eventual-send/test/
|
|
148
|
+
// `'Object.bar (packages/eventual-send/test/deep-send.test.js:13:21)'`.
|
|
133
149
|
// Note that `/packages/` is a convention for monorepos encouraged by
|
|
134
150
|
// lerna.
|
|
135
151
|
const CALLSITE_PACKAGES_PATTERN = /^((?:.*[( ])?)[:/\w_-]*\/(packages\/.+)$/;
|
|
136
152
|
|
|
153
|
+
// The ad-hoc rule of the current pattern is that any likely-file-path or
|
|
154
|
+
// likely url-path prefix of the form `file://` but not `file:///` gets
|
|
155
|
+
// dropped.
|
|
156
|
+
// Anything to the left of the likely path prefix text is kept. Everything to
|
|
157
|
+
// the right of `file://` is kept. Thus
|
|
158
|
+
// `'Object.bar (file:///Users/markmiller/src/ongithub/endojs/endo/packages/eventual-send/test/deep-send.test.js:13:21)'` is unchanged but
|
|
159
|
+
// `'Object.bar (file://test/deep-send.test.js:13:21)'`
|
|
160
|
+
|
|
161
|
+
// simplifies to
|
|
162
|
+
// `'Object.bar (test/deep-send.test.js:13:21)'`.
|
|
163
|
+
// The reason is that `file:///` usually precedes an absolute path which is
|
|
164
|
+
// clickable without removing the `file:///`, whereas `file://` usually precedes
|
|
165
|
+
// a relative path which, for whatever vscode reason, is not clickable until the
|
|
166
|
+
// `file://` is removed.
|
|
167
|
+
const CALLSITE_FILE_2SLASH_PATTERN = /^((?:.*[( ])?)file:\/\/([^/].*)$/;
|
|
168
|
+
|
|
137
169
|
// The use of these callSite patterns below assumes that any match will bind
|
|
138
170
|
// capture groups containing the parts of the original string we want
|
|
139
171
|
// to keep. The parts outside those capture groups will be dropped from concise
|
|
140
172
|
// stacks.
|
|
141
173
|
// TODO Enable users to configure CALLSITE_PATTERNS via `lockdown` options.
|
|
142
174
|
const CALLSITE_PATTERNS = [
|
|
143
|
-
|
|
175
|
+
CALLSITE_ELLIPSIS_PATTERN1,
|
|
176
|
+
CALLSITE_ELLIPSIS_PATTERN2,
|
|
144
177
|
CALLSITE_PACKAGES_PATTERN,
|
|
178
|
+
CALLSITE_FILE_2SLASH_PATTERN,
|
|
145
179
|
];
|
|
146
180
|
|
|
147
181
|
// For a stack frame that should be included in a concise stack trace, if
|
|
@@ -149,6 +183,9 @@ const CALLSITE_PATTERNS = [
|
|
|
149
183
|
// possibly-shorter stringified stack frame that should be shown instead.
|
|
150
184
|
// Exported only so it can be unit tested.
|
|
151
185
|
// TODO Move so that it applies not just to v8.
|
|
186
|
+
/**
|
|
187
|
+
* @param {string} callSiteString
|
|
188
|
+
*/
|
|
152
189
|
export const shortenCallSiteString = callSiteString => {
|
|
153
190
|
for (const filter of CALLSITE_PATTERNS) {
|
|
154
191
|
const match = regexpExec(filter, callSiteString);
|
|
@@ -175,18 +212,24 @@ export const tameV8ErrorConstructor = (
|
|
|
175
212
|
|
|
176
213
|
const originalCaptureStackTrace = OriginalError.captureStackTrace;
|
|
177
214
|
|
|
215
|
+
const omitFrames =
|
|
216
|
+
stackFiltering === 'concise' || stackFiltering === 'omit-frames';
|
|
217
|
+
|
|
218
|
+
const shortenPaths =
|
|
219
|
+
stackFiltering === 'concise' || stackFiltering === 'shorten-paths';
|
|
220
|
+
|
|
178
221
|
// const callSiteFilter = _callSite => true;
|
|
179
222
|
const callSiteFilter = callSite => {
|
|
180
|
-
if (
|
|
181
|
-
|
|
223
|
+
if (omitFrames) {
|
|
224
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
225
|
+
return filterFileName(callSite.getFileName());
|
|
182
226
|
}
|
|
183
|
-
|
|
184
|
-
return filterFileName(callSite.getFileName());
|
|
227
|
+
return true;
|
|
185
228
|
};
|
|
186
229
|
|
|
187
230
|
const callSiteStringifier = callSite => {
|
|
188
231
|
let callSiteString = `${callSite}`;
|
|
189
|
-
if (
|
|
232
|
+
if (shortenPaths) {
|
|
190
233
|
callSiteString = shortenCallSiteString(callSiteString);
|
|
191
234
|
}
|
|
192
235
|
return `\n at ${callSiteString}`;
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
globalThis,
|
|
17
17
|
assign,
|
|
18
18
|
AsyncGeneratorFunctionInstance,
|
|
19
|
+
ArrayBuffer,
|
|
19
20
|
} from './commons.js';
|
|
20
21
|
import { InertCompartment } from './compartment.js';
|
|
21
22
|
|
|
@@ -166,5 +167,15 @@ export const getAnonymousIntrinsics = () => {
|
|
|
166
167
|
);
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
const ab = new ArrayBuffer(0);
|
|
171
|
+
// @ts-expect-error TODO How do I add sliceToImmutable to ArrayBuffer type?
|
|
172
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
173
|
+
const iab = ab.sliceToImmutable();
|
|
174
|
+
const iabProto = getPrototypeOf(iab);
|
|
175
|
+
if (iabProto !== ArrayBuffer.prototype) {
|
|
176
|
+
// In a native implementation, these will be the same prototype
|
|
177
|
+
intrinsics['%ImmutableArrayBufferPrototype%'] = iabProto;
|
|
178
|
+
}
|
|
179
|
+
|
|
169
180
|
return intrinsics;
|
|
170
181
|
};
|