ses 1.9.1 → 1.11.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.
@@ -24,7 +24,7 @@
24
24
  // Typically, this module will not be used directly, but via the
25
25
  // [lockdown-shim] which handles all necessary repairs and taming in SES.
26
26
  //
27
- // In the whitelist, the `prototype`, `__proto__`, and `constructor` must be
27
+ // In the permits, the `prototype`, `__proto__`, and `constructor` must be
28
28
  // specified and point to top level entries in the map. For example,
29
29
  // `Object.__proto__` leads to `FunctionPrototype` which is a top level entry
30
30
  // in the map.
@@ -34,14 +34,14 @@
34
34
  // `Error.stackTraceLimit` leads to 'number'),
35
35
  // * the name of an intrinsic,
36
36
  // * an internal constant(for example, `eval` leads to `fn` which
37
- // is an alias for `FunctionInstance`, a record that whitelist all
37
+ // is an alias for `FunctionInstance`, a record that permits all
38
38
  // properties allowed on such instance).
39
39
  // * false, a property to be removed that we know about.
40
40
  //
41
41
  // All unlisted properties are also removed. But for the ones that are removed
42
42
  // because they are unlisted, as opposed to `false`, we also print their
43
43
  // name to the console as a useful diagnostic, possibly provoking an expansion
44
- // of the whitelist.
44
+ // of the permits.
45
45
 
46
46
  import { permitted, FunctionInstance, isAccessorPermit } from './permits.js';
