ses 1.5.0 → 1.6.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.
@@ -69,11 +69,12 @@ export const setGlobalObjectConstantProperties = globalObject => {
69
69
  * `sharedGlobalPropertyNames`.
70
70
  *
71
71
  * @param {object} globalObject
72
- * @param {object} param1
73
- * @param {object} param1.intrinsics
74
- * @param {object} param1.newGlobalPropertyNames
75
- * @param {Function} param1.makeCompartmentConstructor
76
- * @param {(object) => void} param1.markVirtualizedNativeFunction
72
+ * @param {object} args
73
+ * @param {object} args.intrinsics
74
+ * @param {object} args.newGlobalPropertyNames
75
+ * @param {Function} args.makeCompartmentConstructor
76
+ * @param {(object) => void} args.markVirtualizedNativeFunction
77
+ * @param {Compartment} [args.parentCompartment]
77
78
  */
78
79
  export const setGlobalObjectMutableProperties = (
79
80
  globalObject,
@@ -82,6 +83,7 @@ export const setGlobalObjectMutableProperties = (
82
83
  newGlobalPropertyNames,
83
84
  makeCompartmentConstructor,
84
85
  markVirtualizedNativeFunction,
86
+ parentCompartment,
85
87
  },
86
88
  ) => {
87
89
  for (const [name, intrinsicName] of entries(universalPropertyNames)) {
@@ -115,6 +117,7 @@ export const setGlobalObjectMutableProperties = (
115
117
  makeCompartmentConstructor,
116
118
  intrinsics,
117
119
  markVirtualizedNativeFunction,
120
+ parentCompartment,
118
121
  ),
119
122
  );
120
123
 
package/src/lockdown.js CHANGED
@@ -58,7 +58,7 @@ import { tameFauxDataProperties } from './tame-faux-data-properties.js';
58
58
 
59
59
  /** @import {LockdownOptions} from '../types.js' */
60
60
 
61
- const { Fail, details: d, quote: q } = assert;
61
+ const { Fail, details: X, quote: q } = assert;
62
62
 
63
63
  /** @type {Error=} */
64
64
  let priorRepairIntrinsics;
@@ -200,7 +200,7 @@ export const repairIntrinsics = (options = {}) => {
200
200
  priorRepairIntrinsics === undefined ||
201
201
  // eslint-disable-next-line @endo/no-polymorphic-call
202
202
  assert.fail(
203
- d`Already locked down at ${priorRepairIntrinsics} (SES_ALREADY_LOCKED_DOWN)`,
203
+ X`Already locked down at ${priorRepairIntrinsics} (SES_ALREADY_LOCKED_DOWN)`,
204
204
  TypeError,
205
205
  );
206
206
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_ALREADY_LOCKED_DOWN.md
@@ -298,7 +298,7 @@ export const repairIntrinsics = (options = {}) => {
298
298
  * @type {((error: any) => string | undefined) | undefined}
299
299
  */
300
300
  let optGetStackString;
301
- if (errorTaming !== 'unsafe') {
301
+ if (errorTaming === 'safe') {
302
302
  optGetStackString = intrinsics['%InitialGetStackString%'];
303
303
  }
304
304
  const consoleRecord = tameConsole(
@@ -323,8 +323,12 @@ export const repairIntrinsics = (options = {}) => {
323
323
  }
324
324
 
325
325
  // @ts-ignore assert is absent on globalThis type def.
326
- if (errorTaming === 'unsafe' && globalThis.assert === assert) {
327
- // If errorTaming is 'unsafe' we replace the global assert with
326
+ if (
327
+ (errorTaming === 'unsafe' || errorTaming === 'unsafe-debug') &&
328
+ globalThis.assert === assert
329
+ ) {
330
+ // If errorTaming is 'unsafe' or 'unsafe-debug' we replace the
331
+ // global assert with
328
332
  // one whose `details` template literal tag does not redact
329
333
  // unmarked substitution values. IOW, it blabs information that
330
334
  // was supposed to be secret from callers, as an aid to debugging
@@ -391,7 +395,7 @@ export const repairIntrinsics = (options = {}) => {
391
395
  priorHardenIntrinsics === undefined ||
392
396
  // eslint-disable-next-line @endo/no-polymorphic-call
393
397
  assert.fail(
394
- d`Already locked down at ${priorHardenIntrinsics} (SES_ALREADY_LOCKED_DOWN)`,
398
+ X`Already locked down at ${priorHardenIntrinsics} (SES_ALREADY_LOCKED_DOWN)`,
395
399
  TypeError,
396
400
  );
397
401
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_ALREADY_LOCKED_DOWN.md
@@ -24,9 +24,9 @@ import { compartmentEvaluate } from './compartment-evaluate.js';
24
24
 
25
25
  const { quote: q } = assert;
26
26
 
27
- export const makeThirdPartyModuleInstance = (
27
+ export const makeVirtualModuleInstance = (
28
28
  compartmentPrivateFields,
29
- staticModuleRecord,
29
+ moduleSource,
30
30
  compartment,
31
31
  moduleAliases,
32
32
  moduleSpecifier,
@@ -41,16 +41,16 @@ export const makeThirdPartyModuleInstance = (
41
41
 
42
42
  const notifiers = create(null);
43
43
 
44
- if (staticModuleRecord.exports) {
44
+ if (moduleSource.exports) {
45
45
  if (
46
- !isArray(staticModuleRecord.exports) ||
47
- arraySome(staticModuleRecord.exports, name => typeof name !== 'string')
46
+ !isArray(moduleSource.exports) ||
47
+ arraySome(moduleSource.exports, name => typeof name !== 'string')
48
48
  ) {
49
49
  throw TypeError(
50
- `SES third-party static module record "exports" property must be an array of strings for module ${moduleSpecifier}`,
50
+ `SES virtual module source "exports" property must be an array of strings for module ${moduleSpecifier}`,
51
51
  );
52
52
  }
53
- arrayForEach(staticModuleRecord.exports, name => {
53
+ arrayForEach(moduleSource.exports, name => {
54
54
  let value = exportsTarget[name];
55
55
  const updaters = [];
56
56
 
@@ -96,11 +96,7 @@ export const makeThirdPartyModuleInstance = (
96
96
  localState.activated = true;
97
97
  try {
98
98
  // eslint-disable-next-line @endo/no-polymorphic-call
99
- staticModuleRecord.execute(
100
- exportsTarget,
101
- compartment,
102
- resolvedImports,
103
- );
99
+ moduleSource.execute(exportsTarget, compartment, resolvedImports);
104
100
  } catch (err) {
105
101
  localState.errorFromExecute = err;
106
102
  throw err;
@@ -126,7 +122,7 @@ export const makeModuleInstance = (
126
122
  const {
127
123
  compartment,
128
124
  moduleSpecifier,
129
- staticModuleRecord,
125
+ moduleSource,
130
126
  importMeta: moduleRecordMeta,
131
127
  } = moduleRecord;
132
128
  const {
@@ -137,7 +133,7 @@ export const makeModuleInstance = (
137
133
  __reexportMap__: reexportMap = {},
138
134
  __needsImportMeta__: needsImportMeta = false,
139
135
  __syncModuleFunctor__,
140
- } = staticModuleRecord;
136
+ } = moduleSource;
141
137
 
142
138
  const compartmentFields = weakmapGet(privateFields, compartment);
143
139
 
@@ -1,17 +1,9 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
2
 
3
- // For brevity, in this file, as in module-load.js, the term "moduleRecord"
4
- // without qualification means "module compartment record".
5
- // This is a super-set of the "static module record", that is reusable between
6
- // compartments with different hooks.
7
- // The "module compartment record" captures the compartment and overlays the
8
- // module's "imports" with the more specific "resolvedImports" as inferred from
9
- // the particular compartment's "resolveHook".
10
-
11
3
  import { assert } from './error/assert.js';
12
4
  import {
13
5
  makeModuleInstance,
14
- makeThirdPartyModuleInstance,
6
+ makeVirtualModuleInstance,
15
7
  } from './module-instance.js';
16
8
  import {
17
9
  Map,
@@ -61,56 +53,50 @@ export const link = (
61
53
  return instantiate(compartmentPrivateFields, moduleAliases, moduleRecord);
62
54
  };
63
55
 
64
- function isPrecompiled(staticModuleRecord) {
65
- return typeof staticModuleRecord.__syncModuleProgram__ === 'string';
56
+ function mayBePrecompiledModuleSource(moduleSource) {
57
+ return typeof moduleSource.__syncModuleProgram__ === 'string';
66
58
  }
67
59
 
68
- function validatePrecompiledStaticModuleRecord(
69
- staticModuleRecord,
70
- moduleSpecifier,
71
- ) {
72
- const { __fixedExportMap__, __liveExportMap__ } = staticModuleRecord;
60
+ function validatePrecompiledModuleSource(moduleSource, moduleSpecifier) {
61
+ const { __fixedExportMap__, __liveExportMap__ } = moduleSource;
73
62
  isObject(__fixedExportMap__) ||
74
- Fail`Property '__fixedExportMap__' of a precompiled module record must be an object, got ${q(
63
+ Fail`Property '__fixedExportMap__' of a precompiled module source must be an object, got ${q(
75
64
  __fixedExportMap__,
76
65
  )}, for module ${q(moduleSpecifier)}`;
77
66
  isObject(__liveExportMap__) ||
78
- Fail`Property '__liveExportMap__' of a precompiled module record must be an object, got ${q(
67
+ Fail`Property '__liveExportMap__' of a precompiled module source must be an object, got ${q(
79
68
  __liveExportMap__,
80
69
  )}, for module ${q(moduleSpecifier)}`;
81
70
  }
82
71
 
83
- function isThirdParty(staticModuleRecord) {
84
- return typeof staticModuleRecord.execute === 'function';
72
+ function mayBeVirtualModuleSource(moduleSource) {
73
+ return typeof moduleSource.execute === 'function';
85
74
  }
86
75
 
87
- function validateThirdPartyStaticModuleRecord(
88
- staticModuleRecord,
89
- moduleSpecifier,
90
- ) {
91
- const { exports } = staticModuleRecord;
76
+ function validateVirtualModuleSource(moduleSource, moduleSpecifier) {
77
+ const { exports } = moduleSource;
92
78
  isArray(exports) ||
93
- Fail`Property 'exports' of a third-party static module record must be an array, got ${q(
79
+ Fail`Property 'exports' of a third-party module source must be an array, got ${q(
94
80
  exports,
95
81
  )}, for module ${q(moduleSpecifier)}`;
96
82
  }
97
83
 
98
- function validateStaticModuleRecord(staticModuleRecord, moduleSpecifier) {
99
- isObject(staticModuleRecord) ||
100
- Fail`Static module records must be of type object, got ${q(
101
- staticModuleRecord,
84
+ function validateModuleSource(moduleSource, moduleSpecifier) {
85
+ isObject(moduleSource) ||
86
+ Fail`Module sources must be of type object, got ${q(
87
+ moduleSource,
102
88
  )}, for module ${q(moduleSpecifier)}`;
103
- const { imports, exports, reexports = [] } = staticModuleRecord;
89
+ const { imports, exports, reexports = [] } = moduleSource;
104
90
  isArray(imports) ||
105
- Fail`Property 'imports' of a static module record must be an array, got ${q(
91
+ Fail`Property 'imports' of a module source must be an array, got ${q(
106
92
  imports,
107
93
  )}, for module ${q(moduleSpecifier)}`;
108
94
  isArray(exports) ||
109
- Fail`Property 'exports' of a precompiled module record must be an array, got ${q(
95
+ Fail`Property 'exports' of a precompiled module source must be an array, got ${q(
110
96
  exports,
111
97
  )}, for module ${q(moduleSpecifier)}`;
112
98
  isArray(reexports) ||
113
- Fail`Property 'reexports' of a precompiled module record must be an array if present, got ${q(
99
+ Fail`Property 'reexports' of a precompiled module source must be an array if present, got ${q(
114
100
  reexports,
115
101
  )}, for module ${q(moduleSpecifier)}`;
116
102
  }
@@ -120,7 +106,7 @@ export const instantiate = (
120
106
  moduleAliases,
121
107
  moduleRecord,
122
108
  ) => {
123
- const { compartment, moduleSpecifier, resolvedImports, staticModuleRecord } =
109
+ const { compartment, moduleSpecifier, resolvedImports, moduleSource } =
124
110
  moduleRecord;
125
111
  const { instances } = weakmapGet(compartmentPrivateFields, compartment);
126
112
 
@@ -129,23 +115,23 @@ export const instantiate = (
129
115
  return mapGet(instances, moduleSpecifier);
130
116
  }
131
117
 
132
- validateStaticModuleRecord(staticModuleRecord, moduleSpecifier);
118
+ validateModuleSource(moduleSource, moduleSpecifier);
133
119
 
134
120
  const importedInstances = new Map();
135
121
  let moduleInstance;
136
- if (isPrecompiled(staticModuleRecord)) {
137
- validatePrecompiledStaticModuleRecord(staticModuleRecord, moduleSpecifier);
122
+ if (mayBePrecompiledModuleSource(moduleSource)) {
123
+ validatePrecompiledModuleSource(moduleSource, moduleSpecifier);
138
124
  moduleInstance = makeModuleInstance(
139
125
  compartmentPrivateFields,
140
126
  moduleAliases,
141
127
  moduleRecord,
142
128
  importedInstances,
143
129
  );
144
- } else if (isThirdParty(staticModuleRecord)) {
145
- validateThirdPartyStaticModuleRecord(staticModuleRecord, moduleSpecifier);
146
- moduleInstance = makeThirdPartyModuleInstance(
130
+ } else if (mayBeVirtualModuleSource(moduleSource)) {
131
+ validateVirtualModuleSource(moduleSource, moduleSpecifier);
132
+ moduleInstance = makeVirtualModuleInstance(
147
133
  compartmentPrivateFields,
148
- staticModuleRecord,
134
+ moduleSource,
149
135
  compartment,
150
136
  moduleAliases,
151
137
  moduleSpecifier,
@@ -153,9 +139,7 @@ export const instantiate = (
153
139
  );
154
140
  } else {
155
141
  throw TypeError(
156
- `importHook must return a static module record, got ${q(
157
- staticModuleRecord,
158
- )}`,
142
+ `importHook must provide a module source, got ${q(moduleSource)}`,
159
143
  );
160
144
  }
161
145