ses 1.11.0 → 1.13.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/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,62 +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'])
217
+ ),
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
+ ])
183
227
  ),
184
- stackFiltering = getenv('LOCKDOWN_STACK_FILTERING', 'concise'),
185
- domainTaming = getenv('LOCKDOWN_DOMAIN_TAMING', 'safe'),
186
- evalTaming = getenv('LOCKDOWN_EVAL_TAMING', 'safeEval'),
187
- overrideDebug = arrayFilter(
188
- stringSplit(getenv('LOCKDOWN_OVERRIDE_DEBUG', ''), ','),
189
- /** @param {string} debugName */
190
- debugName => debugName !== '',
228
+ overrideDebug = /** @type {string[]} */ (
229
+ arrayFilter(
230
+ stringSplit(getenv('LOCKDOWN_OVERRIDE_DEBUG', ''), ','),
231
+ /** @param {string} debugName */
232
+ debugName => debugName !== '',
233
+ )
191
234
  ),
192
- legacyRegeneratorRuntimeTaming = getenv(
193
- 'LOCKDOWN_LEGACY_REGENERATOR_RUNTIME_TAMING',
194
- 'safe',
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 === 'unsafeEval' ||
207
- evalTaming === 'safeEval' ||
208
- evalTaming === 'noEval' ||
209
- Fail`lockdown(): non supported option evalTaming: ${q(evalTaming)}`;
210
-
211
248
  // Assert that only supported options were passed.
212
249
  // Use Reflect.ownKeys to reject symbol-named properties as well.
213
250
  const extraOptionsNames = ownKeys(extraOptions);
@@ -218,13 +255,11 @@ export const repairIntrinsics = (options = {}) => {
218
255
  const { warn } = reporter;
219
256
 
220
257
  if (dateTaming !== undefined) {
221
- // eslint-disable-next-line no-console
222
258
  warn(
223
259
  `SES The 'dateTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
224
260
  );
225
261
  }
226
262
  if (mathTaming !== undefined) {
227
- // eslint-disable-next-line no-console
228
263
  warn(
229
264
  `SES The 'mathTaming' option is deprecated and does nothing. In the future specifying it will be an error.`,
230
265
  );
@@ -242,7 +277,19 @@ export const repairIntrinsics = (options = {}) => {
242
277
  // trace retained:
243
278
  priorRepairIntrinsics.stack;
244
279
 
245
- 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
+ }
246
293
 
247
294
  /**
248
295
  * Because of packagers and bundlers, etc, multiple invocations of lockdown
@@ -297,7 +344,6 @@ export const repairIntrinsics = (options = {}) => {
297
344
  const { addIntrinsics, completePrototypes, finalIntrinsics } =
298
345
  makeIntrinsicsCollector(reporter);
299
346
 
300
- // @ts-expect-error __hardenTaming__ could be any string
301
347
  const tamedHarden = tameHarden(safeHarden, __hardenTaming__);
302
348
  addIntrinsics({ harden: tamedHarden });
303
349
 
@@ -408,23 +454,36 @@ export const repairIntrinsics = (options = {}) => {
408
454
  markVirtualizedNativeFunction,
409
455
  });
410
456
 
411
- if (evalTaming === 'noEval') {
457
+ if (
458
+ evalTaming === 'no-eval' ||
459
+ // deprecated
460
+ evalTaming === 'noEval'
461
+ ) {
412
462
  setGlobalObjectEvaluators(
413
463
  globalThis,
414
464
  noEvalEvaluate,
415
465
  markVirtualizedNativeFunction,
416
466
  );
417
- } else if (evalTaming === 'safeEval') {
467
+ } else if (
468
+ evalTaming === 'safe-eval' ||
469
+ // deprecated
470
+ evalTaming === 'safeEval'
471
+ ) {
418
472
  const { safeEvaluate } = makeSafeEvaluator({ globalObject: globalThis });
419
473
  setGlobalObjectEvaluators(
420
474
  globalThis,
421
475
  safeEvaluate,
422
476
  markVirtualizedNativeFunction,
423
477
  );
424
- } else if (evalTaming === 'unsafeEval') {
425
- // Leave eval function and Function constructor of the initial compartment in-tact.
426
- // Other compartments will not have access to these evaluators unless a guest program
427
- // escapes containment.
478
+ } else if (
479
+ evalTaming === 'unsafe-eval' ||
480
+ // deprecated
481
+ evalTaming === 'unsafeEval'
482
+ ) {
483
+ // Leave eval function and Function constructor of the initial
484
+ // compartment intact.
485
+ // Other compartments will not have access to these evaluators unless a
486
+ // guest program escapes containment.
428
487
  }
429
488
 
430
489
  /**
@@ -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,33 @@ 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/tc39/proposal-resizablearraybuffer
1376
+ transfer: fn,
1377
+ resize: fn,
1378
+ resizable: getter,
1379
+ maxByteLength: getter,
1380
+ // https://github.com/tc39/proposal-arraybuffer-transfer
1381
+ transferToFixedLength: fn,
1382
+ detached: getter,
1383
+ // https://github.com/endojs/endo/pull/2309#issuecomment-2155513240
1384
+ // to be proposed
1385
+ transferToImmutable: fn,
1386
+ sliceToImmutable: fn,
1387
+ immutable: getter,
1359
1388
  },
1360
1389
 
1361
1390
  // 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
@@ -6,7 +6,6 @@ import {
6
6
  create,
7
7
  freeze,
8
8
  getOwnPropertyDescriptors,
9
- globalThis,
10
9
  } from './commons.js';
11
10
  import { assert } from './error/assert.js';
12
11
 
@@ -55,7 +54,7 @@ const scopeProxyHandlerProperties = {
55
54
 
56
55
  has(_shadow, prop) {
57
56
  // we must at least return true for all properties on the realm globalThis
58
- return prop in globalThis;
57
+ return true;
59
58
  },
60
59
 
61
60
  // note: this is likely a bug of safari
@@ -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
  }
@@ -6,6 +6,7 @@ import {
6
6
  getPrototypeOf,
7
7
  setPrototypeOf,
8
8
  freeze,
9
+ AsyncGeneratorFunctionInstance,
9
10
  } from './commons.js';
10
11
 
11
12
  // This module replaces the original `Function` constructor, and the original
@@ -126,11 +127,14 @@ export default function tameFunctionConstructors() {
126
127
  '%InertAsyncFunction%',
127
128
  '(async function(){})',
128
129
  );
129
- repairFunction(
130
- 'AsyncGeneratorFunction',
131
- '%InertAsyncGeneratorFunction%',
132
- '(async function*(){})',
133
- );
130
+
131
+ if (AsyncGeneratorFunctionInstance !== undefined) {
132
+ repairFunction(
133
+ 'AsyncGeneratorFunction',
134
+ '%InertAsyncGeneratorFunction%',
135
+ '(async function*(){})',
136
+ );
137
+ }
134
138
 
135
139
  return newIntrinsics;
136
140
  }
@@ -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 = (_ = {}) => {