ses 1.13.0 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- // ses@1.13.0
1
+ // ses@1.13.1
2
2
  (functors => options => {
3
3
  'use strict';
4
4
 
@@ -5223,6 +5223,8 @@ const CommonMath = {
5223
5223
  '[[Proto]]': '%ArrayBufferPrototype%',
5224
5224
  byteLength: getter,
5225
5225
  slice: fn,
5226
+ // See https://github.com/endojs/endo/tree/master/packages/immutable-arraybuffer#purposeful-violation
5227
+ '@@toStringTag': 'string',
5226
5228
  // See https://github.com/tc39/proposal-resizablearraybuffer
5227
5229
  transfer: fn,
5228
5230
  resize: fn,
@@ -11723,18 +11725,49 @@ function validateModuleSource(moduleSource, moduleSpecifier) {
11723
11725
 
11724
11726
 
11725
11727
 
11728
+ /**
11729
+ * @import {ImportHook, ImportMetaHook, ImportNowHook, ModuleDescriptor, ModuleExportsNamespace, ModuleMap, ModuleMapHook, ResolveHook, ModuleSource, CompartmentOptions} from '../types.js'
11730
+ * @import {Transform} from './lockdown.js'
11731
+ * @import {DeferredExports} from './module-proxy.js'
11732
+ */
11726
11733
 
11727
- /** @import {ModuleDescriptor, ModuleExportsNamespace} from '../types.js' */
11728
-
11729
- // moduleAliases associates every public module exports namespace with its
11730
- // corresponding compartment and specifier so they can be used to link modules
11731
- // across compartments.
11732
- // The mechanism to thread an alias is to use the compartment.module function
11733
- // to obtain the exports namespace of a foreign module and pass it into another
11734
- // compartment's moduleMap constructor option.
11734
+ /**
11735
+ * Associates every public module exports namespace with its corresponding
11736
+ * compartment and specifier so they can be used to link modules across
11737
+ * compartments. The mechanism to thread an alias is to use the
11738
+ * {@link Compartment.module} function to obtain the exports namespace of a foreign
11739
+ * module and pass it into another compartment's `moduleMap` constructor option
11740
+ * @type {WeakMap<ModuleExportsNamespace, Compartment>}
11741
+ *
11742
+ */
11735
11743
  const moduleAliases = new WeakMap();
11736
11744
 
11737
- // privateFields captures the private state for each compartment.
11745
+ /**
11746
+ * Private fields for `Compartment` instances
11747
+ * @typedef {object} CompartmentFields
11748
+ * @property {string} name
11749
+ * @property {object} globalObject
11750
+ * @property {Array<Transform>} globalTransforms
11751
+ * @property {(source: string, options?: {localTransforms?: Array<Transform>}) => void} safeEvaluate
11752
+ * @property {ResolveHook} resolveHook
11753
+ * @property {ImportHook} importHook
11754
+ * @property {ImportNowHook} importNowHook
11755
+ * @property {ModuleMap} moduleMap
11756
+ * @property {ModuleMapHook} moduleMapHook
11757
+ * @property {ImportMetaHook} importMetaHook
11758
+ * @property {Map<string, ModuleSource>} moduleRecords
11759
+ * @property {Array<Transform>} __shimTransforms__
11760
+ * @property {DeferredExports} deferredExports
11761
+ * @property {Map<string, ModuleDescriptor>} instances
11762
+ * @property {Compartment} [parentCompartment]
11763
+ * @property {boolean} noNamespaceBox
11764
+ * @property {(fullSpecifier: string) => Promise<ModuleExportsNamespace>} compartmentImport
11765
+ */
11766
+
11767
+ /**
11768
+ * Captures the private state for each {@link Compartment}
11769
+ * @type {WeakMap<Compartment, CompartmentFields>}
11770
+ */
11738
11771
  const privateFields = new WeakMap();
11739
11772
 
11740
11773
  const InertCompartment = function Compartment(
@@ -11750,6 +11783,7 @@ const privateFields = new WeakMap();
11750
11783
  /**
11751
11784
  * @param {Compartment} compartment
11752
11785
  * @param {string} specifier
11786
+ * @returns {{namespace: ModuleExportsNamespace}}
11753
11787
  */$h͏_once.InertCompartment(InertCompartment);
11754
11788
  const compartmentImportNow = (compartment, specifier) => {
11755
11789
  const { execute, exportsProxy } = link(
@@ -11762,27 +11796,20 @@ const compartmentImportNow = (compartment, specifier) => {
11762
11796
  return exportsProxy;
11763
11797
  };
11764
11798
 
11799
+ /** @type {Compartment & {constructor: typeof InertCompartment}} */
11765
11800
  const CompartmentPrototype = {
11766
11801
  constructor: InertCompartment,
11767
11802
 
11768
11803
  get globalThis() {
11769
- return weakmapGet(privateFields, this).globalObject;
11804
+ return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
11805
+ .globalObject;
11770
11806
  },
11771
11807
 
11772
11808
  get name() {
11773
- return weakmapGet(privateFields, this).name;
11809
+ return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
11810
+ .name;
11774
11811
  },
11775
11812
 
11776
- /**
11777
- * @param {string} source is a JavaScript program grammar construction.
11778
- * @param {object} [options]
11779
- * @param {Array<import('./lockdown-shim').Transform>} [options.transforms]
11780
- * @param {boolean} [options.sloppyGlobalsMode]
11781
- * @param {object} [options.__moduleShimLexicals__]
11782
- * @param {boolean} [options.__evadeHtmlCommentTest__]
11783
- * @param {boolean} [options.__evadeImportExpressionTest__]
11784
- * @param {boolean} [options.__rejectSomeDirectEvalExpressions__]
11785
- */
11786
11813
  evaluate(source, options = {}) {
11787
11814
  const compartmentFields = weakmapGet(privateFields, this);
11788
11815
  return compartmentEvaluate(compartmentFields, source, options);
@@ -11804,7 +11831,9 @@ const compartmentImportNow = (compartment, specifier) => {
11804
11831
  },
11805
11832
 
11806
11833
  async import(specifier) {
11807
- const { noNamespaceBox } = weakmapGet(privateFields, this);
11834
+ const { noNamespaceBox } = /** @type {CompartmentFields} */ (
11835
+ weakmapGet(privateFields, this)
11836
+ );
11808
11837
 
11809
11838
  if (typeof specifier !== 'string') {
11810
11839
  throw TypeError('first argument of import() must be a string');
@@ -11843,7 +11872,7 @@ const compartmentImportNow = (compartment, specifier) => {
11843
11872
  }
11844
11873
 
11845
11874
  loadNow(privateFields, moduleAliases, this, specifier);
11846
- return compartmentImportNow(/** @type {Compartment} */ (this), specifier);
11875
+ return compartmentImportNow(this, specifier);
11847
11876
  },
11848
11877
  };
11849
11878
 
@@ -11874,15 +11903,35 @@ defineProperties(InertCompartment, {
11874
11903
  * @returns {Compartment['constructor']}
11875
11904
  */
11876
11905
 
11877
- // In order to facilitate migration from the deprecated signature
11878
- // of the compartment constructor,
11879
- // new Compartent(globals?, modules?, options?)
11880
- // to the new signature:
11881
- // new Compartment(options?)
11882
- // where globals and modules are expressed in the options bag instead of
11883
- // positional arguments, this function detects the temporary sigil __options__
11884
- // on the first argument and coerces compartments arguments into a single
11885
- // compartments object.
11906
+ /**
11907
+ * "Options bag"-style `Compartment` constructor arguments.
11908
+ * @typedef {[options?: CompartmentOptions & { __options__: true }]} CompartmentOptionsArgs
11909
+ */
11910
+
11911
+ /**
11912
+ * Legacy `Compartment` constructor arguments.
11913
+ *
11914
+ * @deprecated
11915
+ * @typedef {[globals?: Map<string, any>, modules?: Map<string, ModuleDescriptor>, options?: CompartmentOptions]} LegacyCompartmentOptionsArgs
11916
+ */
11917
+
11918
+ /**
11919
+ * In order to facilitate migration from the deprecated signature of the
11920
+ * compartment constructor,
11921
+ *
11922
+ * `new Compartent(globals?, modules?, options?)`
11923
+ *
11924
+ * to the new signature:
11925
+ *
11926
+ * `new Compartment(options?)`
11927
+ *
11928
+ * ...where globals and modules are expressed in the options bag instead of
11929
+ * positional arguments, this function detects the temporary sigil __options__
11930
+ * on the first argument and coerces compartments arguments into a single
11931
+ * compartments object.
11932
+ * @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
11933
+ * @returns {CompartmentOptions}
11934
+ */
11886
11935
  const compartmentOptions = (...args) => {
11887
11936
  if (args.length === 0) {
11888
11937
  return {};
@@ -11904,7 +11953,7 @@ defineProperties(InertCompartment, {
11904
11953
  globals = /** @type {Map<string, any>} */ ({}),
11905
11954
  modules = /** @type {Map<string, ModuleDescriptor>} */ ({}),
11906
11955
  options = {},
11907
- ] = args;
11956
+ ] = /** @type {LegacyCompartmentOptionsArgs} */ (args);
11908
11957
  assertEqual(
11909
11958
  options.modules,
11910
11959
  undefined,
@@ -11930,6 +11979,10 @@ defineProperties(InertCompartment, {
11930
11979
  markVirtualizedNativeFunction,
11931
11980
  { parentCompartment = undefined, enforceNew = false } = {},
11932
11981
  ) => {
11982
+ /**
11983
+ *
11984
+ * @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
11985
+ */
11933
11986
  function Compartment(...args) {
11934
11987
  if (enforceNew && new.target === undefined) {
11935
11988
  throw TypeError(
package/dist/ses.cjs CHANGED
@@ -1,4 +1,4 @@
1
- // ses@1.13.0
1
+ // ses@1.13.1
2
2
  (functors => options => {
3
3
  'use strict';
4
4
 
@@ -2088,9 +2088,11 @@ freeze(makeEnvironmentCaptor);
2088
2088
  // === 4. immutable-arraybuffer ./index.js ===
2089
2089
  ({imports:$h͏_imports,liveVar:$h͏_live,onceVar:$h͏_once,import:$h͏_import,importMeta:$h͏____meta})=>(function(){'use strict';$h͏_imports([]);/* global globalThis */
2090
2090
 
2091
- const { setPrototypeOf, getOwnPropertyDescriptors } = Object;
2091
+ const { setPrototypeOf, getOwnPropertyDescriptors, defineProperties } = Object;
2092
2092
  const { apply } = Reflect;
2093
2093
  const { prototype: arrayBufferPrototype } = ArrayBuffer;
2094
+ // Capture structuredClone before it could be scuttled.
2095
+ const { structuredClone: originalStructuredCloneMaybe } = globalThis;
2094
2096
 
2095
2097
  const {
2096
2098
  slice,
@@ -2126,12 +2128,14 @@ let arrayBufferTransfer;
2126
2128
 
2127
2129
  if (transfer) {
2128
2130
  arrayBufferTransfer = arrayBuffer => apply(transfer, arrayBuffer, []);
2129
- } else if (globalThis.structuredClone) {
2131
+ } else if (originalStructuredCloneMaybe) {
2130
2132
  arrayBufferTransfer = arrayBuffer => {
2131
2133
  // Hopefully, a zero-length slice is cheap, but still enforces that
2132
2134
  // `arrayBuffer` is a genuine `ArrayBuffer` exotic object.
2133
2135
  arrayBufferSlice(arrayBuffer, 0, 0);
2134
- return globalThis.structuredClone(arrayBuffer, { transfer: [arrayBuffer] });
2136
+ return originalStructuredCloneMaybe(arrayBuffer, {
2137
+ transfer: [arrayBuffer],
2138
+ });
2135
2139
  };
2136
2140
  } else {
2137
2141
  // Indeed, Node <= 16 has neither.
@@ -2230,6 +2234,16 @@ const {
2230
2234
 
2231
2235
  setPrototypeOf(immutableArrayBufferPrototype, arrayBufferPrototype);
2232
2236
 
2237
+ // See https://github.com/endojs/endo/tree/master/packages/immutable-arraybuffer#purposeful-violation
2238
+ defineProperties(immutableArrayBufferPrototype, {
2239
+ [Symbol.toStringTag]: {
2240
+ value: 'ImmutableArrayBuffer',
2241
+ writable: false,
2242
+ enumerable: false,
2243
+ configurable: true,
2244
+ },
2245
+ });
2246
+
2233
2247
  /**
2234
2248
  * Transfer the contents to a new Immutable ArrayBuffer
2235
2249
  *
@@ -5335,6 +5349,8 @@ const CommonMath = {
5335
5349
  '[[Proto]]': '%ArrayBufferPrototype%',
5336
5350
  byteLength: getter,
5337
5351
  slice: fn,
5352
+ // See https://github.com/endojs/endo/tree/master/packages/immutable-arraybuffer#purposeful-violation
5353
+ '@@toStringTag': 'string',
5338
5354
  // See https://github.com/tc39/proposal-resizablearraybuffer
5339
5355
  transfer: fn,
5340
5356
  resize: fn,
@@ -11835,18 +11851,49 @@ function validateModuleSource(moduleSource, moduleSpecifier) {
11835
11851
 
11836
11852
 
11837
11853
 
11854
+ /**
11855
+ * @import {ImportHook, ImportMetaHook, ImportNowHook, ModuleDescriptor, ModuleExportsNamespace, ModuleMap, ModuleMapHook, ResolveHook, ModuleSource, CompartmentOptions} from '../types.js'
11856
+ * @import {Transform} from './lockdown.js'
11857
+ * @import {DeferredExports} from './module-proxy.js'
11858
+ */
11838
11859
 
11839
- /** @import {ModuleDescriptor, ModuleExportsNamespace} from '../types.js' */
11840
-
11841
- // moduleAliases associates every public module exports namespace with its
11842
- // corresponding compartment and specifier so they can be used to link modules
11843
- // across compartments.
11844
- // The mechanism to thread an alias is to use the compartment.module function
11845
- // to obtain the exports namespace of a foreign module and pass it into another
11846
- // compartment's moduleMap constructor option.
11860
+ /**
11861
+ * Associates every public module exports namespace with its corresponding
11862
+ * compartment and specifier so they can be used to link modules across
11863
+ * compartments. The mechanism to thread an alias is to use the
11864
+ * {@link Compartment.module} function to obtain the exports namespace of a foreign
11865
+ * module and pass it into another compartment's `moduleMap` constructor option
11866
+ * @type {WeakMap<ModuleExportsNamespace, Compartment>}
11867
+ *
11868
+ */
11847
11869
  const moduleAliases = new WeakMap();
11848
11870
 
11849
- // privateFields captures the private state for each compartment.
11871
+ /**
11872
+ * Private fields for `Compartment` instances
11873
+ * @typedef {object} CompartmentFields
11874
+ * @property {string} name
11875
+ * @property {object} globalObject
11876
+ * @property {Array<Transform>} globalTransforms
11877
+ * @property {(source: string, options?: {localTransforms?: Array<Transform>}) => void} safeEvaluate
11878
+ * @property {ResolveHook} resolveHook
11879
+ * @property {ImportHook} importHook
11880
+ * @property {ImportNowHook} importNowHook
11881
+ * @property {ModuleMap} moduleMap
11882
+ * @property {ModuleMapHook} moduleMapHook
11883
+ * @property {ImportMetaHook} importMetaHook
11884
+ * @property {Map<string, ModuleSource>} moduleRecords
11885
+ * @property {Array<Transform>} __shimTransforms__
11886
+ * @property {DeferredExports} deferredExports
11887
+ * @property {Map<string, ModuleDescriptor>} instances
11888
+ * @property {Compartment} [parentCompartment]
11889
+ * @property {boolean} noNamespaceBox
11890
+ * @property {(fullSpecifier: string) => Promise<ModuleExportsNamespace>} compartmentImport
11891
+ */
11892
+
11893
+ /**
11894
+ * Captures the private state for each {@link Compartment}
11895
+ * @type {WeakMap<Compartment, CompartmentFields>}
11896
+ */
11850
11897
  const privateFields = new WeakMap();
11851
11898
 
11852
11899
  const InertCompartment = function Compartment(
@@ -11862,6 +11909,7 @@ const privateFields = new WeakMap();
11862
11909
  /**
11863
11910
  * @param {Compartment} compartment
11864
11911
  * @param {string} specifier
11912
+ * @returns {{namespace: ModuleExportsNamespace}}
11865
11913
  */$h͏_once.InertCompartment(InertCompartment);
11866
11914
  const compartmentImportNow = (compartment, specifier) => {
11867
11915
  const { execute, exportsProxy } = link(
@@ -11874,27 +11922,20 @@ const compartmentImportNow = (compartment, specifier) => {
11874
11922
  return exportsProxy;
11875
11923
  };
11876
11924
 
11925
+ /** @type {Compartment & {constructor: typeof InertCompartment}} */
11877
11926
  const CompartmentPrototype = {
11878
11927
  constructor: InertCompartment,
11879
11928
 
11880
11929
  get globalThis() {
11881
- return weakmapGet(privateFields, this).globalObject;
11930
+ return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
11931
+ .globalObject;
11882
11932
  },
11883
11933
 
11884
11934
  get name() {
11885
- return weakmapGet(privateFields, this).name;
11935
+ return /** @type {CompartmentFields} */ (weakmapGet(privateFields, this))
11936
+ .name;
11886
11937
  },
11887
11938
 
11888
- /**
11889
- * @param {string} source is a JavaScript program grammar construction.
11890
- * @param {object} [options]
11891
- * @param {Array<import('./lockdown-shim').Transform>} [options.transforms]
11892
- * @param {boolean} [options.sloppyGlobalsMode]
11893
- * @param {object} [options.__moduleShimLexicals__]
11894
- * @param {boolean} [options.__evadeHtmlCommentTest__]
11895
- * @param {boolean} [options.__evadeImportExpressionTest__]
11896
- * @param {boolean} [options.__rejectSomeDirectEvalExpressions__]
11897
- */
11898
11939
  evaluate(source, options = {}) {
11899
11940
  const compartmentFields = weakmapGet(privateFields, this);
11900
11941
  return compartmentEvaluate(compartmentFields, source, options);
@@ -11916,7 +11957,9 @@ const compartmentImportNow = (compartment, specifier) => {
11916
11957
  },
11917
11958
 
11918
11959
  async import(specifier) {
11919
- const { noNamespaceBox } = weakmapGet(privateFields, this);
11960
+ const { noNamespaceBox } = /** @type {CompartmentFields} */ (
11961
+ weakmapGet(privateFields, this)
11962
+ );
11920
11963
 
11921
11964
  if (typeof specifier !== 'string') {
11922
11965
  throw TypeError('first argument of import() must be a string');
@@ -11955,7 +11998,7 @@ const compartmentImportNow = (compartment, specifier) => {
11955
11998
  }
11956
11999
 
11957
12000
  loadNow(privateFields, moduleAliases, this, specifier);
11958
- return compartmentImportNow(/** @type {Compartment} */ (this), specifier);
12001
+ return compartmentImportNow(this, specifier);
11959
12002
  },
11960
12003
  };
11961
12004
 
@@ -11986,15 +12029,35 @@ defineProperties(InertCompartment, {
11986
12029
  * @returns {Compartment['constructor']}
11987
12030
  */
11988
12031
 
11989
- // In order to facilitate migration from the deprecated signature
11990
- // of the compartment constructor,
11991
- // new Compartent(globals?, modules?, options?)
11992
- // to the new signature:
11993
- // new Compartment(options?)
11994
- // where globals and modules are expressed in the options bag instead of
11995
- // positional arguments, this function detects the temporary sigil __options__
11996
- // on the first argument and coerces compartments arguments into a single
11997
- // compartments object.
12032
+ /**
12033
+ * "Options bag"-style `Compartment` constructor arguments.
12034
+ * @typedef {[options?: CompartmentOptions & { __options__: true }]} CompartmentOptionsArgs
12035
+ */
12036
+
12037
+ /**
12038
+ * Legacy `Compartment` constructor arguments.
12039
+ *
12040
+ * @deprecated
12041
+ * @typedef {[globals?: Map<string, any>, modules?: Map<string, ModuleDescriptor>, options?: CompartmentOptions]} LegacyCompartmentOptionsArgs
12042
+ */
12043
+
12044
+ /**
12045
+ * In order to facilitate migration from the deprecated signature of the
12046
+ * compartment constructor,
12047
+ *
12048
+ * `new Compartent(globals?, modules?, options?)`
12049
+ *
12050
+ * to the new signature:
12051
+ *
12052
+ * `new Compartment(options?)`
12053
+ *
12054
+ * ...where globals and modules are expressed in the options bag instead of
12055
+ * positional arguments, this function detects the temporary sigil __options__
12056
+ * on the first argument and coerces compartments arguments into a single
12057
+ * compartments object.
12058
+ * @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
12059
+ * @returns {CompartmentOptions}
12060
+ */
11998
12061
  const compartmentOptions = (...args) => {
11999
12062
  if (args.length === 0) {
12000
12063
  return {};
@@ -12016,7 +12079,7 @@ defineProperties(InertCompartment, {
12016
12079
  globals = /** @type {Map<string, any>} */ ({}),
12017
12080
  modules = /** @type {Map<string, ModuleDescriptor>} */ ({}),
12018
12081
  options = {},
12019
- ] = args;
12082
+ ] = /** @type {LegacyCompartmentOptionsArgs} */ (args);
12020
12083
  assertEqual(
12021
12084
  options.modules,
12022
12085
  undefined,
@@ -12042,6 +12105,10 @@ defineProperties(InertCompartment, {
12042
12105
  markVirtualizedNativeFunction,
12043
12106
  { parentCompartment = undefined, enforceNew = false } = {},
12044
12107
  ) => {
12108
+ /**
12109
+ *
12110
+ * @param {CompartmentOptionsArgs|LegacyCompartmentOptionsArgs} args
12111
+ */
12045
12112
  function Compartment(...args) {
12046
12113
  if (enforceNew && new.target === undefined) {
12047
12114
  throw TypeError(