ses 1.10.0 → 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.
package/src/permits.js CHANGED
@@ -1,7 +1,7 @@
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
 
@@ -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',
@@ -143,6 +152,10 @@ 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
  /**
@@ -162,6 +175,10 @@ 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
  /**
@@ -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
  },
@@ -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%': {
@@ -6,8 +6,8 @@ export type Reporter = {
6
6
  };
7
7
 
8
8
  export type GroupReporter = Reporter & {
9
- groupCollapsed: (label: string) => void;
10
- groupEnd: () => void;
9
+ groupCollapsed?: (label: string) => void;
10
+ groupEnd?: () => void;
11
11
  };
12
12
 
13
13
  // Console implements GroupReporter
package/src/reporting.js CHANGED
@@ -80,18 +80,19 @@ export const chooseReporter = reporting => {
80
80
  */
81
81
  export const reportInGroup = (groupLabel, console, callback) => {
82
82
  const { warn, error, groupCollapsed, groupEnd } = console;
83
+ const grouping = groupCollapsed && groupEnd;
83
84
  let groupStarted = false;
84
85
  try {
85
86
  return callback({
86
87
  warn(...args) {
87
- if (!groupStarted) {
88
+ if (grouping && !groupStarted) {
88
89
  groupCollapsed(groupLabel);
89
90
  groupStarted = true;
90
91
  }
91
92
  warn(...args);
92
93
  },
93
94
  error(...args) {
94
- if (!groupStarted) {
95
+ if (grouping && !groupStarted) {
95
96
  groupCollapsed(groupLabel);
96
97
  groupStarted = true;
97
98
  }
@@ -99,8 +100,9 @@ export const reportInGroup = (groupLabel, console, callback) => {
99
100
  },
100
101
  });
101
102
  } finally {
102
- if (groupStarted) {
103
+ if (grouping && groupStarted) {
103
104
  groupEnd();
105
+ groupStarted = false;
104
106
  }
105
107
  }
106
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
 
@@ -7,12 +7,19 @@ import {
7
7
  freeze,
8
8
  getOwnPropertyDescriptors,
9
9
  globalThis,
10
- immutableObject,
11
10
  } from './commons.js';
12
11
  import { assert } from './error/assert.js';
13
12
 
14
13
  const { Fail, quote: q } = assert;
15
14
 
15
+ /**
16
+ * `freeze` but not `harden` the proxy target so it remains trapping.
17
+ * Thus, it should not be shared outside this module.
18
+ *
19
+ * @see https://github.com/endojs/endo/blob/master/packages/ses/docs/preparing-for-stabilize.md
20
+ */
21
+ const objTarget = freeze({ __proto__: null });
22
+
16
23
  /**
17
24
  * alwaysThrowHandler
18
25
  * This is an object that throws if any property is called. It's used as
@@ -21,7 +28,7 @@ const { Fail, quote: q } = assert;
21
28
  * create one and share it between all Proxy handlers.
22
29
  */
23
30
  export const alwaysThrowHandler = new Proxy(
24
- immutableObject,
31
+ objTarget,
25
32
  freeze({
26
33
  get(_shadow, prop) {
27
34
  Fail`Please report unexpected scope handler trap: ${q(String(prop))}`;
@@ -88,6 +95,6 @@ export const strictScopeTerminatorHandler = freeze(
88
95
  );
89
96
 
90
97
  export const strictScopeTerminator = new Proxy(
91
- immutableObject,
98
+ objTarget,
92
99
  strictScopeTerminatorHandler,
93
100
  );
@@ -8,10 +8,7 @@ import {
8
8
  defineProperties,
9
9
  } from './commons.js';
10
10
 
11
- export default function tameDateConstructor(dateTaming = 'safe') {
12
- if (dateTaming !== 'safe' && dateTaming !== 'unsafe') {
13
- throw TypeError(`unrecognized dateTaming ${dateTaming}`);
14
- }
11
+ export default function tameDateConstructor() {
15
12
  const OriginalDate = Date;
16
13
  const DatePrototype = OriginalDate.prototype;
17
14
 
@@ -6,10 +6,7 @@ import {
6
6
  objectPrototype,
7
7
  } from './commons.js';
8
8
 
9
- export default function tameMathObject(mathTaming = 'safe') {
10
- if (mathTaming !== 'safe' && mathTaming !== 'unsafe') {
11
- throw TypeError(`unrecognized mathTaming ${mathTaming}`);
12
- }
9
+ export default function tameMathObject() {
13
10
  const originalMath = Math;
14
11
  const initialMath = originalMath; // to follow the naming pattern
15
12
 
package/src/transforms.js CHANGED
@@ -248,7 +248,8 @@ export const mandatoryTransforms = source => {
248
248
  * @returns {string}
249
249
  */
250
250
  export const applyTransforms = (source, transforms) => {
251
- for (const transform of transforms) {
251
+ for (let i = 0, l = transforms.length; i < l; i += 1) {
252
+ const transform = transforms[i];
252
253
  source = transform(source);
253
254
  }
254
255
  return source;
package/types.d.ts CHANGED
@@ -27,8 +27,14 @@ export interface RepairOptions {
27
27
  reporting?: 'platform' | 'console' | 'none';
28
28
  unhandledRejectionTrapping?: 'report' | 'none';
29
29
  errorTaming?: 'safe' | 'unsafe' | 'unsafe-debug';
30
- dateTaming?: 'safe' | 'unsafe'; // deprecated
31
- mathTaming?: 'safe' | 'unsafe'; // deprecated
30
+ /**
31
+ * @deprecated Deprecated and does nothing. In the future specifying it will be an error.
32
+ */
33
+ dateTaming?: 'safe' | 'unsafe';
34
+ /**
35
+ * @deprecated Deprecated and does nothing. In the future specifying it will be an error.
36
+ */
37
+ mathTaming?: 'safe' | 'unsafe';
32
38
  evalTaming?: 'safeEval' | 'unsafeEval' | 'noEval';
33
39
  stackFiltering?: 'concise' | 'verbose';
34
40
  overrideTaming?: 'moderate' | 'min' | 'severe';
@@ -552,12 +558,12 @@ declare global {
552
558
 
553
559
  // Deprecated:
554
560
  constructor(
555
- globals?: Record<string, any> | undefined,
561
+ globals?: Record<PropertyKey, any> | undefined,
556
562
  modules?: Record<string, ModuleDescriptor>,
557
563
  options?: CompartmentOptions,
558
564
  );
559
565
 
560
- get globalThis(): Record<string, any>;
566
+ get globalThis(): Record<PropertyKey, any>;
561
567
 
562
568
  get name(): string;
563
569