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/index.d.ts CHANGED
@@ -64,9 +64,10 @@ export type FinalStaticModuleType =
64
64
  | ThirdPartyStaticModuleInterface;
65
65
 
66
66
  export interface RedirectStaticModuleInterface {
67
- record: FinalStaticModuleType;
68
67
  specifier: string;
68
+ record?: FinalStaticModuleType;
69
69
  importMeta?: any;
70
+ compartment?: Compartment;
70
71
  }
71
72
 
72
73
  export type StaticModuleType =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ses",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Hardened JavaScript for Fearless Cooperation",
5
5
  "keywords": [
6
6
  "lockdown",
@@ -59,11 +59,11 @@
59
59
  "test:platform-compatibility": "node test/package/test.cjs"
60
60
  },
61
61
  "devDependencies": {
62
- "@endo/compartment-mapper": "^0.8.0",
63
- "@endo/eslint-config": "^0.5.1",
64
- "@endo/static-module-record": "^0.7.15",
65
- "@endo/test262-runner": "^0.1.28",
66
- "ava": "^3.12.1",
62
+ "@endo/compartment-mapper": "^0.8.1",
63
+ "@endo/eslint-config": "^0.5.2",
64
+ "@endo/static-module-record": "^0.7.16",
65
+ "@endo/test262-runner": "^0.1.29",
66
+ "ava": "^5.1.0",
67
67
  "babel-eslint": "^10.0.3",
68
68
  "c8": "^7.7.3",
69
69
  "eslint": "^7.32.0",
@@ -72,7 +72,7 @@
72
72
  "eslint-plugin-eslint-comments": "^3.1.2",
73
73
  "eslint-plugin-import": "^2.26.0",
74
74
  "eslint-plugin-prettier": "^3.4.1",
75
- "prettier": "^1.19.1",
75
+ "prettier": "^2.8.0",
76
76
  "sinon": "8.0.4",
77
77
  "terser": "^4.8.0",
78
78
  "tsd": "^0.24.1",
@@ -170,6 +170,7 @@
170
170
  ]
171
171
  },
172
172
  "prettier": {
173
+ "arrowParens": "avoid",
173
174
  "trailingComma": "all",
174
175
  "singleQuote": true
175
176
  },
@@ -179,5 +180,5 @@
179
180
  ],
180
181
  "timeout": "2m"
181
182
  },
182
- "gitHead": "da16a94856482e36296b7cae16d715aa63344928"
183
+ "gitHead": "ab8d64ae6fc9c628a2d1c02d16bf9ef249f5c8dc"
183
184
  }
