ses 1.5.0 → 1.6.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 +64 -3
- package/README.md +188 -73
- package/dist/lockdown.cjs +10958 -10693
- package/dist/lockdown.mjs +10958 -10693
- package/dist/lockdown.umd.js +10958 -10693
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +10958 -10693
- package/dist/ses.mjs +10958 -10693
- package/dist/ses.umd.js +10958 -10693
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +66 -32
- package/package.json +13 -12
- package/src/compartment.js +70 -50
- package/src/error/README.md +1 -1
- package/src/error/assert.js +19 -3
- package/src/error/tame-error-constructor.js +49 -5
- package/src/error/tame-v8-error-constructor.js +6 -0
- package/src/global-object.js +8 -5
- package/src/lockdown.js +10 -6
- package/src/module-instance.js +10 -14
- package/src/module-link.js +29 -45
- package/src/module-load.js +296 -121
- package/src/permits.js +18 -2
- package/types.d.ts +66 -32
package/dist/types.d.cts
CHANGED
|
@@ -25,7 +25,7 @@ export interface RepairOptions {
|
|
|
25
25
|
consoleTaming?: 'safe' | 'unsafe';
|
|
26
26
|
errorTrapping?: 'platform' | 'exit' | 'abort' | 'report' | 'none';
|
|
27
27
|
unhandledRejectionTrapping?: 'report' | 'none';
|
|
28
|
-
errorTaming?: 'safe' | 'unsafe';
|
|
28
|
+
errorTaming?: 'safe' | 'unsafe' | 'unsafe-debug';
|
|
29
29
|
dateTaming?: 'safe' | 'unsafe'; // deprecated
|
|
30
30
|
mathTaming?: 'safe' | 'unsafe'; // deprecated
|
|
31
31
|
evalTaming?: 'safeEval' | 'unsafeEval' | 'noEval';
|
|
@@ -43,19 +43,23 @@ export type RepairIntrinsics = (options?: LockdownOptions) => void;
|
|
|
43
43
|
export type HardenIntrinsics = () => void;
|
|
44
44
|
export type Lockdown = (options?: LockdownOptions) => void;
|
|
45
45
|
|
|
46
|
+
export type ModuleExportsNamespace = Record<string, any>;
|
|
47
|
+
|
|
46
48
|
export type __LiveExportMap__ = Record<string, [string, boolean]>;
|
|
47
49
|
export type __FixedExportMap__ = Record<string, [string]>;
|
|
50
|
+
export type __ReexportMap__ = Record<string, Array<[string, string]>>;
|
|
48
51
|
|
|
49
|
-
export interface
|
|
52
|
+
export interface PrecompiledModuleSource {
|
|
50
53
|
imports: Array<string>;
|
|
51
54
|
exports: Array<string>;
|
|
52
55
|
reexports: Array<string>;
|
|
53
56
|
__syncModuleProgram__: string;
|
|
54
57
|
__liveExportMap__: __LiveExportMap__;
|
|
55
58
|
__fixedExportMap__: __FixedExportMap__;
|
|
59
|
+
__reexportMap__: __ReexportMap__;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
export interface
|
|
62
|
+
export interface VirtualModuleSource {
|
|
59
63
|
imports: Array<string>;
|
|
60
64
|
exports: Array<string>;
|
|
61
65
|
/**
|
|
@@ -68,34 +72,61 @@ export interface ThirdPartyStaticModuleInterface {
|
|
|
68
72
|
): void;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
export type
|
|
72
|
-
| PrecompiledStaticModuleInterface
|
|
73
|
-
| ThirdPartyStaticModuleInterface;
|
|
75
|
+
export type ModuleSource = PrecompiledModuleSource | VirtualModuleSource;
|
|
74
76
|
|
|
75
|
-
export interface
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
export interface SourceModuleDescriptor {
|
|
78
|
+
source: string | ModuleSource;
|
|
79
|
+
specifier?: string;
|
|
78
80
|
importMeta?: any;
|
|
81
|
+
compartment?: Compartment; // defaults to parent
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface NamespaceModuleDescriptor {
|
|
85
|
+
namespace: string | ModuleExportsNamespace;
|
|
79
86
|
compartment?: Compartment;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
// Deprecated in favor of SourceModuleDescriptor,
|
|
90
|
+
// but beware the change in default compartment.
|
|
91
|
+
export interface RecordModuleDescriptor {
|
|
92
|
+
specifier: string;
|
|
93
|
+
record?: ModuleSource;
|
|
94
|
+
importMeta?: any;
|
|
95
|
+
compartment?: Compartment; // defaults to self
|
|
96
|
+
}
|
|
85
97
|
|
|
86
|
-
export type
|
|
98
|
+
export type ModuleDescriptor =
|
|
99
|
+
| SourceModuleDescriptor
|
|
100
|
+
| NamespaceModuleDescriptor
|
|
101
|
+
// To be deprecated:
|
|
102
|
+
| RecordModuleDescriptor
|
|
103
|
+
| ModuleExportsNamespace
|
|
104
|
+
| VirtualModuleSource
|
|
105
|
+
| PrecompiledModuleSource
|
|
106
|
+
| string;
|
|
107
|
+
|
|
108
|
+
// Deprecated type aliases:
|
|
109
|
+
export type PrecompiledStaticModuleInterface = PrecompiledModuleSource;
|
|
110
|
+
export type ThirdPartyStaticModuleInterface = VirtualModuleSource;
|
|
111
|
+
export type RedirectStaticModuleInterface = RecordModuleDescriptor;
|
|
112
|
+
export type FinalStaticModuleType = ModuleSource;
|
|
113
|
+
export type StaticModuleType = RedirectStaticModuleInterface | ModuleSource;
|
|
87
114
|
|
|
88
115
|
export type Transform = (source: string) => string;
|
|
89
116
|
export type ResolveHook = (
|
|
90
117
|
importSpecifier: string,
|
|
91
118
|
referrerSpecifier: string,
|
|
92
119
|
) => string;
|
|
93
|
-
export type ModuleMap = Record<string, string |
|
|
120
|
+
export type ModuleMap = Record<string, string | ModuleDescriptor>;
|
|
94
121
|
export type ModuleMapHook = (
|
|
95
122
|
moduleSpecifier: string,
|
|
96
|
-
) =>
|
|
97
|
-
export type ImportHook = (moduleSpecifier: string) => Promise<
|
|
98
|
-
export type ImportNowHook = (moduleSpecifier: string) =>
|
|
123
|
+
) => ModuleDescriptor | undefined;
|
|
124
|
+
export type ImportHook = (moduleSpecifier: string) => Promise<ModuleDescriptor>;
|
|
125
|
+
export type ImportNowHook = (moduleSpecifier: string) => ModuleDescriptor;
|
|
126
|
+
export type ImportMetaHook = (
|
|
127
|
+
moduleSpecifier: string,
|
|
128
|
+
importMeta: Object,
|
|
129
|
+
) => void;
|
|
99
130
|
|
|
100
131
|
export interface CompartmentOptions {
|
|
101
132
|
name?: string;
|
|
@@ -103,8 +134,12 @@ export interface CompartmentOptions {
|
|
|
103
134
|
moduleMapHook?: ModuleMapHook;
|
|
104
135
|
importHook?: ImportHook;
|
|
105
136
|
importNowHook?: ImportNowHook;
|
|
137
|
+
importMetaHook?: ImportMetaHook;
|
|
106
138
|
resolveHook?: ResolveHook;
|
|
139
|
+
globals?: Map<string, any>;
|
|
140
|
+
modules?: Map<string, ModuleDescriptor>;
|
|
107
141
|
__shimTransforms__?: Array<Transform>;
|
|
142
|
+
__noNamespaceBox__?: boolean;
|
|
108
143
|
}
|
|
109
144
|
|
|
110
145
|
export interface EvaluateOptions {
|
|
@@ -271,17 +306,17 @@ export interface AssertionFunctions extends BaseAssert {
|
|
|
271
306
|
*
|
|
272
307
|
* Assert that two values must be `Object.is`.
|
|
273
308
|
*/
|
|
274
|
-
equal(
|
|
309
|
+
equal<T>(
|
|
275
310
|
/** What we received */
|
|
276
|
-
actual:
|
|
311
|
+
actual: unknown,
|
|
277
312
|
/** What we wanted */
|
|
278
|
-
expected:
|
|
313
|
+
expected: T,
|
|
279
314
|
/** The details of what was asserted */
|
|
280
315
|
details?: Details,
|
|
281
316
|
/** An optional alternate error constructor to use */
|
|
282
317
|
errConstructor?: GenericErrorConstructor,
|
|
283
318
|
options?: AssertMakeErrorOptions,
|
|
284
|
-
):
|
|
319
|
+
): asserts actual is T;
|
|
285
320
|
|
|
286
321
|
/**
|
|
287
322
|
* The `assert.string` method.
|
|
@@ -346,12 +381,10 @@ export interface AssertionUtilities {
|
|
|
346
381
|
* ```js
|
|
347
382
|
* assert(sky.isBlue(), details`${sky.color} should be "blue"`);
|
|
348
383
|
* ```
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* or following the normal convention to locally rename `details` to `d`
|
|
352
|
-
* and `quote` to `q` like `const { details: d, quote: q } = assert;`:
|
|
384
|
+
* or following the normal convention to locally rename `details` to `X`
|
|
385
|
+
* and `quote` to `q` like `const { details: X, quote: q } = assert;`:
|
|
353
386
|
* ```js
|
|
354
|
-
* assert(sky.isBlue(),
|
|
387
|
+
* assert(sky.isBlue(), X`${sky.color} should be "blue"`);
|
|
355
388
|
* ```
|
|
356
389
|
* However, note that in most cases it is preferable to instead use the `Fail`
|
|
357
390
|
* template literal tag (which has the same input signature as `details`
|
|
@@ -427,10 +460,8 @@ export interface AssertionUtilities {
|
|
|
427
460
|
* sky.color === expectedColor || Fail`${sky.color} should be ${quote(expectedColor)}`;
|
|
428
461
|
* ```
|
|
429
462
|
*
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
* The normal convention is to locally rename `details` to `d` and `quote` to `q`
|
|
433
|
-
* like `const { details: d, quote: q } = assert;`, so the above example would then be
|
|
463
|
+
* The normal convention is to locally rename `details` to `X` and `quote` to `q`
|
|
464
|
+
* like `const { details: X, quote: q } = assert;`, so the above example would then be
|
|
434
465
|
* ```js
|
|
435
466
|
* sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;
|
|
436
467
|
* ```
|
|
@@ -510,9 +541,12 @@ declare global {
|
|
|
510
541
|
* code in a context bound to a new global creates a new compartment.
|
|
511
542
|
*/
|
|
512
543
|
export class Compartment {
|
|
544
|
+
constructor(options?: CompartmentOptions & { __options__: true });
|
|
545
|
+
|
|
546
|
+
// Deprecated:
|
|
513
547
|
constructor(
|
|
514
|
-
globals?:
|
|
515
|
-
|
|
548
|
+
globals?: Record<string, any> | undefined,
|
|
549
|
+
modules?: Record<string, ModuleDescriptor>,
|
|
516
550
|
options?: CompartmentOptions,
|
|
517
551
|
);
|
|
518
552
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -76,26 +76,26 @@
|
|
|
76
76
|
"test:platform-compatibility": "node test/package/test.cjs"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@endo/env-options": "^1.1.
|
|
79
|
+
"@endo/env-options": "^1.1.5"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@endo/compartment-mapper": "^1.
|
|
83
|
-
"@endo/
|
|
84
|
-
"@endo/test262-runner": "^0.1.
|
|
85
|
-
"ava": "^6.1.
|
|
86
|
-
"babel-eslint": "^10.0
|
|
82
|
+
"@endo/compartment-mapper": "^1.2.0",
|
|
83
|
+
"@endo/module-source": "^1.0.0",
|
|
84
|
+
"@endo/test262-runner": "^0.1.38",
|
|
85
|
+
"ava": "^6.1.3",
|
|
86
|
+
"babel-eslint": "^10.1.0",
|
|
87
87
|
"c8": "^7.14.0",
|
|
88
88
|
"core-js": "^3.31.0",
|
|
89
89
|
"eslint": "^8.57.0",
|
|
90
90
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
91
91
|
"eslint-config-prettier": "^9.1.0",
|
|
92
|
-
"eslint-plugin-eslint-comments": "^3.
|
|
93
|
-
"eslint-plugin-import": "^2.29.
|
|
92
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
93
|
+
"eslint-plugin-import": "^2.29.1",
|
|
94
94
|
"prettier": "^3.2.5",
|
|
95
95
|
"sinon": "^15.1.0",
|
|
96
96
|
"terser": "^5.16.6",
|
|
97
97
|
"tsd": "^0.30.7",
|
|
98
|
-
"typescript": "
|
|
98
|
+
"typescript": "5.5.2"
|
|
99
99
|
},
|
|
100
100
|
"files": [
|
|
101
101
|
"LICENSE*",
|
|
@@ -191,12 +191,13 @@
|
|
|
191
191
|
},
|
|
192
192
|
"ava": {
|
|
193
193
|
"files": [
|
|
194
|
-
"test/**/test
|
|
194
|
+
"test/**/test-*.*",
|
|
195
|
+
"test/**/*.test.*"
|
|
195
196
|
],
|
|
196
197
|
"timeout": "2m"
|
|
197
198
|
},
|
|
198
199
|
"typeCoverage": {
|
|
199
200
|
"atLeast": 81.17
|
|
200
201
|
},
|
|
201
|
-
"gitHead": "
|
|
202
|
+
"gitHead": "681b813ccb1fa177905dabf2ed3f5f248cb33ce7"
|
|
202
203
|
}
|
package/src/compartment.js
CHANGED
|
@@ -4,12 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
Map,
|
|
7
|
-
ReferenceError,
|
|
8
7
|
TypeError,
|
|
9
8
|
WeakMap,
|
|
10
9
|
assign,
|
|
11
10
|
defineProperties,
|
|
12
|
-
entries,
|
|
13
11
|
promiseThen,
|
|
14
12
|
toStringTagSymbol,
|
|
15
13
|
weakmapGet,
|
|
@@ -21,15 +19,15 @@ import {
|
|
|
21
19
|
setGlobalObjectMutableProperties,
|
|
22
20
|
setGlobalObjectEvaluators,
|
|
23
21
|
} from './global-object.js';
|
|
22
|
+
import { assertEqual } from './error/assert.js';
|
|
24
23
|
import { sharedGlobalPropertyNames } from './permits.js';
|
|
25
24
|
import { load, loadNow } from './module-load.js';
|
|
26
25
|
import { link } from './module-link.js';
|
|
27
26
|
import { getDeferredExports } from './module-proxy.js';
|
|
28
|
-
import { assert } from './error/assert.js';
|
|
29
27
|
import { compartmentEvaluate } from './compartment-evaluate.js';
|
|
30
28
|
import { makeSafeEvaluator } from './make-safe-evaluator.js';
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
/** @import {ModuleDescriptor} from '../types.js' */
|
|
33
31
|
|
|
34
32
|
// moduleAliases associates every public module exports namespace with its
|
|
35
33
|
// corresponding compartment and specifier so they can be used to link modules
|
|
@@ -42,19 +40,6 @@ const moduleAliases = new WeakMap();
|
|
|
42
40
|
// privateFields captures the private state for each compartment.
|
|
43
41
|
const privateFields = new WeakMap();
|
|
44
42
|
|
|
45
|
-
// Compartments do not need an importHook or resolveHook to be useful
|
|
46
|
-
// as a vessel for evaluating programs.
|
|
47
|
-
// However, any method that operates the module system will throw an exception
|
|
48
|
-
// if these hooks are not available.
|
|
49
|
-
const assertModuleHooks = compartment => {
|
|
50
|
-
const { importHook, resolveHook } = weakmapGet(privateFields, compartment);
|
|
51
|
-
if (typeof importHook !== 'function' || typeof resolveHook !== 'function') {
|
|
52
|
-
throw TypeError(
|
|
53
|
-
'Compartment must be constructed with an importHook and a resolveHook for it to be able to load modules',
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
43
|
export const InertCompartment = function Compartment(
|
|
59
44
|
_endowments = {},
|
|
60
45
|
_modules = {},
|
|
@@ -111,8 +96,6 @@ export const CompartmentPrototype = {
|
|
|
111
96
|
throw TypeError('first argument of module() must be a string');
|
|
112
97
|
}
|
|
113
98
|
|
|
114
|
-
assertModuleHooks(this);
|
|
115
|
-
|
|
116
99
|
const { exportsProxy } = getDeferredExports(
|
|
117
100
|
this,
|
|
118
101
|
weakmapGet(privateFields, this),
|
|
@@ -124,12 +107,12 @@ export const CompartmentPrototype = {
|
|
|
124
107
|
},
|
|
125
108
|
|
|
126
109
|
async import(specifier) {
|
|
110
|
+
const { noNamespaceBox } = weakmapGet(privateFields, this);
|
|
111
|
+
|
|
127
112
|
if (typeof specifier !== 'string') {
|
|
128
113
|
throw TypeError('first argument of import() must be a string');
|
|
129
114
|
}
|
|
130
115
|
|
|
131
|
-
assertModuleHooks(this);
|
|
132
|
-
|
|
133
116
|
return promiseThen(
|
|
134
117
|
load(privateFields, moduleAliases, this, specifier),
|
|
135
118
|
() => {
|
|
@@ -139,6 +122,11 @@ export const CompartmentPrototype = {
|
|
|
139
122
|
/** @type {Compartment} */ (this),
|
|
140
123
|
specifier,
|
|
141
124
|
);
|
|
125
|
+
if (noNamespaceBox) {
|
|
126
|
+
return namespace;
|
|
127
|
+
}
|
|
128
|
+
// Legacy behavior: box the namespace object so that thenable modules
|
|
129
|
+
// do not get coerced into a promise accidentally.
|
|
142
130
|
return { namespace };
|
|
143
131
|
},
|
|
144
132
|
);
|
|
@@ -149,8 +137,6 @@ export const CompartmentPrototype = {
|
|
|
149
137
|
throw TypeError('first argument of load() must be a string');
|
|
150
138
|
}
|
|
151
139
|
|
|
152
|
-
assertModuleHooks(this);
|
|
153
|
-
|
|
154
140
|
return load(privateFields, moduleAliases, this, specifier);
|
|
155
141
|
},
|
|
156
142
|
|
|
@@ -159,7 +145,6 @@ export const CompartmentPrototype = {
|
|
|
159
145
|
throw TypeError('first argument of importNow() must be a string');
|
|
160
146
|
}
|
|
161
147
|
|
|
162
|
-
assertModuleHooks(this);
|
|
163
148
|
loadNow(privateFields, moduleAliases, this, specifier);
|
|
164
149
|
return compartmentImportNow(/** @type {Compartment} */ (this), specifier);
|
|
165
150
|
},
|
|
@@ -186,16 +171,67 @@ defineProperties(InertCompartment, {
|
|
|
186
171
|
* @param {MakeCompartmentConstructor} targetMakeCompartmentConstructor
|
|
187
172
|
* @param {Record<string, any>} intrinsics
|
|
188
173
|
* @param {(object: object) => void} markVirtualizedNativeFunction
|
|
174
|
+
* @param {Compartment} [parentCompartment]
|
|
189
175
|
* @returns {Compartment['constructor']}
|
|
190
176
|
*/
|
|
191
177
|
|
|
178
|
+
// In order to facilitate migration from the deprecated signature
|
|
179
|
+
// of the compartment constructor,
|
|
180
|
+
// new Compartent(globals?, modules?, options?)
|
|
181
|
+
// to the new signature:
|
|
182
|
+
// new Compartment(options?)
|
|
183
|
+
// where globals and modules are expressed in the options bag instead of
|
|
184
|
+
// positional arguments, this function detects the temporary sigil __options__
|
|
185
|
+
// on the first argument and coerces compartments arguments into a single
|
|
186
|
+
// compartments object.
|
|
187
|
+
const compartmentOptions = (...args) => {
|
|
188
|
+
if (args.length === 0) {
|
|
189
|
+
return {};
|
|
190
|
+
}
|
|
191
|
+
if (
|
|
192
|
+
args.length === 1 &&
|
|
193
|
+
typeof args[0] === 'object' &&
|
|
194
|
+
args[0] !== null &&
|
|
195
|
+
'__options__' in args[0]
|
|
196
|
+
) {
|
|
197
|
+
const { __options__, ...options } = args[0];
|
|
198
|
+
assert(
|
|
199
|
+
__options__ === true,
|
|
200
|
+
`Compartment constructor only supports true __options__ sigil, got ${__options__}`,
|
|
201
|
+
);
|
|
202
|
+
return options;
|
|
203
|
+
} else {
|
|
204
|
+
const [
|
|
205
|
+
globals = /** @type {Map<string, any>} */ ({}),
|
|
206
|
+
modules = /** @type {Map<string, ModuleDescriptor>} */ ({}),
|
|
207
|
+
options = {},
|
|
208
|
+
] = args;
|
|
209
|
+
assertEqual(
|
|
210
|
+
options.modules,
|
|
211
|
+
undefined,
|
|
212
|
+
`Compartment constructor must receive either a module map argument or modules option, not both`,
|
|
213
|
+
);
|
|
214
|
+
assertEqual(
|
|
215
|
+
options.globals,
|
|
216
|
+
undefined,
|
|
217
|
+
`Compartment constructor must receive either globals argument or option, not both`,
|
|
218
|
+
);
|
|
219
|
+
return {
|
|
220
|
+
...options,
|
|
221
|
+
globals,
|
|
222
|
+
modules,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
192
227
|
/** @type {MakeCompartmentConstructor} */
|
|
193
228
|
export const makeCompartmentConstructor = (
|
|
194
229
|
targetMakeCompartmentConstructor,
|
|
195
230
|
intrinsics,
|
|
196
231
|
markVirtualizedNativeFunction,
|
|
232
|
+
parentCompartment = undefined,
|
|
197
233
|
) => {
|
|
198
|
-
function Compartment(
|
|
234
|
+
function Compartment(...args) {
|
|
199
235
|
if (new.target === undefined) {
|
|
200
236
|
throw TypeError(
|
|
201
237
|
"Class constructor Compartment cannot be invoked without 'new'",
|
|
@@ -207,13 +243,18 @@ export const makeCompartmentConstructor = (
|
|
|
207
243
|
name = '<unknown>',
|
|
208
244
|
transforms = [],
|
|
209
245
|
__shimTransforms__ = [],
|
|
246
|
+
globals: endowmentsOption = {},
|
|
247
|
+
modules: moduleMapOption = {},
|
|
210
248
|
resolveHook,
|
|
211
249
|
importHook,
|
|
212
250
|
importNowHook,
|
|
213
251
|
moduleMapHook,
|
|
214
252
|
importMetaHook,
|
|
215
|
-
|
|
253
|
+
__noNamespaceBox__: noNamespaceBox = false,
|
|
254
|
+
} = compartmentOptions(...args);
|
|
216
255
|
const globalTransforms = [...transforms, ...__shimTransforms__];
|
|
256
|
+
const endowments = { __proto__: null, ...endowmentsOption };
|
|
257
|
+
const moduleMap = { __proto__: null, ...moduleMapOption };
|
|
217
258
|
|
|
218
259
|
// Map<FullSpecifier, ModuleCompartmentRecord>
|
|
219
260
|
const moduleRecords = new Map();
|
|
@@ -222,30 +263,6 @@ export const makeCompartmentConstructor = (
|
|
|
222
263
|
// Map<FullSpecifier, {ExportsProxy, ProxiedExports, activate()}>
|
|
223
264
|
const deferredExports = new Map();
|
|
224
265
|
|
|
225
|
-
// Validate given moduleMap.
|
|
226
|
-
// The module map gets translated on-demand in module-load.js and the
|
|
227
|
-
// moduleMap can be invalid in ways that cannot be detected in the
|
|
228
|
-
// constructor, but these checks allow us to throw early for a better
|
|
229
|
-
// developer experience.
|
|
230
|
-
for (const [specifier, aliasNamespace] of entries(moduleMap || {})) {
|
|
231
|
-
if (typeof aliasNamespace === 'string') {
|
|
232
|
-
// TODO implement parent module record retrieval.
|
|
233
|
-
throw TypeError(
|
|
234
|
-
`Cannot map module ${q(specifier)} to ${q(
|
|
235
|
-
aliasNamespace,
|
|
236
|
-
)} in parent compartment`,
|
|
237
|
-
);
|
|
238
|
-
} else if (weakmapGet(moduleAliases, aliasNamespace) === undefined) {
|
|
239
|
-
// TODO create and link a synthetic module instance from the given
|
|
240
|
-
// namespace object.
|
|
241
|
-
throw ReferenceError(
|
|
242
|
-
`Cannot map module ${q(
|
|
243
|
-
specifier,
|
|
244
|
-
)} because it has no known compartment in this realm`,
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
266
|
const globalObject = {};
|
|
250
267
|
|
|
251
268
|
setGlobalObjectSymbolUnscopables(globalObject);
|
|
@@ -267,6 +284,7 @@ export const makeCompartmentConstructor = (
|
|
|
267
284
|
intrinsics,
|
|
268
285
|
newGlobalPropertyNames: sharedGlobalPropertyNames,
|
|
269
286
|
makeCompartmentConstructor: targetMakeCompartmentConstructor,
|
|
287
|
+
parentCompartment: this,
|
|
270
288
|
markVirtualizedNativeFunction,
|
|
271
289
|
});
|
|
272
290
|
|
|
@@ -294,6 +312,8 @@ export const makeCompartmentConstructor = (
|
|
|
294
312
|
__shimTransforms__,
|
|
295
313
|
deferredExports,
|
|
296
314
|
instances,
|
|
315
|
+
parentCompartment,
|
|
316
|
+
noNamespaceBox,
|
|
297
317
|
});
|
|
298
318
|
}
|
|
299
319
|
|
package/src/error/README.md
CHANGED
|
@@ -58,7 +58,7 @@ All the above forms of diagnostic information—error stacks, detailed error
|
|
|
58
58
|
|
|
59
59
|
To minimize visual noise, none of the following directly produces any logging output: throwing errors, assertion failure, or error annotation. They record information silently, only to be displayed if reached from an explicit `console` logging action. These logging actions are the root of a graph of this additional accumulated information. The logging action arguments include errors. These errors have both a detailed message that include errors, and detailed message annotations that include errors. Those errors likewise... The console logs this extra information once, with a unique tag per error. Any further occurrences of that error output that unique tag, from which to look up such previous log output.
|
|
60
60
|
|
|
61
|
-
Before repair or `lockdown`, we assume there is some prior "system" console bound to the global `console` in the start compartment. `{ consoleTaming: 'unsafe' }` leaves this unsafe system console in place. This system console is completely ignorant of the extra information in these side tables, which is therefore never seen. This includes the hidden data in the detailed messages. Instead, the system console shows the abbreviated `message` text produced by the `details` template literal that omits censored data. When combined with the default `{ errorTaming: 'safe' }`, the system console may not see error stack information. The `{ errorTaming: 'unsafe' }` setting does not remove error stacks from error objects, in which case the system console will find it as usual.
|
|
61
|
+
Before repair or `lockdown`, we assume there is some prior "system" console bound to the global `console` in the start compartment. `{ consoleTaming: 'unsafe' }` leaves this unsafe system console in place. This system console is completely ignorant of the extra information in these side tables, which is therefore never seen. This includes the hidden data in the detailed messages. Instead, the system console shows the abbreviated `message` text produced by the `details` template literal that omits censored data. When combined with the default `{ errorTaming: 'safe' }`, the system console may not see error stack information. The `{ errorTaming: 'unsafe' }` or `{ errorTaming: 'unsafe-details' }` setting does not remove error stacks from error objects, in which case the system console will find it as usual.
|
|
62
62
|
|
|
63
63
|
The default `{ consoleTaming: 'safe' }` setting replaces the system console with a root console that does use all these side tables to generate a more informative log. This root console wraps the prior system console. This root console outputs its log information only by invoking this wrapped system console, which therefore determines how this log information is made available to the external world. To support determinism, we will also need to support a no-op console setting, as explained at [deterministic handling of adversarial code calling console.log with a Proxy #1852](https://github.com/Agoric/agoric-sdk/issues/1852) and [Need no-op console setting for determinism #487](https://github.com/Agoric/SES-shim/issues/487).
|
|
64
64
|
|
package/src/error/assert.js
CHANGED
|
@@ -150,8 +150,9 @@ freeze(DetailsTokenProto.toString);
|
|
|
150
150
|
|
|
151
151
|
/**
|
|
152
152
|
* Normally this is the function exported as `assert.details` and often
|
|
153
|
-
* spelled `
|
|
154
|
-
* `
|
|
153
|
+
* spelled `X`. However, if the `{errorTaming: 'unsafe'}` or
|
|
154
|
+
* `{errorTaming: 'unsafe-debug'}` option is
|
|
155
|
+
* given to `lockdown`, then `unredactedDetails` is used instead.
|
|
155
156
|
*
|
|
156
157
|
* There are some unconditional uses of `redactedDetails` in this module. All
|
|
157
158
|
* of them should be uses where the template literal has no redacted
|
|
@@ -174,7 +175,8 @@ freeze(redactedDetails);
|
|
|
174
175
|
* `unredactedDetails` is like `details` except that it does not redact
|
|
175
176
|
* anything. It acts like `details` would act if all substitution values
|
|
176
177
|
* were wrapped with the `quote` function above (the function normally
|
|
177
|
-
* spelled `q`). If the `{errorTaming: 'unsafe'}`
|
|
178
|
+
* spelled `q`). If the `{errorTaming: 'unsafe'}`
|
|
179
|
+
* or `{errorTaming: 'unsafe-debug'}` option is given to
|
|
178
180
|
* `lockdown`, then the lockdown-shim arranges for the global `assert` to be
|
|
179
181
|
* one whose `details` property is `unredactedDetails`.
|
|
180
182
|
* This setting optimizes the debugging and testing experience at the price
|
|
@@ -564,3 +566,17 @@ export { makeAssert };
|
|
|
564
566
|
/** @type {Assert} */
|
|
565
567
|
const assert = makeAssert();
|
|
566
568
|
export { assert };
|
|
569
|
+
|
|
570
|
+
// Internal, to obviate polymorphic dispatch, but may become rigorously
|
|
571
|
+
// consistent with @endo/error:
|
|
572
|
+
|
|
573
|
+
/** @type {AssertionFunctions['equal']} */
|
|
574
|
+
const assertEqual = assert.equal;
|
|
575
|
+
|
|
576
|
+
export {
|
|
577
|
+
assertEqual,
|
|
578
|
+
makeError,
|
|
579
|
+
note as annotateError,
|
|
580
|
+
redactedDetails as X,
|
|
581
|
+
quote as q,
|
|
582
|
+
};
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
setPrototypeOf,
|
|
8
8
|
getOwnPropertyDescriptor,
|
|
9
9
|
defineProperty,
|
|
10
|
+
getOwnPropertyDescriptors,
|
|
10
11
|
} from '../commons.js';
|
|
11
12
|
import { NativeErrors } from '../permits.js';
|
|
12
13
|
import { tameV8ErrorConstructor } from './tame-v8-error-constructor.js';
|
|
@@ -29,12 +30,17 @@ const tamedMethods = {
|
|
|
29
30
|
return '';
|
|
30
31
|
},
|
|
31
32
|
};
|
|
33
|
+
let initialGetStackString = tamedMethods.getStackString;
|
|
32
34
|
|
|
33
35
|
export default function tameErrorConstructor(
|
|
34
36
|
errorTaming = 'safe',
|
|
35
37
|
stackFiltering = 'concise',
|
|
36
38
|
) {
|
|
37
|
-
if (
|
|
39
|
+
if (
|
|
40
|
+
errorTaming !== 'safe' &&
|
|
41
|
+
errorTaming !== 'unsafe' &&
|
|
42
|
+
errorTaming !== 'unsafe-debug'
|
|
43
|
+
) {
|
|
38
44
|
throw TypeError(`unrecognized errorTaming ${errorTaming}`);
|
|
39
45
|
}
|
|
40
46
|
if (stackFiltering !== 'concise' && stackFiltering !== 'verbose') {
|
|
@@ -42,9 +48,9 @@ export default function tameErrorConstructor(
|
|
|
42
48
|
}
|
|
43
49
|
const ErrorPrototype = FERAL_ERROR.prototype;
|
|
44
50
|
|
|
45
|
-
const platform =
|
|
46
|
-
typeof FERAL_ERROR.captureStackTrace === 'function' ? 'v8' : 'unknown';
|
|
47
51
|
const { captureStackTrace: originalCaptureStackTrace } = FERAL_ERROR;
|
|
52
|
+
const platform =
|
|
53
|
+
typeof originalCaptureStackTrace === 'function' ? 'v8' : 'unknown';
|
|
48
54
|
|
|
49
55
|
const makeErrorConstructor = (_ = {}) => {
|
|
50
56
|
// eslint-disable-next-line no-shadow
|
|
@@ -122,6 +128,45 @@ export default function tameErrorConstructor(
|
|
|
122
128
|
},
|
|
123
129
|
});
|
|
124
130
|
|
|
131
|
+
if (errorTaming === 'unsafe-debug' && platform === 'v8') {
|
|
132
|
+
// This case is a kludge to work around
|
|
133
|
+
// https://github.com/endojs/endo/issues/1798
|
|
134
|
+
// https://github.com/endojs/endo/issues/2348
|
|
135
|
+
// https://github.com/Agoric/agoric-sdk/issues/8662
|
|
136
|
+
|
|
137
|
+
defineProperties(InitialError, {
|
|
138
|
+
prepareStackTrace: {
|
|
139
|
+
get() {
|
|
140
|
+
return FERAL_ERROR.prepareStackTrace;
|
|
141
|
+
},
|
|
142
|
+
set(newPrepareStackTrace) {
|
|
143
|
+
FERAL_ERROR.prepareStackTrace = newPrepareStackTrace;
|
|
144
|
+
},
|
|
145
|
+
enumerable: false,
|
|
146
|
+
configurable: true,
|
|
147
|
+
},
|
|
148
|
+
captureStackTrace: {
|
|
149
|
+
value: FERAL_ERROR.captureStackTrace,
|
|
150
|
+
writable: true,
|
|
151
|
+
enumerable: false,
|
|
152
|
+
configurable: true,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const descs = getOwnPropertyDescriptors(InitialError);
|
|
157
|
+
defineProperties(SharedError, {
|
|
158
|
+
stackTraceLimit: descs.stackTraceLimit,
|
|
159
|
+
prepareStackTrace: descs.prepareStackTrace,
|
|
160
|
+
captureStackTrace: descs.captureStackTrace,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
'%InitialGetStackString%': initialGetStackString,
|
|
165
|
+
'%InitialError%': InitialError,
|
|
166
|
+
'%SharedError%': SharedError,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
125
170
|
// The default SharedError much be completely powerless even on v8,
|
|
126
171
|
// so the lenient `stackTraceLimit` accessor does nothing on all
|
|
127
172
|
// platforms.
|
|
@@ -171,7 +216,6 @@ export default function tameErrorConstructor(
|
|
|
171
216
|
});
|
|
172
217
|
}
|
|
173
218
|
|
|
174
|
-
let initialGetStackString = tamedMethods.getStackString;
|
|
175
219
|
if (platform === 'v8') {
|
|
176
220
|
initialGetStackString = tameV8ErrorConstructor(
|
|
177
221
|
FERAL_ERROR,
|
|
@@ -179,7 +223,7 @@ export default function tameErrorConstructor(
|
|
|
179
223
|
errorTaming,
|
|
180
224
|
stackFiltering,
|
|
181
225
|
);
|
|
182
|
-
} else if (errorTaming === 'unsafe') {
|
|
226
|
+
} else if (errorTaming === 'unsafe' || errorTaming === 'unsafe-debug') {
|
|
183
227
|
// v8 has too much magic around their 'stack' own property for it to
|
|
184
228
|
// coexist cleanly with this accessor. So only install it on non-v8
|
|
185
229
|
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
weakmapSet,
|
|
17
17
|
weaksetAdd,
|
|
18
18
|
weaksetHas,
|
|
19
|
+
TypeError,
|
|
19
20
|
} from '../commons.js';
|
|
20
21
|
|
|
21
22
|
// Whitelist names from https://v8.dev/docs/stack-trace-api
|
|
@@ -164,6 +165,11 @@ export const tameV8ErrorConstructor = (
|
|
|
164
165
|
errorTaming,
|
|
165
166
|
stackFiltering,
|
|
166
167
|
) => {
|
|
168
|
+
if (errorTaming === 'unsafe-debug') {
|
|
169
|
+
throw TypeError(
|
|
170
|
+
'internal: v8+unsafe-debug special case should already be done',
|
|
171
|
+
);
|
|
172
|
+
}
|
|
167
173
|
// TODO: Proper CallSite types
|
|
168
174
|
/** @typedef {{}} CallSite */
|
|
169
175
|
|