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/src/lockdown.js CHANGED
@@ -15,6 +15,7 @@
15
15
  // @ts-check
16
16
 
17
17
  import { getEnvironmentOption as getenv } from '@endo/env-options';
18
+ import '@endo/immutable-arraybuffer/shim.js';
18
19
  import {
19
20
  FERAL_FUNCTION,
20
21
  FERAL_EVAL,
@@ -100,10 +101,32 @@ const safeHarden = makeHardener();
100
101
  // only ever need to be called once and that simplifying lockdown will improve
101
102
  // the quality of audits.
102
103
 
103
- const assertDirectEvalAvailable = () => {
104
- let allowed = false;
104
+ const probeHostEvaluators = () => {
105
+ let functionAllowed;
105
106
  try {
106
- allowed = FERAL_FUNCTION(
107
+ functionAllowed = FERAL_FUNCTION('return true')();
108
+ } catch (_error) {
109
+ // We reach here if the Function() constructor is outright forbidden by a
110
+ // strict Content Security Policy (containing either a `default-src` or a
111
+ // `script-src` directive), not been implemented in the host, or the host
112
+ // is configured to throw an exception instead of `new Function`.
113
+ functionAllowed = false;
114
+ }
115
+
116
+ let evalAllowed;
117
+ try {
118
+ evalAllowed = FERAL_EVAL('true');
119
+ } catch (_error) {
120
+ // We reach here if `eval` is outright forbidden by a strict Content Security Policy,
121
+ // not implemented in the host, or the host is configured to throw an exception.
122
+ // We allow this for SES usage that delegates the responsibility to isolate
123
+ // guest code to production code generation.
124
+ evalAllowed = false;
125
+ }
126
+
127
+ let directEvalAllowed;
128
+ if (functionAllowed && evalAllowed) {
129
+ directEvalAllowed = FERAL_FUNCTION(
107
130
  'eval',
108
131
  'SES_changed',
109
132
  `\
@@ -115,21 +138,12 @@ const assertDirectEvalAvailable = () => {
115
138
  // and indirect, which generally creates a new global.
116
139
  // We are going to throw an exception for failing to initialize SES, but
117
140
  // good neighbors clean up.
118
- if (!allowed) {
141
+ if (!directEvalAllowed) {
119
142
  delete globalThis.SES_changed;
120
143
  }
121
- } catch (_error) {
122
- // We reach here if eval is outright forbidden by a Content Security Policy.
123
- // We allow this for SES usage that delegates the responsibility to isolate
124
- // guest code to production code generation.
125
- allowed = true;
126
- }
127
- if (!allowed) {
128
- // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
129
- throw TypeError(
130
- `SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`,
131
- );
132
144
  }
145
+
146
+ return { functionAllowed, evalAllowed, directEvalAllowed };
133
147
  };
134
148
 
135
149
  /**
@@ -152,65 +166,85 @@ export const repairIntrinsics = (options = {}) => {
152
166
  // The `stackFiltering` is not a safety issue. Rather it is a tradeoff
153
167
  // between relevance and completeness of the stack frames shown on the
154
168
  // console. Setting`stackFiltering` to `'verbose'` applies no filters, providing
155
- // the raw stack frames that can be quite versbose. Setting
169
+ // the raw stack frames that can be quite verbose. Setting
156
170
  // `stackFrameFiltering` to`'concise'` limits the display to the stack frame
157
171
  // information most likely to be relevant, eliminating distracting frames
158
172
  // such as those from the infrastructure. However, the bug you're trying to
159
- // track down might be in the infrastrure, in which case the `'verbose'` setting
173
+ // track down might be in the infrastructure, in which case the `'verbose'` setting
160
174
  // is useful. See
161
175
  // [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/docs/lockdown.md#stackfiltering-options)
162
176
  // for an explanation.
163
177
 
164
178
  const {
165
- errorTaming = getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
166
- errorTrapping = /** @type {"platform" | "none" | "report" | "abort" | "exit"} */ (
167
- getenv('LOCKDOWN_ERROR_TRAPPING', 'platform')
179
+ errorTaming = /** @type {'safe' | 'unsafe' | 'unsafe-debug'} */ (
180
+ getenv('LOCKDOWN_ERROR_TAMING', 'safe', ['unsafe', 'unsafe-debug'])
168
181
  ),
169
- reporting = /** @type {"platform" | "console" | "none"} */ (
170
- getenv('LOCKDOWN_REPORTING', 'platform')
182
+ errorTrapping = /** @type {'platform' | 'none' | 'report' | 'abort' | 'exit'} */ (
183
+ getenv('LOCKDOWN_ERROR_TRAPPING', 'platform', [
184
+ 'none',
185
+ 'report',
186
+ 'abort',
187
+ 'exit',
188
+ ])
171
189
  ),
172
- unhandledRejectionTrapping = /** @type {"none" | "report"} */ (
173
- getenv('LOCKDOWN_UNHANDLED_REJECTION_TRAPPING', 'report')
190
+ reporting = /** @type {'platform' | 'console' | 'none'} */ (
191
+ getenv('LOCKDOWN_REPORTING', 'platform', ['console', 'none'])
192
+ ),
193
+ unhandledRejectionTrapping = /** @type {'none' | 'report'} */ (
194
+ getenv('LOCKDOWN_UNHANDLED_REJECTION_TRAPPING', 'report', ['none'])
195
+ ),
196
+ regExpTaming = /** @type {'safe' | 'unsafe'} */ (
197
+ getenv('LOCKDOWN_REGEXP_TAMING', 'safe', ['unsafe'])
198
+ ),
199
+ localeTaming = /** @type {'safe' | 'unsafe'} */ (
200
+ getenv('LOCKDOWN_LOCALE_TAMING', 'safe', ['unsafe'])
174
201
  ),
175
- regExpTaming = getenv('LOCKDOWN_REGEXP_TAMING', 'safe'),
176
- localeTaming = getenv('LOCKDOWN_LOCALE_TAMING', 'safe'),
177
-
178
202
  consoleTaming = /** @type {'unsafe' | 'safe'} */ (
179
- getenv('LOCKDOWN_CONSOLE_TAMING', 'safe')
203
+ getenv('LOCKDOWN_CONSOLE_TAMING', 'safe', ['unsafe'])
180
204
  ),
181
205
  overrideTaming = /** @type {'moderate' | 'min' | 'severe'} */ (
182
- getenv('LOCKDOWN_OVERRIDE_TAMING', 'moderate')
206
+ getenv('LOCKDOWN_OVERRIDE_TAMING', 'moderate', ['min', 'severe'])
207
+ ),
208
+ stackFiltering = /** @type {'concise' | 'omit-frames' | 'shorten-paths' | 'verbose'} */ (
209
+ getenv('LOCKDOWN_STACK_FILTERING', 'concise', [
210
+ 'omit-frames',
211
+ 'shorten-paths',
212
+ 'verbose',
213
+ ])
214
+ ),
215
+ domainTaming = /** @type {'safe' | 'unsafe'} */ (
216
+ getenv('LOCKDOWN_DOMAIN_TAMING', 'safe', ['unsafe'])
183
217
  ),
184
- stackFiltering = getenv('LOCKDOWN_STACK_FILTERING', 'concise'),
185
- domainTaming = getenv('LOCKDOWN_DOMAIN_TAMING', 'safe'),
186
- evalTaming = getenv('LOCKDOWN_EVAL_TAMING', 'safe-eval'),
187
- overrideDebug = arrayFilter(
188
- stringSplit(getenv('LOCKDOWN_OVERRIDE_DEBUG', ''), ','),
189
- /** @param {string} debugName */
190
- debugName => debugName !== '',
218
+ evalTaming = /** @type {'safe-eval' | 'unsafe-eval' | 'no-eval'} */ (
219
+ getenv('LOCKDOWN_EVAL_TAMING', 'safe-eval', [
220
+ 'unsafe-eval',
221
+ 'no-eval',
222
+ // deprecated
223
+ 'safeEval',
224
+ 'unsafeEval',
225
+ 'noEval',
226
+ ])
191
227
  ),
192
- legacyRegeneratorRuntimeTaming = getenv(
193
- 'LOCKDOWN_LEGACY_REGENERATOR_RUNTIME_TAMING',
194
- 'safe',
228
+ overrideDebug = /** @type {string[]} */ (
229
+ arrayFilter(
230
+ stringSplit(getenv('LOCKDOWN_OVERRIDE_DEBUG', ''), ','),
231
+ /** @param {string} debugName */
232
+ debugName => debugName !== '',
233
+ )
234
+ ),
235
+ legacyRegeneratorRuntimeTaming = /** @type {'safe' | 'unsafe-ignore'} */ (
236
+ getenv('LOCKDOWN_LEGACY_REGENERATOR_RUNTIME_TAMING', 'safe', [
237
+ 'unsafe-ignore',
238
+ ])
239
+ ),
240
+ __hardenTaming__ = /** @type {'safe' | 'unsafe'} */ (
241
+ getenv('LOCKDOWN_HARDEN_TAMING', 'safe', ['unsafe'])
195
242
  ),
196
- __hardenTaming__ = getenv('LOCKDOWN_HARDEN_TAMING', 'safe'),
197
243
  dateTaming, // deprecated
198
244
  mathTaming, // deprecated
199
245
  ...extraOptions
200
246
  } = options;
201
247
 
202
- legacyRegeneratorRuntimeTaming === 'safe' ||
203
- legacyRegeneratorRuntimeTaming === 'unsafe-ignore' ||
204
- Fail`lockdown(): non supported option legacyRegeneratorRuntimeTaming: ${q(legacyRegeneratorRuntimeTaming)}`;
205
-
206
- evalTaming === 'unsafe-eval' ||
207
- evalTaming === 'unsafeEval' || // deprecated
208
- evalTaming === 'safe-eval' ||
209
- evalTaming === 'safeEval' || // deprecated
210
- evalTaming === 'no-eval' ||
211
- evalTaming === 'noEval' || // deprecated
212
- Fail`lockdown(): non supported option evalTaming: ${q(evalTaming)}`;
213
-
214
248
  // Assert that only supported options were passed.
215
249
  // Use Reflect.ownKeys to reject symbol-named properties as well.
216
250
  const extraOptionsNames = ownKeys(extraOptions);
@@ -221,13 +255,11 @@ export const repairIntrinsics = (options = {}) => {
221
255
  const { warn } = reporter;
222
256
 
223
257
  if (dateTaming !== undefined) {
224
- // eslint-disable-next-line no-console
225
258
  warn(
226
259
  `SES The 'dateTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
227
260
  );
228
261
  }
229
262
  if (mathTaming !== undefined) {
230
- // eslint-disable-next-line no-console
231
263
  warn(
232
264
  `SES The 'mathTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
233
265
  );
@@ -245,7 +277,19 @@ export const repairIntrinsics = (options = {}) => {
245
277
  // trace retained:
246
278
  priorRepairIntrinsics.stack;
247
279
 
248
- assertDirectEvalAvailable();
280
+ const { functionAllowed, evalAllowed, directEvalAllowed } =
281
+ probeHostEvaluators();
282
+
283
+ if (
284
+ directEvalAllowed === false &&
285
+ evalTaming === 'safe-eval' &&
286
+ (functionAllowed || evalAllowed)
287
+ ) {
288
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
289
+ throw TypeError(
290
+ "SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct eval (dynamically scoped eval) (SES_DIRECT_EVAL)",
291
+ );
292
+ }
249
293
 
250
294
  /**
251
295
  * Because of packagers and bundlers, etc, multiple invocations of lockdown
@@ -300,7 +344,6 @@ export const repairIntrinsics = (options = {}) => {
300
344
  const { addIntrinsics, completePrototypes, finalIntrinsics } =
301
345
  makeIntrinsicsCollector(reporter);
302
346
 
303
- // @ts-expect-error __hardenTaming__ could be any string
304
347
  const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
305
348
  addIntrinsics({ harden: tamedHarden });
306
349
 
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * makeEvalFunction()
3
3
  * A safe version of the native eval function which relies on
4
- * the safety of safeEvaluate for confinement.
4
+ * the safety of `safe-eval` for confinement, unless `no-eval`
5
+ * is specified (then a TypeError is thrown on use).
5
6
  *
6
- * @param {Function} safeEvaluate
7
+ * @param {Function} evaluator
7
8
  */
8
- export const makeEvalFunction = safeEvaluate => {
9
+ export const makeEvalFunction = evaluator => {
9
10
  // We use the concise method syntax to create an eval without a
10
11
  // [[Construct]] behavior (such that the invocation "new eval()" throws
11
12
  // TypeError: eval is not a constructor"), but which still accepts a
@@ -19,7 +20,7 @@ export const makeEvalFunction = safeEvaluate => {
19
20
  // rule. Track.
20
21
  return source;
21
22
  }
22
- return safeEvaluate(source);
23
+ return evaluator(source);
23
24
  },
24
25
  }.eval;
25
26
 
@@ -12,9 +12,10 @@ const { Fail } = assert;
12
12
  /*
13
13
  * makeFunctionConstructor()
14
14
  * A safe version of the native Function which relies on
15
- * the safety of safeEvaluate for confinement.
15
+ * the safety of `safe-eval` for confinement, unless `no-eval`
16
+ * is specified (then a TypeError is thrown on use).
16
17
  */
17
- export const makeFunctionConstructor = safeEvaluate => {
18
+ export const makeFunctionConstructor = evaluator => {
18
19
  // Define an unused parameter to ensure Function.length === 1
19
20
  const newFunction = function Function(_body) {
20
21
  // Sanitize all parameters at the entry point.
@@ -54,7 +55,7 @@ export const makeFunctionConstructor = safeEvaluate => {
54
55
  // TODO: since we create an anonymous function, the 'this' value
55
56
  // isn't bound to the global object as per specs, but set as undefined.
56
57
  const src = `(function anonymous(${parameters}\n) {\n${bodyText}\n})`;
57
- return safeEvaluate(src);
58
+ return evaluator(src);
58
59
  };
59
60
 
60
61
  defineProperties(newFunction, {
@@ -72,7 +73,7 @@ export const makeFunctionConstructor = safeEvaluate => {
72
73
  getPrototypeOf(FERAL_FUNCTION) === FERAL_FUNCTION.prototype ||
73
74
  Fail`Function prototype is the same accross compartments`;
74
75
  getPrototypeOf(newFunction) === FERAL_FUNCTION.prototype ||
75
- Fail`Function constructor prototype is the same accross compartments`;
76
+ Fail`Function constructor prototype is the same across compartments`;
76
77
 
77
78
  return newFunction;
78
79
  };
@@ -507,18 +507,17 @@ const memoizedLoadWithErrorAnnotation = (
507
507
  return moduleLoading;
508
508
  };
509
509
 
510
- const asyncJobQueue = () => {
510
+ const asyncJobQueue = (errors = []) => {
511
511
  /** @type {Set<Promise<undefined>>} */
512
512
  const pendingJobs = new Set();
513
- /** @type {Array<Error>} */
514
- const errors = [];
515
513
 
516
514
  /**
517
515
  * Enqueues a job that starts immediately but won't be awaited until drainQueue is called.
518
516
  *
519
- * @template {any[]} T
520
- * @param {(...args: T)=>Promise<*>} func
521
- * @param {T} args
517
+ * @template {(...args: any[]) => Promise<void>} F
518
+ * @param {F} func - An async function to execute
519
+ * @param {Parameters<F>} args - Arguments to pass to the function
520
+ * @returns {void}
522
521
  */
523
522
  const enqueueJob = (func, args) => {
524
523
  setAdd(
@@ -530,8 +529,6 @@ const asyncJobQueue = () => {
530
529
  };
531
530
  /**
532
531
  * Sequentially awaits pending jobs and returns an array of errors
533
- *
534
- * @returns {Promise<Array<Error>>}
535
532
  */
536
533
  const drainQueue = async () => {
537
534
  await null;
@@ -539,9 +536,42 @@ const asyncJobQueue = () => {
539
536
  // eslint-disable-next-line no-await-in-loop
540
537
  await job;
541
538
  }
542
- return errors;
543
539
  };
544
- return { enqueueJob, drainQueue };
540
+ return { enqueueJob, drainQueue, errors };
541
+ };
542
+
543
+ const syncJobQueue = (errors = []) => {
544
+ let current = [];
545
+ let next = [];
546
+
547
+ /**
548
+ * Enqueues a job
549
+ *
550
+ * @template {(...args: any[]) => void} F
551
+ * @param {F} func - An async function to execute
552
+ * @param {Parameters<F>} args - Arguments to pass to the function
553
+ * @returns {void}
554
+ */
555
+ const enqueueJob = (func, args) => {
556
+ arrayPush(next, [func, args]);
557
+ };
558
+ const drainQueue = () => {
559
+ // Attention: load bearing flow order. Calling another enqueued function in the
560
+ // synchronous usecase must happen after the one that enqueued it has finished.
561
+ // Jobs enqueued in one pass do not interleave with jobs resulting from them.
562
+ // It's necessary for efficient memoization and to break cycles.
563
+ for (const [func, args] of current) {
564
+ try {
565
+ func(...args);
566
+ } catch (error) {
567
+ arrayPush(errors, error);
568
+ }
569
+ }
570
+ current = next;
571
+ next = [];
572
+ if (current.length > 0) drainQueue();
573
+ };
574
+ return { enqueueJob, drainQueue, errors };
545
575
  };
546
576
 
547
577
  /**
@@ -553,7 +583,8 @@ const throwAggregateError = ({ errors, errorPrefix }) => {
553
583
  // Throw an aggregate error if there were any errors.
554
584
  if (errors.length > 0) {
555
585
  const verbose =
556
- getenv('COMPARTMENT_LOAD_ERRORS', '', ['verbose']) === 'verbose';
586
+ /** @type {'' | 'verbose'} */
587
+ (getenv('COMPARTMENT_LOAD_ERRORS', '', ['verbose'])) === 'verbose';
557
588
  throw TypeError(
558
589
  `${errorPrefix} (${errors.length} underlying failures: ${arrayJoin(
559
590
  arrayMap(errors, error => error.message + (verbose ? error.stack : '')),
@@ -587,7 +618,7 @@ export const load = async (
587
618
  /** @type {Map<object, Map<string, Promise<Record<any, any>>>>} */
588
619
  const moduleLoads = new Map();
589
620
 
590
- const { enqueueJob, drainQueue } = asyncJobQueue();
621
+ const { enqueueJob, drainQueue, errors } = asyncJobQueue();
591
622
 
592
623
  enqueueJob(memoizedLoadWithErrorAnnotation, [
593
624
  compartmentPrivateFields,
@@ -599,8 +630,7 @@ export const load = async (
599
630
  moduleLoads,
600
631
  ]);
601
632
 
602
- // Drain pending jobs queue and throw an aggregate error
603
- const errors = await drainQueue();
633
+ await drainQueue();
604
634
 
605
635
  throwAggregateError({
606
636
  errors,
@@ -631,16 +661,7 @@ export const loadNow = (
631
661
  /** @type {Map<object, Map<string, Promise<Record<any, any>>>>} */
632
662
  const moduleLoads = new Map();
633
663
 
634
- /** @type {Array<Error>} */
635
- const errors = [];
636
-
637
- const enqueueJob = (func, args) => {
638
- try {
639
- func(...args);
640
- } catch (error) {
641
- arrayPush(errors, error);
642
- }
643
- };
664
+ const { enqueueJob, drainQueue, errors } = syncJobQueue();
644
665
 
645
666
  enqueueJob(memoizedLoadWithErrorAnnotation, [
646
667
  compartmentPrivateFields,
@@ -652,6 +673,8 @@ export const loadNow = (
652
673
  moduleLoads,
653
674
  ]);
654
675
 
676
+ drainQueue();
677
+
655
678
  throwAggregateError({
656
679
  errors,
657
680
  errorPrefix: `Failed to load module ${q(moduleSpecifier)} in package ${q(
package/src/permits.js CHANGED
@@ -6,12 +6,14 @@ import { arrayPush, arrayForEach } from './commons.js';
6
6
  /** @import {GenericErrorConstructor} from '../types.js' */
7
7
 
8
8
  /**
9
- * @module Exports {@code permits}, a recursively defined
9
+ * Exports {@code permits}, a recursively defined
10
10
  * JSON record enumerating all intrinsics and their properties
11
11
  * according to ECMA specs.
12
12
  *
13
13
  * @author JF Paradis
14
14
  * @author Mark S. Miller
15
+ *
16
+ * @module
15
17
  */
16
18
 
17
19
  /**
@@ -1356,6 +1358,35 @@ export const permitted = {
1356
1358
  // https://github.com/tc39/proposal-arraybuffer-transfer
1357
1359
  transferToFixedLength: fn,
1358
1360
  detached: getter,
1361
+ // https://github.com/endojs/endo/pull/2309#issuecomment-2155513240
1362
+ // to be proposed
1363
+ transferToImmutable: fn,
1364
+ sliceToImmutable: fn,
1365
+ immutable: getter,
1366
+ },
1367
+
1368
+ // If this exists, it is purely an artifact of how we currently shim
1369
+ // `transferToImmutable`. As natively implemented, there would be no
1370
+ // such extra prototype.
1371
+ '%ImmutableArrayBufferPrototype%': {
1372
+ '[[Proto]]': '%ArrayBufferPrototype%',
1373
+ byteLength: getter,
1374
+ slice: fn,
1375
+ // See https://github.com/endojs/endo/tree/master/packages/immutable-arraybuffer#purposeful-violation
1376
+ '@@toStringTag': 'string',
1377
+ // See https://github.com/tc39/proposal-resizablearraybuffer
1378
+ transfer: fn,
1379
+ resize: fn,
1380
+ resizable: getter,
1381
+ maxByteLength: getter,
1382
+ // https://github.com/tc39/proposal-arraybuffer-transfer
1383
+ transferToFixedLength: fn,
1384
+ detached: getter,
1385
+ // https://github.com/endojs/endo/pull/2309#issuecomment-2155513240
1386
+ // to be proposed
1387
+ transferToImmutable: fn,
1388
+ sliceToImmutable: fn,
1389
+ immutable: getter,
1359
1390
  },
1360
1391
 
1361
1392
  // SharedArrayBuffer Objects
package/src/reporting.js CHANGED
@@ -1,4 +1,4 @@
1
- import { TypeError, functionBind, globalThis } from './commons.js';
1
+ import { functionBind, globalThis } from './commons.js';
2
2
  import { assert } from './error/assert.js';
3
3
 
4
4
  /**
@@ -51,9 +51,6 @@ export const chooseReporter = reporting => {
51
51
  if (reporting === 'none') {
52
52
  return makeReportPrinter(mute);
53
53
  }
54
- if (reporting !== 'platform' && reporting !== 'console') {
55
- throw new TypeError(`Invalid lockdown reporting option: ${reporting}`);
56
- }
57
54
  if (
58
55
  reporting === 'console' ||
59
56
  globalThis.window === globalThis ||
@@ -11,7 +11,6 @@ import {
11
11
  } from './commons.js';
12
12
 
13
13
  export const shimArrayBufferTransfer = () => {
14
- // @ts-expect-error TODO extend ArrayBuffer type to include transfer, etc.
15
14
  if (typeof arrayBufferPrototype.transfer === 'function') {
16
15
  // Assume already exists so does not need to be shimmed.
17
16
  // Such conditional shimming is ok in this case since ArrayBuffer.p.transfer
@@ -8,10 +8,6 @@ import {
8
8
  } from './commons.js';
9
9
 
10
10
  export function tameDomains(domainTaming = 'safe') {
11
- if (domainTaming !== 'safe' && domainTaming !== 'unsafe') {
12
- throw TypeError(`unrecognized domainTaming ${domainTaming}`);
13
- }
14
-
15
11
  if (domainTaming === 'unsafe') {
16
12
  return;
17
13
  }
@@ -1,14 +1,10 @@
1
1
  /* eslint-disable no-restricted-globals */
2
- import { TypeError, freeze } from './commons.js';
2
+ import { freeze } from './commons.js';
3
3
 
4
4
  /** @import {Harden} from '../types.js'; */
5
5
 
6
6
  /** @type {(safeHarden: Harden, hardenTaming: 'safe' | 'unsafe') => Harden} */
7
7
  export const tameHarden = (safeHarden, hardenTaming) => {
8
- if (hardenTaming !== 'safe' && hardenTaming !== 'unsafe') {
9
- throw TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
10
- }
11
-
12
8
  if (hardenTaming === 'safe') {
13
9
  return safeHarden;
14
10
  }
@@ -44,9 +44,6 @@ const nonLocaleCompare = tamedMethods.localeCompare;
44
44
  const numberToString = tamedMethods.toString;
45
45
 
46
46
  export default function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
47
- if (localeTaming !== 'safe' && localeTaming !== 'unsafe') {
48
- throw TypeError(`unrecognized localeTaming ${localeTaming}`);
49
- }
50
47
  if (localeTaming === 'unsafe') {
51
48
  return;
52
49
  }
@@ -8,9 +8,6 @@ import {
8
8
  } from './commons.js';
9
9
 
10
10
  export default function tameRegExpConstructor(regExpTaming = 'safe') {
11
- if (regExpTaming !== 'safe' && regExpTaming !== 'unsafe') {
12
- throw TypeError(`unrecognized regExpTaming ${regExpTaming}`);
13
- }
14
11
  const RegExpPrototype = FERAL_REG_EXP.prototype;
15
12
 
16
13
  const makeRegExpConstructor = (_ = {}) => {
package/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /**
2
- * @module Types of the SES environment
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 = (moduleSpecifier: string) => ModuleDescriptor;
150
+ export type ImportNowHook = (
151
+ moduleSpecifier: string,
152
+ ) => ModuleDescriptor | undefined;
146
153
  export type ImportMetaHook = (
147
154
  moduleSpecifier: string,
148
- importMeta: Object,
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(specifier: string): Promise<{ namespace: ModuleExportsNamespace }>;
591
+ import(
592
+ specifier: string | null,
593
+ ): Promise<{ namespace: ModuleExportsNamespace }>;
580
594
 
581
595
  load(specifier: string): Promise<void>;
582
596