@@ -13,10 +13,8 @@ import {
13
13
  import { makeSafeEvaluator } from './make-safe-evaluator.js';
14
14
 
15
15
  export const provideCompartmentEvaluator = (compartmentFields, options) => {
16
- const {
17
- sloppyGlobalsMode = false,
18
- __moduleShimLexicals__ = undefined,
19
- } = options;
16
+ const { sloppyGlobalsMode = false, __moduleShimLexicals__ = undefined } =
17
+ options;
20
18
 
21
19
  let safeEvaluate;
22
20
 
@@ -174,12 +174,8 @@ freeze(ErrorInfo);
174
174
 
175
175
  /** @type {MakeCausalConsole} */
176
176
  const makeCausalConsole = (baseConsole, loggedErrorHandler) => {
177
- const {
178
- getStackString,
179
- tagError,
180
- takeMessageLogArgs,
181
- takeNoteLogArgsArray,
182
- } = loggedErrorHandler;
177
+ const { getStackString, tagError, takeMessageLogArgs, takeNoteLogArgsArray } =
178
+ loggedErrorHandler;
183
179
 
184
180
  /**
185
181
  * @param {ReadonlyArray<any>} logArgs
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
  /**
15
- * @typedef {Object} AssertMakeErrorOptions
15
+ * @typedef {object} AssertMakeErrorOptions
16
16
  * @property {string=} errorName
17
17
  */
18
18
 
@@ -59,51 +59,65 @@
59
59
  */
60
60
 
61
61
  // Type all the overloads of the assertTypeof function.
62
- // There may eventually be a better way to do this, but they break with
63
- // Typescript 4.0.
62
+ // There may eventually be a better way to do this, but
63
+ // thems the breaks with Typescript 4.0.
64
64
  /**
65
65
  * @callback AssertTypeofBigint
66
66
  * @param {any} specimen
67
67
  * @param {'bigint'} typename
68
68
  * @param {Details=} optDetails
69
69
  * @returns {asserts specimen is bigint}
70
- *
70
+ */
71
+
72
+ /**
71
73
  * @callback AssertTypeofBoolean
72
74
  * @param {any} specimen
73
75
  * @param {'boolean'} typename
74
76
  * @param {Details=} optDetails
75
77
  * @returns {asserts specimen is boolean}
76
- *
78
+ */
79
+
80
+ /**
77
81
  * @callback AssertTypeofFunction
78
82
  * @param {any} specimen
79
83
  * @param {'function'} typename
80
84
  * @param {Details=} optDetails
81
85
  * @returns {asserts specimen is Function}
82
- *
86
+ */
87
+
88
+ /**
83
89
  * @callback AssertTypeofNumber
84
90
  * @param {any} specimen
85
91
  * @param {'number'} typename
86
92
  * @param {Details=} optDetails
87
93
  * @returns {asserts specimen is number}
88
- *
94
+ */
95
+
96
+ /**
89
97
  * @callback AssertTypeofObject
90
98
  * @param {any} specimen
91
99
  * @param {'object'} typename
92
100
  * @param {Details=} optDetails
93
101
  * @returns {asserts specimen is Record<any, any> | null}
94
- *
102
+ */
103
+
104
+ /**
95
105
  * @callback AssertTypeofString
96
106
  * @param {any} specimen
97
107
  * @param {'string'} typename
98
108
  * @param {Details=} optDetails
99
109
  * @returns {asserts specimen is string}
100
- *
110
+ */
111
+
112
+ /**
101
113
  * @callback AssertTypeofSymbol
102
114
  * @param {any} specimen
103
115
  * @param {'symbol'} typename
104
116
  * @param {Details=} optDetails
105
117
  * @returns {asserts specimen is symbol}
106
- *
118
+ */
119
+
120
+ /**
107
121
  * @callback AssertTypeofUndefined
108
122
  * @param {any} specimen
109
123
  * @param {'undefined'} typename
@@ -157,7 +171,7 @@
157
171
  */
158
172
 
159
173
  /**
160
- * @typedef {Object} StringablePayload
174
+ * @typedef {object} StringablePayload
161
175
  * Holds the payload passed to quote so that its printed form is visible.
162
176
  * @property {() => string} toString How to print the payload
163
177
  */
@@ -45,8 +45,10 @@ export const getAnonymousIntrinsics = () => {
45
45
 
46
46
  // 9.2.4.1 %ThrowTypeError%
47
47
 
48
- const ThrowTypeError = getOwnPropertyDescriptor(makeArguments(), 'callee')
49
- .get;
48
+ const ThrowTypeError = getOwnPropertyDescriptor(
49
+ makeArguments(),
50
+ 'callee',
51
+ ).get;
50
52
 
51
53
  // 21.1.5.2 The %StringIteratorPrototype% Object
52
54
 
@@ -151,10 +151,8 @@ export const repairIntrinsics = (options = {}) => {
151
151
  // [`stackFiltering` options](https://github.com/Agoric/SES-shim/blob/master/packages/ses/lockdown-options.md#stackfiltering-options)
152
152
  // for an explanation.
153
153
 
154
- const {
155
- getEnvironmentOption: getenv,
156
- getCapturedEnvironmentOptionNames,
157
- } = makeEnvironmentCaptor(globalThis);
154
+ const { getEnvironmentOption: getenv, getCapturedEnvironmentOptionNames } =
155
+ makeEnvironmentCaptor(globalThis);
158
156
 
159
157
  const {
160
158
  errorTaming = getenv('LOCKDOWN_ERROR_TAMING', 'safe'),
@@ -260,11 +258,8 @@ export const repairIntrinsics = (options = {}) => {
260
258
 
261
259
  tameDomains(domainTaming);
262
260
 
263
- const {
264
- addIntrinsics,
265
- completePrototypes,
266
- finalIntrinsics,
267
- } = makeIntrinsicsCollector();
261
+ const { addIntrinsics, completePrototypes, finalIntrinsics } =
262
+ makeIntrinsicsCollector();
268
263
 
269
264
  addIntrinsics({ harden });
270
265
 
@@ -134,6 +134,7 @@ export const makeModuleInstance = (
134
134
  __syncModuleProgram__: functorSource,
135
135
  __fixedExportMap__: fixedExportMap = {},
136
136
  __liveExportMap__: liveExportMap = {},
137
+ __reexportMap__: reexportMap = {},
137
138
  __needsImportMeta__: needsImportMeta = false,
138
139
  } = staticModuleRecord;
139
140
 
@@ -387,26 +388,35 @@ export const makeModuleInstance = (
387
388
  }
388
389
  if (arrayIncludes(exportAlls, specifier)) {
389
390
  // Make all these imports candidates.
390
- for (const [importName, importNotify] of entries(importNotifiers)) {
391
- if (candidateAll[importName] === undefined) {
392
- candidateAll[importName] = importNotify;
391
+ // Note names don't change in reexporting all
392
+ for (const [importAndExportName, importNotify] of entries(
393
+ importNotifiers,
394
+ )) {
395
+ if (candidateAll[importAndExportName] === undefined) {
396
+ candidateAll[importAndExportName] = importNotify;
393
397
  } else {
394
398
  // Already a candidate: remove ambiguity.
395
- candidateAll[importName] = false;
399
+ candidateAll[importAndExportName] = false;
396
400
  }
397
401
  }
398
402
  }
403
+ if (reexportMap[specifier]) {
404
+ // Make named reexports candidates too.
405
+ for (const [localName, exportedName] of reexportMap[specifier]) {
406
+ candidateAll[exportedName] = importNotifiers[localName];
407
+ }
408
+ }
399
409
  }
400
410
 
401
- for (const [importName, notify] of entries(candidateAll)) {
402
- if (!notifiers[importName] && notify !== false) {
403
- notifiers[importName] = notify;
411
+ for (const [exportName, notify] of entries(candidateAll)) {
412
+ if (!notifiers[exportName] && notify !== false) {
413
+ notifiers[exportName] = notify;
404
414
 
405
415
  // exported live binding state
406
416
  let value;
407
417
  const update = newValue => (value = newValue);
408
418
  notify(update);
409
- exportsProps[importName] = {
419
+ exportsProps[exportName] = {
410
420
  get() {
411
421
  return value;
412
422
  },
@@ -120,12 +120,8 @@ export const instantiate = (
120
120
  moduleAliases,
121
121
  moduleRecord,
122
122
  ) => {
123
- const {
124
- compartment,
125
- moduleSpecifier,
126
- resolvedImports,
127
- staticModuleRecord,
128
- } = moduleRecord;
123
+ const { compartment, moduleSpecifier, resolvedImports, staticModuleRecord } =
124
+ moduleRecord;
129
125
  const { instances } = weakmapGet(compartmentPrivateFields, compartment);
130
126
 
131
127
  // Memoize.
@@ -54,7 +54,7 @@ const resolveAll = (imports, resolveHook, fullReferrerSpecifier) => {
54
54
  return freeze(resolvedImports);
55
55
  };
56
56
 
57
- const loadRecord = async (
57
+ const loadRecord = (
58
58
  compartmentPrivateFields,
59
59
  moduleAliases,
60
60
  compartment,
@@ -175,27 +175,64 @@ const loadWithoutErrorAnnotation = async (
175
175
  )} in compartment ${q(compartment.name)}`;
176
176
  }
177
177
 
178
- if (staticModuleRecord.record !== undefined) {
179
- const {
180
- compartment: aliasCompartment = compartment,
181
- specifier: aliasSpecifier = moduleSpecifier,
182
- record: aliasModuleRecord,
183
- importMeta,
184
- } = staticModuleRecord;
178
+ // check if record is a RedirectStaticModuleInterface
179
+ if (staticModuleRecord.specifier !== undefined) {
180
+ // check if this redirect with an explicit record
181
+ if (staticModuleRecord.record !== undefined) {
182
+ // ensure expected record shape
183
+ if (staticModuleRecord.compartment !== undefined) {
184
+ throw new TypeError(
185
+ 'Cannot redirect to an explicit record with a specified compartment',
186
+ );
187
+ }
188
+ const {
189
+ compartment: aliasCompartment = compartment,
190
+ specifier: aliasSpecifier = moduleSpecifier,
191
+ record: aliasModuleRecord,
192
+ importMeta,
193
+ } = staticModuleRecord;
185
194
 
186
- const aliasRecord = await loadRecord(
187
- compartmentPrivateFields,
188
- moduleAliases,
189
- aliasCompartment,
190
- aliasSpecifier,
191
- aliasModuleRecord,
192
- pendingJobs,
193
- moduleLoads,
194
- errors,
195
- importMeta,
195
+ const aliasRecord = loadRecord(
196
+ compartmentPrivateFields,
197
+ moduleAliases,
198
+ aliasCompartment,
199
+ aliasSpecifier,
200
+ aliasModuleRecord,
201
+ pendingJobs,
202
+ moduleLoads,
203
+ errors,
204
+ importMeta,
205
+ );
206
+ mapSet(moduleRecords, moduleSpecifier, aliasRecord);
207
+ return aliasRecord;
208
+ }
209
+
210
+ // check if this redirect with an explicit compartment
211
+ if (staticModuleRecord.compartment !== undefined) {
212
+ // ensure expected record shape
213
+ if (staticModuleRecord.importMeta !== undefined) {
214
+ throw new TypeError(
215
+ 'Cannot redirect to an implicit record with a specified importMeta',
216
+ );
217
+ }
218
+ // Behold: recursion.
219
+ // eslint-disable-next-line no-use-before-define
220
+ const aliasRecord = await memoizedLoadWithErrorAnnotation(
221
+ compartmentPrivateFields,
222
+ moduleAliases,
223
+ staticModuleRecord.compartment,
224
+ staticModuleRecord.specifier,
225
+ pendingJobs,
226
+ moduleLoads,
227
+ errors,
228
+ );
229
+ mapSet(moduleRecords, moduleSpecifier, aliasRecord);
230
+ return aliasRecord;
231
+ }
232
+
233
+ throw new TypeError(
234
+ 'Unnexpected RedirectStaticModuleInterface record shape',
196
235
  );
197
- mapSet(moduleRecords, moduleSpecifier, aliasRecord);
198
- return aliasRecord;
199
236
  }
200
237
 
201
238
  return loadRecord(
@@ -5,6 +5,7 @@ import {
5
5
  defineProperties,
6
6
  getPrototypeOf,
7
7
  setPrototypeOf,
8
+ freeze,
8
9
  } from './commons.js';
9
10
 
10
11
  // This module replaces the original `Function` constructor, and the original
@@ -49,7 +50,7 @@ export default function tameFunctionConstructors() {
49
50
  FERAL_FUNCTION.prototype.constructor('return 1');
50
51
  } catch (ignore) {
51
52
  // Throws, no need to patch.
52
- return harden({});
53
+ return freeze({});
53
54
  }
54
55
 
55
56
  const newIntrinsics = {};
@@ -82,7 +83,7 @@ export default function tameFunctionConstructors() {
82
83
  // Prevents the evaluation of source when calling constructor on the
83
84
  // prototype of functions.
84
85
  // eslint-disable-next-line func-names
85
- const InertConstructor = function() {
86
+ const InertConstructor = function () {
86
87
  throw new TypeError(
87
88
  'Function.prototype.constructor is not a valid constructor.',
88
89
  );
@@ -13,9 +13,8 @@ export default function tameMathObject(mathTaming = 'safe') {
13
13
  const originalMath = Math;
14
14
  const initialMath = originalMath; // to follow the naming pattern
15
15
 
16
- const { random: _, ...otherDescriptors } = getOwnPropertyDescriptors(
17
- originalMath,
18
- );
16
+ const { random: _, ...otherDescriptors } =
17
+ getOwnPropertyDescriptors(originalMath);
19
18
 
20
19
  const sharedMath = create(objectPrototype, otherDescriptors);
21
20