ses 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lockdown.mjs CHANGED
@@ -567,7 +567,7 @@ freeze(bestEffortStringify);
567
567
  */
568
568
 
569
569
  /**
570
- * @typedef {Object} AssertMakeErrorOptions
570
+ * @typedef {object} AssertMakeErrorOptions
571
571
  * @property {string=} errorName
572
572
  */
573
573
 
@@ -614,51 +614,65 @@ freeze(bestEffortStringify);
614
614
  */
615
615
 
616
616
  // 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.
617
+ // There may eventually be a better way to do this, but
618
+ // thems the breaks with Typescript 4.0.
619
619
  /**
620
620
  * @callback AssertTypeofBigint
621
621
  * @param {any} specimen
622
622
  * @param {'bigint'} typename
623
623
  * @param {Details=} optDetails
624
624
  * @returns {asserts specimen is bigint}
625
- *
625
+ */
626
+
627
+ /**
626
628
  * @callback AssertTypeofBoolean
627
629
  * @param {any} specimen
628
630
  * @param {'boolean'} typename
629
631
  * @param {Details=} optDetails
630
632
  * @returns {asserts specimen is boolean}
631
- *
633
+ */
634
+
635
+ /**
632
636
  * @callback AssertTypeofFunction
633
637
  * @param {any} specimen
634
638
  * @param {'function'} typename
635
639
  * @param {Details=} optDetails
636
640
  * @returns {asserts specimen is Function}
637
- *
641
+ */
642
+
643
+ /**
638
644
  * @callback AssertTypeofNumber
639
645
  * @param {any} specimen
640
646
  * @param {'number'} typename
641
647
  * @param {Details=} optDetails
642
648
  * @returns {asserts specimen is number}
643
- *
649
+ */
650
+
651
+ /**
644
652
  * @callback AssertTypeofObject
645
653
  * @param {any} specimen
646
654
  * @param {'object'} typename
647
655
  * @param {Details=} optDetails
648
656
  * @returns {asserts specimen is Record<any, any> | null}
649
- *
657
+ */
658
+
659
+ /**
650
660
  * @callback AssertTypeofString
651
661
  * @param {any} specimen
652
662
  * @param {'string'} typename
653
663
  * @param {Details=} optDetails
654
664
  * @returns {asserts specimen is string}
655
- *
665
+ */
666
+
667
+ /**
656
668
  * @callback AssertTypeofSymbol
657
669
  * @param {any} specimen
658
670
  * @param {'symbol'} typename
659
671
  * @param {Details=} optDetails
660
672
  * @returns {asserts specimen is symbol}
661
- *
673
+ */
674
+
675
+ /**
662
676
  * @callback AssertTypeofUndefined
663
677
  * @param {any} specimen
664
678
  * @param {'undefined'} typename
@@ -712,7 +726,7 @@ freeze(bestEffortStringify);
712
726
  */
713
727
 
714
728
  /**
715
- * @typedef {Object} StringablePayload
729
+ * @typedef {object} StringablePayload
716
730
  * Holds the payload passed to quote so that its printed form is visible.
717
731
  * @property {() => string} toString How to print the payload
718
732
  */
