ses 1.10.0 → 1.12.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/dist/lockdown.cjs +3986 -3668
- package/dist/lockdown.mjs +3986 -3668
- package/dist/lockdown.umd.js +3986 -3668
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +13146 -0
- package/dist/ses.cjs +3986 -3668
- package/dist/ses.mjs +3986 -3668
- package/dist/ses.umd.js +3986 -3668
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +18 -5
- package/package.json +31 -9
- package/src/commons.js +59 -17
- package/src/compartment-shim.js +3 -0
- package/src/compartment.js +91 -7
- package/src/error/console.js +38 -29
- package/src/get-anonymous-intrinsics.js +23 -18
- package/src/global-object.js +4 -1
- package/src/lockdown.js +44 -14
- package/src/make-safe-evaluator.js +8 -6
- package/src/module-instance.js +14 -1
- package/src/permits.js +92 -12
- package/src/reporting-types.d.ts +2 -2
- package/src/reporting.js +5 -3
- package/src/sloppy-globals-scope-terminator.js +9 -2
- package/src/strict-scope-terminator.js +11 -5
- package/src/tame-date-constructor.js +1 -4
- package/src/tame-function-constructors.js +9 -5
- package/src/tame-math-object.js +1 -4
- package/src/transforms.js +2 -1
- package/types.d.ts +18 -5
package/dist/types.d.cts
CHANGED
|
@@ -27,9 +27,22 @@ export interface RepairOptions {
|
|
|
27
27
|
reporting?: 'platform' | 'console' | 'none';
|
|
28
28
|
unhandledRejectionTrapping?: 'report' | 'none';
|
|
29
29
|
errorTaming?: 'safe' | 'unsafe' | 'unsafe-debug';
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Deprecated and does nothing. In the future specifying it will be an error.
|
|
32
|
+
*/
|
|
33
|
+
dateTaming?: 'safe' | 'unsafe';
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Deprecated and does nothing. In the future specifying it will be an error.
|
|
36
|
+
*/
|
|
37
|
+
mathTaming?: 'safe' | 'unsafe';
|
|
38
|
+
evalTaming?:
|
|
39
|
+
| 'safe-eval'
|
|
40
|
+
| 'unsafe-eval'
|
|
41
|
+
| 'no-eval'
|
|
42
|
+
// deprecated
|
|
43
|
+
| 'safeEval'
|
|
44
|
+
| 'unsafeEval'
|
|
45
|
+
| 'noEval';
|
|
33
46
|
stackFiltering?: 'concise' | 'verbose';
|
|
34
47
|
overrideTaming?: 'moderate' | 'min' | 'severe';
|
|
35
48
|
overrideDebug?: Array<string>;
|
|
@@ -552,12 +565,12 @@ declare global {
|
|
|
552
565
|
|
|
553
566
|
// Deprecated:
|
|
554
567
|
constructor(
|
|
555
|
-
globals?: Record<
|
|
568
|
+
globals?: Record<PropertyKey, any> | undefined,
|
|
556
569
|
modules?: Record<string, ModuleDescriptor>,
|
|
557
570
|
options?: CompartmentOptions,
|
|
558
571
|
);
|
|
559
572
|
|
|
560
|
-
get globalThis(): Record<
|
|
573
|
+
get globalThis(): Record<PropertyKey, any>;
|
|
561
574
|
|
|
562
575
|
get name(): string;
|
|
563
576
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ses",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Hardened JavaScript for Fearless Cooperation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lockdown",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
".": {
|
|
39
39
|
"import": {
|
|
40
40
|
"types": "./types.d.ts",
|
|
41
|
+
"xs": "./src-xs/index.js",
|
|
41
42
|
"default": "./index.js"
|
|
42
43
|
},
|
|
43
44
|
"require": {
|
|
@@ -55,15 +56,29 @@
|
|
|
55
56
|
"default": "./dist/ses.cjs"
|
|
56
57
|
}
|
|
57
58
|
},
|
|
59
|
+
"./hermes": {
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./dist/types.d.cts",
|
|
62
|
+
"default": "./dist/ses-hermes.cjs"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
58
65
|
"./tools.js": "./tools.js",
|
|
59
66
|
"./assert-shim.js": "./assert-shim.js",
|
|
60
|
-
"./lockdown-shim.js":
|
|
61
|
-
|
|
67
|
+
"./lockdown-shim.js": {
|
|
68
|
+
"xs": "./src-xs/lockdown-shim.js",
|
|
69
|
+
"default": "./lockdown-shim.js"
|
|
70
|
+
},
|
|
71
|
+
"./compartment-shim.js": {
|
|
72
|
+
"xs": "./src-xs/compartment-shim.js",
|
|
73
|
+
"default": "./compartment-shim.js"
|
|
74
|
+
},
|
|
62
75
|
"./console-shim.js": "./console-shim.js",
|
|
63
76
|
"./package.json": "./package.json"
|
|
64
77
|
},
|
|
65
78
|
"scripts": {
|
|
66
|
-
"build": "node scripts/bundle.js",
|
|
79
|
+
"build:vanilla": "node scripts/bundle.js",
|
|
80
|
+
"build:hermes": "node scripts/bundle.js hermes",
|
|
81
|
+
"build": "yarn build:vanilla && yarn build:hermes",
|
|
67
82
|
"clean": "rm -rf dist",
|
|
68
83
|
"cover": "c8 ava",
|
|
69
84
|
"demo": "python3 -m http.server",
|
|
@@ -74,16 +89,22 @@
|
|
|
74
89
|
"prepare": "npm run clean && npm run build",
|
|
75
90
|
"qt": "ava",
|
|
76
91
|
"test": "tsd && ava",
|
|
77
|
-
"test:
|
|
92
|
+
"test:hermes": "./scripts/hermes-test.sh",
|
|
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",
|
|
78
94
|
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
|
|
79
95
|
},
|
|
80
96
|
"dependencies": {
|
|
81
97
|
"@endo/env-options": "^1.1.8"
|
|
82
98
|
},
|
|
83
99
|
"devDependencies": {
|
|
84
|
-
"@
|
|
85
|
-
"@
|
|
86
|
-
"@
|
|
100
|
+
"@babel/generator": "^7.26.3",
|
|
101
|
+
"@babel/parser": "~7.26.2",
|
|
102
|
+
"@babel/traverse": "~7.25.9",
|
|
103
|
+
"@babel/types": "~7.26.0",
|
|
104
|
+
"@endo/compartment-mapper": "^1.6.0",
|
|
105
|
+
"@endo/module-source": "^1.3.0",
|
|
106
|
+
"@endo/test262-runner": "^0.1.45",
|
|
107
|
+
"@types/babel__traverse": "^7.20.5",
|
|
87
108
|
"ava": "^6.1.3",
|
|
88
109
|
"babel-eslint": "^10.1.0",
|
|
89
110
|
"c8": "^7.14.0",
|
|
@@ -93,6 +114,7 @@
|
|
|
93
114
|
"eslint-config-prettier": "^9.1.0",
|
|
94
115
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
95
116
|
"eslint-plugin-import": "^2.29.1",
|
|
117
|
+
"hermes-engine-cli": "^0.12.0",
|
|
96
118
|
"prettier": "^3.3.3",
|
|
97
119
|
"terser": "^5.16.6",
|
|
98
120
|
"tsd": "^0.31.2",
|
|
@@ -203,5 +225,5 @@
|
|
|
203
225
|
"typeCoverage": {
|
|
204
226
|
"atLeast": 81.17
|
|
205
227
|
},
|
|
206
|
-
"gitHead": "
|
|
228
|
+
"gitHead": "9b6784831d37db948cdd61f6da1f3489e8f97906"
|
|
207
229
|
}
|
package/src/commons.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
/* global globalThis */
|
|
2
|
-
/* eslint-disable no-restricted-globals */
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* @module Captures native intrinsics during initialization, so vetted shims
|
|
3
|
+
* (running between initialization of SES and calling lockdown) are free to
|
|
4
|
+
* modify the environment without compromising the integrity of SES. For
|
|
5
|
+
* example, a vetted shim can modify Object.assign because we capture and
|
|
6
|
+
* export Object and assign here, then never again consult Object to get its
|
|
7
|
+
* assign property.
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* This pattern of use is enforced by eslint rules no-restricted-globals and
|
|
10
|
+
* no-polymorphic-call.
|
|
11
|
+
* We maintain the list of restricted globals in ../package.json.
|
|
13
12
|
*/
|
|
14
13
|
|
|
14
|
+
/* global globalThis */
|
|
15
|
+
/* eslint-disable no-restricted-globals */
|
|
16
|
+
|
|
15
17
|
// We cannot use globalThis as the local name since it would capture the
|
|
16
18
|
// lexical name.
|
|
17
19
|
const universalThis = globalThis;
|
|
@@ -267,12 +269,6 @@ export const finalizationRegistryUnregister =
|
|
|
267
269
|
export const getConstructorOf = fn =>
|
|
268
270
|
reflectGet(getPrototypeOf(fn), 'constructor');
|
|
269
271
|
|
|
270
|
-
/**
|
|
271
|
-
* immutableObject
|
|
272
|
-
* An immutable (frozen) empty object that is safe to share.
|
|
273
|
-
*/
|
|
274
|
-
export const immutableObject = freeze(create(null));
|
|
275
|
-
|
|
276
272
|
/**
|
|
277
273
|
* isObject tests whether a value is an object.
|
|
278
274
|
* Today, this is equivalent to:
|
|
@@ -305,6 +301,12 @@ export const isObject = value => Object(value) === value;
|
|
|
305
301
|
*/
|
|
306
302
|
export const isError = value => value instanceof FERAL_ERROR;
|
|
307
303
|
|
|
304
|
+
/**
|
|
305
|
+
* @template T
|
|
306
|
+
* @param {T} x
|
|
307
|
+
*/
|
|
308
|
+
export const identity = x => x;
|
|
309
|
+
|
|
308
310
|
// The original unsafe untamed eval function, which must not escape.
|
|
309
311
|
// Sample at module initialization time, which is before lockdown can
|
|
310
312
|
// repair it. Use it only to build powerless abstractions.
|
|
@@ -318,7 +320,7 @@ export const FERAL_FUNCTION = Function;
|
|
|
318
320
|
|
|
319
321
|
export const noEvalEvaluate = () => {
|
|
320
322
|
// See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
|
|
321
|
-
throw TypeError('Cannot eval with evalTaming set to "
|
|
323
|
+
throw TypeError('Cannot eval with evalTaming set to "no-eval" (SES_NO_EVAL)');
|
|
322
324
|
};
|
|
323
325
|
|
|
324
326
|
// ////////////////// FERAL_STACK_GETTER FERAL_STACK_SETTER ////////////////////
|
|
@@ -378,3 +380,43 @@ export const FERAL_STACK_GETTER = feralStackGetter;
|
|
|
378
380
|
* @type {((newValue: any) => void) | undefined}
|
|
379
381
|
*/
|
|
380
382
|
export const FERAL_STACK_SETTER = feralStackSetter;
|
|
383
|
+
|
|
384
|
+
const getAsyncGeneratorFunctionInstance = () => {
|
|
385
|
+
// Test for async generator function syntax support.
|
|
386
|
+
try {
|
|
387
|
+
// Wrapping one in an new Function lets the `hermesc` binary file
|
|
388
|
+
// parse the Metro js bundle without SyntaxError, to generate the
|
|
389
|
+
// optimised Hermes bytecode bundle, when `gradlew` is called to
|
|
390
|
+
// assemble the release build APK for React Native prod Android apps.
|
|
391
|
+
// Delaying the error until runtime lets us customise lockdown behaviour.
|
|
392
|
+
return new FERAL_FUNCTION(
|
|
393
|
+
'return (async function* AsyncGeneratorFunctionInstance() {})',
|
|
394
|
+
)();
|
|
395
|
+
} catch (error) {
|
|
396
|
+
// Note: `Error.prototype.jsEngine` is only set by React Native runtime, not Hermes:
|
|
397
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/ReactCommon/hermes/executor/HermesExecutorFactory.cpp#L224-L230
|
|
398
|
+
if (error.name === 'SyntaxError') {
|
|
399
|
+
// Swallows Hermes error `async generators are unsupported` at runtime.
|
|
400
|
+
// Note: `console` is not a JS built-in, so Hermes engine throws:
|
|
401
|
+
// Uncaught ReferenceError: Property 'console' doesn't exist
|
|
402
|
+
// See: https://github.com/facebook/hermes/issues/675
|
|
403
|
+
// However React Native provides a `console` implementation when setting up error handling:
|
|
404
|
+
// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/InitializeCore.js
|
|
405
|
+
return undefined;
|
|
406
|
+
} else if (error.name === 'EvalError') {
|
|
407
|
+
// eslint-disable-next-line no-empty-function
|
|
408
|
+
return async function* AsyncGeneratorFunctionInstance() {};
|
|
409
|
+
} else {
|
|
410
|
+
throw error;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* If the platform supports async generator functions, this will be an
|
|
417
|
+
* async generator function instance. Otherwise, it will be `undefined`.
|
|
418
|
+
*
|
|
419
|
+
* @type {AsyncGeneratorFunction | undefined}
|
|
420
|
+
*/
|
|
421
|
+
export const AsyncGeneratorFunctionInstance =
|
|
422
|
+
getAsyncGeneratorFunctionInstance();
|
package/src/compartment-shim.js
CHANGED
package/src/compartment.js
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Provides the mechanism to create a Compartment constructor that
|
|
3
|
+
* can provide either shim-specific or native XS features depending on
|
|
4
|
+
* the __native__ constructor option.
|
|
5
|
+
* This is necessary because a native Compartment can handle native ModuleSource
|
|
6
|
+
* but cannot handle shim-specific pre-compiled ModuleSources like the JSON
|
|
7
|
+
* representation of a module that Compartment Mapper can put in bundles.
|
|
8
|
+
* Pre-compiling ModuleSource during bundling helps avoid paying the cost
|
|
9
|
+
* of importing Babel and transforming ESM syntax to a form that can be
|
|
10
|
+
* confined by the shim, which is prohibitively expensive for a web runtime
|
|
11
|
+
* and for XS _without this adapter_.
|
|
12
|
+
*
|
|
13
|
+
* Since any invocation of the Compartment constructor may occur standing
|
|
14
|
+
* on a native-flavor or shim-flavor compartment, we create parallel compartment
|
|
15
|
+
* constructor trees for compartments created with the Compartment constructor
|
|
16
|
+
* of a specific compartment.
|
|
17
|
+
*
|
|
18
|
+
* A compartment's importHook, importNowHook, moduleMapHook, and the modules
|
|
19
|
+
* map itself may provide module descriptors that address another compartment,
|
|
20
|
+
* using a compartment instance as a token indicating the compartment the
|
|
21
|
+
* module should be loaded or initialized in.
|
|
22
|
+
* Consequently, the compartment instance must be a suitable token for the
|
|
23
|
+
* underlying native-flavor or shim-flavor compartment.
|
|
24
|
+
* We are not in a position to fidddle with the native compartments behavior,
|
|
25
|
+
* so adapted compartments use the identity of the native compartment.
|
|
26
|
+
* We replace all of the methods of the native compartment prototype with
|
|
27
|
+
* thunks that choose behavior based on whether the compartment was
|
|
28
|
+
* constructed with the __native__ option.
|
|
29
|
+
* The SES shim associates a compartment with its private fields using a weak
|
|
30
|
+
* map exported by ../src/compartment.js and held closely by ses by the
|
|
31
|
+
* enforcement of explicit exports in package.json, since Node.js 12.11.0.
|
|
32
|
+
*
|
|
33
|
+
* Evaluating ./compartment.js does not have global side-effects.
|
|
34
|
+
* We defer modification of the global environment until the evaluation
|
|
35
|
+
* of ./compartment-shim.js.
|
|
36
|
+
*/
|
|
37
|
+
|
|
1
38
|
// @ts-check
|
|
2
39
|
/* eslint-disable no-underscore-dangle */
|
|
3
40
|
/// <reference types="ses">
|
|
@@ -6,8 +43,10 @@ import {
|
|
|
6
43
|
Map,
|
|
7
44
|
TypeError,
|
|
8
45
|
WeakMap,
|
|
46
|
+
arrayFlatMap,
|
|
9
47
|
assign,
|
|
10
48
|
defineProperties,
|
|
49
|
+
identity,
|
|
11
50
|
promiseThen,
|
|
12
51
|
toStringTagSymbol,
|
|
13
52
|
weakmapGet,
|
|
@@ -19,7 +58,7 @@ import {
|
|
|
19
58
|
setGlobalObjectMutableProperties,
|
|
20
59
|
setGlobalObjectEvaluators,
|
|
21
60
|
} from './global-object.js';
|
|
22
|
-
import { assert, assertEqual } from './error/assert.js';
|
|
61
|
+
import { assert, assertEqual, q } from './error/assert.js';
|
|
23
62
|
import { sharedGlobalPropertyNames } from './permits.js';
|
|
24
63
|
import { load, loadNow } from './module-load.js';
|
|
25
64
|
import { link } from './module-link.js';
|
|
@@ -27,7 +66,7 @@ import { getDeferredExports } from './module-proxy.js';
|
|
|
27
66
|
import { compartmentEvaluate } from './compartment-evaluate.js';
|
|
28
67
|
import { makeSafeEvaluator } from './make-safe-evaluator.js';
|
|
29
68
|
|
|
30
|
-
/** @import {ModuleDescriptor} from '../types.js' */
|
|
69
|
+
/** @import {ModuleDescriptor, ModuleExportsNamespace} from '../types.js' */
|
|
31
70
|
|
|
32
71
|
// moduleAliases associates every public module exports namespace with its
|
|
33
72
|
// corresponding compartment and specifier so they can be used to link modules
|
|
@@ -171,7 +210,9 @@ defineProperties(InertCompartment, {
|
|
|
171
210
|
* @param {MakeCompartmentConstructor} targetMakeCompartmentConstructor
|
|
172
211
|
* @param {Record<string, any>} intrinsics
|
|
173
212
|
* @param {(object: object) => void} markVirtualizedNativeFunction
|
|
174
|
-
* @param {
|
|
213
|
+
* @param {object} [options]
|
|
214
|
+
* @param {Compartment} [options.parentCompartment]
|
|
215
|
+
* @param {boolean} [options.enforceNew]
|
|
175
216
|
* @returns {Compartment['constructor']}
|
|
176
217
|
*/
|
|
177
218
|
|
|
@@ -184,7 +225,7 @@ defineProperties(InertCompartment, {
|
|
|
184
225
|
// positional arguments, this function detects the temporary sigil __options__
|
|
185
226
|
// on the first argument and coerces compartments arguments into a single
|
|
186
227
|
// compartments object.
|
|
187
|
-
const compartmentOptions = (...args) => {
|
|
228
|
+
export const compartmentOptions = (...args) => {
|
|
188
229
|
if (args.length === 0) {
|
|
189
230
|
return {};
|
|
190
231
|
}
|
|
@@ -229,10 +270,10 @@ export const makeCompartmentConstructor = (
|
|
|
229
270
|
targetMakeCompartmentConstructor,
|
|
230
271
|
intrinsics,
|
|
231
272
|
markVirtualizedNativeFunction,
|
|
232
|
-
parentCompartment = undefined,
|
|
273
|
+
{ parentCompartment = undefined, enforceNew = false } = {},
|
|
233
274
|
) => {
|
|
234
275
|
function Compartment(...args) {
|
|
235
|
-
if (new.target === undefined) {
|
|
276
|
+
if (enforceNew && new.target === undefined) {
|
|
236
277
|
throw TypeError(
|
|
237
278
|
"Class constructor Compartment cannot be invoked without 'new'",
|
|
238
279
|
);
|
|
@@ -252,7 +293,10 @@ export const makeCompartmentConstructor = (
|
|
|
252
293
|
importMetaHook,
|
|
253
294
|
__noNamespaceBox__: noNamespaceBox = false,
|
|
254
295
|
} = compartmentOptions(...args);
|
|
255
|
-
const globalTransforms =
|
|
296
|
+
const globalTransforms = arrayFlatMap(
|
|
297
|
+
[transforms, __shimTransforms__],
|
|
298
|
+
identity,
|
|
299
|
+
);
|
|
256
300
|
const endowments = { __proto__: null, ...endowmentsOption };
|
|
257
301
|
const moduleMap = { __proto__: null, ...moduleMapOption };
|
|
258
302
|
|
|
@@ -265,6 +309,8 @@ export const makeCompartmentConstructor = (
|
|
|
265
309
|
|
|
266
310
|
const globalObject = {};
|
|
267
311
|
|
|
312
|
+
const compartment = this;
|
|
313
|
+
|
|
268
314
|
setGlobalObjectSymbolUnscopables(globalObject);
|
|
269
315
|
|
|
270
316
|
// We must initialize all constant properties first because
|
|
@@ -297,6 +343,43 @@ export const makeCompartmentConstructor = (
|
|
|
297
343
|
|
|
298
344
|
assign(globalObject, endowments);
|
|
299
345
|
|
|
346
|
+
/**
|
|
347
|
+
* In support dynamic import in a module source loaded by this compartment,
|
|
348
|
+
* like `await import(importSpecifier)`, induces this compartment to import
|
|
349
|
+
* a module, returning a promise for the resulting module exports
|
|
350
|
+
* namespace.
|
|
351
|
+
* Unlike `compartment.import`, never creates a box object for the
|
|
352
|
+
* namespace as that behavior is deprecated and inconsistent with the
|
|
353
|
+
* standard behavior of dynamic import.
|
|
354
|
+
* Obliges the caller to resolve import specifiers to their corresponding
|
|
355
|
+
* full specifier.
|
|
356
|
+
* That is, every module must have its own dynamic import function that
|
|
357
|
+
* closes over the surrounding module's full module specifier and calls
|
|
358
|
+
* through to this function.
|
|
359
|
+
* @param {string} fullSpecifier - A full specifier is a key in the
|
|
360
|
+
* compartment's module memo.
|
|
361
|
+
* The method `compartment.import` accepts a full specifier, but dynamic
|
|
362
|
+
* import accepts an import specifier and resolves it to a full specifier
|
|
363
|
+
* relative to the calling module's full specifier.
|
|
364
|
+
* @returns {Promise<ModuleExportsNamespace>}
|
|
365
|
+
*/
|
|
366
|
+
const compartmentImport = async fullSpecifier => {
|
|
367
|
+
if (typeof resolveHook !== 'function') {
|
|
368
|
+
throw TypeError(
|
|
369
|
+
`Compartment does not support dynamic import: no configured resolveHook for compartment ${q(name)}`,
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
await load(privateFields, moduleAliases, compartment, fullSpecifier);
|
|
373
|
+
const { execute, exportsProxy } = link(
|
|
374
|
+
privateFields,
|
|
375
|
+
moduleAliases,
|
|
376
|
+
compartment,
|
|
377
|
+
fullSpecifier,
|
|
378
|
+
);
|
|
379
|
+
execute();
|
|
380
|
+
return exportsProxy;
|
|
381
|
+
};
|
|
382
|
+
|
|
300
383
|
weakmapSet(privateFields, this, {
|
|
301
384
|
name: `${name}`,
|
|
302
385
|
globalTransforms,
|
|
@@ -314,6 +397,7 @@ export const makeCompartmentConstructor = (
|
|
|
314
397
|
instances,
|
|
315
398
|
parentCompartment,
|
|
316
399
|
noNamespaceBox,
|
|
400
|
+
compartmentImport,
|
|
317
401
|
});
|
|
318
402
|
}
|
|
319
403
|
|
package/src/error/console.js
CHANGED
|
@@ -28,6 +28,20 @@ import {
|
|
|
28
28
|
* @import {ErrorInfo, ErrorInfoKind, LogRecord, NoteCallback, LoggedErrorHandler, MakeCausalConsole, MakeLoggingConsoleKit} from "./internal-types.js";
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Explicitly set a function's name, supporting use of arrow functions for which
|
|
33
|
+
* source text doesn't include a name and no initial name is set by
|
|
34
|
+
* NamedEvaluation
|
|
35
|
+
* https://tc39.es/ecma262/multipage/syntax-directed-operations.html#sec-runtime-semantics-namedevaluation
|
|
36
|
+
* Instead, we hope that tooling uses only the explicit `name` property.
|
|
37
|
+
*
|
|
38
|
+
* @template {Function} F
|
|
39
|
+
* @param {string} name
|
|
40
|
+
* @param {F} fn
|
|
41
|
+
* @returns {F}
|
|
42
|
+
*/
|
|
43
|
+
const defineName = (name, fn) => defineProperty(fn, 'name', { value: name });
|
|
44
|
+
|
|
31
45
|
// For our internal debugging purposes, uncomment
|
|
32
46
|
// const internalDebugConsole = console;
|
|
33
47
|
|
|
@@ -159,16 +173,12 @@ export const makeLoggingConsoleKit = (
|
|
|
159
173
|
|
|
160
174
|
const loggingConsole = fromEntries(
|
|
161
175
|
arrayMap(consoleMethodPermits, ([name, _]) => {
|
|
162
|
-
// Use an arrow function so that it doesn't come with its own name in
|
|
163
|
-
// its printed form. Instead, we're hoping that tooling uses only
|
|
164
|
-
// the `.name` property set below.
|
|
165
176
|
/**
|
|
166
177
|
* @param {...any} args
|
|
167
178
|
*/
|
|
168
|
-
const method = (...args) => {
|
|
179
|
+
const method = defineName(name, (...args) => {
|
|
169
180
|
arrayPush(logArray, [name, ...args]);
|
|
170
|
-
};
|
|
171
|
-
defineProperty(method, 'name', { value: name });
|
|
181
|
+
});
|
|
172
182
|
return [name, freeze(method)];
|
|
173
183
|
}),
|
|
174
184
|
);
|
|
@@ -288,8 +298,10 @@ export const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
|
|
|
288
298
|
logError(severity, subError);
|
|
289
299
|
}
|
|
290
300
|
} finally {
|
|
291
|
-
|
|
292
|
-
|
|
301
|
+
if (baseConsole.groupEnd) {
|
|
302
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
303
|
+
baseConsole.groupEnd();
|
|
304
|
+
}
|
|
293
305
|
}
|
|
294
306
|
};
|
|
295
307
|
|
|
@@ -368,7 +380,7 @@ export const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
|
|
|
368
380
|
/**
|
|
369
381
|
* @param {...any} logArgs
|
|
370
382
|
*/
|
|
371
|
-
const levelMethod = (...logArgs) => {
|
|
383
|
+
const levelMethod = defineName(level, (...logArgs) => {
|
|
372
384
|
const subErrors = [];
|
|
373
385
|
const argTags = extractErrorArgs(logArgs, subErrors);
|
|
374
386
|
if (baseConsole[level]) {
|
|
@@ -377,8 +389,7 @@ export const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
|
|
|
377
389
|
}
|
|
378
390
|
// @ts-expect-error ConsoleProp vs LogSeverity mismatch
|
|
379
391
|
logSubErrors(level, subErrors);
|
|
380
|
-
};
|
|
381
|
-
defineProperty(levelMethod, 'name', { value: level });
|
|
392
|
+
});
|
|
382
393
|
return [level, freeze(levelMethod)];
|
|
383
394
|
});
|
|
384
395
|
const otherMethodNames = arrayFilter(
|
|
@@ -389,13 +400,12 @@ export const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
|
|
|
389
400
|
/**
|
|
390
401
|
* @param {...any} args
|
|
391
402
|
*/
|
|
392
|
-
const otherMethod = (...args) => {
|
|
403
|
+
const otherMethod = defineName(name, (...args) => {
|
|
393
404
|
// @ts-ignore
|
|
394
405
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
395
406
|
baseConsole[name](...args);
|
|
396
407
|
return undefined;
|
|
397
|
-
};
|
|
398
|
-
defineProperty(otherMethod, 'name', { value: name });
|
|
408
|
+
});
|
|
399
409
|
return [name, freeze(otherMethod)];
|
|
400
410
|
});
|
|
401
411
|
|
|
@@ -456,23 +466,21 @@ export const defineCausalConsoleFromLogger = loggedErrorHandler => {
|
|
|
456
466
|
}
|
|
457
467
|
return tlogger(...args);
|
|
458
468
|
};
|
|
459
|
-
const makeNamed = (name, fn) =>
|
|
460
|
-
({ [name]: (...args) => fn(...args) })[name];
|
|
461
469
|
|
|
462
470
|
const baseConsole = fromEntries([
|
|
463
471
|
...arrayMap(consoleLevelMethods, ([name]) => [
|
|
464
472
|
name,
|
|
465
|
-
|
|
473
|
+
defineName(name, (...args) => logWithIndent(...args)),
|
|
466
474
|
]),
|
|
467
475
|
...arrayMap(consoleOtherMethods, ([name]) => [
|
|
468
476
|
name,
|
|
469
|
-
|
|
477
|
+
defineName(name, (...args) => logWithIndent(name, ...args)),
|
|
470
478
|
]),
|
|
471
479
|
]);
|
|
472
480
|
// https://console.spec.whatwg.org/#grouping
|
|
473
481
|
for (const name of ['group', 'groupCollapsed']) {
|
|
474
482
|
if (baseConsole[name]) {
|
|
475
|
-
baseConsole[name] =
|
|
483
|
+
baseConsole[name] = defineName(name, (...args) => {
|
|
476
484
|
if (args.length >= 1) {
|
|
477
485
|
// Prefix the logged data with "group" or "groupCollapsed".
|
|
478
486
|
logWithIndent(...args);
|
|
@@ -482,16 +490,17 @@ export const defineCausalConsoleFromLogger = loggedErrorHandler => {
|
|
|
482
490
|
arrayPush(indents, ' ');
|
|
483
491
|
});
|
|
484
492
|
} else {
|
|
485
|
-
baseConsole[name] = () => {};
|
|
493
|
+
baseConsole[name] = defineName(name, () => {});
|
|
486
494
|
}
|
|
487
495
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
496
|
+
baseConsole.groupEnd = defineName(
|
|
497
|
+
'groupEnd',
|
|
498
|
+
baseConsole.groupEnd
|
|
499
|
+
? (...args) => {
|
|
500
|
+
arrayPop(indents);
|
|
501
|
+
}
|
|
502
|
+
: () => {},
|
|
503
|
+
);
|
|
495
504
|
harden(baseConsole);
|
|
496
505
|
const causalConsole = makeCausalConsole(
|
|
497
506
|
/** @type {VirtualConsole} */ (baseConsole),
|
|
@@ -516,14 +525,14 @@ export const filterConsole = (baseConsole, filter, _topic = undefined) => {
|
|
|
516
525
|
/**
|
|
517
526
|
* @param {...any} args
|
|
518
527
|
*/
|
|
519
|
-
const method = (...args) => {
|
|
528
|
+
const method = defineName(name, (...args) => {
|
|
520
529
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
521
530
|
if (severity === undefined || filter.canLog(severity)) {
|
|
522
531
|
// @ts-ignore
|
|
523
532
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
524
533
|
baseConsole[name](...args);
|
|
525
534
|
}
|
|
526
|
-
};
|
|
535
|
+
});
|
|
527
536
|
return [name, freeze(method)];
|
|
528
537
|
});
|
|
529
538
|
const filteringConsole = fromEntries(methods);
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
matchAllSymbol,
|
|
15
15
|
regexpPrototype,
|
|
16
16
|
globalThis,
|
|
17
|
+
assign,
|
|
18
|
+
AsyncGeneratorFunctionInstance,
|
|
17
19
|
} from './commons.js';
|
|
18
20
|
import { InertCompartment } from './compartment.js';
|
|
19
21
|
|
|
@@ -95,20 +97,6 @@ export const getAnonymousIntrinsics = () => {
|
|
|
95
97
|
|
|
96
98
|
const Generator = GeneratorFunction.prototype;
|
|
97
99
|
|
|
98
|
-
// 25.3.1 The AsyncGeneratorFunction Constructor
|
|
99
|
-
|
|
100
|
-
// eslint-disable-next-line no-empty-function
|
|
101
|
-
async function* AsyncGeneratorFunctionInstance() {}
|
|
102
|
-
const AsyncGeneratorFunction = getConstructorOf(
|
|
103
|
-
AsyncGeneratorFunctionInstance,
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
// 25.3.2.2 AsyncGeneratorFunction.prototype
|
|
107
|
-
const AsyncGenerator = AsyncGeneratorFunction.prototype;
|
|
108
|
-
// 25.5.1 Properties of the AsyncGenerator Prototype Object
|
|
109
|
-
const AsyncGeneratorPrototype = AsyncGenerator.prototype;
|
|
110
|
-
const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);
|
|
111
|
-
|
|
112
100
|
// 25.7.1 The AsyncFunction Constructor
|
|
113
101
|
|
|
114
102
|
// eslint-disable-next-line no-empty-function
|
|
@@ -119,10 +107,6 @@ export const getAnonymousIntrinsics = () => {
|
|
|
119
107
|
'%InertFunction%': InertFunction,
|
|
120
108
|
'%ArrayIteratorPrototype%': ArrayIteratorPrototype,
|
|
121
109
|
'%InertAsyncFunction%': AsyncFunction,
|
|
122
|
-
'%AsyncGenerator%': AsyncGenerator,
|
|
123
|
-
'%InertAsyncGeneratorFunction%': AsyncGeneratorFunction,
|
|
124
|
-
'%AsyncGeneratorPrototype%': AsyncGeneratorPrototype,
|
|
125
|
-
'%AsyncIteratorPrototype%': AsyncIteratorPrototype,
|
|
126
110
|
'%Generator%': Generator,
|
|
127
111
|
'%InertGeneratorFunction%': GeneratorFunction,
|
|
128
112
|
'%IteratorPrototype%': IteratorPrototype,
|
|
@@ -135,6 +119,27 @@ export const getAnonymousIntrinsics = () => {
|
|
|
135
119
|
'%InertCompartment%': InertCompartment,
|
|
136
120
|
};
|
|
137
121
|
|
|
122
|
+
if (AsyncGeneratorFunctionInstance !== undefined) {
|
|
123
|
+
// 25.3.1 The AsyncGeneratorFunction Constructor
|
|
124
|
+
|
|
125
|
+
const AsyncGeneratorFunction = getConstructorOf(
|
|
126
|
+
AsyncGeneratorFunctionInstance,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// 25.3.2.2 AsyncGeneratorFunction.prototype
|
|
130
|
+
const AsyncGenerator = AsyncGeneratorFunction.prototype;
|
|
131
|
+
// 25.5.1 Properties of the AsyncGenerator Prototype Object
|
|
132
|
+
const AsyncGeneratorPrototype = AsyncGenerator.prototype;
|
|
133
|
+
const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);
|
|
134
|
+
|
|
135
|
+
assign(intrinsics, {
|
|
136
|
+
'%AsyncGenerator%': AsyncGenerator,
|
|
137
|
+
'%InertAsyncGeneratorFunction%': AsyncGeneratorFunction,
|
|
138
|
+
'%AsyncGeneratorPrototype%': AsyncGeneratorPrototype,
|
|
139
|
+
'%AsyncIteratorPrototype%': AsyncIteratorPrototype,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
138
143
|
if (globalThis.Iterator) {
|
|
139
144
|
intrinsics['%IteratorHelperPrototype%'] = getPrototypeOf(
|
|
140
145
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
package/src/global-object.js
CHANGED