ses 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ses.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // ses@1.4.0
1
+ // ses@1.5.0
2
2
  'use strict';
3
3
  (() => {
4
4
  const functors = [
@@ -138,6 +138,10 @@ const { prototype: weakmapPrototype}= WeakMap;$h‍_once.weakmapPrototy
138
138
  const { prototype: weaksetPrototype}= WeakSet;$h‍_once.weaksetPrototype(weaksetPrototype);
139
139
  const { prototype: functionPrototype}= Function;$h‍_once.functionPrototype(functionPrototype);
140
140
  const { prototype: promisePrototype}= Promise;$h‍_once.promisePrototype(promisePrototype);
141
+ const { prototype: generatorPrototype}= getPrototypeOf(
142
+ // eslint-disable-next-line no-empty-function, func-names
143
+ function*() { });$h‍_once.generatorPrototype(generatorPrototype);
144
+
141
145
 
142
146
  const typedArrayPrototype= getPrototypeOf(Uint8Array.prototype);$h‍_once.typedArrayPrototype(typedArrayPrototype);
143
147
 
@@ -195,13 +199,16 @@ const matchAllRegExp= uncurryThis(regexpPrototype[matchAllSymbol]);
195
199
  $h‍_once.matchAllRegExp(matchAllRegExp);const stringEndsWith=uncurryThis(stringPrototype.endsWith);$h‍_once.stringEndsWith(stringEndsWith);
196
200
  const stringIncludes= uncurryThis(stringPrototype.includes);$h‍_once.stringIncludes(stringIncludes);
197
201
  const stringIndexOf= uncurryThis(stringPrototype.indexOf);$h‍_once.stringIndexOf(stringIndexOf);
198
- const stringMatch= uncurryThis(stringPrototype.match);
202
+ const stringMatch= uncurryThis(stringPrototype.match);$h‍_once.stringMatch(stringMatch);
203
+ const generatorNext= uncurryThis(generatorPrototype.next);$h‍_once.generatorNext(generatorNext);
204
+ const generatorThrow= uncurryThis(generatorPrototype.throw);
205
+
199
206
  /**
200
207
  * @type { &
201
208
  * ((thisArg: string, searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string) => string) &
202
209
  * ((thisArg: string, searchValue: { [Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string; }, replacer: (substring: string, ...args: any[]) => string) => string)
203
210
  * }
204
- */$h‍_once.stringMatch(stringMatch);
211
+ */$h‍_once.generatorThrow(generatorThrow);
205
212
  const stringReplace= /** @type {any} */
206
213
  uncurryThis(stringPrototype.replace);$h‍_once.stringReplace(stringReplace);
207
214
 
@@ -221,9 +228,10 @@ const weakmapSet= uncurryThis(weakmapPrototype.set);
221
228
  $h‍_once.weakmapSet(weakmapSet);const weaksetAdd=uncurryThis(weaksetPrototype.add);$h‍_once.weaksetAdd(weaksetAdd);
222
229
  const weaksetHas= uncurryThis(weaksetPrototype.has);
223
230
  //
224
- $h‍_once.weaksetHas(weaksetHas);const functionToString=uncurryThis(functionPrototype.toString);
231
+ $h‍_once.weaksetHas(weaksetHas);const functionToString=uncurryThis(functionPrototype.toString);$h‍_once.functionToString(functionToString);
232
+ const functionBind= uncurryThis(bind);
225
233
  //
226
- $h‍_once.functionToString(functionToString);const{all}=Promise;
234
+ $h‍_once.functionBind(functionBind);const{all}=Promise;
227
235
  const promiseAll= (promises)=>apply(all, Promise, [promises]);$h‍_once.promiseAll(promiseAll);
228
236
  const promiseCatch= uncurryThis(promisePrototype.catch);
229
237
  /** @type {<T, TResult1 = T, TResult2 = never>(thisArg: T, onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null) => Promise<TResult1 | TResult2>} */$h‍_once.promiseCatch(promiseCatch);
@@ -298,7 +306,65 @@ $h‍_once.FERAL_EVAL(FERAL_EVAL);const FERAL_FUNCTION=Function;$h‍_once.FERAL
298
306
  const noEvalEvaluate= ()=> {
299
307
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_EVAL.md
300
308
  throw TypeError('Cannot eval with evalTaming set to "noEval" (SES_NO_EVAL)');
301
- };$h‍_once.noEvalEvaluate(noEvalEvaluate);
309
+ };
310
+
311
+ // ////////////////// FERAL_STACK_GETTER FERAL_STACK_SETTER ////////////////////
312
+ $h‍_once.noEvalEvaluate(noEvalEvaluate);
313
+ const er1StackDesc= getOwnPropertyDescriptor(Error('er1'), 'stack');
314
+ const er2StackDesc= getOwnPropertyDescriptor(TypeError('er2'), 'stack');
315
+
316
+ let feralStackGetter;
317
+ let feralStackSetter;
318
+ if( er1StackDesc&& er2StackDesc&& er1StackDesc.get) {
319
+ // We should only encounter this case on v8 because of its problematic
320
+ // error own stack accessor behavior.
321
+ // Note that FF/SpiderMonkey, Moddable/XS, and the error stack proposal
322
+ // all inherit a stack accessor property from Error.prototype, which is
323
+ // great. That case needs no heroics to secure.
324
+ if(
325
+ // In the v8 case as we understand it, all errors have an own stack
326
+ // accessor property, but within the same realm, all these accessor
327
+ // properties have the same getter and have the same setter.
328
+ // This is therefore the case that we repair.
329
+ typeof er1StackDesc.get=== 'function'&&
330
+ er1StackDesc.get=== er2StackDesc.get&&
331
+ typeof er1StackDesc.set=== 'function'&&
332
+ er1StackDesc.set=== er2StackDesc.set)
333
+ {
334
+ // Otherwise, we have own stack accessor properties that are outside
335
+ // our expectations, that therefore need to be understood better
336
+ // before we know how to repair them.
337
+ feralStackGetter= freeze(er1StackDesc.get);
338
+ feralStackSetter= freeze(er1StackDesc.set);
339
+ }else {
340
+ // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_UNEXPECTED_ERROR_OWN_STACK_ACCESSOR.md
341
+ throw TypeError(
342
+ 'Unexpected Error own stack accessor functions (SES_UNEXPECTED_ERROR_OWN_STACK_ACCESSOR)');
343
+
344
+ }
345
+ }
346
+
347
+ /**
348
+ * If on a v8 with the problematic error own stack accessor behavior,
349
+ * `FERAL_STACK_GETTER` will be the shared getter of all those accessors
350
+ * and `FERAL_STACK_SETTER` will be the shared setter. On any platform
351
+ * without this problem, `FERAL_STACK_GETTER` and `FERAL_STACK_SETTER` are
352
+ * both `undefined`.
353
+ *
354
+ * @type {(() => any) | undefined}
355
+ */
356
+ const FERAL_STACK_GETTER= feralStackGetter;
357
+
358
+ /**
359
+ * If on a v8 with the problematic error own stack accessor behavior,
360
+ * `FERAL_STACK_GETTER` will be the shared getter of all those accessors
361
+ * and `FERAL_STACK_SETTER` will be the shared setter. On any platform
362
+ * without this problem, `FERAL_STACK_GETTER` and `FERAL_STACK_SETTER` are
363
+ * both `undefined`.
364
+ *
365
+ * @type {((newValue: any) => void) | undefined}
366
+ */$h‍_once.FERAL_STACK_GETTER(FERAL_STACK_GETTER);
367
+ const FERAL_STACK_SETTER= feralStackSetter;$h‍_once.FERAL_STACK_SETTER(FERAL_STACK_SETTER);
302
368
  })()
303
369
  ,
304
370
  // === functors[1] ===