@@ -2379,10 +2393,8 @@ const makeSafeEvaluator= ({
2379
2393
 
2380
2394
 
2381
2395
  const provideCompartmentEvaluator= (compartmentFields, options)=> {
2382
- const {
2383
- sloppyGlobalsMode= false,
2384
- __moduleShimLexicals__= undefined}=
2385
- options;
2396
+ const { sloppyGlobalsMode= false, __moduleShimLexicals__= undefined}=
2397
+ options;
2386
2398
 
2387
2399
  let safeEvaluate;
2388
2400
 
@@ -4175,7 +4187,7 @@ $h‍_once.makeAlias(makeAlias);const resolveAll=(imports,resolveHook,fullReferr
4175
4187
  return freeze(resolvedImports);
4176
4188
  };
4177
4189
 
4178
- const loadRecord= async(
4190
+ const loadRecord= (
4179
4191
  compartmentPrivateFields,
4180
4192
  moduleAliases,
4181
4193
  compartment,
@@ -4296,27 +4308,64 @@ const loadWithoutErrorAnnotation= async(
4296
4308
  } in compartment ${q(compartment.name)}`;
4297
4309
  }
4298
4310
 
4299
- if( staticModuleRecord.record!== undefined) {
4300
- const {
4301
- compartment: aliasCompartment= compartment,
4302
- specifier: aliasSpecifier= moduleSpecifier,
4303
- record: aliasModuleRecord,
4304
- importMeta}=
4305
- staticModuleRecord;
4311
+ // check if record is a RedirectStaticModuleInterface
4312
+ if( staticModuleRecord.specifier!== undefined) {
4313
+ // check if this redirect with an explicit record
4314
+ if( staticModuleRecord.record!== undefined) {
4315
+ // ensure expected record shape
4316
+ if( staticModuleRecord.compartment!== undefined) {
4317
+ throw new TypeError(
4318
+ 'Cannot redirect to an explicit record with a specified compartment');
4306
4319
 
4307
- const aliasRecord= await loadRecord(
4308
- compartmentPrivateFields,
4309
- moduleAliases,
4310
- aliasCompartment,
4311
- aliasSpecifier,
4312
- aliasModuleRecord,
4313
- pendingJobs,
4314
- moduleLoads,
4315
- errors,
4316
- importMeta);
4320
+ }
4321
+ const {
4322
+ compartment: aliasCompartment= compartment,
4323
+ specifier: aliasSpecifier= moduleSpecifier,
4324
+ record: aliasModuleRecord,
4325
+ importMeta}=
4326
+ staticModuleRecord;
4327
+
4328
+ const aliasRecord= loadRecord(
4329
+ compartmentPrivateFields,
4330
+ moduleAliases,
4331
+ aliasCompartment,
4332
+ aliasSpecifier,
4333
+ aliasModuleRecord,
4334
+ pendingJobs,
4335
+ moduleLoads,
4336
+ errors,
4337
+ importMeta);
4338
+
4339
+ mapSet(moduleRecords, moduleSpecifier, aliasRecord);
4340
+ return aliasRecord;
4341
+ }
4342
+
4343
+ // check if this redirect with an explicit compartment
4344
+ if( staticModuleRecord.compartment!== undefined) {
4345
+ // ensure expected record shape
4346
+ if( staticModuleRecord.importMeta!== undefined) {
4347
+ throw new TypeError(
4348
+ 'Cannot redirect to an implicit record with a specified importMeta');
4349
+
4350
+ }
4351
+ // Behold: recursion.
4352
+ // eslint-disable-next-line no-use-before-define
4353
+ const aliasRecord= await memoizedLoadWithErrorAnnotation(
4354
+ compartmentPrivateFields,
4355
+ moduleAliases,
4356
+ staticModuleRecord.compartment,
4357
+ staticModuleRecord.specifier,
4358
+ pendingJobs,
4359
+ moduleLoads,
4360
+ errors);
4361
+
4362
+ mapSet(moduleRecords, moduleSpecifier, aliasRecord);
4363
+ return aliasRecord;
4364
+ }
4365
+
4366
+ throw new TypeError(
4367
+ 'Unnexpected RedirectStaticModuleInterface record shape');
4317
4368
 
4318
- mapSet(moduleRecords, moduleSpecifier, aliasRecord);
4319
- return aliasRecord;
4320
4369
  }
4321
4370
 
4322
4371
  return loadRecord(
@@ -4759,6 +4808,7 @@ $h‍_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
4759
4808
  __syncModuleProgram__: functorSource,
4760
4809
  __fixedExportMap__: fixedExportMap= {},
4761
4810
  __liveExportMap__: liveExportMap= {},
4811
+ __reexportMap__: reexportMap= {},
4762
4812
  __needsImportMeta__: needsImportMeta= false}=
4763
4813
  staticModuleRecord;
4764
4814
 
@@ -5012,26 +5062,35 @@ $h‍_once.makeThirdPartyModuleInstance(makeThirdPartyModuleInstance);const make
5012
5062
  }
5013
5063
  if( arrayIncludes(exportAlls, specifier)) {
5014
5064
  // Make all these imports candidates.
5015
- for( const [importName, importNotify]of entries(importNotifiers)) {
5016
- if( candidateAll[importName]=== undefined) {
5017
- candidateAll[importName]= importNotify;
5065
+ // Note names don't change in reexporting all
5066
+ for( const [importAndExportName, importNotify]of entries(
5067
+ importNotifiers))
5068
+ {
5069
+ if( candidateAll[importAndExportName]=== undefined) {
5070
+ candidateAll[importAndExportName]= importNotify;
5018
5071
  }else {
5019
5072
  // Already a candidate: remove ambiguity.
5020
- candidateAll[importName]= false;
5073
+ candidateAll[importAndExportName]= false;
5021
5074
  }
5022
5075
  }
5023
5076
  }
5077
+ if( reexportMap[specifier]) {
5078
+ // Make named reexports candidates too.
5079
+ for( const [localName, exportedName]of reexportMap[specifier]) {
5080
+ candidateAll[exportedName]= importNotifiers[localName];
5081
+ }
5082
+ }
5024
5083
  }
5025
5084
 
5026
- for( const [importName, notify]of entries(candidateAll)) {
5027
- if( !notifiers[importName]&& notify!== false) {
5028
- notifiers[importName]= notify;
5085
+ for( const [exportName, notify]of entries(candidateAll)) {
5086
+ if( !notifiers[exportName]&& notify!== false) {
5087
+ notifiers[exportName]= notify;
5029
5088
 
5030
5089
  // exported live binding state
5031
5090
  let value;
5032
5091
  const update= (newValue)=> value= newValue;
5033
5092
  notify(update);
5034
- exportsProps[importName]= {
5093
+ exportsProps[exportName]= {
5035
5094
  get() {
5036
5095
  return value;
5037
5096
  },
@@ -5223,12 +5282,8 @@ const instantiate= (
5223
5282
  moduleAliases,
5224
5283
  moduleRecord)=>
5225
5284
  {
5226
- const {
5227
- compartment,
5228
- moduleSpecifier,
5229
- resolvedImports,
5230
- staticModuleRecord}=
5231
- moduleRecord;
5285
+ const { compartment, moduleSpecifier, resolvedImports, staticModuleRecord}=
5286
+ moduleRecord;
5232
5287
  const { instances}= weakmapGet(compartmentPrivateFields, compartment);
5233
5288
 
5234
5289
  // Memoize.
@@ -6481,12 +6536,8 @@ freeze(ErrorInfo);
6481
6536
 
6482
6537
  /** @type {MakeCausalConsole} */
6483
6538
  const makeCausalConsole= (baseConsole, loggedErrorHandler)=> {
6484
- const {
6485
- getStackString,
6486
- tagError,
6487
- takeMessageLogArgs,
6488
- takeNoteLogArgsArray}=
6489
- loggedErrorHandler;
6539
+ const { getStackString, tagError, takeMessageLogArgs, takeNoteLogArgsArray}=
6540
+ loggedErrorHandler;
6490
6541
 
6491
6542
  /**
6492
6543
  * @param {ReadonlyArray<any>} logArgs
@@ -7600,8 +7651,10 @@ const getAnonymousIntrinsics= ()=> {
7600
7651
 
7601
7652
  // 9.2.4.1 %ThrowTypeError%
7602
7653
 
7603
- const ThrowTypeError= getOwnPropertyDescriptor(makeArguments(), 'callee').
7604
- get;
7654
+ const ThrowTypeError= getOwnPropertyDescriptor(
7655
+ makeArguments(),
7656
+ 'callee').
7657
+ get;
7605
7658
 
7606
7659
  // 21.1.5.2 The %StringIteratorPrototype% Object
7607
7660
 
@@ -8103,7 +8156,8 @@ function tameDomains(domainTaming= 'safe') {
8103
8156
  })
8104
8157
  ,
8105
8158
  // === 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)]]]]]);
8159
+ (({ 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)]]]]]);
8160
+
8107
8161
 
8108
8162
 
8109
8163
 
@@ -8154,7 +8208,7 @@ function tameFunctionConstructors() {
8154
8208
  FERAL_FUNCTION.prototype.constructor('return 1');
8155
8209
  }catch( ignore) {
8156
8210
  // Throws, no need to patch.
8157
- return harden({});
8211
+ return freeze({});
8158
8212
  }
8159
8213
 
8160
8214
  const newIntrinsics= {};
@@ -8187,7 +8241,7 @@ function tameFunctionConstructors() {
8187
8241
  // Prevents the evaluation of source when calling constructor on the
8188
8242
  // prototype of functions.
8189
8243
  // eslint-disable-next-line func-names
8190
- const InertConstructor= function() {
8244
+ const InertConstructor= function() {
8191
8245
  throw new TypeError(
8192
8246
  'Function.prototype.constructor is not a valid constructor.');
8193
8247
 
@@ -8393,9 +8447,8 @@ function tameMathObject(mathTaming= 'safe') {
8393
8447
  const originalMath= Math;
8394
8448
  const initialMath= originalMath; // to follow the naming pattern
8395
8449
 
8396
- const { random: _, ...otherDescriptors}= getOwnPropertyDescriptors(
8397
- originalMath);
8398
-
8450
+ const { random: _, ...otherDescriptors}=
8451
+ getOwnPropertyDescriptors(originalMath);
8399
8452
 
8400
8453
  const sharedMath= create(objectPrototype, otherDescriptors);
8401
8454
 
@@ -8930,10 +8983,8 @@ const repairIntrinsics= (options= {})=> {
8930
8983
  // [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/lockdown-options.md#stackfiltering-options)
8931
8984
  // for an explanation.
8932
8985
 
8933
- const {
8934
- getEnvironmentOption: getenv,
8935
- getCapturedEnvironmentOptionNames}=
8936
- makeEnvironmentCaptor(globalThis);
8986
+ const { getEnvironmentOption: getenv, getCapturedEnvironmentOptionNames}=
8987
+ makeEnvironmentCaptor(globalThis);
8937
8988
 
8938
8989
  const {
8939
8990
  errorTaming= getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
@@ -9039,11 +9090,8 @@ const repairIntrinsics= (options= {})=> {
9039
9090
 
9040
9091
  tameDomains(domainTaming);
9041
9092
 
9042
- const {
9043
- addIntrinsics,
9044
- completePrototypes,
9045
- finalIntrinsics}=
9046
- makeIntrinsicsCollector();
9093
+ const { addIntrinsics, completePrototypes, finalIntrinsics}=
9094
+ makeIntrinsicsCollector();
9047
9095
 
9048
9096
  addIntrinsics({ harden});
9049
9097
 
@@ -9234,23 +9282,25 @@ assign(globalThis, {
9234
9282
  ,
9235
9283
  ]; // functors end
9236
9284
 
9237
- function cell(name, value = undefined) {
9285
+ const cell = (name, value = undefined) => {
9238
9286
  const observers = [];
9239
- function set(newValue) {
9240
- value = newValue;
9241
- for (const observe of observers) {
9287
+ return Object.freeze({
9288
+ get: Object.freeze(() => {
9289
+ return value;
9290
+ }),
9291
+ set: Object.freeze((newValue) => {
9292
+ value = newValue;
9293
+ for (const observe of observers) {
9294
+ observe(value);
9295
+ }
9296
+ }),
9297
+ observe: Object.freeze((observe) => {
9298
+ observers.push(observe);
9242
9299
  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
- }
9300
+ }),
9301
+ enumerable: true,
9302
+ });
9303
+ };
9254
9304
 
9255
9305
  const cells = [
9256
9306
  {
@@ -9555,23 +9605,24 @@ assign(globalThis, {
9555
9605
  ];
9556
9606
 
9557
9607
 
9558
- const namespaces = cells.map(cells => Object.create(null, cells));
9608
+ const namespaces = cells.map(cells => Object.freeze(Object.create(null, cells)));
9559
9609
 
9560
9610
  for (let index = 0; index < namespaces.length; index += 1) {
9561
9611
  cells[index]['*'] = cell('*', namespaces[index]);
9562
9612
  }
9563
9613
 
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
- }
9614
+ function observeImports(map, importName, importIndex) {
9615
+ for (const [name, observers] of map.get(importName)) {
9616
+ const cell = cells[importIndex][name];
9617
+ if (cell === undefined) {
9618
+ throw new ReferenceError(`Cannot import name ${name}`);
9619
+ }
9620
+ for (const observer of observers) {
9621
+ cell.observe(observer);
9573
9622
  }
9574
9623
  }
9624
+ }
9625
+
9575
9626
 
9576
9627
  functors[0]({
9577
9628
  imports(entries) {