ses 0.18.0 → 0.18.2

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.
Files changed (43) hide show
  1. package/NEWS.md +17 -0
  2. package/README.md +10 -5
  3. package/SECURITY.md +1 -1
  4. package/dist/lockdown.cjs +319 -243
  5. package/dist/lockdown.mjs +319 -243
  6. package/dist/lockdown.umd.js +319 -243
  7. package/dist/lockdown.umd.min.js +1 -1
  8. package/dist/ses.cjs +319 -243
  9. package/dist/ses.mjs +319 -243
  10. package/dist/ses.umd.js +319 -243
  11. package/dist/ses.umd.min.js +1 -1
  12. package/index.js +1 -0
  13. package/package.json +15 -12
  14. package/src/commons.js +2 -0
  15. package/src/compartment-evaluate.js +2 -4
  16. package/src/compartment-shim.js +3 -3
  17. package/src/enablements.js +12 -0
  18. package/src/environment-options.js +10 -19
  19. package/src/error/assert.js +24 -16
  20. package/src/error/console.js +2 -6
  21. package/src/error/internal-types.js +3 -3
  22. package/src/error/types.js +76 -81
  23. package/src/get-anonymous-intrinsics.js +6 -4
  24. package/src/get-source-url.js +3 -0
  25. package/src/global-object.js +9 -9
  26. package/src/intrinsics.js +1 -1
  27. package/src/lockdown-shim.js +11 -13
  28. package/src/make-hardener.js +1 -1
  29. package/src/make-safe-evaluator.js +4 -4
  30. package/src/module-instance.js +29 -13
  31. package/src/module-link.js +2 -6
  32. package/src/module-load.js +58 -21
  33. package/src/scope-constants.js +2 -2
  34. package/src/sloppy-globals-scope-terminator.js +1 -0
  35. package/src/tame-domains.js +1 -0
  36. package/src/tame-function-constructors.js +3 -2
  37. package/src/tame-locale-methods.js +2 -2
  38. package/src/tame-math-object.js +2 -3
  39. package/src/transforms.js +15 -0
  40. package/src/whitelist-intrinsics.js +2 -2
  41. package/tools.js +25 -0
  42. package/{index.d.ts → types.d.ts} +2 -1
  43. package/CHANGELOG.md +0 -596
