ses 2.2.0 → 2.3.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/CHANGELOG.md +1462 -0
- package/README.md +4 -0
- package/dist/lockdown.cjs +764 -346
- package/dist/lockdown.mjs +764 -346
- package/dist/lockdown.umd.js +764 -346
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +764 -346
- package/dist/ses.cjs +764 -346
- package/dist/ses.mjs +764 -346
- package/dist/ses.umd.js +764 -346
- package/dist/ses.umd.min.js +1 -1
- package/dist/types.d.cts +31 -2
- package/package.json +38 -9
- package/src/commons.js +0 -1
- package/src/compartment.js +5 -1
- package/src/enablements.js +48 -57
- package/src/error/assert.js +59 -14
- package/src/error/console.js +201 -30
- package/src/error/fatal-assert.js +2 -2
- package/src/error/stringify-utils.js +2 -4
- package/src/error/tame-console.js +0 -2
- package/src/error/tame-error-constructor.js +1 -1
- package/src/get-anonymous-intrinsics.js +0 -12
- package/src/module-load.js +0 -2
- package/src/permits.js +55 -31
- package/src/tame-faux-data-properties.js +1 -1
- package/src/tame-function-constructors.js +1 -1
- package/src/transforms.js +91 -6
- package/types.d.ts +31 -2
package/src/error/console.js
CHANGED
|
@@ -15,12 +15,15 @@ import {
|
|
|
15
15
|
defineProperty,
|
|
16
16
|
freeze,
|
|
17
17
|
fromEntries,
|
|
18
|
+
globalThis,
|
|
18
19
|
isError,
|
|
19
20
|
stringEndsWith,
|
|
20
21
|
stringIncludes,
|
|
21
22
|
stringSplit,
|
|
22
23
|
weaksetAdd,
|
|
23
24
|
weaksetHas,
|
|
25
|
+
stringIndexOf,
|
|
26
|
+
stringSlice,
|
|
24
27
|
} from '../commons.js';
|
|
25
28
|
|
|
26
29
|
/**
|
|
@@ -75,7 +78,7 @@ const defineName = (name, fn) => defineProperty(fn, 'name', { value: name });
|
|
|
75
78
|
* This is the same as the log severity of these on other
|
|
76
79
|
* platform console implementations when they all agree.
|
|
77
80
|
*
|
|
78
|
-
* @type {readonly [ConsoleProps, LogSeverity
|
|
81
|
+
* @type {readonly [ConsoleProps, LogSeverity][]}
|
|
79
82
|
*/
|
|
80
83
|
export const consoleLevelMethods = freeze([
|
|
81
84
|
['debug', 'debug'], // (fmt?, ...args) verbose level on Chrome
|
|
@@ -90,25 +93,35 @@ export const consoleLevelMethods = freeze([
|
|
|
90
93
|
['groupCollapsed', 'log'], // (fmt?, ...args) but TS typed (...label)
|
|
91
94
|
]);
|
|
92
95
|
|
|
96
|
+
/**
|
|
97
|
+
* We special case `console.assert` because it contains `fmt?, ...args` just
|
|
98
|
+
* like the `consoleLevelMethods`, but not in the same place.
|
|
99
|
+
* We special case `console.timeLog` because it contains the same kind of
|
|
100
|
+
* `...args`, but with no format string.
|
|
101
|
+
*
|
|
102
|
+
* @type {readonly [ConsoleProps, LogSeverity][]}
|
|
103
|
+
*/
|
|
104
|
+
export const consoleSpecialMethods = freeze([
|
|
105
|
+
['assert', 'error'], // (value, fmt?, ...args)
|
|
106
|
+
['timeLog', 'log'], // (label?, ...args) no fmt string
|
|
107
|
+
]);
|
|
108
|
+
|
|
93
109
|
/**
|
|
94
110
|
* Those console methods other than those already enumerated by
|
|
95
|
-
* `consoleLevelMethods`.
|
|
111
|
+
* `consoleLevelMethods` and `consoleSpecialMethods`.
|
|
96
112
|
*
|
|
97
113
|
* Each is paired with what we consider to be their log severity level.
|
|
98
114
|
* This is the same as the log severity of these on other
|
|
99
115
|
* platform console implementations when they all agree.
|
|
100
116
|
*
|
|
101
|
-
* @type {readonly [ConsoleProps, LogSeverity
|
|
117
|
+
* @type {readonly [ConsoleProps, LogSeverity][]}
|
|
102
118
|
*/
|
|
103
119
|
export const consoleOtherMethods = freeze([
|
|
104
|
-
['assert', 'error'], // (value, fmt?, ...args)
|
|
105
|
-
['timeLog', 'log'], // (label?, ...args) no fmt string
|
|
106
|
-
|
|
107
120
|
// Insensitive to whether any argument is an error. All arguments can pass
|
|
108
121
|
// thru to baseConsole as is.
|
|
109
|
-
['clear',
|
|
122
|
+
['clear', 'info'], // (), level is not well defined
|
|
110
123
|
['count', 'info'], // (label?)
|
|
111
|
-
['countReset',
|
|
124
|
+
['countReset', 'info'], // (label?), level is not well defined
|
|
112
125
|
['dir', 'log'], // (item, options?)
|
|
113
126
|
['groupEnd', 'log'], // ()
|
|
114
127
|
// In theory tabular data may be or contain an error. However, we currently
|
|
@@ -118,14 +131,15 @@ export const consoleOtherMethods = freeze([
|
|
|
118
131
|
['timeEnd', 'info'], // (label?)
|
|
119
132
|
|
|
120
133
|
// Node Inspector only, MDN, and TypeScript, but not whatwg
|
|
121
|
-
['profile',
|
|
122
|
-
['profileEnd',
|
|
123
|
-
['timeStamp',
|
|
134
|
+
['profile', 'info'], // (label?)
|
|
135
|
+
['profileEnd', 'info'], // (label?)
|
|
136
|
+
['timeStamp', 'info'], // (label?)
|
|
124
137
|
]);
|
|
125
138
|
|
|
126
|
-
/** @type {readonly [ConsoleProps, LogSeverity
|
|
139
|
+
/** @type {readonly [ConsoleProps, LogSeverity][]} */
|
|
127
140
|
const consoleMethodPermits = freeze([
|
|
128
141
|
...consoleLevelMethods,
|
|
142
|
+
...consoleSpecialMethods,
|
|
129
143
|
...consoleOtherMethods,
|
|
130
144
|
]);
|
|
131
145
|
|
|
@@ -156,6 +170,111 @@ const consoleMethodPermits = freeze([
|
|
|
156
170
|
* ]);
|
|
157
171
|
*/
|
|
158
172
|
|
|
173
|
+
/**
|
|
174
|
+
* If `formatData` consists of `[fmt, ...args]` and `fmt` is a string
|
|
175
|
+
* containing a `%c` specifier that acts as an `%c` specifier
|
|
176
|
+
* according to https://console.spec.whatwg.org/#formatting-specifiers
|
|
177
|
+
* then omit it and its corresponding argument. For the rest of the `fmt`
|
|
178
|
+
* string and its corresponding arguments, return them as a replacement
|
|
179
|
+
* `formatData` to be fed to the underlying console log functions.
|
|
180
|
+
*
|
|
181
|
+
* The test takes into account the number of remaining `args`.
|
|
182
|
+
* A `%c` beyond `args` does not act as a specifier.
|
|
183
|
+
* The additional issue not mentioned at
|
|
184
|
+
* https://console.spec.whatwg.org/#formatting-specifiers
|
|
185
|
+
* is that `%%` is an escaped `%`, so the `%c` found within,
|
|
186
|
+
* for example, `%%c` does not act as a specifier.
|
|
187
|
+
* Instead, it gets rendered as `%c` without consuming an argument.
|
|
188
|
+
*
|
|
189
|
+
* Note terminology differences from the spec-internal `Logger` function
|
|
190
|
+
* at https://console.spec.whatwg.org/#formatting-specifiers .
|
|
191
|
+
*
|
|
192
|
+
* | `Logger` terminology | `sanitizeFormatData` terminology |
|
|
193
|
+
* | ---------------------|----------------------------------|
|
|
194
|
+
* | `args` | `formatData` |
|
|
195
|
+
* | `first` | `fmt` |
|
|
196
|
+
* | `rest` | `args` |
|
|
197
|
+
*
|
|
198
|
+
* Exported only for testing.
|
|
199
|
+
*
|
|
200
|
+
* @param {any[]} formatData
|
|
201
|
+
* @returns {any[]}
|
|
202
|
+
*/
|
|
203
|
+
export const sanitizeFormatData = ([...formatData]) => {
|
|
204
|
+
freeze(formatData);
|
|
205
|
+
if (formatData.length <= 1) {
|
|
206
|
+
return formatData;
|
|
207
|
+
}
|
|
208
|
+
const [fmt, ...args] = formatData;
|
|
209
|
+
if (typeof fmt !== 'string' || !stringIncludes(fmt, '%')) {
|
|
210
|
+
return formatData;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let startPos = 0;
|
|
214
|
+
let argI = 0;
|
|
215
|
+
let newFmt = '';
|
|
216
|
+
const newArgs = [];
|
|
217
|
+
for (
|
|
218
|
+
let percentPos = stringIndexOf(fmt, '%');
|
|
219
|
+
// Notice the `- 1` below, which leaves room for one more character after
|
|
220
|
+
// the `'%'`.
|
|
221
|
+
percentPos >= startPos && percentPos < fmt.length - 1 && argI < args.length;
|
|
222
|
+
percentPos = stringIndexOf(fmt, '%', startPos)
|
|
223
|
+
) {
|
|
224
|
+
// The four cases in the following switch are purposely partially
|
|
225
|
+
// redundant. But the total code is small and our attempts at more
|
|
226
|
+
// reuse made the code less clear. Clarity sometimes wins over DRY.
|
|
227
|
+
const char = fmt[percentPos + 1];
|
|
228
|
+
switch (char) {
|
|
229
|
+
case 's':
|
|
230
|
+
case 'd':
|
|
231
|
+
case 'i':
|
|
232
|
+
case 'f':
|
|
233
|
+
case 'o':
|
|
234
|
+
case 'O': {
|
|
235
|
+
// transfer segment + % + char
|
|
236
|
+
newFmt += stringSlice(fmt, startPos, percentPos + 2);
|
|
237
|
+
startPos = percentPos + 2;
|
|
238
|
+
// transfer 1 arg
|
|
239
|
+
arrayPush(newArgs, args[argI]);
|
|
240
|
+
argI += 1;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case 'c': {
|
|
244
|
+
// transfer segment. Consume %c
|
|
245
|
+
newFmt += stringSlice(fmt, startPos, percentPos);
|
|
246
|
+
startPos = percentPos + 2;
|
|
247
|
+
// consume 1 arg
|
|
248
|
+
argI += 1;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case '%': {
|
|
252
|
+
// transfer segment + % + char. Ignore args
|
|
253
|
+
newFmt += stringSlice(fmt, startPos, percentPos + 2);
|
|
254
|
+
startPos = percentPos + 2;
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
default: {
|
|
258
|
+
// transfer segment + %% + char. Ignore args
|
|
259
|
+
// So that %<unspecified> is treated as unknown even if
|
|
260
|
+
// implemented by the local platform, such as %j on Node.
|
|
261
|
+
newFmt += stringSlice(fmt, startPos, percentPos);
|
|
262
|
+
newFmt += `%%${char}`;
|
|
263
|
+
startPos = percentPos + 2;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (startPos < fmt.length) {
|
|
269
|
+
newFmt += stringSlice(fmt, startPos, fmt.length);
|
|
270
|
+
}
|
|
271
|
+
for (; argI < args.length; argI += 1) {
|
|
272
|
+
arrayPush(newArgs, args[argI]);
|
|
273
|
+
}
|
|
274
|
+
return /** @type {any[]} */ (freeze([newFmt, ...newArgs]));
|
|
275
|
+
};
|
|
276
|
+
freeze(sanitizeFormatData);
|
|
277
|
+
|
|
159
278
|
// //////////////////////////// Logging Console ////////////////////////////////
|
|
160
279
|
|
|
161
280
|
/** @type {MakeLoggingConsoleKit} */
|
|
@@ -224,11 +343,32 @@ const ErrorInfo = {
|
|
|
224
343
|
freeze(ErrorInfo);
|
|
225
344
|
|
|
226
345
|
/** @type {MakeCausalConsole} */
|
|
227
|
-
export const makeCausalConsole = (
|
|
228
|
-
if (!
|
|
346
|
+
export const makeCausalConsole = (feralConsole, loggedErrorHandler) => {
|
|
347
|
+
if (!feralConsole) {
|
|
229
348
|
return undefined;
|
|
230
349
|
}
|
|
231
350
|
|
|
351
|
+
// In Node.js, the global console does a deep scan of its inputs for methods
|
|
352
|
+
// keyed by Symbol.for('nodejs.util.inspect.custom'), and invokes any that are
|
|
353
|
+
// found with unhardened arguments as described at
|
|
354
|
+
// https://nodejs.org/docs/latest/api/util.html#custom-inspection-functions-on-objects
|
|
355
|
+
// To circumvent that problematic behavior, we use its
|
|
356
|
+
// https://nodejs.org/docs/latest/api/console.html#class-console Console
|
|
357
|
+
// constructor to build a replacement that explicitly opts out by setting the
|
|
358
|
+
// `customInspect` option to false.
|
|
359
|
+
// https://nodejs.org/docs/latest/api/util.html#utilinspectobject-options
|
|
360
|
+
/** @type {new (options: any) => typeof console} */
|
|
361
|
+
const Console = /** @type {any} */ (feralConsole).Console;
|
|
362
|
+
const { stdout, stderr } = globalThis.process || { __proto__: null };
|
|
363
|
+
const baseConsole =
|
|
364
|
+
typeof Console === 'function' && (stdout || stderr)
|
|
365
|
+
? new Console({
|
|
366
|
+
stdout,
|
|
367
|
+
stderr,
|
|
368
|
+
inspectOptions: { colors: undefined, customInspect: false },
|
|
369
|
+
})
|
|
370
|
+
: feralConsole;
|
|
371
|
+
|
|
232
372
|
const { getStackString, tagError, takeMessageLogArgs, takeNoteLogArgsArray } =
|
|
233
373
|
loggedErrorHandler;
|
|
234
374
|
|
|
@@ -376,32 +516,53 @@ export const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
|
|
|
376
516
|
logSubErrors(severity, subErrors, errorTag);
|
|
377
517
|
};
|
|
378
518
|
|
|
379
|
-
const levelMethods = arrayMap(consoleLevelMethods, ([
|
|
519
|
+
const levelMethods = arrayMap(consoleLevelMethods, ([name, level]) => {
|
|
380
520
|
/**
|
|
381
521
|
* @param {...any} logArgs
|
|
382
522
|
*/
|
|
383
|
-
const levelMethod = defineName(
|
|
523
|
+
const levelMethod = defineName(name, (...logArgs) => {
|
|
384
524
|
const subErrors = [];
|
|
385
|
-
const argTags = extractErrorArgs(logArgs, subErrors);
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
baseConsole[level](...argTags);
|
|
389
|
-
}
|
|
390
|
-
// @ts-expect-error ConsoleProp vs LogSeverity mismatch
|
|
525
|
+
const argTags = extractErrorArgs(sanitizeFormatData(logArgs), subErrors);
|
|
526
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
527
|
+
baseConsole[name](...argTags);
|
|
391
528
|
logSubErrors(level, subErrors);
|
|
392
529
|
});
|
|
393
|
-
return [
|
|
530
|
+
return [name, freeze(levelMethod)];
|
|
394
531
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
(
|
|
398
|
-
|
|
399
|
-
|
|
532
|
+
|
|
533
|
+
const assertMethod = defineName('assert', (...assertArgs) => {
|
|
534
|
+
if (assertArgs.length <= 1) {
|
|
535
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
536
|
+
baseConsole.assert(...assertArgs);
|
|
537
|
+
} else {
|
|
538
|
+
const [cond, ...logArgs] = assertArgs;
|
|
539
|
+
const subErrors = [];
|
|
540
|
+
const argTags = extractErrorArgs(sanitizeFormatData(logArgs), subErrors);
|
|
541
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
542
|
+
baseConsole.assert(cond, ...argTags);
|
|
543
|
+
logSubErrors('error', subErrors);
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
const timeLogMethod = defineName('timeLog', (...timeLogArgs) => {
|
|
548
|
+
if (timeLogArgs.length <= 1) {
|
|
549
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
550
|
+
baseConsole.timeLog(...timeLogArgs);
|
|
551
|
+
} else {
|
|
552
|
+
const [label, ...logArgs] = timeLogArgs;
|
|
553
|
+
const subErrors = [];
|
|
554
|
+
const argTags = extractErrorArgs(sanitizeFormatData(logArgs), subErrors);
|
|
555
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
556
|
+
baseConsole.timeLog(label, ...argTags);
|
|
557
|
+
logSubErrors('log', subErrors);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
const otherMethods = arrayMap(consoleOtherMethods, ([name, _level]) => {
|
|
400
562
|
/**
|
|
401
563
|
* @param {...any} args
|
|
402
564
|
*/
|
|
403
565
|
const otherMethod = defineName(name, (...args) => {
|
|
404
|
-
// @ts-ignore
|
|
405
566
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
406
567
|
baseConsole[name](...args);
|
|
407
568
|
return undefined;
|
|
@@ -409,7 +570,17 @@ export const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
|
|
|
409
570
|
return [name, freeze(otherMethod)];
|
|
410
571
|
});
|
|
411
572
|
|
|
412
|
-
const
|
|
573
|
+
const methodEntries = arrayFilter(
|
|
574
|
+
[
|
|
575
|
+
...levelMethods,
|
|
576
|
+
['assert', assertMethod],
|
|
577
|
+
['timeLog', timeLogMethod],
|
|
578
|
+
...otherMethods,
|
|
579
|
+
],
|
|
580
|
+
([name, _]) => name in baseConsole,
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
const causalConsole = fromEntries(methodEntries);
|
|
413
584
|
return /** @type {VirtualConsole} */ (freeze(causalConsole));
|
|
414
585
|
};
|
|
415
586
|
freeze(makeCausalConsole);
|
|
@@ -20,9 +20,9 @@ if (typeof abandon === 'function') {
|
|
|
20
20
|
/** @param {Error} reason */
|
|
21
21
|
raise = reason => {
|
|
22
22
|
// Check `console` each time `raise` is called.
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
if (typeof console === 'object' && typeof console.error === 'function') {
|
|
25
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
25
|
+
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
26
26
|
console.error('Failed because:', reason);
|
|
27
27
|
}
|
|
28
28
|
abandon(1);
|
|
@@ -51,7 +51,7 @@ export const enJoin = (terms, conjunction) => {
|
|
|
51
51
|
* @param {string} str The noun to prepend
|
|
52
52
|
* @returns {string} The noun prepended with a/an
|
|
53
53
|
*/
|
|
54
|
-
const an = str => {
|
|
54
|
+
export const an = str => {
|
|
55
55
|
str = `${str}`;
|
|
56
56
|
if (str.length >= 1 && stringIncludes('aeiouAEIOU', str[0])) {
|
|
57
57
|
return `an ${str}`;
|
|
@@ -59,7 +59,6 @@ const an = str => {
|
|
|
59
59
|
return `a ${str}`;
|
|
60
60
|
};
|
|
61
61
|
freeze(an);
|
|
62
|
-
export { an };
|
|
63
62
|
|
|
64
63
|
/**
|
|
65
64
|
* Like `JSON.stringify` but does not blow up if given a cycle or a bigint.
|
|
@@ -88,7 +87,7 @@ export { an };
|
|
|
88
87
|
* @param {(string|number)=} spaces
|
|
89
88
|
* @returns {string}
|
|
90
89
|
*/
|
|
91
|
-
const bestEffortStringify = (payload, spaces = undefined) => {
|
|
90
|
+
export const bestEffortStringify = (payload, spaces = undefined) => {
|
|
92
91
|
const seenSet = new Set();
|
|
93
92
|
const replacer = (_, val) => {
|
|
94
93
|
switch (typeof val) {
|
|
@@ -192,4 +191,3 @@ const bestEffortStringify = (payload, spaces = undefined) => {
|
|
|
192
191
|
}
|
|
193
192
|
};
|
|
194
193
|
freeze(bestEffortStringify);
|
|
195
|
-
export { bestEffortStringify };
|
|
@@ -51,7 +51,6 @@ export const tameConsole = (
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
// eslint-disable-next-line no-restricted-globals
|
|
55
54
|
const originalConsole = /** @type {VirtualConsole} */ (
|
|
56
55
|
// eslint-disable-next-line no-nested-ternary
|
|
57
56
|
typeof globalThis.console !== 'undefined'
|
|
@@ -61,7 +60,6 @@ export const tameConsole = (
|
|
|
61
60
|
// log at a specific level with no special argument interpretation).
|
|
62
61
|
// https://console.spec.whatwg.org/#logging
|
|
63
62
|
(p => freeze({ debug: p, log: p, info: p, warn: p, error: p }))(
|
|
64
|
-
// eslint-disable-next-line no-undef
|
|
65
63
|
wrapLogger(globalThis.print),
|
|
66
64
|
)
|
|
67
65
|
: undefined
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
globalThis,
|
|
17
17
|
assign,
|
|
18
18
|
AsyncGeneratorFunctionInstance,
|
|
19
|
-
ArrayBuffer,
|
|
20
19
|
} from './commons.js';
|
|
21
20
|
import { InertCompartment } from './compartment.js';
|
|
22
21
|
|
|
@@ -54,7 +53,6 @@ export const getAnonymousIntrinsics = () => {
|
|
|
54
53
|
|
|
55
54
|
// 21.1.5.2 The %StringIteratorPrototype% Object
|
|
56
55
|
|
|
57
|
-
// eslint-disable-next-line no-new-wrappers
|
|
58
56
|
const StringIteratorObject = iterateString(new String());
|
|
59
57
|
const StringIteratorPrototype = getPrototypeOf(StringIteratorObject);
|
|
60
58
|
|
|
@@ -66,7 +64,6 @@ export const getAnonymousIntrinsics = () => {
|
|
|
66
64
|
|
|
67
65
|
// 22.1.5.2 The %ArrayIteratorPrototype% Object
|
|
68
66
|
|
|
69
|
-
// eslint-disable-next-line no-array-constructor
|
|
70
67
|
const ArrayIteratorObject = iterateArray([]);
|
|
71
68
|
const ArrayIteratorPrototype = getPrototypeOf(ArrayIteratorObject);
|
|
72
69
|
|
|
@@ -167,14 +164,5 @@ export const getAnonymousIntrinsics = () => {
|
|
|
167
164
|
);
|
|
168
165
|
}
|
|
169
166
|
|
|
170
|
-
const ab = new ArrayBuffer(0);
|
|
171
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
172
|
-
const iab = ab.sliceToImmutable();
|
|
173
|
-
const iabProto = getPrototypeOf(iab);
|
|
174
|
-
if (iabProto !== ArrayBuffer.prototype) {
|
|
175
|
-
// In a native implementation, these will be the same prototype
|
|
176
|
-
intrinsics['%ImmutableArrayBufferPrototype%'] = iabProto;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
167
|
return intrinsics;
|
|
180
168
|
};
|
package/src/module-load.js
CHANGED
|
@@ -179,7 +179,6 @@ function* loadWithoutErrorAnnotation(
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
if (typeof moduleDescriptor === 'string') {
|
|
182
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
183
182
|
throw makeError(
|
|
184
183
|
X`Cannot map module ${q(moduleSpecifier)} to ${q(
|
|
185
184
|
moduleDescriptor,
|
|
@@ -491,7 +490,6 @@ const memoizedLoadWithErrorAnnotation = (
|
|
|
491
490
|
moduleLoads,
|
|
492
491
|
],
|
|
493
492
|
error => {
|
|
494
|
-
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
495
493
|
annotateError(
|
|
496
494
|
error,
|
|
497
495
|
X`${error.message}, loading ${q(moduleSpecifier)} in compartment ${q(
|
package/src/permits.js
CHANGED
|
@@ -6,7 +6,7 @@ import { arrayPush, arrayForEach } from './commons.js';
|
|
|
6
6
|
/** @import {GenericErrorConstructor} from '../types.js' */
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Exports
|
|
9
|
+
* Exports `permits`, a recursively defined
|
|
10
10
|
* JSON record enumerating all intrinsics and their properties
|
|
11
11
|
* according to ECMA specs.
|
|
12
12
|
*
|
|
@@ -102,6 +102,15 @@ export const universalPropertyNames = {
|
|
|
102
102
|
JSON: 'JSON',
|
|
103
103
|
Reflect: 'Reflect',
|
|
104
104
|
|
|
105
|
+
// WHATWG Encoding Standard
|
|
106
|
+
// https://encoding.spec.whatwg.org/
|
|
107
|
+
// TextEncoder and TextDecoder are pure transformations between string and
|
|
108
|
+
// Uint8Array with no static side channels and no exposed iterator
|
|
109
|
+
// prototype. They are permitted universally; on hosts that do not provide
|
|
110
|
+
// them (XS), the sampling pass tolerates the absence.
|
|
111
|
+
TextEncoder: 'TextEncoder',
|
|
112
|
+
TextDecoder: 'TextDecoder',
|
|
113
|
+
|
|
105
114
|
// *** Annex B
|
|
106
115
|
|
|
107
116
|
escape: 'escape',
|
|
@@ -259,20 +268,20 @@ export { NativeErrors };
|
|
|
259
268
|
* are also considered blacklisted and are removed.
|
|
260
269
|
* <li>A string value equal to a primitive ("number", "string", etc),
|
|
261
270
|
* in which case the property is permitted if its value property
|
|
262
|
-
* is typeof the given type. For example,
|
|
263
|
-
* "number" and property values that fail
|
|
271
|
+
* is typeof the given type. For example, `Infinity` leads to
|
|
272
|
+
* "number" and property values that fail `typeof "number`.
|
|
264
273
|
* are removed.
|
|
265
274
|
* <li>A string value equal to an intinsic name ("ObjectPrototype",
|
|
266
275
|
* "Array", etc), in which case the property permitted if its
|
|
267
276
|
* value property is equal to the value of the corresponfing
|
|
268
|
-
* intrinsics. For example,
|
|
277
|
+
* intrinsics. For example, `Map.prototype` leads to
|
|
269
278
|
* "MapPrototype" and the property is removed if its value is
|
|
270
279
|
* not equal to %MapPrototype%
|
|
271
280
|
* <li>Another record, in which case this property is simply
|
|
272
281
|
* permitted and that next record represents the disposition of
|
|
273
|
-
* the object which is its value. For example,
|
|
274
|
-
* leads to another record explaining what properties
|
|
275
|
-
*
|
|
282
|
+
* the object which is its value. For example, `Object`
|
|
283
|
+
* leads to another record explaining what properties
|
|
284
|
+
* `Object` may have and how each such property should be treated.
|
|
276
285
|
*
|
|
277
286
|
* <p>Notes:
|
|
278
287
|
* <li>"[[Proto]]" is used to refer to the "[[Prototype]]" internal
|
|
@@ -1387,30 +1396,6 @@ export const permitted = {
|
|
|
1387
1396
|
immutable: getter,
|
|
1388
1397
|
},
|
|
1389
1398
|
|
|
1390
|
-
// If this exists, it is purely an artifact of how we currently shim
|
|
1391
|
-
// `transferToImmutable`. As natively implemented, there would be no
|
|
1392
|
-
// such extra prototype.
|
|
1393
|
-
'%ImmutableArrayBufferPrototype%': {
|
|
1394
|
-
'[[Proto]]': '%ArrayBufferPrototype%',
|
|
1395
|
-
byteLength: getter,
|
|
1396
|
-
slice: fn,
|
|
1397
|
-
// See https://github.com/endojs/endo/tree/master/packages/immutable-arraybuffer#purposeful-violation
|
|
1398
|
-
'@@toStringTag': 'string',
|
|
1399
|
-
// See https://github.com/tc39/proposal-resizablearraybuffer
|
|
1400
|
-
transfer: fn,
|
|
1401
|
-
resize: fn,
|
|
1402
|
-
resizable: getter,
|
|
1403
|
-
maxByteLength: getter,
|
|
1404
|
-
// https://github.com/tc39/proposal-arraybuffer-transfer
|
|
1405
|
-
transferToFixedLength: fn,
|
|
1406
|
-
detached: getter,
|
|
1407
|
-
// https://github.com/endojs/endo/pull/2309#issuecomment-2155513240
|
|
1408
|
-
// to be proposed
|
|
1409
|
-
transferToImmutable: fn,
|
|
1410
|
-
sliceToImmutable: fn,
|
|
1411
|
-
immutable: getter,
|
|
1412
|
-
},
|
|
1413
|
-
|
|
1414
1399
|
// SharedArrayBuffer Objects
|
|
1415
1400
|
SharedArrayBuffer: false, // UNSAFE and purposely suppressed.
|
|
1416
1401
|
'%SharedArrayBufferPrototype%': false, // UNSAFE and purposely suppressed.
|
|
@@ -2083,6 +2068,44 @@ export const permitted = {
|
|
|
2083
2068
|
'@@toStringTag': 'string',
|
|
2084
2069
|
},
|
|
2085
2070
|
|
|
2071
|
+
// WHATWG Encoding Standard
|
|
2072
|
+
// https://encoding.spec.whatwg.org/
|
|
2073
|
+
|
|
2074
|
+
TextEncoder: {
|
|
2075
|
+
// Properties of the TextEncoder Constructor
|
|
2076
|
+
'[[Proto]]': '%FunctionPrototype%',
|
|
2077
|
+
prototype: '%TextEncoderPrototype%',
|
|
2078
|
+
},
|
|
2079
|
+
|
|
2080
|
+
'%TextEncoderPrototype%': {
|
|
2081
|
+
constructor: 'TextEncoder',
|
|
2082
|
+
encode: fn,
|
|
2083
|
+
encodeInto: fn,
|
|
2084
|
+
encoding: getter,
|
|
2085
|
+
'@@toStringTag': 'string',
|
|
2086
|
+
|
|
2087
|
+
// Non-standard property used by Node.js
|
|
2088
|
+
'RegisteredSymbol(nodejs.util.inspect.custom)': false,
|
|
2089
|
+
},
|
|
2090
|
+
|
|
2091
|
+
TextDecoder: {
|
|
2092
|
+
// Properties of the TextDecoder Constructor
|
|
2093
|
+
'[[Proto]]': '%FunctionPrototype%',
|
|
2094
|
+
prototype: '%TextDecoderPrototype%',
|
|
2095
|
+
},
|
|
2096
|
+
|
|
2097
|
+
'%TextDecoderPrototype%': {
|
|
2098
|
+
constructor: 'TextDecoder',
|
|
2099
|
+
decode: fn,
|
|
2100
|
+
encoding: getter,
|
|
2101
|
+
fatal: getter,
|
|
2102
|
+
ignoreBOM: getter,
|
|
2103
|
+
'@@toStringTag': 'string',
|
|
2104
|
+
|
|
2105
|
+
// Non-standard property used by Node.js
|
|
2106
|
+
'RegisteredSymbol(nodejs.util.inspect.custom)': false,
|
|
2107
|
+
},
|
|
2108
|
+
|
|
2086
2109
|
// Appendix B
|
|
2087
2110
|
|
|
2088
2111
|
// Annex B: Additional Properties of the Global Object
|
|
@@ -2113,6 +2136,7 @@ export const permitted = {
|
|
|
2113
2136
|
load: asyncFn,
|
|
2114
2137
|
importNow: fn,
|
|
2115
2138
|
module: fn,
|
|
2139
|
+
__noNamespaceBox__: getter,
|
|
2116
2140
|
'@@toStringTag': 'string',
|
|
2117
2141
|
},
|
|
2118
2142
|
|
|
@@ -49,7 +49,7 @@ export default function tameFunctionConstructors() {
|
|
|
49
49
|
// Verify that the method is not callable.
|
|
50
50
|
// eslint-disable-next-line @endo/no-polymorphic-call
|
|
51
51
|
FERAL_FUNCTION.prototype.constructor('return 1');
|
|
52
|
-
} catch (
|
|
52
|
+
} catch (_err) {
|
|
53
53
|
// Throws, no need to patch.
|
|
54
54
|
return freeze({});
|
|
55
55
|
}
|