@@ -482,6 +548,8 @@ const {
482
548
 
483
549
 
484
550
 
551
+
552
+ /** @import {StringablePayload} from '../../types.js' */
485
553
 
486
554
  /**
487
555
  * Joins English terms with commas and an optional conjunction.
@@ -657,371 +725,7 @@ freeze(bestEffortStringify);
657
725
  // === functors[5] ===
658
726
  ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; $h‍_imports([]); // @ts-check
659
727
 
660
- /**
661
- * TypeScript does not treat `AggregateErrorConstructor` as a subtype of
662
- * `ErrorConstructor`, which makes sense because their constructors
663
- * have incompatible signatures. However, we want to parameterize some
664
- * operations by any error constructor, including possible `AggregateError`.
665
- * So we introduce `GenericErrorConstructor` as a common supertype. Any call
666
- * to it to make an instance must therefore first case split on whether the
667
- * constructor is an AggregateErrorConstructor or a normal ErrorConstructor.
668
- *
669
- * @typedef {ErrorConstructor | AggregateErrorConstructor} GenericErrorConstructor
670
- */
671
-
672
- /**
673
- * @callback BaseAssert
674
- * The `assert` function itself.
675
- *
676
- * @param {any} flag The truthy/falsy value
677
- * @param {Details} [optDetails] The details to throw
678
- * @param {GenericErrorConstructor} [errConstructor]
679
- * An optional alternate error constructor to use.
680
- * @param {AssertMakeErrorOptions} [options]
681
- * @returns {asserts flag}
682
- */
683
-
684
- /**
685
- * @typedef {object} AssertMakeErrorOptions
686
- * @property {string} [errorName]
687
- * @property {Error} [cause]
688
- * @property {Error[]} [errors]
689
- * Normally only used when the ErrorConstuctor is `AggregateError`
690
- */
691
-
692
- /**
693
- * @callback AssertMakeError
694
- *
695
- * The `assert.error` method, recording details for the console.
696
- *
697
- * The optional `optDetails` can be a string.
698
- * @param {Details} [optDetails] The details of what was asserted
699
- * @param {GenericErrorConstructor} [errConstructor]
700
- * An optional alternate error constructor to use.
701
- * @param {AssertMakeErrorOptions} [options]
702
- * @returns {Error}
703
- */
704
-
705
- /**
706
- * @callback AssertFail
707
- *
708
- * The `assert.fail` method.
709
- *
710
- * Fail an assertion, recording full details to the console and
711
- * raising an exception with a message in which `details` substitution values
712
- * have been redacted.
713
- *
714
- * The optional `optDetails` can be a string for backwards compatibility
715
- * with the nodejs assertion library.
716
- * @param {Details} [optDetails] The details of what was asserted
717
- * @param {GenericErrorConstructor} [errConstructor]
718
- * An optional alternate error constructor to use.
719
- * @param {AssertMakeErrorOptions} [options]
720
- * @returns {never}
721
- */
722
-
723
- /**
724
- * @callback AssertEqual
725
- * The `assert.equal` method
726
- *
727
- * Assert that two values must be `Object.is`.
728
- * @param {any} actual The value we received
729
- * @param {any} expected What we wanted
730
- * @param {Details} [optDetails] The details to throw
731
- * @param {GenericErrorConstructor} [errConstructor]
732
- * An optional alternate error constructor to use.
733
- * @param {AssertMakeErrorOptions} [options]
734
- * @returns {void}
735
- */
736
-
737
- // Type all the overloads of the assertTypeof function.
738
- // There may eventually be a better way to do this, but
739
- // thems the breaks with Typescript 4.0.
740
- /**
741
- * @callback AssertTypeofBigint
742
- * @param {any} specimen
743
- * @param {'bigint'} typename
744
- * @param {Details} [optDetails]
745
- * @returns {asserts specimen is bigint}
746
- */
747
-
748
- /**
749
- * @callback AssertTypeofBoolean
750
- * @param {any} specimen
751
- * @param {'boolean'} typename
752
- * @param {Details} [optDetails]
753
- * @returns {asserts specimen is boolean}
754
- */
755
-
756
- /**
757
- * @callback AssertTypeofFunction
758
- * @param {any} specimen
759
- * @param {'function'} typename
760
- * @param {Details} [optDetails]
761
- * @returns {asserts specimen is Function}
762
- */
763
-
764
- /**
765
- * @callback AssertTypeofNumber
766
- * @param {any} specimen
767
- * @param {'number'} typename
768
- * @param {Details} [optDetails]
769
- * @returns {asserts specimen is number}
770
- */
771
-
772
- /**
773
- * @callback AssertTypeofObject
774
- * @param {any} specimen
775
- * @param {'object'} typename
776
- * @param {Details} [optDetails]
777
- * @returns {asserts specimen is Record<any, any> | null}
778
- */
779
-
780
- /**
781
- * @callback AssertTypeofString
782
- * @param {any} specimen
783
- * @param {'string'} typename
784
- * @param {Details} [optDetails]
785
- * @returns {asserts specimen is string}
786
- */
787
-
788
- /**
789
- * @callback AssertTypeofSymbol
790
- * @param {any} specimen
791
- * @param {'symbol'} typename
792
- * @param {Details} [optDetails]
793
- * @returns {asserts specimen is symbol}
794
- */
795
-
796
- /**
797
- * @callback AssertTypeofUndefined
798
- * @param {any} specimen
799
- * @param {'undefined'} typename
800
- * @param {Details} [optDetails]
801
- * @returns {asserts specimen is undefined}
802
- */
803
-
804
- /**
805
- * The `assert.typeof` method
806
- *
807
- * @typedef {AssertTypeofBigint & AssertTypeofBoolean & AssertTypeofFunction & AssertTypeofNumber & AssertTypeofObject & AssertTypeofString & AssertTypeofSymbol & AssertTypeofUndefined} AssertTypeof
808
- */
809
-
810
- /**
811
- * @callback AssertString
812
- * The `assert.string` method.
813
- *
814
- * `assert.string(v)` is equivalent to `assert.typeof(v, 'string')`. We
815
- * special case this one because it is the most frequently used.
816
- *
817
- * Assert an expected typeof result.
818
- * @param {any} specimen The value to get the typeof
819
- * @param {Details} [optDetails] The details to throw
820
- * @returns {asserts specimen is string}
821
- */
822
-
823
- /**
824
- * @callback AssertNote
825
- * The `assert.note` method.
826
- *
827
- * Annotate an error with details, potentially to be used by an
828
- * augmented console such as the causal console of `console.js`, to
829
- * provide extra information associated with logged errors.
830
- *
831
- * @param {Error} error
832
- * @param {Details} detailsNote
833
- * @returns {void}
834
- */
835
-
836
- // /////////////////////////////////////////////////////////////////////////////
837
-
838
- /**
839
- * @typedef {{}} DetailsToken
840
- * A call to the `details` template literal makes and returns a fresh details
841
- * token, which is a frozen empty object associated with the arguments of that
842
- * `details` template literal expression.
843
- */
844
-
845
- /**
846
- * @typedef {string | DetailsToken} Details
847
- * Either a plain string, or made by the `details` template literal tag.
848
- */
849
-
850
- /**
851
- * @typedef {object} StringablePayload
852
- * Holds the payload passed to quote so that its printed form is visible.
853
- * @property {() => string} toString How to print the payload
854
- */
855
-
856
- /**
857
- * To "declassify" and quote a substitution value used in a
858
- * ``` details`...` ``` template literal, enclose that substitution expression
859
- * in a call to `quote`. This makes the value appear quoted
860
- * (as if with `JSON.stringify`) in the message of the thrown error. The
861
- * payload itself is still passed unquoted to the console as it would be
862
- * without `quote`.
863
- *
864
- * For example, the following will reveal the expected sky color, but not the
865
- * actual incorrect sky color, in the thrown error's message:
866
- * ```js
867
- * sky.color === expectedColor || Fail`${sky.color} should be ${quote(expectedColor)}`;
868
- * ```
869
- *
870
- * // TODO Update SES-shim to new convention, where `details` is
871
- * // renamed to `X` rather than `d`.
872
- * The normal convention is to locally rename `details` to `d` and `quote` to `q`
873
- * like `const { details: d, quote: q } = assert;`, so the above example would then be
874
- * ```js
875
- * sky.color === expectedColor || Fail`${sky.color} should be ${q(expectedColor)}`;
876
- * ```
877
- *
878
- * @callback AssertQuote
879
- * @param {any} payload What to declassify
880
- * @param {(string|number)} [spaces]
881
- * @returns {StringablePayload} The declassified payload
882
- */
883
-
884
- /**
885
- * @callback Raise
886
- *
887
- * To make an `assert` which terminates some larger unit of computation
888
- * like a transaction, vat, or process, call `makeAssert` with a `Raise`
889
- * callback, where that callback actually performs that larger termination.
890
- * If possible, the callback should also report its `reason` parameter as
891
- * the alleged reason for the termination.
892
- *
893
- * @param {Error} reason
894
- */
895
-
896
- /**
897
- * @callback MakeAssert
898
- *
899
- * Makes and returns an `assert` function object that shares the bookkeeping
900
- * state defined by this module with other `assert` function objects made by
901
- * `makeAssert`. This state is per-module-instance and is exposed by the
902
- * `loggedErrorHandler` above. We refer to `assert` as a "function object"
903
- * because it can be called directly as a function, but also has methods that
904
- * can be called.
905
- *
906
- * If `optRaise` is provided, the returned `assert` function object will call
907
- * `optRaise(reason)` before throwing the error. This enables `optRaise` to
908
- * engage in even more violent termination behavior, like terminating the vat,
909
- * that prevents execution from reaching the following throw. However, if
910
- * `optRaise` returns normally, which would be unusual, the throw following
911
- * `optRaise(reason)` would still happen.
912
- *
913
- * @param {Raise} [optRaise]
914
- * @param {boolean} [unredacted]
915
- * @returns {Assert}
916
- */
917
-
918
- /**
919
- * @typedef {(template: TemplateStringsArray | string[], ...args: any) => DetailsToken} DetailsTag
920
- *
921
- * Use the `details` function as a template literal tag to create
922
- * informative error messages. The assertion functions take such messages
923
- * as optional arguments:
924
- * ```js
925
- * assert(sky.isBlue(), details`${sky.color} should be "blue"`);
926
- * ```
927
- * // TODO Update SES-shim to new convention, where `details` is
928
- * // renamed to `X` rather than `d`.
929
- * or following the normal convention to locally rename `details` to `d`
930
- * and `quote` to `q` like `const { details: d, quote: q } = assert;`:
931
- * ```js
932
- * assert(sky.isBlue(), d`${sky.color} should be "blue"`);
933
- * ```
934
- * However, note that in most cases it is preferable to instead use the `Fail`
935
- * template literal tag (which has the same input signature as `details`
936
- * but automatically creates and throws an error):
937
- * ```js
938
- * sky.isBlue() || Fail`${sky.color} should be "blue"`;
939
- * ```
940
- *
941
- * The details template tag returns a `DetailsToken` object that can print
942
- * itself with the formatted message in two ways.
943
- * It will report full details to the console, but
944
- * mask embedded substitution values with their typeof information in the thrown error
945
- * to prevent revealing secrets up the exceptional path. In the example
946
- * above, the thrown error may reveal only that `sky.color` is a string,
947
- * whereas the same diagnostic printed to the console reveals that the
948
- * sky was green. This masking can be disabled for an individual substitution value
949
- * using `quote`.
950
- *
951
- * The `raw` property of an input template array is ignored, so a simple
952
- * array of strings may be provided directly.
953
- */
954
-
955
- /**
956
- * @typedef {(template: TemplateStringsArray | string[], ...args: any) => never} FailTag
957
- *
958
- * Use the `Fail` function as a template literal tag to efficiently
959
- * create and throw a `details`-style error only when a condition is not satisfied.
960
- * ```js
961
- * condition || Fail`...complaint...`;
962
- * ```
963
- * This avoids the overhead of creating usually-unnecessary errors like
964
- * ```js
965
- * assert(condition, details`...complaint...`);
966
- * ```
967
- * while improving readability over alternatives like
968
- * ```js
969
- * condition || assert.fail(details`...complaint...`);
970
- * ```
971
- *
972
- * However, due to current weakness in TypeScript, static reasoning
973
- * is less powerful with the `||` patterns than with an `assert` call.
974
- * Until/unless https://github.com/microsoft/TypeScript/issues/51426 is fixed,
975
- * for `||`-style assertions where this loss of static reasoning is a problem,
976
- * instead express the assertion as
977
- * ```js
978
- * if (!condition) {
979
- * Fail`...complaint...`;
980
- * }
981
- * ```
982
- * or, if needed,
983
- * ```js
984
- * if (!condition) {
985
- * // `throw` is noop since `Fail` throws, but it improves static analysis
986
- * throw Fail`...complaint...`;
987
- * }
988
- * ```
989
- */
990
-
991
- /**
992
- * assert that expr is truthy, with an optional details to describe
993
- * the assertion. It is a tagged template literal like
994
- * ```js
995
- * assert(expr, details`....`);`
996
- * ```
997
- *
998
- * The literal portions of the template are assumed non-sensitive, as
999
- * are the `typeof` types of the substitution values. These are
1000
- * assembled into the thrown error message. The actual contents of the
1001
- * substitution values are assumed sensitive, to be revealed to
1002
- * the console only. We assume only the virtual platform's owner can read
1003
- * what is written to the console, where the owner is in a privileged
1004
- * position over computation running on that platform.
1005
- *
1006
- * The optional `optDetails` can be a string for backwards compatibility
1007
- * with the nodejs assertion library.
1008
- *
1009
- * @typedef { BaseAssert & {
1010
- * typeof: AssertTypeof,
1011
- * error: AssertMakeError,
1012
- * fail: AssertFail,
1013
- * equal: AssertEqual,
1014
- * string: AssertString,
1015
- * note: AssertNote,
1016
- * details: DetailsTag,
1017
- * Fail: FailTag,
1018
- * quote: AssertQuote,
1019
- * bare: AssertQuote,
1020
- * makeAssert: MakeAssert,
1021
- * } } Assert
1022
- */
1023
-
1024
- // /////////////////////////////////////////////////////////////////////////////
728
+ /** @import {GenericErrorConstructor, AssertMakeErrorOptions, DetailsToken, StringablePayload} from '../../types.js' */
1025
729
 
1026
730
  /**
1027
731
  * @typedef {object} VirtualConsole
@@ -1478,7 +1182,9 @@ freeze(makeNoteLogArgsArrayKit);
1478
1182
  })()
1479
1183
  ,
1480
1184
  // === functors[9] ===
1481
- ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let RangeError,TypeError,WeakMap,arrayJoin,arrayMap,arrayPop,arrayPush,assign,freeze,defineProperty,globalThis,is,isError,regexpTest,stringIndexOf,stringReplace,stringSlice,stringStartsWith,weakmapDelete,weakmapGet,weakmapHas,weakmapSet,AggregateError,an,bestEffortStringify,makeNoteLogArgsArrayKit;$h‍_imports([["../commons.js", [["RangeError", [$h‍_a => (RangeError = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["WeakMap", [$h‍_a => (WeakMap = $h‍_a)]],["arrayJoin", [$h‍_a => (arrayJoin = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]],["arrayPop", [$h‍_a => (arrayPop = $h‍_a)]],["arrayPush", [$h‍_a => (arrayPush = $h‍_a)]],["assign", [$h‍_a => (assign = $h‍_a)]],["freeze", [$h‍_a => (freeze = $h‍_a)]],["defineProperty", [$h‍_a => (defineProperty = $h‍_a)]],["globalThis", [$h‍_a => (globalThis = $h‍_a)]],["is", [$h‍_a => (is = $h‍_a)]],["isError", [$h‍_a => (isError = $h‍_a)]],["regexpTest", [$h‍_a => (regexpTest = $h‍_a)]],["stringIndexOf", [$h‍_a => (stringIndexOf = $h‍_a)]],["stringReplace", [$h‍_a => (stringReplace = $h‍_a)]],["stringSlice", [$h‍_a => (stringSlice = $h‍_a)]],["stringStartsWith", [$h‍_a => (stringStartsWith = $h‍_a)]],["weakmapDelete", [$h‍_a => (weakmapDelete = $h‍_a)]],["weakmapGet", [$h‍_a => (weakmapGet = $h‍_a)]],["weakmapHas", [$h‍_a => (weakmapHas = $h‍_a)]],["weakmapSet", [$h‍_a => (weakmapSet = $h‍_a)]],["AggregateError", [$h‍_a => (AggregateError = $h‍_a)]]]],["./stringify-utils.js", [["an", [$h‍_a => (an = $h‍_a)]],["bestEffortStringify", [$h‍_a => (bestEffortStringify = $h‍_a)]]]],["./types.js", []],["./internal-types.js", []],["./note-log-args.js", [["makeNoteLogArgsArrayKit", [$h‍_a => (makeNoteLogArgsArrayKit = $h‍_a)]]]]]);
1185
+ ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let RangeError,TypeError,WeakMap,arrayJoin,arrayMap,arrayPop,arrayPush,assign,freeze,defineProperty,globalThis,is,isError,regexpTest,stringIndexOf,stringReplace,stringSlice,stringStartsWith,weakmapDelete,weakmapGet,weakmapHas,weakmapSet,AggregateError,getOwnPropertyDescriptors,ownKeys,create,objectPrototype,objectHasOwnProperty,an,bestEffortStringify,makeNoteLogArgsArrayKit;$h‍_imports([["../commons.js", [["RangeError", [$h‍_a => (RangeError = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["WeakMap", [$h‍_a => (WeakMap = $h‍_a)]],["arrayJoin", [$h‍_a => (arrayJoin = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]],["arrayPop", [$h‍_a => (arrayPop = $h‍_a)]],["arrayPush", [$h‍_a => (arrayPush = $h‍_a)]],["assign", [$h‍_a => (assign = $h‍_a)]],["freeze", [$h‍_a => (freeze = $h‍_a)]],["defineProperty", [$h‍_a => (defineProperty = $h‍_a)]],["globalThis", [$h‍_a => (globalThis = $h‍_a)]],["is", [$h‍_a => (is = $h‍_a)]],["isError", [$h‍_a => (isError = $h‍_a)]],["regexpTest", [$h‍_a => (regexpTest = $h‍_a)]],["stringIndexOf", [$h‍_a => (stringIndexOf = $h‍_a)]],["stringReplace", [$h‍_a => (stringReplace = $h‍_a)]],["stringSlice", [$h‍_a => (stringSlice = $h‍_a)]],["stringStartsWith", [$h‍_a => (stringStartsWith = $h‍_a)]],["weakmapDelete", [$h‍_a => (weakmapDelete = $h‍_a)]],["weakmapGet", [$h‍_a => (weakmapGet = $h‍_a)]],["weakmapHas", [$h‍_a => (weakmapHas = $h‍_a)]],["weakmapSet", [$h‍_a => (weakmapSet = $h‍_a)]],["AggregateError", [$h‍_a => (AggregateError = $h‍_a)]],["getOwnPropertyDescriptors", [$h‍_a => (getOwnPropertyDescriptors = $h‍_a)]],["ownKeys", [$h‍_a => (ownKeys = $h‍_a)]],["create", [$h‍_a => (create = $h‍_a)]],["objectPrototype", [$h‍_a => (objectPrototype = $h‍_a)]],["objectHasOwnProperty", [$h‍_a => (objectHasOwnProperty = $h‍_a)]]]],["./stringify-utils.js", [["an", [$h‍_a => (an = $h‍_a)]],["bestEffortStringify", [$h‍_a => (bestEffortStringify = $h‍_a)]]]],["./types.js", []],["./internal-types.js", []],["./note-log-args.js", [["makeNoteLogArgsArrayKit", [$h‍_a => (makeNoteLogArgsArrayKit = $h‍_a)]]]]]);
1186
+
1187
+
1482
1188
 
1483
1189
 
1484
1190
 
@@ -1520,6 +1226,13 @@ freeze(makeNoteLogArgsArrayKit);
1520
1226
 
1521
1227
 
1522
1228
 
1229
+
1230
+
1231
+
1232
+
1233
+ /**
1234
+ * @import {BaseAssert, Assert, AssertionFunctions, AssertionUtilities, StringablePayload, DetailsToken, MakeAssert} from '../../types.js'
1235
+ */
1523
1236
 
1524
1237
  // For our internal debugging purposes, uncomment
1525
1238
  // const internalDebugConsole = console;
@@ -1529,7 +1242,7 @@ freeze(makeNoteLogArgsArrayKit);
1529
1242
  /** @type {WeakMap<StringablePayload, any>} */
1530
1243
  const declassifiers= new WeakMap();
1531
1244
 
1532
- /** @type {AssertQuote} */
1245
+ /** @type {AssertionUtilities['quote']} */
1533
1246
  const quote= (payload, spaces= undefined)=> {
1534
1247
  const result= freeze({
1535
1248
  toString: freeze(()=> bestEffortStringify(payload, spaces))});
@@ -1542,19 +1255,7 @@ freeze(quote);
1542
1255
  const canBeBare= freeze(/^[\w:-]( ?[\w:-])*$/);
1543
1256
 
1544
1257
  /**
1545
- * Embed a string directly into error details without wrapping punctuation.
1546
- * To avoid injection attacks that exploit quoting confusion, this must NEVER
1547
- * be used with data that is possibly attacker-controlled.
1548
- * As a further safeguard, we fall back to quoting any input that is not a
1549
- * string of sufficiently word-like parts separated by isolated spaces (rather
1550
- * than throwing an exception, which could hide the original problem for which
1551
- * explanatory details are being constructed---i.e., ``` assert.details`...` ```
1552
- * should never be the source of a new exception, nor should an attempt to
1553
- * render its output, although we _could_ instead decide to handle the latter
1554
- * by inline replacement similar to that of `bestEffortStringify` for producing
1555
- * rendered messages like `(an object) was tagged "[Unsafe bare string]"`).
1556
- *
1557
- * @type {AssertQuote}
1258
+ * @type {AssertionUtilities['bare']}
1558
1259
  */
1559
1260
  const bare= (payload, spaces= undefined)=> {
1560
1261
  if( typeof payload!== 'string'|| !regexpTest(canBeBare, payload)) {
@@ -1640,7 +1341,7 @@ freeze(DetailsTokenProto.toString);
1640
1341
  * of them should be uses where the template literal has no redacted
1641
1342
  * substitution values. In those cases, the two are equivalent.
1642
1343
  *
1643
- * @type {DetailsTag}
1344
+ * @type {AssertionUtilities['details']}
1644
1345
  */
1645
1346
  const redactedDetails= (template, ...args)=> {
1646
1347
  // Keep in mind that the vast majority of calls to `details` creates
@@ -1649,7 +1350,7 @@ const redactedDetails= (template, ...args)=> {
1649
1350
  // all the work to happen only if needed, for example, if an assertion fails.
1650
1351
  const detailsToken= freeze({ __proto__: DetailsTokenProto});
1651
1352
  weakmapSet(hiddenDetailsMap, detailsToken, { template, args});
1652
- return detailsToken;
1353
+ return (/** @type {DetailsToken} */ /** @type {unknown} */ detailsToken);
1653
1354
  };
1654
1355
  freeze(redactedDetails);
1655
1356
 
@@ -1664,7 +1365,7 @@ freeze(redactedDetails);
1664
1365
  * of safety. `unredactedDetails` also sacrifices the speed of `details`,
1665
1366
  * which is usually fine in debugging and testing.
1666
1367
  *
1667
- * @type {DetailsTag}
1368
+ * @type {AssertionUtilities['details']}
1668
1369
  */
1669
1370
  const unredactedDetails= (template, ...args)=> {
1670
1371
  args= arrayMap(args, (arg)=>
@@ -1735,12 +1436,79 @@ const tagError= (err, optErrorName= err.name)=> {
1735
1436
  };
1736
1437
 
1737
1438
  /**
1738
- * @type {AssertMakeError}
1439
+ * Make reasonable best efforts to make a `Passable` error.
1440
+ * - `sanitizeError` will remove any "extraneous" own properties already added
1441
+ * by the host,
1442
+ * such as `fileName`,`lineNumber` on FireFox or `line` on Safari.
1443
+ * - If any such "extraneous" properties were removed, `sanitizeError` will
1444
+ * annotate
1445
+ * the error with them, so they still appear on the causal console
1446
+ * log output for diagnostic purposes, but not be otherwise visible.
1447
+ * - `sanitizeError` will ensure that any expected properties already
1448
+ * added by the host are data
1449
+ * properties, converting accessor properties to data properties as needed,
1450
+ * such as `stack` on v8 (Chrome, Brave, Edge?)
1451
+ * - `sanitizeError` will freeze the error, preventing any correct engine from
1452
+ * adding or
1453
+ * altering any of the error's own properties `sanitizeError` is done.
1454
+ *
1455
+ * However, `sanitizeError` will not, for example, `harden`
1456
+ * (i.e., deeply freeze)
1457
+ * or ensure that the `cause` or `errors` property satisfy the `Passable`
1458
+ * constraints. The purpose of `sanitizeError` is only to protect against
1459
+ * mischief the host may have already added to the error as created,
1460
+ * not to ensure that the error is actually Passable. For that,
1461
+ * see `toPassableError` in `@endo/pass-style`.
1462
+ *
1463
+ * @param {Error} error
1739
1464
  */
1465
+ const sanitizeError= (error)=>{
1466
+ const descs= getOwnPropertyDescriptors(error);
1467
+ const {
1468
+ name: _nameDesc,
1469
+ message: _messageDesc,
1470
+ errors: _errorsDesc= undefined,
1471
+ cause: _causeDesc= undefined,
1472
+ stack: _stackDesc= undefined,
1473
+ ...restDescs}=
1474
+ descs;
1475
+
1476
+ const restNames= ownKeys(restDescs);
1477
+ if( restNames.length>= 1) {
1478
+ for( const name of restNames) {
1479
+ delete error[name];
1480
+ }
1481
+ const droppedNote= create(objectPrototype, restDescs);
1482
+ // eslint-disable-next-line no-use-before-define
1483
+ note(
1484
+ error,
1485
+ redactedDetails `originally with properties ${quote(droppedNote)}`);
1486
+
1487
+ }
1488
+ for( const name of ownKeys(error)) {
1489
+ // @ts-expect-error TS still confused by symbols as property names
1490
+ const desc= descs[name];
1491
+ if( desc&& objectHasOwnProperty(desc, 'get')) {
1492
+ defineProperty(error, name, {
1493
+ value: error[name] // invoke the getter to convert to data property
1494
+ });
1495
+ }
1496
+ }
1497
+ freeze(error);
1498
+ };
1499
+
1500
+ /**
1501
+ * @type {AssertionUtilities['error']}
1502
+ */$h‍_once.sanitizeError(sanitizeError);
1740
1503
  const makeError= (
1741
1504
  optDetails= redactedDetails `Assert failed`,
1742
1505
  errConstructor= globalThis.Error,
1743
- { errorName= undefined, cause= undefined, errors= undefined}= {})=>
1506
+ {
1507
+ errorName= undefined,
1508
+ cause= undefined,
1509
+ errors= undefined,
1510
+ sanitize= true}=
1511
+ {})=>
1744
1512
  {
1745
1513
  if( typeof optDetails=== 'string') {
1746
1514
  // If it is a string, use it as the literal part of the template so
@@ -1779,6 +1547,9 @@ const makeError= (
1779
1547
  if( errorName!== undefined) {
1780
1548
  tagError(error, errorName);
1781
1549
  }
1550
+ if( sanitize) {
1551
+ sanitizeError(error);
1552
+ }
1782
1553
  // The next line is a particularly fruitful place to put a breakpoint.
1783
1554
  return error;
1784
1555
  };
@@ -1802,7 +1573,7 @@ const { addLogArgs, takeLogArgsArray}= makeNoteLogArgsArrayKit();
1802
1573
  */
1803
1574
  const hiddenNoteCallbackArrays= new WeakMap();
1804
1575
 
1805
- /** @type {AssertNote} */
1576
+ /** @type {AssertionUtilities['note']} */
1806
1577
  const note= (error, detailsNote)=> {
1807
1578
  if( typeof detailsNote=== 'string') {
1808
1579
  // If it is a string, use it as the literal part of the template so
@@ -1883,7 +1654,7 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
1883
1654
  const details= unredacted? unredactedDetails: redactedDetails;
1884
1655
  const assertFailedDetails= details `Check failed`;
1885
1656
 
1886
- /** @type {AssertFail} */
1657
+ /** @type {AssertionFunctions['fail']} */
1887
1658
  const fail= (
1888
1659
  optDetails= assertFailedDetails,
1889
1660
  errConstructor= undefined,
@@ -1891,13 +1662,14 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
1891
1662
  {
1892
1663
  const reason= makeError(optDetails, errConstructor, options);
1893
1664
  if( optRaise!== undefined) {
1665
+ // @ts-ignore returns `never` doesn't mean it isn't callable
1894
1666
  optRaise(reason);
1895
1667
  }
1896
1668
  throw reason;
1897
1669
  };
1898
1670
  freeze(fail);
1899
1671
 
1900
- /** @type {FailTag} */
1672
+ /** @type {AssertionUtilities['Fail']} */
1901
1673
  const Fail= (template, ...args)=> fail(details(template, ...args));
1902
1674
 
1903
1675
  // Don't freeze or export `baseAssert` until we add methods.
@@ -1913,7 +1685,7 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
1913
1685
  flag|| fail(optDetails, errConstructor, options);
1914
1686
  }
1915
1687
 
1916
- /** @type {AssertEqual} */
1688
+ /** @type {AssertionFunctions['equal']} */
1917
1689
  const equal= (
1918
1690
  actual,
1919
1691
  expected,
@@ -1930,7 +1702,7 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
1930
1702
  };
1931
1703
  freeze(equal);
1932
1704
 
1933
- /** @type {AssertTypeof} */
1705
+ /** @type {AssertionFunctions['typeof']} */
1934
1706
  const assertTypeof= (specimen, typename, optDetails)=> {
1935
1707
  // This will safely fall through if typename is not a string,
1936
1708
  // which is what we want.
@@ -1949,7 +1721,7 @@ const makeAssert= (optRaise= undefined, unredacted= false)=> {
1949
1721
  };
1950
1722
  freeze(assertTypeof);
1951
1723
 
1952
- /** @type {AssertString} */
1724
+ /** @type {AssertionFunctions['string']} */
1953
1725
  const assertString= (specimen, optDetails= undefined)=>
1954
1726
  assertTypeof(specimen, 'string', optDetails);
1955
1727
 
@@ -1978,7 +1750,7 @@ const assert= makeAssert();$h‍_once.assert(assert);
1978
1750
  })()
1979
1751
  ,
1980
1752
  // === functors[10] ===
1981
- ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let Set,String,TypeError,WeakMap,WeakSet,globalThis,apply,arrayForEach,defineProperty,freeze,getOwnPropertyDescriptor,getOwnPropertyDescriptors,getPrototypeOf,isInteger,isObject,objectHasOwnProperty,ownKeys,preventExtensions,setAdd,setForEach,setHas,toStringTagSymbol,typedArrayPrototype,weakmapGet,weakmapSet,weaksetAdd,weaksetHas,assert;$h‍_imports([["./commons.js", [["Set", [$h‍_a => (Set = $h‍_a)]],["String", [$h‍_a => (String = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["WeakMap", [$h‍_a => (WeakMap = $h‍_a)]],["WeakSet", [$h‍_a => (WeakSet = $h‍_a)]],["globalThis", [$h‍_a => (globalThis = $h‍_a)]],["apply", [$h‍_a => (apply = $h‍_a)]],["arrayForEach", [$h‍_a => (arrayForEach = $h‍_a)]],["defineProperty", [$h‍_a => (defineProperty = $h‍_a)]],["freeze", [$h‍_a => (freeze = $h‍_a)]],["getOwnPropertyDescriptor", [$h‍_a => (getOwnPropertyDescriptor = $h‍_a)]],["getOwnPropertyDescriptors", [$h‍_a => (getOwnPropertyDescriptors = $h‍_a)]],["getPrototypeOf", [$h‍_a => (getPrototypeOf = $h‍_a)]],["isInteger", [$h‍_a => (isInteger = $h‍_a)]],["isObject", [$h‍_a => (isObject = $h‍_a)]],["objectHasOwnProperty", [$h‍_a => (objectHasOwnProperty = $h‍_a)]],["ownKeys", [$h‍_a => (ownKeys = $h‍_a)]],["preventExtensions", [$h‍_a => (preventExtensions = $h‍_a)]],["setAdd", [$h‍_a => (setAdd = $h‍_a)]],["setForEach", [$h‍_a => (setForEach = $h‍_a)]],["setHas", [$h‍_a => (setHas = $h‍_a)]],["toStringTagSymbol", [$h‍_a => (toStringTagSymbol = $h‍_a)]],["typedArrayPrototype", [$h‍_a => (typedArrayPrototype = $h‍_a)]],["weakmapGet", [$h‍_a => (weakmapGet = $h‍_a)]],["weakmapSet", [$h‍_a => (weakmapSet = $h‍_a)]],["weaksetAdd", [$h‍_a => (weaksetAdd = $h‍_a)]],["weaksetHas", [$h‍_a => (weaksetHas = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]]]);
1753
+ ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let Set,String,TypeError,WeakSet,globalThis,apply,arrayForEach,defineProperty,freeze,getOwnPropertyDescriptor,getOwnPropertyDescriptors,getPrototypeOf,isInteger,isObject,objectHasOwnProperty,ownKeys,preventExtensions,setAdd,setForEach,setHas,toStringTagSymbol,typedArrayPrototype,weaksetAdd,weaksetHas,FERAL_STACK_GETTER,FERAL_STACK_SETTER,isError,assert;$h‍_imports([["./commons.js", [["Set", [$h‍_a => (Set = $h‍_a)]],["String", [$h‍_a => (String = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["WeakSet", [$h‍_a => (WeakSet = $h‍_a)]],["globalThis", [$h‍_a => (globalThis = $h‍_a)]],["apply", [$h‍_a => (apply = $h‍_a)]],["arrayForEach", [$h‍_a => (arrayForEach = $h‍_a)]],["defineProperty", [$h‍_a => (defineProperty = $h‍_a)]],["freeze", [$h‍_a => (freeze = $h‍_a)]],["getOwnPropertyDescriptor", [$h‍_a => (getOwnPropertyDescriptor = $h‍_a)]],["getOwnPropertyDescriptors", [$h‍_a => (getOwnPropertyDescriptors = $h‍_a)]],["getPrototypeOf", [$h‍_a => (getPrototypeOf = $h‍_a)]],["isInteger", [$h‍_a => (isInteger = $h‍_a)]],["isObject", [$h‍_a => (isObject = $h‍_a)]],["objectHasOwnProperty", [$h‍_a => (objectHasOwnProperty = $h‍_a)]],["ownKeys", [$h‍_a => (ownKeys = $h‍_a)]],["preventExtensions", [$h‍_a => (preventExtensions = $h‍_a)]],["setAdd", [$h‍_a => (setAdd = $h‍_a)]],["setForEach", [$h‍_a => (setForEach = $h‍_a)]],["setHas", [$h‍_a => (setHas = $h‍_a)]],["toStringTagSymbol", [$h‍_a => (toStringTagSymbol = $h‍_a)]],["typedArrayPrototype", [$h‍_a => (typedArrayPrototype = $h‍_a)]],["weaksetAdd", [$h‍_a => (weaksetAdd = $h‍_a)]],["weaksetHas", [$h‍_a => (weaksetHas = $h‍_a)]],["FERAL_STACK_GETTER", [$h‍_a => (FERAL_STACK_GETTER = $h‍_a)]],["FERAL_STACK_SETTER", [$h‍_a => (FERAL_STACK_SETTER = $h‍_a)]],["isError", [$h‍_a => (isError = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]]]);
1982
1754
 
1983
1755
 
1984
1756
 
@@ -2033,7 +1805,7 @@ const assert= makeAssert();$h‍_once.assert(assert);
2033
1805
 
2034
1806
 
2035
1807
  /**
2036
- * @typedef {import('../types.js').Harden} Harden
1808
+ * @import {Harden} from '../types.js'
2037
1809
  */
2038
1810
 
2039
1811
  // Obtain the string tag accessor of of TypedArray so we can indirectly use the
@@ -2124,15 +1896,13 @@ const makeHardener= ()=> {
2124
1896
  */
2125
1897
  harden(root) {
2126
1898
  const toFreeze= new Set();
2127
- const paths= new WeakMap();
2128
1899
 
2129
1900
  // If val is something we should be freezing but aren't yet,
2130
1901
  // add it to toFreeze.
2131
1902
  /**
2132
1903
  * @param {any} val
2133
- * @param {string} [path]
2134
1904
  */
2135
- function enqueue(val, path= undefined) {
1905
+ function enqueue(val) {
2136
1906
  if( !isObject(val)) {
2137
1907
  // ignore primitives
2138
1908
  return;
@@ -2148,13 +1918,12 @@ const makeHardener= ()=> {
2148
1918
  }
2149
1919
  // console.warn(`adding ${val} to toFreeze`, val);
2150
1920
  setAdd(toFreeze, val);
2151
- weakmapSet(paths, val, path);
2152
1921
  }
2153
1922
 
2154
1923
  /**
2155
1924
  * @param {any} obj
2156
1925
  */
2157
- function freezeAndTraverse(obj) {
1926
+ const baseFreezeAndTraverse= (obj)=>{
2158
1927
  // Now freeze the object to ensure reactive
2159
1928
  // objects such as proxies won't add properties
2160
1929
  // during traversal, before they get frozen.
@@ -2173,13 +1942,11 @@ const makeHardener= ()=> {
2173
1942
 
2174
1943
  // get stable/immutable outbound links before a Proxy has a chance to do
2175
1944
  // something sneaky.
2176
- const path= weakmapGet(paths, obj)|| 'unknown';
2177
1945
  const descs= getOwnPropertyDescriptors(obj);
2178
1946
  const proto= getPrototypeOf(obj);
2179
- enqueue(proto, `${path}.__proto__`);
1947
+ enqueue(proto);
2180
1948
 
2181
1949
  arrayForEach(ownKeys(descs), (/** @type {string | symbol} */ name)=> {
2182
- const pathname= `${path}.${String(name)}`;
2183
1950
  // The 'name' may be a symbol, and TypeScript doesn't like us to
2184
1951
  // index arbitrary symbols on objects, so we pretend they're just
2185
1952
  // strings.
@@ -2192,27 +1959,60 @@ const makeHardener= ()=> {
2192
1959
  // whether 'value' is present or not, which tells us for sure that
2193
1960
  // this is a data property.
2194
1961
  if( objectHasOwnProperty(desc, 'value')) {
2195
- enqueue(desc.value, `${pathname}`);
1962
+ enqueue(desc.value);
2196
1963
  }else {
2197
- enqueue(desc.get, `${pathname}(get)`);
2198
- enqueue(desc.set, `${pathname}(set)`);
1964
+ enqueue(desc.get);
1965
+ enqueue(desc.set);
2199
1966
  }
2200
1967
  });
2201
- }
1968
+ };
1969
+
1970
+ const freezeAndTraverse=
1971
+ FERAL_STACK_GETTER=== undefined&& FERAL_STACK_SETTER=== undefined?
1972
+ // On platforms without v8's error own stack accessor problem,
1973
+ // don't pay for any extra overhead.
1974
+ baseFreezeAndTraverse:
1975
+ (obj)=>{
1976
+ if( isError(obj)) {
1977
+ // Only pay the overhead if it first passes this cheap isError
1978
+ // check. Otherwise, it will be unrepaired, but won't be judged
1979
+ // to be a passable error anyway, so will not be unsafe.
1980
+ const stackDesc= getOwnPropertyDescriptor(obj, 'stack');
1981
+ if(
1982
+ stackDesc&&
1983
+ stackDesc.get=== FERAL_STACK_GETTER&&
1984
+ stackDesc.configurable)
1985
+ {
1986
+ // Can only repair if it is configurable. Otherwise, leave
1987
+ // unrepaired, in which case it will not be judged passable,
1988
+ // avoiding a safety problem.
1989
+ defineProperty(obj, 'stack', {
1990
+ // NOTE: Calls getter during harden, which seems dangerous.
1991
+ // But we're only calling the problematic getter whose
1992
+ // hazards we think we understand.
1993
+ // @ts-expect-error TS should know FERAL_STACK_GETTER
1994
+ // cannot be `undefined` here.
1995
+ // See https://github.com/endojs/endo/pull/2232#discussion_r1575179471
1996
+ value: apply(FERAL_STACK_GETTER, obj, [])});
1997
+
1998
+ }
1999
+ }
2000
+ return baseFreezeAndTraverse(obj);
2001
+ };
2202
2002
 
2203
- function dequeue() {
2003
+ const dequeue= ()=> {
2204
2004
  // New values added before forEach() has finished will be visited.
2205
2005
  setForEach(toFreeze, freezeAndTraverse);
2206
- }
2006
+ };
2207
2007
 
2208
2008
  /** @param {any} value */
2209
- function markHardened(value) {
2009
+ const markHardened= (value)=>{
2210
2010
  weaksetAdd(hardened, value);
2211
- }
2011
+ };
2212
2012
 
2213
- function commit() {
2013
+ const commit= ()=> {
2214
2014
  setForEach(toFreeze, markHardened);
2215
- }
2015
+ };
2216
2016
 
2217
2017
  enqueue(root);
2218
2018
  dequeue();
@@ -2233,6 +2033,8 @@ const makeHardener= ()=> {
2233
2033
 
2234
2034
 
2235
2035
 
2036
+ /** @import {GenericErrorConstructor} from '../types.js' */
2037
+
2236
2038
  /**
2237
2039
  * @file Exports {@code whitelist}, a recursively defined
2238
2040
  * JSON record enumerating all intrinsics and their properties
@@ -7338,14 +7140,14 @@ const tameConsole= (
7338
7140
  typeof globalThis.console!== 'undefined'?
7339
7141
  globalThis.console:
7340
7142
  typeof globalThis.print=== 'function'?
7341
- // Make a good-enough console for eshost (including only functions that
7342
- // log at a specific level with no special argument interpretation).
7343
- // https://console.spec.whatwg.org/#logging
7344
- ((p)=>freeze({ debug: p, log: p, info: p, warn: p, error: p}))(
7345
- // eslint-disable-next-line no-undef
7346
- wrapLogger(globalThis.print)):
7143
+ // Make a good-enough console for eshost (including only functions that
7144
+ // log at a specific level with no special argument interpretation).
7145
+ // https://console.spec.whatwg.org/#logging
7146
+ ((p)=>freeze({ debug: p, log: p, info: p, warn: p, error: p}))(
7147
+ // eslint-disable-next-line no-undef
7148
+ wrapLogger(globalThis.print)):
7347
7149
 
7348
- undefined;
7150
+ undefined;
7349
7151
 
7350
7152
 
7351
7153
  // Upgrade a log-only console (as in `eshost -h SpiderMonkey`).
@@ -8070,7 +7872,9 @@ function tameErrorConstructor(
8070
7872
  })()
8071
7873
  ,
8072
7874
  // === functors[39] ===
8073
- ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let ReferenceError,TypeError,Map,Set,arrayJoin,arrayMap,arrayPush,create,freeze,mapGet,mapHas,mapSet,setAdd,promiseCatch,promiseThen,values,weakmapGet,assert;$h‍_imports([["./commons.js", [["ReferenceError", [$h‍_a => (ReferenceError = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["Map", [$h‍_a => (Map = $h‍_a)]],["Set", [$h‍_a => (Set = $h‍_a)]],["arrayJoin", [$h‍_a => (arrayJoin = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]],["arrayPush", [$h‍_a => (arrayPush = $h‍_a)]],["create", [$h‍_a => (create = $h‍_a)]],["freeze", [$h‍_a => (freeze = $h‍_a)]],["mapGet", [$h‍_a => (mapGet = $h‍_a)]],["mapHas", [$h‍_a => (mapHas = $h‍_a)]],["mapSet", [$h‍_a => (mapSet = $h‍_a)]],["setAdd", [$h‍_a => (setAdd = $h‍_a)]],["promiseCatch", [$h‍_a => (promiseCatch = $h‍_a)]],["promiseThen", [$h‍_a => (promiseThen = $h‍_a)]],["values", [$h‍_a => (values = $h‍_a)]],["weakmapGet", [$h‍_a => (weakmapGet = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]]]);
7875
+ ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let getenv,ReferenceError,TypeError,Map,Set,arrayJoin,arrayMap,arrayPush,create,freeze,mapGet,mapHas,mapSet,setAdd,promiseThen,values,weakmapGet,generatorNext,generatorThrow,assert;$h‍_imports([["@endo/env-options", [["getEnvironmentOption", [$h‍_a => (getenv = $h‍_a)]]]],["./commons.js", [["ReferenceError", [$h‍_a => (ReferenceError = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["Map", [$h‍_a => (Map = $h‍_a)]],["Set", [$h‍_a => (Set = $h‍_a)]],["arrayJoin", [$h‍_a => (arrayJoin = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]],["arrayPush", [$h‍_a => (arrayPush = $h‍_a)]],["create", [$h‍_a => (create = $h‍_a)]],["freeze", [$h‍_a => (freeze = $h‍_a)]],["mapGet", [$h‍_a => (mapGet = $h‍_a)]],["mapHas", [$h‍_a => (mapHas = $h‍_a)]],["mapSet", [$h‍_a => (mapSet = $h‍_a)]],["setAdd", [$h‍_a => (setAdd = $h‍_a)]],["promiseThen", [$h‍_a => (promiseThen = $h‍_a)]],["values", [$h‍_a => (values = $h‍_a)]],["weakmapGet", [$h‍_a => (weakmapGet = $h‍_a)]],["generatorNext", [$h‍_a => (generatorNext = $h‍_a)]],["generatorThrow", [$h‍_a => (generatorThrow = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]]]);
7876
+
7877
+
8074
7878
 
8075
7879
 
8076
7880
 
@@ -8103,6 +7907,33 @@ const { Fail, details: d, quote: q}= assert;
8103
7907
 
8104
7908
  const noop= ()=> { };
8105
7909
 
7910
+ async function asyncTrampoline(generatorFunc, args, errorWrapper) {
7911
+ const iterator= generatorFunc(...args);
7912
+ let result= generatorNext(iterator);
7913
+ while( !result.done) {
7914
+ try {
7915
+ // eslint-disable-next-line no-await-in-loop
7916
+ const val= await result.value;
7917
+ result= generatorNext(iterator, val);
7918
+ }catch( error) {
7919
+ result= generatorThrow(iterator, errorWrapper(error));
7920
+ }
7921
+ }
7922
+ return result.value;
7923
+ }
7924
+
7925
+ function syncTrampoline(generatorFunc, args) {
7926
+ const iterator= generatorFunc(...args);
7927
+ let result= generatorNext(iterator);
7928
+ while( !result.done) {
7929
+ try {
7930
+ result= generatorNext(iterator, result.value);
7931
+ }catch( error) {
7932
+ result= generatorThrow(iterator, error);
7933
+ }
7934
+ }
7935
+ return result.value;
7936
+ }
8106
7937
  // `makeAlias` constructs compartment specifier tuples for the `aliases`
8107
7938
  // private field of compartments.
8108
7939
  // These aliases allow a compartment to alias an internal module specifier to a
@@ -8132,9 +7963,9 @@ const loadRecord= (
8132
7963
  compartment,
8133
7964
  moduleSpecifier,
8134
7965
  staticModuleRecord,
8135
- pendingJobs,
7966
+ enqueueJob,
7967
+ selectImplementation,
8136
7968
  moduleLoads,
8137
- errors,
8138
7969
  importMeta)=>
8139
7970
  {
8140
7971
  const { resolveHook, moduleRecords}= weakmapGet(
@@ -8160,20 +7991,14 @@ const loadRecord= (
8160
7991
  for( const fullSpecifier of values(resolvedImports)) {
8161
7992
  // Behold: recursion.
8162
7993
  // eslint-disable-next-line no-use-before-define
8163
- const dependencyLoaded= memoizedLoadWithErrorAnnotation(
7994
+ enqueueJob(memoizedLoadWithErrorAnnotation, [
8164
7995
  compartmentPrivateFields,
8165
7996
  moduleAliases,
8166
7997
  compartment,
8167
7998
  fullSpecifier,
8168
- pendingJobs,
8169
- moduleLoads,
8170
- errors);
8171
-
8172
- setAdd(
8173
- pendingJobs,
8174
- promiseThen(dependencyLoaded, noop, (error)=>{
8175
- arrayPush(errors, error);
8176
- }));
7999
+ enqueueJob,
8000
+ selectImplementation,
8001
+ moduleLoads]);
8177
8002
 
8178
8003
  }
8179
8004
 
@@ -8182,19 +8007,17 @@ const loadRecord= (
8182
8007
  return moduleRecord;
8183
8008
  };
8184
8009
 
8185
- const loadWithoutErrorAnnotation= async(
8010
+ function* loadWithoutErrorAnnotation(
8186
8011
  compartmentPrivateFields,
8187
8012
  moduleAliases,
8188
8013
  compartment,
8189
8014
  moduleSpecifier,
8190
- pendingJobs,
8191
- moduleLoads,
8192
- errors)=>
8193
- {
8194
- const { importHook, moduleMap, moduleMapHook, moduleRecords}= weakmapGet(
8195
- compartmentPrivateFields,
8196
- compartment);
8197
-
8015
+ enqueueJob,
8016
+ selectImplementation,
8017
+ moduleLoads)
8018
+ {
8019
+ const { importHook, importNowHook, moduleMap, moduleMapHook, moduleRecords}=
8020
+ weakmapGet(compartmentPrivateFields, compartment);
8198
8021
 
8199
8022
  // Follow moduleMap, or moduleMapHook if present.
8200
8023
  let aliasNamespace= moduleMap[moduleSpecifier];
@@ -8222,14 +8045,14 @@ const loadWithoutErrorAnnotation= async(
8222
8045
  }
8223
8046
  // Behold: recursion.
8224
8047
  // eslint-disable-next-line no-use-before-define
8225
- const aliasRecord= await memoizedLoadWithErrorAnnotation(
8048
+ const aliasRecord= yield memoizedLoadWithErrorAnnotation(
8226
8049
  compartmentPrivateFields,
8227
8050
  moduleAliases,
8228
8051
  alias.compartment,
8229
8052
  alias.specifier,
8230
- pendingJobs,
8231
- moduleLoads,
8232
- errors);
8053
+ enqueueJob,
8054
+ selectImplementation,
8055
+ moduleLoads);
8233
8056
 
8234
8057
  mapSet(moduleRecords, moduleSpecifier, aliasRecord);
8235
8058
  return aliasRecord;
@@ -8239,7 +8062,10 @@ const loadWithoutErrorAnnotation= async(
8239
8062
  return mapGet(moduleRecords, moduleSpecifier);
8240
8063
  }
8241
8064
 
8242
- const staticModuleRecord= await importHook(moduleSpecifier);
8065
+ const staticModuleRecord= yield selectImplementation(
8066
+ importHook,
8067
+ importNowHook)(
8068
+ moduleSpecifier);
8243
8069
 
8244
8070
  if( staticModuleRecord=== null|| typeof staticModuleRecord!== 'object') {
8245
8071
  Fail `importHook must return a promise for an object, for module ${q(
@@ -8270,9 +8096,9 @@ const loadWithoutErrorAnnotation= async(
8270
8096
  aliasCompartment,
8271
8097
  aliasSpecifier,
8272
8098
  aliasModuleRecord,
8273
- pendingJobs,
8099
+ enqueueJob,
8100
+ selectImplementation,
8274
8101
  moduleLoads,
8275
- errors,
8276
8102
  importMeta);
8277
8103
 
8278
8104
  mapSet(moduleRecords, moduleSpecifier, aliasRecord);
@@ -8289,14 +8115,14 @@ const loadWithoutErrorAnnotation= async(
8289
8115
  }
8290
8116
  // Behold: recursion.
8291
8117
  // eslint-disable-next-line no-use-before-define
8292
- const aliasRecord= await memoizedLoadWithErrorAnnotation(
8118
+ const aliasRecord= yield memoizedLoadWithErrorAnnotation(
8293
8119
  compartmentPrivateFields,
8294
8120
  moduleAliases,
8295
8121
  staticModuleRecord.compartment,
8296
8122
  staticModuleRecord.specifier,
8297
- pendingJobs,
8298
- moduleLoads,
8299
- errors);
8123
+ enqueueJob,
8124
+ selectImplementation,
8125
+ moduleLoads);
8300
8126
 
8301
8127
  mapSet(moduleRecords, moduleSpecifier, aliasRecord);
8302
8128
  return aliasRecord;
@@ -8311,20 +8137,20 @@ const loadWithoutErrorAnnotation= async(
8311
8137
  compartment,
8312
8138
  moduleSpecifier,
8313
8139
  staticModuleRecord,
8314
- pendingJobs,
8315
- moduleLoads,
8316
- errors);
8140
+ enqueueJob,
8141
+ selectImplementation,
8142
+ moduleLoads);
8317
8143
 
8318
- };
8144
+ }
8319
8145
 
8320
- const memoizedLoadWithErrorAnnotation= async(
8146
+ const memoizedLoadWithErrorAnnotation= (
8321
8147
  compartmentPrivateFields,
8322
8148
  moduleAliases,
8323
8149
  compartment,
8324
8150
  moduleSpecifier,
8325
- pendingJobs,
8326
- moduleLoads,
8327
- errors)=>
8151
+ enqueueJob,
8152
+ selectImplementation,
8153
+ moduleLoads)=>
8328
8154
  {
8329
8155
  const { name: compartmentName}= weakmapGet(
8330
8156
  compartmentPrivateFields,
@@ -8342,15 +8168,16 @@ const memoizedLoadWithErrorAnnotation= async(
8342
8168
  return moduleLoading;
8343
8169
  }
8344
8170
 
8345
- moduleLoading= promiseCatch(
8346
- loadWithoutErrorAnnotation(
8171
+ moduleLoading= selectImplementation(asyncTrampoline, syncTrampoline)(
8172
+ loadWithoutErrorAnnotation,
8173
+ [
8347
8174
  compartmentPrivateFields,
8348
8175
  moduleAliases,
8349
8176
  compartment,
8350
8177
  moduleSpecifier,
8351
- pendingJobs,
8352
- moduleLoads,
8353
- errors),
8178
+ enqueueJob,
8179
+ selectImplementation,
8180
+ moduleLoads],
8354
8181
 
8355
8182
  (error)=>{
8356
8183
  // eslint-disable-next-line @endo/no-polymorphic-call
@@ -8369,6 +8196,64 @@ const memoizedLoadWithErrorAnnotation= async(
8369
8196
  return moduleLoading;
8370
8197
  };
8371
8198
 
8199
+ function asyncJobQueue() {
8200
+ /** @type {Set<Promise<undefined>>} */
8201
+ const pendingJobs= new Set();
8202
+ /** @type {Array<Error>} */
8203
+ const errors= [];
8204
+
8205
+ /**
8206
+ * Enqueues a job that starts immediately but won't be awaited until drainQueue is called.
8207
+ *
8208
+ * @template {any[]} T
8209
+ * @param {(...args: T)=>Promise<*>} func
8210
+ * @param {T} args
8211
+ */
8212
+ const enqueueJob= (func, args)=> {
8213
+ setAdd(
8214
+ pendingJobs,
8215
+ promiseThen(func(...args), noop, (error)=>{
8216
+ arrayPush(errors, error);
8217
+ }));
8218
+
8219
+ };
8220
+ /**
8221
+ * Sequentially awaits pending jobs and returns an array of errors
8222
+ *
8223
+ * @returns {Promise<Array<Error>>}
8224
+ */
8225
+ const drainQueue= async()=> {
8226
+ for( const job of pendingJobs) {
8227
+ // eslint-disable-next-line no-await-in-loop
8228
+ await job;
8229
+ }
8230
+ return errors;
8231
+ };
8232
+ return { enqueueJob, drainQueue};
8233
+ }
8234
+
8235
+ /**
8236
+ * @param {object} options
8237
+ * @param {Array<Error>} options.errors
8238
+ * @param {string} options.errorPrefix
8239
+ */
8240
+ function throwAggregateError({ errors, errorPrefix}) {
8241
+ // Throw an aggregate error if there were any errors.
8242
+ if( errors.length> 0) {
8243
+ const verbose=
8244
+ getenv('COMPARTMENT_LOAD_ERRORS', '', ['verbose'])=== 'verbose';
8245
+ throw TypeError(
8246
+ `${errorPrefix} (${errors.length} underlying failures: ${arrayJoin(
8247
+ arrayMap(errors, (error)=>error.message+( verbose? error.stack: '')),
8248
+ ', ')
8249
+ }`);
8250
+
8251
+ }
8252
+ }
8253
+
8254
+ const preferSync= (_asyncImpl, syncImpl)=> syncImpl;
8255
+ const preferAsync= (asyncImpl, _syncImpl)=> asyncImpl;
8256
+
8372
8257
  /*
8373
8258
  * `load` asynchronously gathers the `StaticModuleRecord`s for a module and its
8374
8259
  * transitive dependencies.
@@ -8387,50 +8272,81 @@ const load= async(
8387
8272
  compartment);
8388
8273
 
8389
8274
 
8390
- /** @type {Set<Promise<undefined>>} */
8391
- const pendingJobs= new Set();
8392
8275
  /** @type {Map<object, Map<string, Promise<Record<any, any>>>>} */
8393
8276
  const moduleLoads= new Map();
8394
- /** @type {Array<Error>} */
8395
- const errors= [];
8396
8277
 
8397
- const dependencyLoaded= memoizedLoadWithErrorAnnotation(
8278
+ const { enqueueJob, drainQueue}= asyncJobQueue();
8279
+
8280
+ enqueueJob(memoizedLoadWithErrorAnnotation, [
8398
8281
  compartmentPrivateFields,
8399
8282
  moduleAliases,
8400
8283
  compartment,
8401
8284
  moduleSpecifier,
8402
- pendingJobs,
8403
- moduleLoads,
8404
- errors);
8285
+ enqueueJob,
8286
+ preferAsync,
8287
+ moduleLoads]);
8288
+
8289
+
8290
+ // Drain pending jobs queue and throw an aggregate error
8291
+ const errors= await drainQueue();
8292
+
8293
+ throwAggregateError({
8294
+ errors,
8295
+ errorPrefix: `Failed to load module ${q(moduleSpecifier)} in package ${q(
8296
+ compartmentName)
8297
+ }`});
8298
+
8299
+ };
8300
+
8301
+ /*
8302
+ * `loadNow` synchronously gathers the `StaticModuleRecord`s for a module and its
8303
+ * transitive dependencies.
8304
+ * The module records refer to each other by a reference to the dependency's
8305
+ * compartment and the specifier of the module within its own compartment.
8306
+ * This graph is then ready to be synchronously linked and executed.
8307
+ */$h‍_once.load(load);
8308
+ const loadNow= (
8309
+ compartmentPrivateFields,
8310
+ moduleAliases,
8311
+ compartment,
8312
+ moduleSpecifier)=>
8313
+ {
8314
+ const { name: compartmentName}= weakmapGet(
8315
+ compartmentPrivateFields,
8316
+ compartment);
8317
+
8318
+
8319
+ /** @type {Map<object, Map<string, Promise<Record<any, any>>>>} */
8320
+ const moduleLoads= new Map();
8405
8321
 
8406
- setAdd(
8407
- pendingJobs,
8408
- promiseThen(dependencyLoaded, noop, (error)=>{
8322
+ /** @type {Array<Error>} */
8323
+ const errors= [];
8324
+
8325
+ const enqueueJob= (func, args)=> {
8326
+ try {
8327
+ func(...args);
8328
+ }catch( error) {
8409
8329
  arrayPush(errors, error);
8410
- }));
8330
+ }
8331
+ };
8411
8332
 
8333
+ enqueueJob(memoizedLoadWithErrorAnnotation, [
8334
+ compartmentPrivateFields,
8335
+ moduleAliases,
8336
+ compartment,
8337
+ moduleSpecifier,
8338
+ enqueueJob,
8339
+ preferSync,
8340
+ moduleLoads]);
8412
8341
 
8413
- // Drain pending jobs queue.
8414
- // Each job is a promise for undefined, regardless of success or failure.
8415
- // Before we add a job to the queue, we catch any error and push it into the
8416
- // `errors` accumulator.
8417
- for( const job of pendingJobs) {
8418
- // eslint-disable-next-line no-await-in-loop
8419
- await job;
8420
- }
8421
8342
 
8422
- // Throw an aggregate error if there were any errors.
8423
- if( errors.length> 0) {
8424
- throw TypeError(
8425
- `Failed to load module ${q(moduleSpecifier)} in package ${q(
8426
- compartmentName)
8427
- } (${errors.length} underlying failures: ${arrayJoin(
8428
- arrayMap(errors, (error)=>error.message),
8429
- ', ')
8430
- }`);
8343
+ throwAggregateError({
8344
+ errors,
8345
+ errorPrefix: `Failed to load module ${q(moduleSpecifier)} in package ${q(
8346
+ compartmentName)
8347
+ }`});
8431
8348
 
8432
- }
8433
- };$h‍_once.load(load);
8349
+ };$h‍_once.loadNow(loadNow);
8434
8350
  })()
8435
8351
  ,
8436
8352
  // === functors[40] ===
@@ -9404,7 +9320,7 @@ const instantiate= (
9404
9320
  })()
9405
9321
  ,
9406
9322
  // === functors[44] ===
9407
- ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let Map,ReferenceError,TypeError,WeakMap,assign,defineProperties,entries,promiseThen,toStringTagSymbol,weakmapGet,weakmapSet,setGlobalObjectSymbolUnscopables,setGlobalObjectConstantProperties,setGlobalObjectMutableProperties,setGlobalObjectEvaluators,sharedGlobalPropertyNames,load,link,getDeferredExports,assert,compartmentEvaluate,makeSafeEvaluator;$h‍_imports([["./commons.js", [["Map", [$h‍_a => (Map = $h‍_a)]],["ReferenceError", [$h‍_a => (ReferenceError = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["WeakMap", [$h‍_a => (WeakMap = $h‍_a)]],["assign", [$h‍_a => (assign = $h‍_a)]],["defineProperties", [$h‍_a => (defineProperties = $h‍_a)]],["entries", [$h‍_a => (entries = $h‍_a)]],["promiseThen", [$h‍_a => (promiseThen = $h‍_a)]],["toStringTagSymbol", [$h‍_a => (toStringTagSymbol = $h‍_a)]],["weakmapGet", [$h‍_a => (weakmapGet = $h‍_a)]],["weakmapSet", [$h‍_a => (weakmapSet = $h‍_a)]]]],["./global-object.js", [["setGlobalObjectSymbolUnscopables", [$h‍_a => (setGlobalObjectSymbolUnscopables = $h‍_a)]],["setGlobalObjectConstantProperties", [$h‍_a => (setGlobalObjectConstantProperties = $h‍_a)]],["setGlobalObjectMutableProperties", [$h‍_a => (setGlobalObjectMutableProperties = $h‍_a)]],["setGlobalObjectEvaluators", [$h‍_a => (setGlobalObjectEvaluators = $h‍_a)]]]],["./permits.js", [["sharedGlobalPropertyNames", [$h‍_a => (sharedGlobalPropertyNames = $h‍_a)]]]],["./module-load.js", [["load", [$h‍_a => (load = $h‍_a)]]]],["./module-link.js", [["link", [$h‍_a => (link = $h‍_a)]]]],["./module-proxy.js", [["getDeferredExports", [$h‍_a => (getDeferredExports = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]],["./compartment-evaluate.js", [["compartmentEvaluate", [$h‍_a => (compartmentEvaluate = $h‍_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h‍_a => (makeSafeEvaluator = $h‍_a)]]]]]);
9323
+ ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let Map,ReferenceError,TypeError,WeakMap,assign,defineProperties,entries,promiseThen,toStringTagSymbol,weakmapGet,weakmapSet,setGlobalObjectSymbolUnscopables,setGlobalObjectConstantProperties,setGlobalObjectMutableProperties,setGlobalObjectEvaluators,sharedGlobalPropertyNames,load,loadNow,link,getDeferredExports,assert,compartmentEvaluate,makeSafeEvaluator;$h‍_imports([["./commons.js", [["Map", [$h‍_a => (Map = $h‍_a)]],["ReferenceError", [$h‍_a => (ReferenceError = $h‍_a)]],["TypeError", [$h‍_a => (TypeError = $h‍_a)]],["WeakMap", [$h‍_a => (WeakMap = $h‍_a)]],["assign", [$h‍_a => (assign = $h‍_a)]],["defineProperties", [$h‍_a => (defineProperties = $h‍_a)]],["entries", [$h‍_a => (entries = $h‍_a)]],["promiseThen", [$h‍_a => (promiseThen = $h‍_a)]],["toStringTagSymbol", [$h‍_a => (toStringTagSymbol = $h‍_a)]],["weakmapGet", [$h‍_a => (weakmapGet = $h‍_a)]],["weakmapSet", [$h‍_a => (weakmapSet = $h‍_a)]]]],["./global-object.js", [["setGlobalObjectSymbolUnscopables", [$h‍_a => (setGlobalObjectSymbolUnscopables = $h‍_a)]],["setGlobalObjectConstantProperties", [$h‍_a => (setGlobalObjectConstantProperties = $h‍_a)]],["setGlobalObjectMutableProperties", [$h‍_a => (setGlobalObjectMutableProperties = $h‍_a)]],["setGlobalObjectEvaluators", [$h‍_a => (setGlobalObjectEvaluators = $h‍_a)]]]],["./permits.js", [["sharedGlobalPropertyNames", [$h‍_a => (sharedGlobalPropertyNames = $h‍_a)]]]],["./module-load.js", [["load", [$h‍_a => (load = $h‍_a)]],["loadNow", [$h‍_a => (loadNow = $h‍_a)]]]],["./module-link.js", [["link", [$h‍_a => (link = $h‍_a)]]]],["./module-proxy.js", [["getDeferredExports", [$h‍_a => (getDeferredExports = $h‍_a)]]]],["./error/assert.js", [["assert", [$h‍_a => (assert = $h‍_a)]]]],["./compartment-evaluate.js", [["compartmentEvaluate", [$h‍_a => (compartmentEvaluate = $h‍_a)]]]],["./make-safe-evaluator.js", [["makeSafeEvaluator", [$h‍_a => (makeSafeEvaluator = $h‍_a)]]]]]);
9408
9324
 
9409
9325
 
9410
9326
 
@@ -9566,7 +9482,7 @@ const CompartmentPrototype= {
9566
9482
  }
9567
9483
 
9568
9484
  assertModuleHooks(this);
9569
-
9485
+ loadNow(privateFields, moduleAliases, this, specifier);
9570
9486
  return compartmentImportNow(/** @type {Compartment} */ this, specifier);
9571
9487
  }};
9572
9488
 
@@ -9615,6 +9531,7 @@ const makeCompartmentConstructor= (
9615
9531
  __shimTransforms__= [],
9616
9532
  resolveHook,
9617
9533
  importHook,
9534
+ importNowHook,
9618
9535
  moduleMapHook,
9619
9536
  importMetaHook}=
9620
9537
  options;
@@ -9691,6 +9608,7 @@ const makeCompartmentConstructor= (
9691
9608
  safeEvaluate,
9692
9609
  resolveHook,
9693
9610
  importHook,
9611
+ importNowHook,
9694
9612
  moduleMap,
9695
9613
  moduleMapHook,
9696
9614
  importMetaHook,
@@ -9904,7 +9822,8 @@ freeze(tameHarden);
9904
9822
  })()
9905
9823
  ,
9906
9824
  // === functors[47] ===
9907
- ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let Symbol,entries,fromEntries,getOwnPropertyDescriptors,defineProperties,arrayMap;$h‍_imports([["./commons.js", [["Symbol", [$h‍_a => (Symbol = $h‍_a)]],["entries", [$h‍_a => (entries = $h‍_a)]],["fromEntries", [$h‍_a => (fromEntries = $h‍_a)]],["getOwnPropertyDescriptors", [$h‍_a => (getOwnPropertyDescriptors = $h‍_a)]],["defineProperties", [$h‍_a => (defineProperties = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]]]]]);
9825
+ ({ imports: $h‍_imports, liveVar: $h‍_live, onceVar: $h‍_once, importMeta: $h‍____meta, }) => (function () { 'use strict'; let Symbol,entries,fromEntries,getOwnPropertyDescriptors,defineProperties,arrayMap,functionBind;$h‍_imports([["./commons.js", [["Symbol", [$h‍_a => (Symbol = $h‍_a)]],["entries", [$h‍_a => (entries = $h‍_a)]],["fromEntries", [$h‍_a => (fromEntries = $h‍_a)]],["getOwnPropertyDescriptors", [$h‍_a => (getOwnPropertyDescriptors = $h‍_a)]],["defineProperties", [$h‍_a => (defineProperties = $h‍_a)]],["arrayMap", [$h‍_a => (arrayMap = $h‍_a)]],["functionBind", [$h‍_a => (functionBind = $h‍_a)]]]]]);
9826
+
9908
9827
 
9909
9828
 
9910
9829
 
@@ -9943,11 +9862,9 @@ const tameSymbolConstructor= ()=> {
9943
9862
  const OriginalSymbol= Symbol;
9944
9863
  const SymbolPrototype= OriginalSymbol.prototype;
9945
9864
 
9946
- const SharedSymbol= {
9947
- Symbol(description) {
9948
- return OriginalSymbol(description);
9949
- }}.
9950
- Symbol;
9865
+ // Bypass Hermes bug, fixed in: https://github.com/facebook/hermes/commit/00f18c89c720e1c34592bb85a1a8d311e6e99599
9866
+ // Make a "copy" of the primordial [Symbol "constructor"](https://tc39.es/ecma262/#sec-symbol-description) which maintains all observable behavior. The primordial explicitly throws on `[[Construct]]` and has a `[[Call]]` which ignores the receiver. Binding also maintains the `toString` source as a native function. The `name` is restored below when copying own properties.
9867
+ const SharedSymbol= functionBind(Symbol, undefined);
9951
9868
 
9952
9869
  defineProperties(SymbolPrototype, {
9953
9870
  constructor: {
@@ -10243,7 +10160,7 @@ const tameFauxDataProperties= (intrinsics)=>{
10243
10160
 
10244
10161
 
10245
10162
 
10246
- /** @typedef {import('../types.js').LockdownOptions} LockdownOptions */
10163
+ /** @import {LockdownOptions} from '../types.js' */
10247
10164
 
10248
10165
  const { Fail, details: d, quote: q}= assert;
10249
10166
 
@@ -10637,8 +10554,10 @@ const repairIntrinsics= (options= {})=> {
10637
10554
 
10638
10555
 
10639
10556
 
10557
+ /** @import {LockdownOptions} from '../types.js' */
10558
+
10640
10559
  /**
10641
- * @param {import('./lockdown.js').LockdownOptions} options
10560
+ * @param {LockdownOptions} options
10642
10561
  */
10643
10562
  globalThis.lockdown= (options)=>{
10644
10563
  const hardenIntrinsics= repairIntrinsics(options);
@@ -10646,7 +10565,7 @@ globalThis.lockdown= (options)=>{
10646
10565
  };
10647
10566
 
10648
10567
  /**
10649
- * @param {import('./lockdown.js').LockdownOptions} options
10568
+ * @param {LockdownOptions} options
10650
10569
  */
10651
10570
  globalThis.repairIntrinsics= (options)=>{
10652
10571
  const hardenIntrinsics= repairIntrinsics(options);
@@ -10845,6 +10764,7 @@ globalThis[MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA]=
10845
10764
  weaksetPrototype: cell("weaksetPrototype"),
10846
10765
  functionPrototype: cell("functionPrototype"),
10847
10766
  promisePrototype: cell("promisePrototype"),
10767
+ generatorPrototype: cell("generatorPrototype"),
10848
10768
  typedArrayPrototype: cell("typedArrayPrototype"),
10849
10769
  uncurryThis: cell("uncurryThis"),
10850
10770
  objectHasOwnProperty: cell("objectHasOwnProperty"),
@@ -10878,6 +10798,8 @@ globalThis[MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA]=
10878
10798
  stringIncludes: cell("stringIncludes"),
10879
10799
  stringIndexOf: cell("stringIndexOf"),
10880
10800
  stringMatch: cell("stringMatch"),
10801
+ generatorNext: cell("generatorNext"),
10802
+ generatorThrow: cell("generatorThrow"),
10881
10803
  stringReplace: cell("stringReplace"),
10882
10804
  stringSearch: cell("stringSearch"),
10883
10805
  stringSlice: cell("stringSlice"),
@@ -10891,6 +10813,7 @@ globalThis[MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA]=
10891
10813
  weaksetAdd: cell("weaksetAdd"),
10892
10814
  weaksetHas: cell("weaksetHas"),
10893
10815
  functionToString: cell("functionToString"),
10816
+ functionBind: cell("functionBind"),
10894
10817
  promiseAll: cell("promiseAll"),
10895
10818
  promiseCatch: cell("promiseCatch"),
10896
10819
  promiseThen: cell("promiseThen"),
@@ -10903,6 +10826,8 @@ globalThis[MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA]=
10903
10826
  FERAL_EVAL: cell("FERAL_EVAL"),
10904
10827
  FERAL_FUNCTION: cell("FERAL_FUNCTION"),
10905
10828
  noEvalEvaluate: cell("noEvalEvaluate"),
10829
+ FERAL_STACK_GETTER: cell("FERAL_STACK_GETTER"),
10830
+ FERAL_STACK_SETTER: cell("FERAL_STACK_SETTER"),
10906
10831
  },
10907
10832
  {
10908
10833
  },
@@ -10934,6 +10859,7 @@ globalThis[MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA]=
10934
10859
  loggedErrorHandler: cell("loggedErrorHandler"),
10935
10860
  makeAssert: cell("makeAssert"),
10936
10861
  assert: cell("assert"),
10862
+ sanitizeError: cell("sanitizeError"),
10937
10863
  },
10938
10864
  {
10939
10865
  isTypedArray: cell("isTypedArray"),
@@ -11059,6 +10985,7 @@ globalThis[MAKE_CAUSAL_CONSOLE_FROM_LOGGER_KEY_FOR_SES_AVA]=
11059
10985
  {
11060
10986
  makeAlias: cell("makeAlias"),
11061
10987
  load: cell("load"),
10988
+ loadNow: cell("loadNow"),
11062
10989
  },
11063
10990
  {
11064
10991
  deferExports: cell("deferExports"),
@@ -11221,6 +11148,7 @@ function observeImports(map, importName, importIndex) {
11221
11148
  weaksetPrototype: cells[0].weaksetPrototype.set,
11222
11149
  functionPrototype: cells[0].functionPrototype.set,
11223
11150
  promisePrototype: cells[0].promisePrototype.set,
11151
+ generatorPrototype: cells[0].generatorPrototype.set,
11224
11152
  typedArrayPrototype: cells[0].typedArrayPrototype.set,
11225
11153
  uncurryThis: cells[0].uncurryThis.set,
11226
11154
  objectHasOwnProperty: cells[0].objectHasOwnProperty.set,
@@ -11254,6 +11182,8 @@ function observeImports(map, importName, importIndex) {
11254
11182
  stringIncludes: cells[0].stringIncludes.set,
11255
11183
  stringIndexOf: cells[0].stringIndexOf.set,
11256
11184
  stringMatch: cells[0].stringMatch.set,
11185
+ generatorNext: cells[0].generatorNext.set,
11186
+ generatorThrow: cells[0].generatorThrow.set,
11257
11187
  stringReplace: cells[0].stringReplace.set,
11258
11188
  stringSearch: cells[0].stringSearch.set,
11259
11189
  stringSlice: cells[0].stringSlice.set,
@@ -11267,6 +11197,7 @@ function observeImports(map, importName, importIndex) {
11267
11197
  weaksetAdd: cells[0].weaksetAdd.set,
11268
11198
  weaksetHas: cells[0].weaksetHas.set,
11269
11199
  functionToString: cells[0].functionToString.set,
11200
+ functionBind: cells[0].functionBind.set,
11270
11201
  promiseAll: cells[0].promiseAll.set,
11271
11202
  promiseCatch: cells[0].promiseCatch.set,
11272
11203
  promiseThen: cells[0].promiseThen.set,
@@ -11279,6 +11210,8 @@ function observeImports(map, importName, importIndex) {
11279
11210
  FERAL_EVAL: cells[0].FERAL_EVAL.set,
11280
11211
  FERAL_FUNCTION: cells[0].FERAL_FUNCTION.set,
11281
11212
  noEvalEvaluate: cells[0].noEvalEvaluate.set,
11213
+ FERAL_STACK_GETTER: cells[0].FERAL_STACK_GETTER.set,
11214
+ FERAL_STACK_SETTER: cells[0].FERAL_STACK_SETTER.set,
11282
11215
  },
11283
11216
  importMeta: {},
11284
11217
  });
@@ -11392,6 +11325,7 @@ function observeImports(map, importName, importIndex) {
11392
11325
  loggedErrorHandler: cells[9].loggedErrorHandler.set,
11393
11326
  makeAssert: cells[9].makeAssert.set,
11394
11327
  assert: cells[9].assert.set,
11328
+ sanitizeError: cells[9].sanitizeError.set,
11395
11329
  },
11396
11330
  importMeta: {},
11397
11331
  });
@@ -11808,6 +11742,7 @@ function observeImports(map, importName, importIndex) {
11808
11742
  functors[39]({
11809
11743
  imports(entries) {
11810
11744
  const map = new Map(entries);
11745
+ observeImports(map, "@endo/env-options", 3);
11811
11746
  observeImports(map, "./commons.js", 0);
11812
11747
  observeImports(map, "./error/assert.js", 9);
11813
11748
  },
@@ -11816,6 +11751,7 @@ function observeImports(map, importName, importIndex) {
11816
11751
  onceVar: {
11817
11752
  makeAlias: cells[39].makeAlias.set,
11818
11753
  load: cells[39].load.set,
11754
+ loadNow: cells[39].loadNow.set,
11819
11755
  },
11820
11756
  importMeta: {},
11821
11757
  });