package/dist/ses.umd.js CHANGED
@@ -101,6 +101,7 @@ const defineProperty= (object, prop, descriptor)=> {
101
101
  // Instead, to workaround the Safari bug
102
102
  const result= originalDefineProperty(object, prop, descriptor);
103
103
  if( result!== object) {
104
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DEFINE_PROPERTY_FAILED_SILENTLY.md
104
105
  throw TypeError(
105
106
  `Please report that the original defineProperty silently failed to set ${stringifyJson(
106
107
  String(prop))
@@ -283,6 +284,7 @@ $h‍_once.isError(isError);const FERAL_EVAL=eval;
283
284
  $h‍_once.FERAL_EVAL(FERAL_EVAL);const FERAL_FUNCTION=Function;$h‍_once.FERAL_FUNCTION(FERAL_FUNCTION);
284
285
 
285
286
  const noEvalEvaluate= ()=> {
287
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
286
288
  throw new TypeError(
287
289
  'Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)');
288
290
 
@@ -317,7 +319,7 @@ const noEvalEvaluate= ()=> {
317
319
  */
318
320
 
319
321
  /**
320
- * @typedef {Object} LoggedErrorHandler
322
+ * @typedef {object} LoggedErrorHandler
321
323
  *
322
324
  * Used to parameterize `makeCausalConsole` to give it access to potentially
323
325
  * hidden information to augment the logging of errors.
@@ -337,13 +339,13 @@ const noEvalEvaluate= ()=> {
337
339
  */
338
340
 
339
341
  /**
340
- * @typedef {Object} LoggingConsoleKit
342
+ * @typedef {object} LoggingConsoleKit
341
343
  * @property {VirtualConsole} loggingConsole
342
344
  * @property {() => readonly LogRecord[]} takeLog
343
345
  */
344
346
 
345
347
  /**
346
- * @typedef {Object} MakeLoggingConsoleKitOptions
348
+ * @typedef {object} MakeLoggingConsoleKitOptions
347
349
  * @property {boolean=} shouldResetForDebugging
348
350
  */
349
351
 
@@ -567,7 +569,7 @@ freeze(bestEffortStringify);
567
569
  */
568
570
 
569
571
  /**
570
- * @typedef {Object} AssertMakeErrorOptions
572
+ * @typedef {object} AssertMakeErrorOptions
571
573
  * @property {string=} errorName
572
574
  */
573
575
 
@@ -589,8 +591,9 @@ freeze(bestEffortStringify);
589
591
  *
590
592
  * The `assert.fail` method.
591
593
  *
592
- * Fail an assertion, recording details to the console and
593
- * raising an exception with just type information.
594
+ * Fail an assertion, recording full details to the console and
595
+ * raising an exception with a message in which `details` substitution values
596
+ * have been redacted.
594
597
  *
595
598
  * The optional `optDetails` can be a string for backwards compatibility
596
599
  * with the nodejs assertion library.
@@ -614,51 +617,65 @@ freeze(bestEffortStringify);
614
617
  */
615
618
 
616
619
  // Type all the overloads of the assertTypeof function.
617
- // There may eventually be a better way to do this, but they break with
618
- // Typescript 4.0.
620
+ // There may eventually be a better way to do this, but
621
+ // thems the breaks with Typescript 4.0.
619
622
  /**
620
623
  * @callback AssertTypeofBigint
621
624
  * @param {any} specimen
622
625
  * @param {'bigint'} typename
623
626
  * @param {Details=} optDetails
624
627
  * @returns {asserts specimen is bigint}
625
- *
628
+ */
629
+
630
+ /**
626
631
  * @callback AssertTypeofBoolean
627
632
  * @param {any} specimen
628
633
  * @param {'boolean'} typename
629
634
  * @param {Details=} optDetails
630
635
  * @returns {asserts specimen is boolean}
631
- *
636
+ */
637
+
638
+ /**
632
639
  * @callback AssertTypeofFunction
633
640
  * @param {any} specimen
634
641
  * @param {'function'} typename
635
642
  * @param {Details=} optDetails
636
643
  * @returns {asserts specimen is Function}
637
- *
644
+ */
645
+
646
+ /**
638
647
  * @callback AssertTypeofNumber
639
648
  * @param {any} specimen
640
649
  * @param {'number'} typename
641
650
  * @param {Details=} optDetails
642
651
  * @returns {asserts specimen is number}
643
- *
652
+ */
653
+
654
+ /**
644
655
  * @callback AssertTypeofObject
645
656
  * @param {any} specimen
646
657
  * @param {'object'} typename
647
658
  * @param {Details=} optDetails
648
659
  * @returns {asserts specimen is Record<any, any> | null}
649
- *
660
+ */
661
+
662
+ /**
650
663
  * @callback AssertTypeofString
651
664
  * @param {any} specimen
652
665
  * @param {'string'} typename
653
666
  * @param {Details=} optDetails
654
667
  * @returns {asserts specimen is string}
655
- *
668
+ */
669
+
670
+ /**
656
671
  * @callback AssertTypeofSymbol
657
672
  * @param {any} specimen
658
673
  * @param {'symbol'} typename
659
674
  * @param {Details=} optDetails
660
675
  * @returns {asserts specimen is symbol}
661
- *
676
+ */
677
+
678
+ /**
662
679
  * @callback AssertTypeofUndefined
663
680
  * @param {any} specimen
664
681
  * @param {'undefined'} typename
@@ -682,14 +699,15 @@ freeze(bestEffortStringify);
682
699
  * Assert an expected typeof result.
683
700
  * @param {any} specimen The value to get the typeof
684
701
  * @param {Details=} optDetails The details to throw
702
+ * @returns {asserts specimen is string}
685
703
  */
686
704
 
687
705
  /**
688
706
  * @callback AssertNote
689
707
  * The `assert.note` method.
690
708
  *
691
- * Annotate this error with these details, potentially to be used by an
692
- * augmented console, like the causal console of `console.js`, to
709
+ * Annotate an error with details, potentially to be used by an
710
+ * augmented console such as the causal console of `console.js`, to
693
711
  * provide extra information associated with logged errors.
694
712
  *
695
713
  * @param {Error} error
@@ -712,45 +730,31 @@ freeze(bestEffortStringify);
712
730
  */
713
731
 
714
732
  /**
715
- * @typedef {Object} StringablePayload
733
+ * @typedef {object} StringablePayload
716
734
  * Holds the payload passed to quote so that its printed form is visible.
717
735
  * @property {() => string} toString How to print the payload
718
736
  */
719
737
 
720
738
  /**
721
739
  * To "declassify" and quote a substitution value used in a
722
- * details`...` template literal, enclose that substitution expression
723
- * in a call to `quote`. This states that the argument should appear quoted
724
- * (as if with `JSON.stringify`), in the error message of the thrown error. The
740
+ * ``` details`...` ``` template literal, enclose that substitution expression
741
+ * in a call to `quote`. This makes the value appear quoted
742
+ * (as if with `JSON.stringify`) in the message of the thrown error. The
725
743
  * payload itself is still passed unquoted to the console as it would be
726
744
  * without `quote`.
727
745
  *
728
- * Starting from the example in the `details` comment, say instead that the
729
- * color the sky is supposed to be is also computed. Say that we still don't
730
- * want to reveal the sky's actual color, but we do want the thrown error's
731
- * message to reveal what color the sky was supposed to be:
746
+ * For example, the following will reveal the expected sky color, but not the
747
+ * actual incorrect sky color, in the thrown error's message:
732
748
  * ```js
733
- * assert.equal(
734
- * sky.color,
735
- * color,
736
- * details`${sky.color} should be ${quote(color)}`,
737
- * );
749
+ * sky.color === expectedColor || Fail`${sky.color} should be ${quote(expectedColor)}`;
738
750
  * ```
739
751
  *
740
752
  * // TODO Update SES-shim to new convention, where `details` is
741
753
  * // renamed to `X` rather than `d`.
742
- * The normal convention is to locally rename `quote` to `q` and
743
- * `details` to `d`
754
+ * The normal convention is to locally rename `details` to `d` and `quote` to `q`
755
+ * like `const { details: d, quote: q } = assert;`, so the above example would then be
744
756
  * ```js
745
- * const { details: d, quote: q } = assert;
746
- * ```
747
- * so the above example would then be
748
- * ```js
749
- * assert.equal(
750
- * sky.color,
751
- * color,
752
- * d`${sky.color} should be ${q(color)}`,
753
- * );
757
+ * sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;
754
758
  * ```
755
759
  *
756
760
  * @callback AssertQuote
@@ -802,75 +806,68 @@ freeze(bestEffortStringify);
802
806
  * ```js
803
807
  * assert(sky.isBlue(), details`${sky.color} should be "blue"`);
804
808
  * ```
809
+ * // TODO Update SES-shim to new convention, where `details` is
810
+ * // renamed to `X` rather than `d`.
811
+ * or following the normal convention to locally rename `details` to `d`
812
+ * and `quote` to `q` like `const { details: d, quote: q } = assert;`:
813
+ * ```js
814
+ * assert(sky.isBlue(), d`${sky.color} should be "blue"`);
815
+ * ```
816
+ * However, note that in most cases it is preferable to instead use the `Fail`
817
+ * template literal tag (which has the same input signature as `details`
818
+ * but automatically creates and throws an error):
819
+ * ```js
820
+ * sky.isBlue() || Fail`${sky.color} should be "blue"`;
821
+ * ```
822
+ *
805
823
  * The details template tag returns a `DetailsToken` object that can print
806
824
  * itself with the formatted message in two ways.
807
- * It will report the real details to
808
- * the console but include only the typeof information in the thrown error
825
+ * It will report full details to the console, but
826
+ * mask embedded substitution values with their typeof information in the thrown error
809
827
  * to prevent revealing secrets up the exceptional path. In the example
810
828
  * above, the thrown error may reveal only that `sky.color` is a string,
811
829
  * whereas the same diagnostic printed to the console reveals that the
812
- * sky was green.
830
+ * sky was green. This masking can be disabled for an individual substitution value
831
+ * using `quote`.
813
832
  *
814
- * The `raw` member of a `template` is ignored, so a simple
815
- * `string[]` can also be used as a template.
833
+ * The `raw` property of an input template array is ignored, so a simple
834
+ * array of strings may be provided directly.
816
835
  */
817
836
 
818
837
  /**
819
838
  * @typedef {(template: TemplateStringsArray | string[], ...args: any) => never} FailTag
820
- * The `Fail` tamplate tag supports replacing patterns like
821
- * ```js
822
- * assert(cond, X`...complaint...`);
823
- * ```
824
- * or
825
- * ```js
826
- * cond || assert.fail(X`...complaint...`);
827
- * ```
828
- * with patterns like
829
- * ```js
830
- * cond || Fail`...complaint...`;
831
- * ```
832
839
  *
833
- * However, due to [weakness in current
834
- * TypeScript](https://github.com/microsoft/TypeScript/issues/51426), the `||`
835
- * patterns are not as powerful as the `assert(...)` call at enabling static
836
- * reasoning. Of the `||`, again due to weaknesses in current TypeScript,
837
- * the
840
+ * Use the `Fail` function as a template literal tag to efficiently
841
+ * create and throw a `details`-style error only when a condition is not satisfied.
838
842
  * ```js
839
- * cond || Fail`...complaint...`
843
+ * condition || Fail`...complaint...`;
840
844
  * ```
841
- * pattern is not as powerful as the
845
+ * This avoids the overhead of creating usually-unnecessary errors like
842
846
  * ```js
843
- * cond || assert.fail(X`...complaint...`);
847
+ * assert(condition, details`...complaint...`);
844
848
  * ```
845
- * at enabling static resoning. Despite these problems, we do not want to
846
- * return to the
849
+ * while improving readability over alternatives like
847
850
  * ```js
848
- * assert(cond, X`...complaint...`)
851
+ * condition || assert.fail(details`...complaint...`);
849
852
  * ```
850
- * style because of the substantial overhead in
851
- * evaluating the `X` template in the typical `true` case where it is not
852
- * needed. And we do not want to return to the
853
- * ```js
854
- * assert.fail(X`...complaint...`)`
855
- * ```
856
- * because of the verbosity and loss of readability. Instead, until/unless
857
- * https://github.com/microsoft/TypeScript/issues/51426 is fixed, for those
858
- * new-style assertions where this loss of static reasoning is a problem,
853
+ *
854
+ * However, due to current weakness in TypeScript, static reasoning
855
+ * is less powerful with the `||` patterns than with an `assert` call.
856
+ * Until/unless https://github.com/microsoft/TypeScript/issues/51426 is fixed,
857
+ * for `||`-style assertions where this loss of static reasoning is a problem,
859
858
  * instead express the assertion as
860
859
  * ```js
861
- * if (!cond) {
860
+ * if (!condition) {
862
861
  * Fail`...complaint...`;
863
862
  * }
864
863
  * ```
865
864
  * or, if needed,
866
865
  * ```js
867
- * if (!cond) {
868
- * // `throw` is noop since `Fail` throws. But linter confused
866
+ * if (!condition) {
867
+ * // `throw` is noop since `Fail` throws, but it improves static analysis
869
868
  * throw Fail`...complaint...`;
870
869
  * }
871
870
  * ```
872
- * This avoid the TypeScript bugs that cause the loss of static reasoning,
873
- * but with no loss of efficiency and little loss of readability.
874
871
  */
875
872
 
876
873
  /**
@@ -908,7 +905,7 @@ freeze(bestEffortStringify);
908
905
  // /////////////////////////////////////////////////////////////////////////////
909
906
 
910
907
  /**
911
- * @typedef {Object} VirtualConsole
908
+ * @typedef {object} VirtualConsole
912
909
  * @property {Console['debug']} debug
913
910
  * @property {Console['log']} log
914
911
  * @property {Console['info']} info
@@ -1025,7 +1022,7 @@ freeze(quote);
1025
1022
  // /////////////////////////////////////////////////////////////////////////////
1026
1023
 
1027
1024
  /**
1028
- * @typedef {Object} HiddenDetails
1025
+ * @typedef {object} HiddenDetails
1029
1026
  *
1030
1027
  * Captures the arguments passed to the `details` template string tag.
1031
1028
  *
@@ -1329,9 +1326,11 @@ freeze(loggedErrorHandler);
1329
1326
  */
1330
1327
  const makeAssert= (optRaise= undefined, unredacted= false)=> {
1331
1328
  const details= unredacted? unredactedDetails: redactedDetails;
1329
+ const assertFailedDetails= details `Check failed`;
1330
+
1332
1331
  /** @type {AssertFail} */
1333
1332
  const fail= (
1334
- optDetails= details `Assert failed`,
1333
+ optDetails= assertFailedDetails,
1335
1334
  ErrorConstructor= globalThis.Error)=>
1336
1335
  {
1337
1336
  const reason= makeError(optDetails, ErrorConstructor);
@@ -1351,30 +1350,36 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
1351
1350
  /** @type {BaseAssert} */
1352
1351
  function baseAssert(
1353
1352
  flag,
1354
- optDetails= details `Check failed`,
1355
- ErrorConstructor= globalThis.Error)
1353
+ optDetails= undefined,
1354
+ ErrorConstructor= undefined)
1356
1355
  {
1357
- if( !flag) {
1358
- throw fail(optDetails, ErrorConstructor);
1359
- }
1356
+ flag|| fail(optDetails, ErrorConstructor);
1360
1357
  }
1361
1358
 
1362
1359
  /** @type {AssertEqual} */
1363
1360
  const equal= (
1364
1361
  actual,
1365
1362
  expected,
1366
- optDetails= details `Expected ${actual} is same as ${expected}`,
1367
- ErrorConstructor= RangeError)=>
1363
+ optDetails= undefined,
1364
+ ErrorConstructor= undefined)=>
1368
1365
  {
1369
- baseAssert(is(actual, expected), optDetails, ErrorConstructor);
1366
+ is(actual, expected)||
1367
+ fail(
1368
+ optDetails|| details `Expected ${actual} is same as ${expected}`,
1369
+ ErrorConstructor|| RangeError);
1370
+
1370
1371
  };
1371
1372
  freeze(equal);
1372
1373
 
1373
1374
  /** @type {AssertTypeof} */
1374
1375
  const assertTypeof= (specimen, typename, optDetails)=> {
1375
- baseAssert(
1376
- typeof typename=== 'string',
1377
- details `${quote(typename)} must be a string`);
1376
+ // This will safely fall through if typename is not a string,
1377
+ // which is what we want.
1378
+ // eslint-disable-next-line valid-typeof
1379
+ if( typeof specimen=== typename) {
1380
+ return;
1381
+ }
1382
+ typeof typename=== 'string'|| Fail `${quote(typename)} must be a string`;
1378
1383
 
1379
1384
  if( optDetails=== undefined) {
1380
1385
  // Like
@@ -1385,12 +1390,12 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
1385
1390
  // so it doesn't get quoted.
1386
1391
  optDetails= details(['', ` must be ${an(typename)}`],specimen);
1387
1392
  }
1388
- equal(typeof specimen, typename, optDetails, TypeError);
1393
+ fail(optDetails, TypeError);
1389
1394
  };
1390
1395
  freeze(assertTypeof);
1391
1396
 
1392
1397
  /** @type {AssertString} */
1393
- const assertString= (specimen, optDetails)=>
1398
+ const assertString= (specimen, optDetails= undefined)=>
1394
1399
  assertTypeof(specimen, 'string', optDetails);
1395
1400
 
1396
1401
  // Note that "assert === baseAssert"
@@ -1652,8 +1657,8 @@ function isImmutableDataProperty(obj, name) {
1652
1657
  * service if any of the names are keywords or keyword-like. This is
1653
1658
  * safe and only prevent performance optimization.
1654
1659
  *
1655
- * @param {Object} globalObject
1656
- * @param {Object} moduleLexicals
1660
+ * @param {object} globalObject
1661
+ * @param {object} moduleLexicals
1657
1662
  */
1658
1663
  const getScopeConstants= (globalObject, moduleLexicals= {})=> {
1659
1664
  // getOwnPropertyNames() does ignore Symbols so we don't need to
@@ -1945,6 +1950,7 @@ const createSloppyGlobalsScopeTerminator= (globalObject)=>{
1945
1950
 
1946
1951
  return sloppyGlobalsScopeTerminator;
1947
1952
  };$h‍_once.createSloppyGlobalsScopeTerminator(createSloppyGlobalsScopeTerminator);
1953
+ freeze(createSloppyGlobalsScopeTerminator);
1948
1954
  })
1949
1955
  ,
1950
1956
  // === functors[10] ===
@@ -1963,6 +1969,9 @@ const sourceMetaEntriesRegExp= new FERAL_REG_EXP(
1963
1969
  `(?:\\s*//${sourceMetaEntryRegExp}|/\\*${sourceMetaEntryRegExp}\\s*\\*/)\\s*$`);
1964
1970
 
1965
1971
 
1972
+ /**
1973
+ * @param {string} src
1974
+ */
1966
1975
  const getSourceURL= (src)=>{
1967
1976
  let sourceURL= '<unknown>';
1968
1977
 
@@ -1998,7 +2007,8 @@ const getSourceURL= (src)=>{
1998
2007
  })
1999
2008
  ,
2000
2009
  // === functors[11] ===
2001
- (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => { let FERAL_REG_EXP,SyntaxError,stringReplace,stringSearch,stringSlice,stringSplit,getSourceURL;$h‍_imports([["./commons.js", [["FERAL_REG_EXP", [$h‍_a => (FERAL_REG_EXP = $h‍_a)]],["SyntaxError", [$h‍_a => (SyntaxError = $h‍_a)]],["stringReplace", [$h‍_a => (stringReplace = $h‍_a)]],["stringSearch", [$h‍_a => (stringSearch = $h‍_a)]],["stringSlice", [$h‍_a => (stringSlice = $h‍_a)]],["stringSplit", [$h‍_a => (stringSplit = $h‍_a)]]]],["./get-source-url.js", [["getSourceURL", [$h‍_a => (getSourceURL = $h‍_a)]]]]]);
2010
+ (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => { let FERAL_REG_EXP,SyntaxError,stringReplace,stringSearch,stringSlice,stringSplit,freeze,getSourceURL;$h‍_imports([["./commons.js", [["FERAL_REG_EXP", [$h‍_a => (FERAL_REG_EXP = $h‍_a)]],["SyntaxError", [$h‍_a => (SyntaxError = $h‍_a)]],["stringReplace", [$h‍_a => (stringReplace = $h‍_a)]],["stringSearch", [$h‍_a => (stringSearch = $h‍_a)]],["stringSlice", [$h‍_a => (stringSlice = $h‍_a)]],["stringSplit", [$h‍_a => (stringSplit = $h‍_a)]],["freeze", [$h‍_a => (freeze = $h‍_a)]]]],["./get-source-url.js", [["getSourceURL", [$h‍_a => (getSourceURL = $h‍_a)]]]]]);
2011
+
2002
2012
 
2003
2013
 
2004
2014
 
@@ -2069,6 +2079,7 @@ const rejectHtmlComments= (src)=>{
2069
2079
  return src;
2070
2080
  }
2071
2081
  const name= getSourceURL(src);
2082
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_HTML_COMMENT_REJECTED.md
2072
2083
  throw new SyntaxError(
2073
2084
  `Possible HTML comment rejected at ${name}:${lineNumber}. (SES_HTML_COMMENT_REJECTED)`);
2074
2085
 
@@ -2144,6 +2155,7 @@ const rejectImportExpressions= (src)=>{
2144
2155
  return src;
2145
2156
  }
2146
2157
  const name= getSourceURL(src);
2158
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_IMPORT_REJECTED.md
2147
2159
  throw new SyntaxError(
2148
2160
  `Possible import expression rejected at ${name}:${lineNumber}. (SES_IMPORT_REJECTED)`);
2149
2161
 
@@ -2215,6 +2227,7 @@ const rejectSomeDirectEvalExpressions= (src)=>{
2215
2227
  return src;
2216
2228
  }
2217
2229
  const name= getSourceURL(src);
2230
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_EVAL_REJECTED.md
2218
2231
  throw new SyntaxError(
2219
2232
  `Possible direct eval expression rejected at ${name}:${lineNumber}. (SES_EVAL_REJECTED)`);
2220
2233
 
@@ -2248,7 +2261,17 @@ const applyTransforms= (source, transforms)=> {
2248
2261
  source= transform(source);
2249
2262
  }
2250
2263
  return source;
2251
- };$h‍_once.applyTransforms(applyTransforms);
2264
+ };
2265
+
2266
+ // export all as a frozen object
2267
+ $h‍_once.applyTransforms(applyTransforms);const transforms=freeze({
2268
+ rejectHtmlComments: freeze(rejectHtmlComments),
2269
+ evadeHtmlCommentTest: freeze(evadeHtmlCommentTest),
2270
+ rejectImportExpressions: freeze(rejectImportExpressions),
2271
+ evadeImportExpressionTest: freeze(evadeImportExpressionTest),
2272
+ rejectSomeDirectEvalExpressions: freeze(rejectSomeDirectEvalExpressions),
2273
+ mandatoryTransforms: freeze(mandatoryTransforms),
2274
+ applyTransforms: freeze(applyTransforms)});$h‍_once.transforms(transforms);
2252
2275
  })
2253
2276
  ,
2254
2277
  // === functors[12] ===
@@ -2270,9 +2293,9 @@ const { Fail}= assert;
2270
2293
  * Build the low-level operation used by all evaluators:
2271
2294
  * eval(), Function(), Compartment.prototype.evaluate().
2272
2295
  *
2273
- * @param {Object} options
2274
- * @param {Object} options.globalObject
2275
- * @param {Object} [options.moduleLexicals]
2296
+ * @param {object} options
2297
+ * @param {object} options.globalObject
2298
+ * @param {object} [options.moduleLexicals]
2276
2299
  * @param {Array<Transform>} [options.globalTransforms]
2277
2300
  * @param {bool} [options.sloppyGlobalsMode]
2278
2301
  */
@@ -2307,7 +2330,7 @@ const makeSafeEvaluator= ({
2307
2330
 
2308
2331
  /**
2309
2332
  * @param {string} source
2310
- * @param {Object} [options]
2333
+ * @param {object} [options]
2311
2334
  * @param {Array<Transform>} [options.localTransforms]
2312
2335
  */
2313
2336
  const safeEvaluate= (source, { localTransforms= []}= {})=> {
@@ -2379,10 +2402,8 @@ const makeSafeEvaluator= ({
2379
2402
 
2380
2403
 
2381
2404
  const provideCompartmentEvaluator= (compartmentFields, options)=> {
2382
- const {
2383
- sloppyGlobalsMode= false,
2384
- __moduleShimLexicals__= undefined}=
2385
- options;
2405
+ const { sloppyGlobalsMode= false, __moduleShimLexicals__= undefined}=
2406
+ options;
2386
2407
 
2387
2408
  let safeEvaluate;
2388
2409
 
@@ -3973,7 +3994,7 @@ const whitelist= {
3973
3994
  * But, we can install this setter to prevent a program from proceding on
3974
3995
  * this false assumption.
3975
3996
  *
3976
- * @param {Object} globalObject
3997
+ * @param {object} globalObject
3977
3998
  */
3978
3999
  const setGlobalObjectSymbolUnscopables= (globalObject)=>{
3979
4000
  defineProperty(
@@ -3999,7 +4020,7 @@ const setGlobalObjectSymbolUnscopables= (globalObject)=>{
3999
4020
  * (SetDefaultGlobalBindings). This process is split between this function and
4000
4021
  * `setGlobalObjectMutableProperties`.
4001
4022
  *
4002
- * @param {Object} globalObject
4023
+ * @param {object} globalObject
4003
4024
  */$h‍_once.setGlobalObjectSymbolUnscopables(setGlobalObjectSymbolUnscopables);
4004
4025
  const setGlobalObjectConstantProperties= (globalObject)=>{
4005
4026
  for( const [name, constant]of entries(constantProperties)) {
@@ -4019,12 +4040,12 @@ const setGlobalObjectConstantProperties= (globalObject)=>{
4019
4040
  * `newGlobalPropertyNames` should be either `initialGlobalPropertyNames` or
4020
4041
  * `sharedGlobalPropertyNames`.
4021
4042
  *
4022
- * @param {Object} globalObject
4023
- * @param {Object} param1
4024
- * @param {Object} param1.intrinsics
4025
- * @param {Object} param1.newGlobalPropertyNames
4043
+ * @param {object} globalObject
4044
+ * @param {object} param1
4045
+ * @param {object} param1.intrinsics
4046
+ * @param {object} param1.newGlobalPropertyNames
4026
4047
  * @param {Function} param1.makeCompartmentConstructor
4027
- * @param {(Object) => void} param1.markVirtualizedNativeFunction
4048
+ * @param {(object) => void} param1.markVirtualizedNativeFunction
4028
4049
  */$h‍_once.setGlobalObjectConstantProperties(setGlobalObjectConstantProperties);
4029
4050
  const setGlobalObjectMutableProperties= (
4030
4051
  globalObject,
@@ -4086,9 +4107,9 @@ const setGlobalObjectMutableProperties= (
4086
4107
  * setGlobalObjectEvaluators()
4087
4108
  * Set the eval and the Function evaluator on the global object with given evalTaming policy.
4088
4109
  *
4089
- * @param {Object} globalObject
4110
+ * @param {object} globalObject
4090
4111
  * @param {Function} evaluator
4091
- * @param {(Object) => void} markVirtualizedNativeFunction
4112
+ * @param {(object) => void} markVirtualizedNativeFunction
4092
4113
  */$h‍_once.setGlobalObjectMutableProperties(setGlobalObjectMutableProperties);
4093
4114
  const setGlobalObjectEvaluators= (
4094
4115
  globalObject,
@@ -4175,7 +4196,7 @@ $h‍_once.makeAlias(makeAlias);const resolveAll=(imports,resolveHook,fullReferr
4175
4196
  return freeze(resolvedImports);
4176
4197
  };
4177
4198
 
4178
- const loadRecord= async(
4199
+ const loadRecord= (
4179
4200
  compartmentPrivateFields,
4180
4201
  moduleAliases,
4181
4202
  compartment,
@@ -4296,27 +4317,64 @@ const loadWithoutErrorAnnotation= async(
4296
4317
  } in compartment ${q(compartment.name)}`;
4297
4318
  }
4298
4319
 
4299
- if( staticModuleRecord.record!== undefined) {
4300
- const {
4301
- compartment: aliasCompartment= compartment,
4302
- specifier: aliasSpecifier= moduleSpecifier,
4303
- record: aliasModuleRecord,
4304
- importMeta}=
4305
- staticModuleRecord;
4320
+ // check if record is a RedirectStaticModuleInterface
4321
+ if( staticModuleRecord.specifier!== undefined) {
4322
+ // check if this redirect with an explicit record
4323
+ if( staticModuleRecord.record!== undefined) {
4324
+ // ensure expected record shape
4325
+ if( staticModuleRecord.compartment!== undefined) {
4326
+ throw new TypeError(
4327
+ 'Cannot redirect to an explicit record with a specified compartment');
4306
4328
 
4307
- const aliasRecord= await loadRecord(
4308
- compartmentPrivateFields,
4309
- moduleAliases,
4310
- aliasCompartment,
4311
- aliasSpecifier,
4312
- aliasModuleRecord,
4313
- pendingJobs,
4314
- moduleLoads,
4315
- errors,
4316
- importMeta);
4329
+ }
4330
+ const {
4331
+ compartment: aliasCompartment= compartment,
4332
+ specifier: aliasSpecifier= moduleSpecifier,
4333
+ record: aliasModuleRecord,
4334
+ importMeta}=
4335
+ staticModuleRecord;
4336
+
4337
+ const aliasRecord= loadRecord(
4338
+ compartmentPrivateFields,
4339
+ moduleAliases,
4340
+ aliasCompartment,
4341
+ aliasSpecifier,
4342
+ aliasModuleRecord,
4343
+ pendingJobs,
4344
+ moduleLoads,
4345
+ errors,
4346
+ importMeta);
4347
+
4348
+ mapSet(moduleRecords, moduleSpecifier, aliasRecord);
4349
+ return aliasRecord;
4350
+ }
4351
+
4352
+ // check if this redirect with an explicit compartment
4353
+ if( staticModuleRecord.compartment!== undefined) {
4354
+ // ensure expected record shape
4355
+ if( staticModuleRecord.importMeta!== undefined) {
4356
+ throw new TypeError(
4357
+ 'Cannot redirect to an implicit record with a specified importMeta');
4358
+
4359
+ }
4360
+ // Behold: recursion.
4361
+ // eslint-disable-next-line no-use-before-define
4362
+ const aliasRecord= await memoizedLoadWithErrorAnnotation(
4363
+ compartmentPrivateFields,
4364
+ moduleAliases,
4365
+ staticModuleRecord.compartment,
4366
+ staticModuleRecord.specifier,
4367
+ pendingJobs,
4368
+ moduleLoads,
4369
+ errors);
4370
+
4371
+ mapSet(moduleRecords, moduleSpecifier, aliasRecord);
4372
+ return aliasRecord;
4373
+ }
4374
+
4375
+ throw new TypeError(
4376
+ 'Unnexpected RedirectStaticModuleInterface record shape');
4317
4377
 
4318
- mapSet(moduleRecords, moduleSpecifier, aliasRecord);
4319
- return aliasRecord;
4320
4378
  }
4321
4379
 
4322
4380
  return loadRecord(
@@ -4403,7 +4461,7 @@ const load= async(
4403
4461
 
4404
4462
  /** @type {Set<Promise<undefined>>} */
4405
4463
  const pendingJobs= new Set();
4406
- /** @type {Map<Object, Map<string, Promise<Record>>} */
4464
+ /** @type {Map<object, Map<string, Promise<Record>>} */
4407
4465
  const moduleLoads= new Map();
4408
4466
  /** @type {Array<Error>} */
4409
4467
  const errors= [];
@@ -4759,7 +4817,9 @@ $h‍_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
4759
4817
  __syncModuleProgram__: functorSource,
4760
4818
  __fixedExportMap__: fixedExportMap= {},
4761
4819
  __liveExportMap__: liveExportMap= {},
4762
- __needsImportMeta__: needsImportMeta= false}=
4820
+ __reexportMap__: reexportMap= {},
4821
+ __needsImportMeta__: needsImportMeta= false,
4822
+ __syncModuleFunctor__}=
4763
4823
  staticModuleRecord;
4764
4824
 
4765
4825
  const compartmentFields= weakmapGet(privateFields, compartment);
@@ -5012,26 +5072,35 @@ $h‍_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
5012
5072
  }
5013
5073
  if( arrayIncludes(exportAlls, specifier)) {
5014
5074
  // Make all these imports candidates.
5015
- for( const [importName, importNotify]of entries(importNotifiers)) {
5016
- if( candidateAll[importName]=== undefined) {
5017
- candidateAll[importName]= importNotify;
5075
+ // Note names don't change in reexporting all
5076
+ for( const [importAndExportName, importNotify]of entries(
5077
+ importNotifiers))
5078
+ {
5079
+ if( candidateAll[importAndExportName]=== undefined) {
5080
+ candidateAll[importAndExportName]= importNotify;
5018
5081
  }else {
5019
5082
  // Already a candidate: remove ambiguity.
5020
- candidateAll[importName]= false;
5083
+ candidateAll[importAndExportName]= false;
5021
5084
  }
5022
5085
  }
5023
5086
  }
5087
+ if( reexportMap[specifier]) {
5088
+ // Make named reexports candidates too.
5089
+ for( const [localName, exportedName]of reexportMap[specifier]) {
5090
+ candidateAll[exportedName]= importNotifiers[localName];
5091
+ }
5092
+ }
5024
5093
  }
5025
5094
 
5026
- for( const [importName, notify]of entries(candidateAll)) {
5027
- if( !notifiers[importName]&& notify!== false) {
5028
- notifiers[importName]= notify;
5095
+ for( const [exportName, notify]of entries(candidateAll)) {
5096
+ if( !notifiers[exportName]&& notify!== false) {
5097
+ notifiers[exportName]= notify;
5029
5098
 
5030
5099
  // exported live binding state
5031
5100
  let value;
5032
5101
  const update= (newValue)=> value= newValue;
5033
5102
  notify(update);
5034
- exportsProps[importName]= {
5103
+ exportsProps[exportName]= {
5035
5104
  get() {
5036
5105
  return value;
5037
5106
  },
@@ -5059,11 +5128,16 @@ $h‍_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
5059
5128
  activate();
5060
5129
  }
5061
5130
 
5062
- let optFunctor= compartmentEvaluate(compartmentFields, functorSource, {
5063
- globalObject: compartment.globalThis,
5064
- transforms: __shimTransforms__,
5065
- __moduleShimLexicals__: moduleLexicals});
5131
+ let optFunctor;
5132
+ if( __syncModuleFunctor__!== undefined) {
5133
+ optFunctor= __syncModuleFunctor__;
5134
+ }else {
5135
+ optFunctor= compartmentEvaluate(compartmentFields, functorSource, {
5136
+ globalObject: compartment.globalThis,
5137
+ transforms: __shimTransforms__,
5138
+ __moduleShimLexicals__: moduleLexicals});
5066
5139
 
5140
+ }
5067
5141
  let didThrow= false;
5068
5142
  let thrownError;
5069
5143
  function execute() {
@@ -5223,12 +5297,8 @@ const instantiate= (
5223
5297
  moduleAliases,
5224
5298
  moduleRecord)=>
5225
5299
  {
5226
- const {
5227
- compartment,
5228
- moduleSpecifier,
5229
- resolvedImports,
5230
- staticModuleRecord}=
5231
- moduleRecord;
5300
+ const { compartment, moduleSpecifier, resolvedImports, staticModuleRecord}=
5301
+ moduleRecord;
5232
5302
  const { instances}= weakmapGet(compartmentPrivateFields, compartment);
5233
5303
 
5234
5304
  // Memoize.
@@ -5383,10 +5453,10 @@ const CompartmentPrototype= {
5383
5453
 
5384
5454
  /**
5385
5455
  * @param {string} source is a JavaScript program grammar construction.
5386
- * @param {Object} [options]
5456
+ * @param {object} [options]
5387
5457
  * @param {Array<Transform>} [options.transforms]
5388
5458
  * @param {boolean} [options.sloppyGlobalsMode]
5389
- * @param {Object} [options.__moduleShimLexicals__]
5459
+ * @param {object} [options.__moduleShimLexicals__]
5390
5460
  * @param {boolean} [options.__evadeHtmlCommentTest__]
5391
5461
  * @param {boolean} [options.__evadeImportExpressionTest__]
5392
5462
  * @param {boolean} [options.__rejectSomeDirectEvalExpressions__]
@@ -5467,7 +5537,7 @@ defineProperties(InertCompartment, {
5467
5537
  * @callback MakeCompartmentConstructor
5468
5538
  * @param {MakeCompartmentConstructor} targetMakeCompartmentConstructor
5469
5539
  * @param {Record<string, any>} intrinsics
5470
- * @param {(object: Object) => void} markVirtualizedNativeFunction
5540
+ * @param {(object: object) => void} markVirtualizedNativeFunction
5471
5541
  * @returns {Compartment['constructor']}
5472
5542
  */
5473
5543
 
@@ -5746,7 +5816,7 @@ const makeIntrinsicsCollector= ()=> {
5746
5816
  * If run before lockdown, the returned intrinsics record will carry the
5747
5817
  * *original* unsafe (feral, untamed) bindings of these global variables.
5748
5818
  *
5749
- * @param {Object} globalObject
5819
+ * @param {object} globalObject
5750
5820
  */$h‍_once.makeIntrinsicsCollector(makeIntrinsicsCollector);
5751
5821
  const getGlobalIntrinsics= (globalObject)=>{
5752
5822
  const { addIntrinsics, finalIntrinsics}= makeIntrinsicsCollector();
@@ -5965,7 +6035,19 @@ const severeEnablements= {
5965
6035
  * include enough of the `TypeArray` methods that here, the `severe`
5966
6036
  * enablements just enable them all.
5967
6037
  */
5968
- '%TypedArrayPrototype%': '*'};$h‍_once.severeEnablements(severeEnablements);
6038
+ '%TypedArrayPrototype%': '*',
6039
+
6040
+ /**
6041
+ * Needed to work with Immer before https://github.com/immerjs/immer/pull/914
6042
+ * is accepted.
6043
+ */
6044
+ '%MapPrototype%': '*',
6045
+
6046
+ /**
6047
+ * Needed to work with Immer before https://github.com/immerjs/immer/pull/914
6048
+ * is accepted.
6049
+ */
6050
+ '%SetPrototype%': '*'};$h‍_once.severeEnablements(severeEnablements);
5969
6051
  })
5970
6052
  ,
5971
6053
  // === functors[25] ===
@@ -6183,7 +6265,7 @@ function enablePropertyOverrides(
6183
6265
 
6184
6266
 
6185
6267
 
6186
- const { details: X, Fail, quote: q}= assert;
6268
+ const { Fail, quote: q}= assert;
6187
6269
 
6188
6270
  /**
6189
6271
  * JavaScript module semantics resists attempts to parameterize a module's
@@ -6233,7 +6315,7 @@ const { details: X, Fail, quote: q}= assert;
6233
6315
  * variables, if they are needed, and a way to catalog the names of all
6234
6316
  * the environment variables that were captured.
6235
6317
  *
6236
- * @param {Object} aGlobal
6318
+ * @param {object} aGlobal
6237
6319
  */
6238
6320
  const makeEnvironmentCaptor= (aGlobal)=>{
6239
6321
  const capturedEnvironmentOptionNames= [];
@@ -6248,19 +6330,13 @@ const makeEnvironmentCaptor= (aGlobal)=>{
6248
6330
  */
6249
6331
  const getEnvironmentOption= (optionName, defaultSetting)=> {
6250
6332
  // eslint-disable-next-line @endo/no-polymorphic-call
6251
- assert.typeof(
6252
- optionName,
6253
- 'string',
6254
- X `Environment option name ${q(optionName)} must be a string.`);
6255
-
6333
+ typeof optionName=== 'string'||
6334
+ Fail `Environment option name ${q(optionName)} must be a string.`;
6256
6335
  // eslint-disable-next-line @endo/no-polymorphic-call
6257
- assert.typeof(
6258
- defaultSetting,
6259
- 'string',
6260
- X `Environment option default setting ${q(
6336
+ typeof defaultSetting=== 'string'||
6337
+ Fail `Environment option default setting ${q(
6261
6338
  defaultSetting)
6262
- } must be a string.`);
6263
-
6339
+ } must be a string.`;
6264
6340
 
6265
6341
  /** @type {string} */
6266
6342
  let setting= defaultSetting;
@@ -6272,15 +6348,12 @@ const makeEnvironmentCaptor= (aGlobal)=>{
6272
6348
  arrayPush(capturedEnvironmentOptionNames, optionName);
6273
6349
  const optionValue= globalEnv[optionName];
6274
6350
  // eslint-disable-next-line @endo/no-polymorphic-call
6275
- assert.typeof(
6276
- optionValue,
6277
- 'string',
6278
- X `Environment option named ${q(
6351
+ typeof optionValue=== 'string'||
6352
+ Fail `Environment option named ${q(
6279
6353
  optionName)
6280
6354
  }, if present, must have a corresponding string value, got ${q(
6281
6355
  optionValue)
6282
- }`);
6283
-
6356
+ }`;
6284
6357
  setting= optionValue;
6285
6358
  }
6286
6359
  }
@@ -6481,12 +6554,8 @@ freeze(ErrorInfo);
6481
6554
 
6482
6555
  /** @type {MakeCausalConsole} */
6483
6556
  const makeCausalConsole= (baseConsole, loggedErrorHandler)=> {
6484
- const {
6485
- getStackString,
6486
- tagError,
6487
- takeMessageLogArgs,
6488
- takeNoteLogArgsArray}=
6489
- loggedErrorHandler;
6557
+ const { getStackString, tagError, takeMessageLogArgs, takeNoteLogArgsArray}=
6558
+ loggedErrorHandler;
6490
6559
 
6491
6560
  /**
6492
6561
  * @param {ReadonlyArray<any>} logArgs
@@ -7575,7 +7644,7 @@ function tameErrorConstructor(
7575
7644
  * Object.getConstructorOf()
7576
7645
  * Helper function to improve readability, similar to Object.getPrototypeOf().
7577
7646
  *
7578
- * @param {Object} obj
7647
+ * @param {object} obj
7579
7648
  */
7580
7649
  function getConstructorOf(obj) {
7581
7650
  return getPrototypeOf(obj).constructor;
@@ -7593,15 +7662,17 @@ function makeArguments() {
7593
7662
  * Get the intrinsics not otherwise reachable by named own property
7594
7663
  * traversal from the global object.
7595
7664
  *
7596
- * @returns {Object}
7665
+ * @returns {object}
7597
7666
  */
7598
7667
  const getAnonymousIntrinsics= ()=> {
7599
7668
  const InertFunction= FERAL_FUNCTION.prototype.constructor;
7600
7669
 
7601
7670
  // 9.2.4.1 %ThrowTypeError%
7602
7671
 
7603
- const ThrowTypeError= getOwnPropertyDescriptor(makeArguments(), 'callee').
7604
- get;
7672
+ const ThrowTypeError= getOwnPropertyDescriptor(
7673
+ makeArguments(),
7674
+ 'callee').
7675
+ get;
7605
7676
 
7606
7677
  // 21.1.5.2 The %StringIteratorPrototype% Object
7607
7678
 
@@ -7748,7 +7819,7 @@ const getAnonymousIntrinsics= ()=> {
7748
7819
 
7749
7820
 
7750
7821
  /**
7751
- * @typedef {import('../index.js').Harden} Harden
7822
+ * @typedef {import('../types.js').Harden} Harden
7752
7823
  */
7753
7824
 
7754
7825
  // Obtain the string tag accessor of of TypedArray so we can indirectly use the
@@ -8082,6 +8153,7 @@ function tameDomains(domainTaming= 'safe') {
8082
8153
  if( domainDescriptor!== undefined&& domainDescriptor.get!== undefined) {
8083
8154
  // The domain descriptor on Node.js initially has value: null, which
8084
8155
  // becomes a get, set pair after domains initialize.
8156
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_DOMAINS.md
8085
8157
  throw new TypeError(
8086
8158
  `SES failed to lockdown, Node.js domains have been initialized (SES_NO_DOMAINS)`);
8087
8159
 
@@ -8103,7 +8175,8 @@ function tameDomains(domainTaming= 'safe') {
8103
8175
  })
8104
8176
  ,
8105
8177
  // === functors[36] ===
8106
- (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => { let FERAL_FUNCTION,SyntaxError,TypeError,defineProperties,getPrototypeOf,setPrototypeOf;$h‍_imports([["./commons.js", [["FERAL_FUNCTION", [$h‍_a => (FERAL_FUNCTION = $h‍_a)]],["SyntaxError", [$h‍_a => (SyntaxError = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["defineProperties", [$h‍_a => (defineProperties = $h‍_a)]],["getPrototypeOf", [$h‍_a => (getPrototypeOf = $h‍_a)]],["setPrototypeOf", [$h‍_a => (setPrototypeOf = $h‍_a)]]]]]);
8178
+ (({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => { let FERAL_FUNCTION,SyntaxError,TypeError,defineProperties,getPrototypeOf,setPrototypeOf,freeze;$h‍_imports([["./commons.js", [["FERAL_FUNCTION", [$h‍_a => (FERAL_FUNCTION = $h‍_a)]],["SyntaxError", [$h‍_a => (SyntaxError = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["defineProperties", [$h‍_a => (defineProperties = $h‍_a)]],["getPrototypeOf", [$h‍_a => (getPrototypeOf = $h‍_a)]],["setPrototypeOf", [$h‍_a => (setPrototypeOf = $h‍_a)]],["freeze", [$h‍_a => (freeze = $h‍_a)]]]]]);
8179
+
8107
8180
 
8108
8181
 
8109
8182
 
@@ -8154,7 +8227,7 @@ function tameFunctionConstructors() {
8154
8227
  FERAL_FUNCTION.prototype.constructor('return 1');
8155
8228
  }catch( ignore) {
8156
8229
  // Throws, no need to patch.
8157
- return harden({});
8230
+ return freeze({});
8158
8231
  }
8159
8232
 
8160
8233
  const newIntrinsics= {};
@@ -8187,7 +8260,7 @@ function tameFunctionConstructors() {
8187
8260
  // Prevents the evaluation of source when calling constructor on the
8188
8261
  // prototype of functions.
8189
8262
  // eslint-disable-next-line func-names
8190
- const InertConstructor= function() {
8263
+ const InertConstructor= function() {
8191
8264
  throw new TypeError(
8192
8265
  'Function.prototype.constructor is not a valid constructor.');
8193
8266
 
@@ -8313,14 +8386,14 @@ const localePattern= /^(\w*[a-z])Locale([A-Z]\w*)$/;
8313
8386
  // behavior or `.prototype` property.
8314
8387
  const tamedMethods= {
8315
8388
  // See https://tc39.es/ecma262/#sec-string.prototype.localecompare
8316
- localeCompare(that) {
8389
+ localeCompare(arg) {
8317
8390
  if( this=== null|| this=== undefined) {
8318
8391
  throw new TypeError(
8319
8392
  'Cannot localeCompare with null or undefined "this" value');
8320
8393
 
8321
8394
  }
8322
8395
  const s= `${this}`;
8323
- that= `${that}`;
8396
+ const that= `${arg}`;
8324
8397
  if( s< that) {
8325
8398
  return -1;
8326
8399
  }
@@ -8393,9 +8466,8 @@ function tameMathObject(mathTaming= 'safe') {
8393
8466
  const originalMath= Math;
8394
8467
  const initialMath= originalMath; // to follow the naming pattern
8395
8468
 
8396
- const { random: _, ...otherDescriptors}= getOwnPropertyDescriptors(
8397
- originalMath);
8398
-
8469
+ const { random: _, ...otherDescriptors}=
8470
+ getOwnPropertyDescriptors(originalMath);
8399
8471
 
8400
8472
  const sharedMath= create(objectPrototype, otherDescriptors);
8401
8473
 
@@ -8530,8 +8602,8 @@ function tameRegExpConstructor(regExpTaming= 'safe') {
8530
8602
  * Removes all non-allowed properties found by recursively and
8531
8603
  * reflectively walking own property chains.
8532
8604
  *
8533
- * @param {Object} intrinsics
8534
- * @param {(Object) => void} markVirtualizedNativeFunction
8605
+ * @param {object} intrinsics
8606
+ * @param {(object) => void} markVirtualizedNativeFunction
8535
8607
  */
8536
8608
  function whitelistIntrinsics(
8537
8609
  intrinsics,
@@ -8832,7 +8904,7 @@ function whitelistIntrinsics(
8832
8904
 
8833
8905
 
8834
8906
 
8835
- /** @typedef {import('../index.js').LockdownOptions} LockdownOptions */
8907
+ /** @typedef {import('../types.js').LockdownOptions} LockdownOptions */
8836
8908
 
8837
8909
  const { Fail, details: d, quote: q}= assert;
8838
8910
 
@@ -8856,9 +8928,9 @@ const harden= makeHardener();
8856
8928
 
8857
8929
  /**
8858
8930
  * @callback CompartmentConstructor
8859
- * @param {Object} endowments
8860
- * @param {Object} moduleMap
8861
- * @param {Object} [options]
8931
+ * @param {object} endowments
8932
+ * @param {object} moduleMap
8933
+ * @param {object} [options]
8862
8934
  * @param {Array<Transform>} [options.transforms]
8863
8935
  * @param {Array<Transform>} [options.__shimTransforms__]
8864
8936
  */
@@ -8894,6 +8966,7 @@ const assertDirectEvalAvailable= ()=> {
8894
8966
  allowed= true;
8895
8967
  }
8896
8968
  if( !allowed) {
8969
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_DIRECT_EVAL.md
8897
8970
  throw new TypeError(
8898
8971
  `SES cannot initialize unless 'eval' is the original intrinsic 'eval', suitable for direct-eval (dynamically scoped eval) (SES_DIRECT_EVAL)`);
8899
8972
 
@@ -8930,10 +9003,8 @@ const repairIntrinsics= (options= {})=> {
8930
9003
  // [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/lockdown-options.md#stackfiltering-options)
8931
9004
  // for an explanation.
8932
9005
 
8933
- const {
8934
- getEnvironmentOption: getenv,
8935
- getCapturedEnvironmentOptionNames}=
8936
- makeEnvironmentCaptor(globalThis);
9006
+ const { getEnvironmentOption: getenv, getCapturedEnvironmentOptionNames}=
9007
+ makeEnvironmentCaptor(globalThis);
8937
9008
 
8938
9009
  const {
8939
9010
  errorTaming= getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
@@ -8987,6 +9058,7 @@ const repairIntrinsics= (options= {})=> {
8987
9058
  d `Already locked down at ${priorLockdown} (SES_ALREADY_LOCKED_DOWN)`,
8988
9059
  TypeError);
8989
9060
 
9061
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_ALREADY_LOCKED_DOWN.md
8990
9062
  priorLockdown= new TypeError('Prior lockdown (SES_ALREADY_LOCKED_DOWN)');
8991
9063
  // Tease V8 to generate the stack string and release the closures the stack
8992
9064
  // trace retained:
@@ -9028,6 +9100,7 @@ const repairIntrinsics= (options= {})=> {
9028
9100
  };
9029
9101
 
9030
9102
  if( seemsToBeLockedDown()) {
9103
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_MULTIPLE_INSTANCES.md
9031
9104
  throw new TypeError(
9032
9105
  `Already locked down but not by this SES instance (SES_MULTIPLE_INSTANCES)`);
9033
9106
 
@@ -9039,11 +9112,8 @@ const repairIntrinsics= (options= {})=> {
9039
9112
 
9040
9113
  tameDomains(domainTaming);
9041
9114
 
9042
- const {
9043
- addIntrinsics,
9044
- completePrototypes,
9045
- finalIntrinsics}=
9046
- makeIntrinsicsCollector();
9115
+ const { addIntrinsics, completePrototypes, finalIntrinsics}=
9116
+ makeIntrinsicsCollector();
9047
9117
 
9048
9118
  addIntrinsics({ harden});
9049
9119
 
@@ -9215,6 +9285,7 @@ function getThis() {
9215
9285
  }
9216
9286
 
9217
9287
  if( getThis()) {
9288
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_SLOPPY.md
9218
9289
  throw new TypeError( `SES failed to initialize, sloppy mode (SES_NO_SLOPPY)`);
9219
9290
  }
9220
9291
 
@@ -9234,23 +9305,25 @@ assign(globalThis, {
9234
9305
  ,
9235
9306
  ]; // functors end
9236
9307
 
9237
- function cell(name, value = undefined) {
9308
+ const cell = (name, value = undefined) => {
9238
9309
  const observers = [];
9239
- function set(newValue) {
9240
- value = newValue;
9241
- for (const observe of observers) {
9310
+ return Object.freeze({
9311
+ get: Object.freeze(() => {
9312
+ return value;
9313
+ }),
9314
+ set: Object.freeze((newValue) => {
9315
+ value = newValue;
9316
+ for (const observe of observers) {
9317
+ observe(value);
9318
+ }
9319
+ }),
9320
+ observe: Object.freeze((observe) => {
9321
+ observers.push(observe);
9242
9322
  observe(value);
9243
- }
9244
- }
9245
- function get() {
9246
- return value;
9247
- }
9248
- function observe(observe) {
9249
- observers.push(observe);
9250
- observe(value);
9251
- }
9252
- return { get, set, observe, enumerable: true };
9253
- }
9323
+ }),
9324
+ enumerable: true,
9325
+ });
9326
+ };
9254
9327
 
9255
9328
  const cells = [
9256
9329
  {
@@ -9428,6 +9501,7 @@ assign(globalThis, {
9428
9501
  rejectSomeDirectEvalExpressions: cell("rejectSomeDirectEvalExpressions"),
9429
9502
  mandatoryTransforms: cell("mandatoryTransforms"),
9430
9503
  applyTransforms: cell("applyTransforms"),
9504
+ transforms: cell("transforms"),
9431
9505
  },
9432
9506
  {
9433
9507
  makeSafeEvaluator: cell("makeSafeEvaluator"),
@@ -9555,23 +9629,24 @@ assign(globalThis, {
9555
9629
  ];
9556
9630
 
9557
9631
 
9558
- const namespaces = cells.map(cells => Object.create(null, cells));
9632
+ const namespaces = cells.map(cells => Object.freeze(Object.create(null, cells)));
9559
9633
 
9560
9634
  for (let index = 0; index < namespaces.length; index += 1) {
9561
9635
  cells[index]['*'] = cell('*', namespaces[index]);
9562
9636
  }
9563
9637
 
9564
- function observeImports(map, importName, importIndex) {
9565
- for (const [name, observers] of map.get(importName)) {
9566
- const cell = cells[importIndex][name];
9567
- if (cell === undefined) {
9568
- throw new ReferenceError(`Cannot import name ${name}`);
9569
- }
9570
- for (const observer of observers) {
9571
- cell.observe(observer);
9572
- }
9638
+ function observeImports(map, importName, importIndex) {
9639
+ for (const [name, observers] of map.get(importName)) {
9640
+ const cell = cells[importIndex][name];
9641
+ if (cell === undefined) {
9642
+ throw new ReferenceError(`Cannot import name ${name}`);
9643
+ }
9644
+ for (const observer of observers) {
9645
+ cell.observe(observer);
9573
9646
  }
9574
9647
  }
9648
+ }
9649
+
9575
9650
 
9576
9651
  functors[0]({
9577
9652
  imports(entries) {
@@ -9859,6 +9934,7 @@ assign(globalThis, {
9859
9934
  rejectSomeDirectEvalExpressions: cells[11].rejectSomeDirectEvalExpressions.set,
9860
9935
  mandatoryTransforms: cells[11].mandatoryTransforms.set,
9861
9936
  applyTransforms: cells[11].applyTransforms.set,
9937
+ transforms: cells[11].transforms.set,
9862
9938
  },
9863
9939
  importMeta: {},
9864
9940
  });