47
47
  import {
@@ -61,30 +61,25 @@ import {
61
61
  ownKeys,
62
62
  symbolKeyFor,
63
63
  } from './commons.js';
64
+ import { cauterizeProperty } from './cauterize-property.js';
65
+
66
+ /**
67
+ * @import {Reporter} from './reporting-types.js'
68
+ */
64
69
 
65
70
  /**
66
- * whitelistIntrinsics()
67
71
  * Removes all non-allowed properties found by recursively and
68
72
  * reflectively walking own property chains.
69
73
  *
70
74
  * @param {object} intrinsics
71
- * @param {(object) => void} markVirtualizedNativeFunction
75
+ * @param {(virtualizedNativeFunction: object) => void} markVirtualizedNativeFunction
76
+ * @param {Reporter} reporter
72
77
  */
73
- export default function whitelistIntrinsics(
78
+ export default function removeUnpermittedIntrinsics(
74
79
  intrinsics,
75
80
  markVirtualizedNativeFunction,
81
+ reporter,
76
82
  ) {
77
- let groupStarted = false;
78
- const inConsoleGroup = (level, ...args) => {
79
- if (!groupStarted) {
80
- // eslint-disable-next-line @endo/no-polymorphic-call
81
- console.groupCollapsed('Removing unpermitted intrinsics');
82
- groupStarted = true;
83
- }
84
- // eslint-disable-next-line @endo/no-polymorphic-call
85
- return console[level](...args);
86
- };
87
-
88
83
  // These primitives are allowed for permits.
89
84
  const primitives = ['undefined', 'boolean', 'number', 'string', 'symbol'];
90
85
 
@@ -148,7 +143,7 @@ export default function whitelistIntrinsics(
148
143
 
149
144
  // Assert: protoName, if provided, is a string.
150
145
  if (protoName !== undefined && typeof protoName !== 'string') {
151
- throw TypeError(`Malformed whitelist permit ${path}.__proto__`);
146
+ throw TypeError(`Malformed permit ${path}.__proto__`);
152
147
  }
153
148
 
154
149
  // If permit not specified, default to Object.prototype.
@@ -164,7 +159,7 @@ export default function whitelistIntrinsics(
164
159
 
165
160
  /*
166
161
  * isAllowedPropertyValue()
167
- * Whitelist a single property value against a permit.
162
+ * enforce permit for a single property value.
168
163
  */
169
164
  function isAllowedPropertyValue(path, value, prop, permit) {
170
165
  if (typeof permit === 'object') {
@@ -192,7 +187,7 @@ export default function whitelistIntrinsics(
192
187
 
193
188
  if (objectHasOwnProperty(intrinsics, permit)) {
194
189
  if (value !== intrinsics[permit]) {
195
- throw TypeError(`Does not match whitelist ${path}`);
190
+ throw TypeError(`Does not match permit for ${path}`);
196
191
  }
197
192
  return true;
198
193
  }
@@ -285,50 +280,12 @@ export default function whitelistIntrinsics(
285
280
  const subPermit = getSubPermit(obj, permit, propString);
286
281
 
287
282
  if (!subPermit || !isAllowedProperty(subPath, obj, prop, subPermit)) {
288
- // Either the object lacks a permit or the object doesn't match the
289
- // permit.
290
- // If the permit is specifically false, not merely undefined,
291
- // this is a property we expect to see because we know it exists in
292
- // some environments and we have expressly decided to exclude it.
293
- // Any other disallowed property is one we have not audited and we log
294
- // that we are removing it so we know to look into it, as happens when
295
- // the language evolves new features to existing intrinsics.
296
- if (subPermit !== false) {
297
- inConsoleGroup('warn', `Removing ${subPath}`);
298
- }
299
- try {
300
- delete obj[prop];
301
- } catch (err) {
302
- if (prop in obj) {
303
- if (typeof obj === 'function' && prop === 'prototype') {
304
- obj.prototype = undefined;
305
- if (obj.prototype === undefined) {
306
- inConsoleGroup(
307
- 'warn',
308
- `Tolerating undeletable ${subPath} === undefined`,
309
- );
310
- // eslint-disable-next-line no-continue
311
- continue;
312
- }
313
- }
314
- inConsoleGroup('error', `failed to delete ${subPath}`, err);
315
- } else {
316
- inConsoleGroup('error', `deleting ${subPath} threw`, err);
317
- }
318
- throw err;
319
- }
283
+ cauterizeProperty(obj, prop, subPermit === false, subPath, reporter);
320
284
  }
321
285
  }
322
286
  }
323
287
 
324
- try {
325
- // Start path with 'intrinsics' to clarify that properties are not
326
- // removed from the global object by the whitelisting operation.
327
- visitProperties('intrinsics', intrinsics, permitted);
328
- } finally {
329
- if (groupStarted) {
330
- // eslint-disable-next-line @endo/no-polymorphic-call
331
- console.groupEnd();
332
- }
333
- }
288
+ // Start path with 'intrinsics' to clarify that properties are not
289
+ // removed from the global object by the permitting operation.
290
+ visitProperties('intrinsics', intrinsics, permitted);
334
291
  }
package/src/permits.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable no-restricted-globals */
2
2
  /* eslint max-lines: 0 */
3
3
 
4
- import { arrayPush } from './commons.js';
4
+ import { arrayPush, arrayForEach } from './commons.js';
5
5
 
6
6
  /** @import {GenericErrorConstructor} from '../types.js' */
7
7
 
8
8
  /**
9
- * @file Exports {@code whitelist}, a recursively defined
9
+ * @module Exports {@code permits}, a recursively defined
10
10
  * JSON record enumerating all intrinsics and their properties
11
11
  * according to ECMA specs.
12
12
  *
@@ -32,7 +32,7 @@ export const constantProperties = {
32
32
  * universalPropertyNames
33
33
  * Properties of all global objects.
34
34
  * Must be powerless.
35
- * Maps from property name to the intrinsic name in the whitelist.
35
+ * Maps from property name to the intrinsic name in the permits.
36
36
  */
37
37
  export const universalPropertyNames = {
38
38
  // *** Function Properties of the Global Object
@@ -89,6 +89,15 @@ export const universalPropertyNames = {
89
89
  // https://github.com/endojs/endo/issues/550
90
90
  AggregateError: 'AggregateError',
91
91
 
92
+ // https://github.com/tc39/proposal-explicit-resource-management
93
+ // TODO DisposableStack, AsyncDisposableStack
94
+ // DisposableStack: 'DisposableStack',
95
+ // AsyncDisposableStack: 'AsyncDisposableStack',
96
+
97
+ // https://tc39.es/proposal-shadowrealm/
98
+ // TODO ShadowRealm
99
+ // ShadowRealm: 'ShadowRealm',
100
+
92
101
  // *** Other Properties of the Global Object
93
102
 
94
103
  JSON: 'JSON',
@@ -115,7 +124,7 @@ export const universalPropertyNames = {
115
124
  * Those found only on the initial global, i.e., the global of the
116
125
  * start compartment, as well as any compartments created before lockdown.
117
126
  * These may provide much of the power provided by the original.
118
- * Maps from property name to the intrinsic name in the whitelist.
127
+ * Maps from property name to the intrinsic name in the permits.
119
128
  */
120
129
  export const initialGlobalPropertyNames = {
121
130
  // *** Constructor Properties of the Global Object
@@ -125,7 +134,7 @@ export const initialGlobalPropertyNames = {
125
134
  RegExp: '%InitialRegExp%',
126
135
 
127
136
  // Omit `Symbol`, because we want the original to appear on the
128
- // start compartment without passing through the whitelist mechanism, since
137
+ // start compartment without passing through the permits mechanism, since
129
138
  // we want to preserve all its properties, even if we never heard of them.
130
139
  // Symbol: '%InitialSymbol%',
131
140
 
@@ -143,13 +152,17 @@ export const initialGlobalPropertyNames = {
143
152
  // TODO https://github.com/Agoric/SES-shim/issues/551
144
153
  // Need initial WeakRef and FinalizationGroup in
145
154
  // start compartment only.
155
+
156
+ // TODO Temporal
157
+ // https://github.com/tc39/proposal-temporal
158
+ // Temporal: '%InitialTemporal%' // with Temporal.Now
146
159
  };
147
160
 
148
161
  /**
149
162
  * sharedGlobalPropertyNames
150
163
  * Those found only on the globals of new compartments created after lockdown,
151
164
  * which must therefore be powerless.
152
- * Maps from property name to the intrinsic name in the whitelist.
165
+ * Maps from property name to the intrinsic name in the permits.
153
166
  */
154
167
  export const sharedGlobalPropertyNames = {
155
168
  // *** Constructor Properties of the Global Object
@@ -162,13 +175,17 @@ export const sharedGlobalPropertyNames = {
162
175
  // *** Other Properties of the Global Object
163
176
 
164
177
  Math: '%SharedMath%',
178
+
179
+ // TODO Temporal
180
+ // https://github.com/tc39/proposal-temporal
181
+ // Temporal: '%SharedTemporal%' // without Temporal.Now
165
182
  };
166
183
 
167
184
  /**
168
185
  * uniqueGlobalPropertyNames
169
186
  * Those made separately for each global, including the initial global
170
187
  * of the start compartment.
171
- * Maps from property name to the intrinsic name in the whitelist
188
+ * Maps from property name to the intrinsic name in the permits
172
189
  * (which is currently always the same).
173
190
  */
174
191
  export const uniqueGlobalPropertyNames = {
@@ -228,18 +245,18 @@ export { NativeErrors };
228
245
  * blacklisted and simply removed. Properties not mentioned
229
246
  * are also considered blacklisted and are removed.
230
247
  * <li>A string value equal to a primitive ("number", "string", etc),
231
- * in which case the property is whitelisted if its value property
248
+ * in which case the property is permitted if its value property
232
249
  * is typeof the given type. For example, {@code "Infinity"} leads to
233
250
  * "number" and property values that fail {@code typeof "number"}.
234
251
  * are removed.
235
252
  * <li>A string value equal to an intinsic name ("ObjectPrototype",
236
- * "Array", etc), in which case the property whitelisted if its
253
+ * "Array", etc), in which case the property permitted if its
237
254
  * value property is equal to the value of the corresponfing
238
255
  * intrinsics. For example, {@code Map.prototype} leads to
239
256
  * "MapPrototype" and the property is removed if its value is
240
257
  * not equal to %MapPrototype%
241
258
  * <li>Another record, in which case this property is simply
242
- * whitelisted and that next record represents the disposition of
259
+ * permitted and that next record represents the disposition of
243
260
  * the object which is its value. For example, {@code "Object"}
244
261
  * leads to another record explaining what properties {@code
245
262
  * "Object"} may have and how each such property should be treated.
@@ -299,6 +316,24 @@ const accessor = {
299
316
  set: fn,
300
317
  };
301
318
 
319
+ // eslint-disable-next-line func-names
320
+ const strict = function () {
321
+ 'use strict';
322
+ };
323
+
324
+ // TODO Remove this once we no longer support the Hermes that needed this.
325
+ arrayForEach(['caller', 'arguments'], prop => {
326
+ try {
327
+ strict[prop];
328
+ } catch (e) {
329
+ // https://github.com/facebook/hermes/blob/main/test/hermes/function-non-strict.js
330
+ if (e.message === 'Restricted in strict mode') {
331
+ // Fixed in Static Hermes: https://github.com/facebook/hermes/issues/1582
332
+ FunctionInstance[prop] = accessor;
333
+ }
334
+ }
335
+ });
336
+
302
337
  export const isAccessorPermit = permit => {
303
338
  return permit === getter || permit === accessor;
304
339
  };
@@ -393,6 +428,11 @@ const CommonMath = {
393
428
  tan: fn,
394
429
  tanh: fn,
395
430
  trunc: fn,
431
+ // https://github.com/tc39/proposal-float16array
432
+ f16round: fn,
433
+ // https://github.com/tc39/proposal-math-sum
434
+ sumPrecise: fn,
435
+
396
436
  // See https://github.com/Moddable-OpenSource/moddable/issues/523
397
437
  idiv: false,
398
438
  // See https://github.com/Moddable-OpenSource/moddable/issues/523
@@ -455,7 +495,6 @@ export const permitted = {
455
495
  getOwnPropertyNames: fn,
456
496
  getOwnPropertySymbols: fn,
457
497
  getPrototypeOf: fn,
458
- hasOwn: fn,
459
498
  is: fn,
460
499
  isExtensible: fn,
461
500
  isFrozen: fn,
@@ -466,6 +505,8 @@ export const permitted = {
466
505
  seal: fn,
467
506
  setPrototypeOf: fn,
468
507
  values: fn,
508
+ // https://github.com/tc39/proposal-accessible-object-hasownproperty
509
+ hasOwn: fn,
469
510
  // https://github.com/tc39/proposal-array-grouping
470
511
  groupBy: fn,
471
512
  // Seen on QuickJS
@@ -537,9 +578,7 @@ export const permitted = {
537
578
  '%SharedSymbol%': {
538
579
  // Properties of the Symbol Constructor
539
580
  '[[Proto]]': '%FunctionPrototype%',
540
- asyncDispose: 'symbol',
541
581
  asyncIterator: 'symbol',
542
- dispose: 'symbol',
543
582
  for: fn,
544
583
  hasInstance: 'symbol',
545
584
  isConcatSpreadable: 'symbol',
@@ -555,6 +594,10 @@ export const permitted = {
555
594
  toPrimitive: 'symbol',
556
595
  toStringTag: 'symbol',
557
596
  unscopables: 'symbol',
597
+ // https://github.com/tc39/proposal-explicit-resource-management
598
+ asyncDispose: 'symbol',
599
+ // https://github.com/tc39/proposal-explicit-resource-management
600
+ dispose: 'symbol',
558
601
  // Seen at core-js https://github.com/zloirock/core-js#ecmascript-symbol
559
602
  useSimple: false,
560
603
  // Seen at core-js https://github.com/zloirock/core-js#ecmascript-symbol
@@ -583,6 +626,8 @@ export const permitted = {
583
626
  stackTraceLimit: accessor,
584
627
  // Non standard, v8 only, used by several, tamed to accessor
585
628
  prepareStackTrace: accessor,
629
+ // https://github.com/tc39/proposal-is-error
630
+ isError: fn,
586
631
  },
587
632
 
588
633
  '%SharedError%': {
@@ -595,6 +640,8 @@ export const permitted = {
595
640
  stackTraceLimit: accessor,
596
641
  // Non standard, v8 only, used by several, tamed to accessor
597
642
  prepareStackTrace: accessor,
643
+ // https://github.com/tc39/proposal-is-error
644
+ isError: fn,
598
645
  },
599
646
 
600
647
  '%ErrorPrototype%': {
@@ -623,6 +670,10 @@ export const permitted = {
623
670
  // https://github.com/endojs/endo/issues/550
624
671
  AggregateError: NativeError('%AggregateErrorPrototype%'),
625
672
 
673
+ // TODO SuppressedError
674
+ // https://github.com/tc39/proposal-explicit-resource-management
675
+ // SuppressedError: NativeError('%SuppressedErrorPrototype%'),
676
+
626
677
  '%EvalErrorPrototype%': NativeErrorPrototype('EvalError'),
627
678
  '%RangeErrorPrototype%': NativeErrorPrototype('RangeError'),
628
679
  '%ReferenceErrorPrototype%': NativeErrorPrototype('ReferenceError'),
@@ -631,6 +682,13 @@ export const permitted = {
631
682
  '%URIErrorPrototype%': NativeErrorPrototype('URIError'),
632
683
  // https://github.com/endojs/endo/issues/550
633
684
  '%AggregateErrorPrototype%': NativeErrorPrototype('AggregateError'),
685
+ // TODO AggregateError .errors
686
+
687
+ // TODO SuppressedError
688
+ // https://github.com/tc39/proposal-explicit-resource-management
689
+ // '%SuppressedErrorPrototype%': NativeErrorPrototype('SuppressedError'),
690
+ // TODO SuppressedError .error
691
+ // TODO SuppressedError .suppressed
634
692
 
635
693
  // *** Numbers and Dates
636
694
 
@@ -809,7 +867,6 @@ export const permitted = {
809
867
  '%StringPrototype%': {
810
868
  // Properties of the String Prototype Object
811
869
  length: 'number',
812
- at: fn,
813
870
  charAt: fn,
814
871
  charCodeAt: fn,
815
872
  codePointAt: fn,
@@ -843,6 +900,13 @@ export const permitted = {
843
900
  trimStart: fn,
844
901
  valueOf: fn,
845
902
  '@@iterator': fn,
903
+ // Failed tc39 proposal
904
+ // https://github.com/tc39/proposal-relative-indexing-method
905
+ at: fn,
906
+ // https://github.com/tc39/proposal-is-usv-string
907
+ isWellFormed: fn,
908
+ toWellFormed: fn,
909
+ unicodeSets: fn,
846
910
 
847
911
  // Annex B: Additional Properties of the String.prototype Object
848
912
  substr: fn,
@@ -863,10 +927,6 @@ export const permitted = {
863
927
  trimRight: fn,
864
928
  // See https://github.com/Moddable-OpenSource/moddable/issues/523
865
929
  compare: false,
866
- // https://github.com/tc39/proposal-is-usv-string
867
- isWellFormed: fn,
868
- toWellFormed: fn,
869
- unicodeSets: fn,
870
930
  // Seen on QuickJS
871
931
  __quote: false,
872
932
  },
@@ -882,6 +942,8 @@ export const permitted = {
882
942
  '[[Proto]]': '%FunctionPrototype%',
883
943
  prototype: '%RegExpPrototype%',
884
944
  '@@species': getter,
945
+ // https://github.com/tc39/proposal-regex-escaping
946
+ escape: fn,
885
947
 
886
948
  // The https://github.com/tc39/proposal-regexp-legacy-features
887
949
  // are all optional, unsafe, and omitted
@@ -911,6 +973,8 @@ export const permitted = {
911
973
  '[[Proto]]': '%FunctionPrototype%',
912
974
  prototype: '%RegExpPrototype%',
913
975
  '@@species': getter,
976
+ // https://github.com/tc39/proposal-regex-escaping
977
+ escape: fn,
914
978
  },
915
979
 
916
980
  '%RegExpPrototype%': {
@@ -957,7 +1021,7 @@ export const permitted = {
957
1021
  prototype: '%ArrayPrototype%',
958
1022
  '@@species': getter,
959
1023
 
960
- // Stage 3:
1024
+ // Failed tc39 proposal
961
1025
  // https://tc39.es/proposal-relative-indexing-method/
962
1026
  at: fn,
963
1027
  // https://tc39.es/proposal-array-from-async/
@@ -966,7 +1030,6 @@ export const permitted = {
966
1030
 
967
1031
  '%ArrayPrototype%': {
968
1032
  // Properties of the Array Prototype Object
969
- at: fn,
970
1033
  length: 'number',
971
1034
  concat: fn,
972
1035
  constructor: 'Array',
@@ -1014,6 +1077,7 @@ export const permitted = {
1014
1077
  keys: 'boolean',
1015
1078
  values: 'boolean',
1016
1079
  // Failed tc39 proposal
1080
+ // https://tc39.es/proposal-relative-indexing-method/
1017
1081
  // Seen on FF Nightly 88.0a1
1018
1082
  at: 'boolean',
1019
1083
  // See https://github.com/tc39/proposal-array-find-from-last
@@ -1041,6 +1105,9 @@ export const permitted = {
1041
1105
  group: fn, // Not in proposal? Where?
1042
1106
  groupToMap: fn, // Not in proposal? Where?
1043
1107
  groupBy: fn,
1108
+ // Failed tc39 proposal
1109
+ // https://tc39.es/proposal-relative-indexing-method/
1110
+ at: fn,
1044
1111
  },
1045
1112
 
1046
1113
  '%ArrayIteratorPrototype%': {
@@ -1062,7 +1129,6 @@ export const permitted = {
1062
1129
  },
1063
1130
 
1064
1131
  '%TypedArrayPrototype%': {
1065
- at: fn,
1066
1132
  buffer: getter,
1067
1133
  byteLength: getter,
1068
1134
  byteOffset: getter,
@@ -1095,6 +1161,9 @@ export const permitted = {
1095
1161
  values: fn,
1096
1162
  '@@iterator': fn,
1097
1163
  '@@toStringTag': getter,
1164
+ // Failed tc39 proposal
1165
+ // https://tc39.es/proposal-relative-indexing-method/
1166
+ at: fn,
1098
1167
  // See https://github.com/tc39/proposal-array-find-from-last
1099
1168
  findLast: fn,
1100
1169
  findLastIndex: fn,
@@ -1352,6 +1421,11 @@ export const permitted = {
1352
1421
  '[[Proto]]': '%FunctionPrototype%',
1353
1422
  prototype: '%IteratorPrototype%',
1354
1423
  from: fn,
1424
+ // https://github.com/tc39/proposal-joint-iteration
1425
+ zip: fn,
1426
+ zipKeyed: fn,
1427
+ // https://github.com/tc39/proposal-iterator-sequencing
1428
+ concat: fn,
1355
1429
  },
1356
1430
 
1357
1431
  '%IteratorPrototype%': {
@@ -1373,6 +1447,7 @@ export const permitted = {
1373
1447
  '@@toStringTag': 'string',
1374
1448
  // https://github.com/tc39/proposal-async-iterator-helpers
1375
1449
  toAsync: fn,
1450
+ // https://github.com/tc39/proposal-explicit-resource-management
1376
1451
  // See https://github.com/Moddable-OpenSource/moddable/issues/523#issuecomment-1942904505
1377
1452
  '@@dispose': false,
1378
1453
  },
@@ -1417,6 +1492,7 @@ export const permitted = {
1417
1492
  every: fn,
1418
1493
  find: fn,
1419
1494
  '@@toStringTag': 'string',
1495
+ // https://github.com/tc39/proposal-explicit-resource-management
1420
1496
  // See https://github.com/Moddable-OpenSource/moddable/issues/523#issuecomment-1942904505
1421
1497
  '@@asyncDispose': false,
1422
1498
  },
@@ -1496,7 +1572,7 @@ export const permitted = {
1496
1572
  //
1497
1573
  // We will likely change this to add a property to Promise called
1498
1574
  // Promise.delegate and put static methods on it, which will necessitate
1499
- // another whitelist change to update to the current proposed standard.
1575
+ // another permits change to update to the current proposed standard.
1500
1576
  HandledPromise: {
1501
1577
  '[[Proto]]': 'Promise',
1502
1578
  applyFunction: fn,
@@ -1524,6 +1600,10 @@ export const permitted = {
1524
1600
  bindings: getter,
1525
1601
  needsImport: getter,
1526
1602
  needsImportMeta: getter,
1603
+ // @endo/module-source provides a legacy interface
1604
+ imports: getter,
1605
+ exports: getter,
1606
+ reexports: getter,
1527
1607
  },
1528
1608
 
1529
1609
  '%AbstractModuleSource%': {
@@ -1549,6 +1629,8 @@ export const permitted = {
1549
1629
  // https://github.com/tc39/proposal-promise-with-resolvers
1550
1630
  withResolvers: fn,
1551
1631
  '@@species': getter,
1632
+ // https://github.com/tc39/proposal-promise-try
1633
+ try: fn,
1552
1634
  },
1553
1635
 
1554
1636
  '%PromisePrototype%': {
@@ -0,0 +1,13 @@
1
+ /* eslint-disable no-restricted-globals */
2
+
3
+ export type Reporter = {
4
+ warn: (...message: Array<any>) => void;
5
+ error: (...message: Array<string>) => void;
6
+ };
7
+
8
+ export type GroupReporter = Reporter & {
9
+ groupCollapsed?: (label: string) => void;
10
+ groupEnd?: () => void;
11
+ };
12
+
13
+ // Console implements GroupReporter
@@ -0,0 +1,108 @@
1
+ import { TypeError, functionBind, globalThis } from './commons.js';
2
+ import { assert } from './error/assert.js';
3
+
4
+ /**
5
+ * @import {Reporter, GroupReporter} from './reporting-types.js'
6
+ */
7
+
8
+ /**
9
+ * Creates a suitable reporter for internal errors and warnings out of the
10
+ * Node.js console.error to ensure all messages to go stderr, including the
11
+ * group label.
12
+ * Accounts for the extra space introduced by console.error as a delimiter
13
+ * between the indent and subsequent arguments.
14
+ *
15
+ * @param {(...message: Array<any>) => void} print
16
+ */
17
+ const makeReportPrinter = print => {
18
+ let indent = false;
19
+ /** @param {Array<any>} args */
20
+ const printIndent = (...args) => {
21
+ if (indent) {
22
+ print(' ', ...args);
23
+ } else {
24
+ print(...args);
25
+ }
26
+ };
27
+ return /** @type {GroupReporter} */ ({
28
+ warn(...args) {
29
+ printIndent(...args);
30
+ },
31
+ error(...args) {
32
+ printIndent(...args);
33
+ },
34
+ groupCollapsed(...args) {
35
+ assert(!indent);
36
+ print(...args);
37
+ indent = true;
38
+ },
39
+ groupEnd() {
40
+ indent = false;
41
+ },
42
+ });
43
+ };
44
+
45
+ const mute = () => {};
46
+
47
+ /**
48
+ * @param {"platform" | "console" | "none"} reporting
49
+ */
50
+ export const chooseReporter = reporting => {
51
+ if (reporting === 'none') {
52
+ return makeReportPrinter(mute);
53
+ }
54
+ if (reporting !== 'platform' && reporting !== 'console') {
55
+ throw new TypeError(`Invalid lockdown reporting option: ${reporting}`);
56
+ }
57
+ if (
58
+ reporting === 'console' ||
59
+ globalThis.window === globalThis ||
60
+ globalThis.importScripts !== undefined
61
+ ) {
62
+ return console;
63
+ }
64
+ if (globalThis.console !== undefined) {
65
+ // On Node.js, we send all feedback to stderr, regardless of purported level.
66
+ const console = globalThis.console;
67
+ const error = functionBind(console.error, console);
68
+ return makeReportPrinter(error);
69
+ }
70
+ if (globalThis.print !== undefined) {
71
+ return makeReportPrinter(globalThis.print);
72
+ }
73
+ return makeReportPrinter(mute);
74
+ };
75
+
76
+ /**
77
+ * @param {string} groupLabel
78
+ * @param {GroupReporter} console
79
+ * @param {(internalConsole: Reporter) => void} callback
80
+ */
81
+ export const reportInGroup = (groupLabel, console, callback) => {
82
+ const { warn, error, groupCollapsed, groupEnd } = console;
83
+ const grouping = groupCollapsed && groupEnd;
84
+ let groupStarted = false;
85
+ try {
86
+ return callback({
87
+ warn(...args) {
88
+ if (grouping && !groupStarted) {
89
+ groupCollapsed(groupLabel);
90
+ groupStarted = true;
91
+ }
92
+ warn(...args);
93
+ },
94
+ error(...args) {
95
+ if (grouping && !groupStarted) {
96
+ groupCollapsed(groupLabel);
97
+ groupStarted = true;
98
+ }
99
+ error(...args);
100
+ },
101
+ });
102
+ } finally {
103
+ if (grouping && groupStarted) {
104
+ groupEnd();
105
+ groupStarted = false;
106
+ }
107
+ }
108
+ };
@@ -3,7 +3,6 @@ import {
3
3
  create,
4
4
  freeze,
5
5
  getOwnPropertyDescriptors,
6
- immutableObject,
7
6
  reflectSet,
8
7
  } from './commons.js';
9
8
  import {
@@ -11,6 +10,14 @@ import {
11
10
  alwaysThrowHandler,
12
11
  } from './strict-scope-terminator.js';
13
12
 
13
+ /**
14
+ * `freeze` but not `harden` the proxy target so it remains trapping.
15
+ * Thus, it should not be shared outside this module.
16
+ *
17
+ * @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
18
+ */
19
+ const objTarget = freeze({ __proto__: null });
20
+
14
21
  /*
15
22
  * createSloppyGlobalsScopeTerminator()
16
23
  * strictScopeTerminatorHandler manages a scopeTerminator Proxy which serves as
@@ -45,7 +52,7 @@ export const createSloppyGlobalsScopeTerminator = globalObject => {
45
52
  );
46
53
 
47
54
  const sloppyGlobalsScopeTerminator = new Proxy(
48
- immutableObject,
55
+ objTarget,
49
56
  sloppyGlobalsScopeTerminatorHandler,
50
57
  );
51
58