ses 0.18.3 → 0.18.5

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.
Files changed (49) hide show
  1. package/NEWS.md +16 -0
  2. package/README.md +105 -47
  3. package/dist/lockdown.cjs +6779 -6508
  4. package/dist/lockdown.mjs +6779 -6508
  5. package/dist/lockdown.umd.js +6779 -6508
  6. package/dist/lockdown.umd.min.js +1 -1
  7. package/dist/ses.cjs +6779 -6508
  8. package/dist/ses.mjs +6779 -6508
  9. package/dist/ses.umd.js +6779 -6508
  10. package/dist/ses.umd.min.js +1 -1
  11. package/index.js +1 -1
  12. package/package.json +17 -13
  13. package/src/commons.js +14 -11
  14. package/src/compartment-evaluate.js +1 -1
  15. package/src/compartment-shim.js +10 -14
  16. package/src/enable-property-overrides.js +4 -4
  17. package/src/error/assert.js +36 -9
  18. package/src/error/note-log-args.js +2 -4
  19. package/src/error/tame-console.js +1 -1
  20. package/src/error/tame-error-constructor.js +3 -3
  21. package/src/error/tame-v8-error-constructor.js +1 -1
  22. package/src/error/types.js +1 -0
  23. package/src/eval-scope.js +4 -2
  24. package/src/get-anonymous-intrinsics.js +25 -4
  25. package/src/global-object.js +2 -2
  26. package/src/intrinsics.js +14 -11
  27. package/src/lockdown-shim.js +13 -26
  28. package/src/make-hardener.js +8 -1
  29. package/src/make-safe-evaluator.js +6 -5
  30. package/src/module-instance.js +8 -11
  31. package/src/module-link.js +2 -2
  32. package/src/module-load.js +5 -7
  33. package/src/module-proxy.js +12 -12
  34. package/src/{whitelist-intrinsics.js → permits-intrinsics.js} +24 -20
  35. package/src/{whitelist.js → permits.js} +135 -8
  36. package/src/scope-constants.js +1 -0
  37. package/src/strict-scope-terminator.js +10 -4
  38. package/src/tame-date-constructor.js +1 -1
  39. package/src/tame-domains.js +2 -2
  40. package/src/tame-function-constructors.js +2 -2
  41. package/src/tame-function-tostring.js +1 -1
  42. package/src/tame-harden.js +7 -1
  43. package/src/tame-locale-methods.js +2 -2
  44. package/src/tame-math-object.js +1 -1
  45. package/src/tame-regexp-constructor.js +11 -2
  46. package/src/tame-symbol-constructor.js +65 -0
  47. package/src/transforms.js +3 -3
  48. package/types.d.ts +1 -0
  49. package/src/environment-options.js +0 -117
@@ -67,7 +67,6 @@ export const universalPropertyNames = {
67
67
  ReferenceError: 'ReferenceError',
68
68
  Set: 'Set',
69
69
  String: 'String',
70
- Symbol: 'Symbol',
71
70
  SyntaxError: 'SyntaxError',
72
71
  TypeError: 'TypeError',
73
72
  Uint8Array: 'Uint8Array',
@@ -77,6 +76,10 @@ export const universalPropertyNames = {
77
76
  URIError: 'URIError',
78
77
  WeakMap: 'WeakMap',
79
78
  WeakSet: 'WeakSet',
79
+ // https://github.com/tc39/proposal-iterator-helpers
80
+ Iterator: 'Iterator',
81
+ // https://github.com/tc39/proposal-async-iterator-helpers
82
+ AsyncIterator: 'AsyncIterator',
80
83
 
81
84
  // *** Other Properties of the Global Object
82
85
 
@@ -109,6 +112,11 @@ export const initialGlobalPropertyNames = {
109
112
  Error: '%InitialError%',
110
113
  RegExp: '%InitialRegExp%',
111
114
 
115
+ // Omit `Symbol`, because we want the original to appear on the
116
+ // start compartment without passing through the whitelist mechanism, since
117
+ // we want to preserve all its properties, even if we never heard of them.
118
+ // Symbol: '%InitialSymbol%',
119
+
112
120
  // *** Other Properties of the Global Object
113
121
 
114
122
  Math: '%InitialMath%',
@@ -137,6 +145,7 @@ export const sharedGlobalPropertyNames = {
137
145
  Date: '%SharedDate%',
138
146
  Error: '%SharedError%',
139
147
  RegExp: '%SharedRegExp%',
148
+ Symbol: '%SharedSymbol%',
140
149
 
141
150
  // *** Other Properties of the Global Object
142
151
 
@@ -241,7 +250,7 @@ export const FunctionInstance = {
241
250
  };
242
251
 
243
252
  // AsyncFunction Instances
244
- const AsyncFunctionInstance = {
253
+ export const AsyncFunctionInstance = {
245
254
  // This property is not mentioned in ECMA 262, but is present in V8 and
246
255
  // necessary for lockdown to succeed.
247
256
  '[[Proto]]': '%AsyncFunctionPrototype%',
@@ -375,7 +384,7 @@ const SharedMath = {
375
384
  mod: false,
376
385
  };
377
386
 
378
- export const whitelist = {
387
+ export const permitted = {
379
388
  // ECMA https://tc39.es/ecma262
380
389
 
381
390
  // The intrinsics object has no prototype to avoid conflicts.
@@ -432,6 +441,8 @@ export const whitelist = {
432
441
  seal: fn,
433
442
  setPrototypeOf: fn,
434
443
  values: fn,
444
+ // https://github.com/tc39/proposal-array-grouping
445
+ groupBy: 'boolean',
435
446
  },
436
447
 
437
448
  '%ObjectPrototype%': {
@@ -474,9 +485,9 @@ export const whitelist = {
474
485
  constructor: '%InertFunction%',
475
486
  toString: fn,
476
487
  '@@hasInstance': fn,
477
- // proposed but not yet std yet. To be removed if there
488
+ // proposed but not yet std. To be removed if there
478
489
  caller: false,
479
- // proposed but not yet std yet. To be removed if there
490
+ // proposed but not yet std. To be removed if there
480
491
  arguments: false,
481
492
  },
482
493
 
@@ -492,10 +503,12 @@ export const whitelist = {
492
503
  valueOf: fn,
493
504
  },
494
505
 
495
- Symbol: {
506
+ '%SharedSymbol%': {
496
507
  // Properties of the Symbol Constructor
497
508
  '[[Proto]]': '%FunctionPrototype%',
509
+ asyncDispose: 'symbol',
498
510
  asyncIterator: 'symbol',
511
+ dispose: 'symbol',
499
512
  for: fn,
500
513
  hasInstance: 'symbol',
501
514
  isConcatSpreadable: 'symbol',
@@ -511,11 +524,15 @@ export const whitelist = {
511
524
  toPrimitive: 'symbol',
512
525
  toStringTag: 'symbol',
513
526
  unscopables: 'symbol',
527
+ // Seen at core-js https://github.com/zloirock/core-js#ecmascript-symbol
528
+ useSimple: false,
529
+ // Seen at core-js https://github.com/zloirock/core-js#ecmascript-symbol
530
+ useSetter: false,
514
531
  },
515
532
 
516
533
  '%SymbolPrototype%': {
517
534
  // Properties of the Symbol Prototype Object
518
- constructor: 'Symbol',
535
+ constructor: '%SharedSymbol%',
519
536
  description: getter,
520
537
  toString: fn,
521
538
  valueOf: fn,
@@ -780,6 +797,10 @@ export const whitelist = {
780
797
  trimRight: fn,
781
798
  // See https://github.com/Moddable-OpenSource/moddable/issues/523
782
799
  compare: false,
800
+ // https://github.com/tc39/proposal-is-usv-string
801
+ isWellFormed: fn,
802
+ toWellFormed: fn,
803
+ unicodeSets: fn,
783
804
  },
784
805
 
785
806
  '%StringIteratorPrototype%': {
@@ -872,6 +893,8 @@ export const whitelist = {
872
893
  // Stage 3:
873
894
  // https://tc39.es/proposal-relative-indexing-method/
874
895
  at: fn,
896
+ // https://tc39.es/proposal-array-from-async/
897
+ fromAsync: fn,
875
898
  },
876
899
 
877
900
  '%ArrayPrototype%': {
@@ -925,14 +948,32 @@ export const whitelist = {
925
948
  values: 'boolean',
926
949
  // Failed tc39 proposal
927
950
  // Seen on FF Nightly 88.0a1
928
- at: false,
951
+ at: 'boolean',
929
952
  // See https://github.com/tc39/proposal-array-find-from-last
930
953
  findLast: 'boolean',
931
954
  findLastIndex: 'boolean',
955
+ // https://github.com/tc39/proposal-change-array-by-copy
956
+ toReversed: 'boolean',
957
+ toSorted: 'boolean',
958
+ toSpliced: 'boolean',
959
+ with: 'boolean',
960
+ // https://github.com/tc39/proposal-array-grouping
961
+ group: 'boolean',
962
+ groupToMap: 'boolean',
963
+ groupBy: 'boolean',
932
964
  },
933
965
  // See https://github.com/tc39/proposal-array-find-from-last
934
966
  findLast: fn,
935
967
  findLastIndex: fn,
968
+ // https://github.com/tc39/proposal-change-array-by-copy
969
+ toReversed: fn,
970
+ toSorted: fn,
971
+ toSpliced: fn,
972
+ with: fn,
973
+ // https://github.com/tc39/proposal-array-grouping
974
+ group: fn, // Not in proposal? Where?
975
+ groupToMap: fn, // Not in proposal? Where?
976
+ groupBy: fn,
936
977
  },
937
978
 
938
979
  '%ArrayIteratorPrototype%': {
@@ -990,6 +1031,10 @@ export const whitelist = {
990
1031
  // See https://github.com/tc39/proposal-array-find-from-last
991
1032
  findLast: fn,
992
1033
  findLastIndex: fn,
1034
+ // https://github.com/tc39/proposal-change-array-by-copy
1035
+ toReversed: fn,
1036
+ toSorted: fn,
1037
+ with: fn,
993
1038
  },
994
1039
 
995
1040
  // The TypedArray Constructors
@@ -1134,6 +1179,9 @@ export const whitelist = {
1134
1179
  resize: fn,
1135
1180
  resizable: getter,
1136
1181
  maxByteLength: getter,
1182
+ // https://github.com/tc39/proposal-arraybuffer-transfer
1183
+ transferToFixedLength: fn,
1184
+ detached: getter,
1137
1185
  },
1138
1186
 
1139
1187
  // SharedArrayBuffer Objects
@@ -1182,18 +1230,97 @@ export const whitelist = {
1182
1230
  parse: fn,
1183
1231
  stringify: fn,
1184
1232
  '@@toStringTag': 'string',
1233
+ // https://github.com/tc39/proposal-json-parse-with-source/
1234
+ rawJSON: fn,
1235
+ isRawJSON: fn,
1185
1236
  },
1186
1237
 
1187
1238
  // *** Control Abstraction Objects
1188
1239
 
1240
+ // https://github.com/tc39/proposal-iterator-helpers
1241
+ Iterator: {
1242
+ // Properties of the Iterator Constructor
1243
+ '[[Proto]]': '%FunctionPrototype%',
1244
+ prototype: '%IteratorPrototype%',
1245
+ from: fn,
1246
+ },
1247
+
1189
1248
  '%IteratorPrototype%': {
1190
1249
  // The %IteratorPrototype% Object
1191
1250
  '@@iterator': fn,
1251
+ // https://github.com/tc39/proposal-iterator-helpers
1252
+ constructor: 'Iterator',
1253
+ map: fn,
1254
+ filter: fn,
1255
+ take: fn,
1256
+ drop: fn,
1257
+ flatMap: fn,
1258
+ reduce: fn,
1259
+ toArray: fn,
1260
+ forEach: fn,
1261
+ some: fn,
1262
+ every: fn,
1263
+ find: fn,
1264
+ '@@toStringTag': 'string',
1265
+ // https://github.com/tc39/proposal-async-iterator-helpers
1266
+ toAsync: fn,
1267
+ },
1268
+
1269
+ // https://github.com/tc39/proposal-iterator-helpers
1270
+ '%WrapForValidIteratorPrototype%': {
1271
+ '[[Proto]]': '%IteratorPrototype%',
1272
+ next: fn,
1273
+ return: fn,
1274
+ },
1275
+
1276
+ // https://github.com/tc39/proposal-iterator-helpers
1277
+ '%IteratorHelperPrototype%': {
1278
+ '[[Proto]]': '%IteratorPrototype%',
1279
+ next: fn,
1280
+ return: fn,
1281
+ '@@toStringTag': 'string',
1282
+ },
1283
+
1284
+ // https://github.com/tc39/proposal-async-iterator-helpers
1285
+ AsyncIterator: {
1286
+ // Properties of the Iterator Constructor
1287
+ '[[Proto]]': '%FunctionPrototype%',
1288
+ prototype: '%AsyncIteratorPrototype%',
1289
+ from: fn,
1192
1290
  },
1193
1291
 
1194
1292
  '%AsyncIteratorPrototype%': {
1195
1293
  // The %AsyncIteratorPrototype% Object
1196
1294
  '@@asyncIterator': fn,
1295
+ // https://github.com/tc39/proposal-async-iterator-helpers
1296
+ constructor: 'AsyncIterator',
1297
+ map: fn,
1298
+ filter: fn,
1299
+ take: fn,
1300
+ drop: fn,
1301
+ flatMap: fn,
1302
+ reduce: fn,
1303
+ toArray: fn,
1304
+ forEach: fn,
1305
+ some: fn,
1306
+ every: fn,
1307
+ find: fn,
1308
+ '@@toStringTag': 'string',
1309
+ },
1310
+
1311
+ // https://github.com/tc39/proposal-async-iterator-helpers
1312
+ '%WrapForValidAsyncIteratorPrototype%': {
1313
+ '[[Proto]]': '%AsyncIteratorPrototype%',
1314
+ next: fn,
1315
+ return: fn,
1316
+ },
1317
+
1318
+ // https://github.com/tc39/proposal-async-iterator-helpers
1319
+ '%AsyncIteratorHelperPrototype%': {
1320
+ '[[Proto]]': '%AsyncIteratorPrototype%',
1321
+ next: fn,
1322
+ return: fn,
1323
+ '@@toStringTag': 'string',
1197
1324
  },
1198
1325
 
1199
1326
  '%InertGeneratorFunction%': {
@@ -115,6 +115,7 @@ export const isValidIdentifierName = name => {
115
115
  function isImmutableDataProperty(obj, name) {
116
116
  const desc = getOwnPropertyDescriptor(obj, name);
117
117
  return (
118
+ desc &&
118
119
  //
119
120
  // The getters will not have .writable, don't let the falsyness of
120
121
  // 'undefined' trick us: test with === false, not ! . However descriptors
@@ -43,7 +43,7 @@ const scopeProxyHandlerProperties = {
43
43
  set(_shadow, prop, _value) {
44
44
  // We should only hit this if the has() hook returned true matches the v8
45
45
  // ReferenceError message "Uncaught ReferenceError: xyz is not defined"
46
- throw new ReferenceError(`${String(prop)} is not defined`);
46
+ throw ReferenceError(`${String(prop)} is not defined`);
47
47
  },
48
48
 
49
49
  has(_shadow, prop) {
@@ -53,22 +53,28 @@ const scopeProxyHandlerProperties = {
53
53
 
54
54
  // note: this is likely a bug of safari
55
55
  // https://bugs.webkit.org/show_bug.cgi?id=195534
56
- getPrototypeOf() {
56
+ getPrototypeOf(_shadow) {
57
57
  return null;
58
58
  },
59
59
 
60
60
  // See https://github.com/endojs/endo/issues/1510
61
61
  // TODO: report as bug to v8 or Chrome, and record issue link here.
62
- getOwnPropertyDescriptor(_target, prop) {
62
+ getOwnPropertyDescriptor(_shadow, prop) {
63
63
  // Coerce with `String` in case prop is a symbol.
64
64
  const quotedProp = q(String(prop));
65
65
  // eslint-disable-next-line @endo/no-polymorphic-call
66
66
  console.warn(
67
67
  `getOwnPropertyDescriptor trap on scopeTerminatorHandler for ${quotedProp}`,
68
- new TypeError().stack,
68
+ TypeError().stack,
69
69
  );
70
70
  return undefined;
71
71
  },
72
+
73
+ // See https://github.com/endojs/endo/issues/1490
74
+ // TODO Report bug to JSC or Safari
75
+ ownKeys(_shadow) {
76
+ return [];
77
+ },
72
78
  };
73
79
 
74
80
  // The scope handler's prototype is a proxy that throws if any trap other
@@ -10,7 +10,7 @@ import {
10
10
 
11
11
  export default function tameDateConstructor(dateTaming = 'safe') {
12
12
  if (dateTaming !== 'safe' && dateTaming !== 'unsafe') {
13
- throw new TypeError(`unrecognized dateTaming ${dateTaming}`);
13
+ throw TypeError(`unrecognized dateTaming ${dateTaming}`);
14
14
  }
15
15
  const OriginalDate = Date;
16
16
  const DatePrototype = OriginalDate.prototype;
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  export function tameDomains(domainTaming = 'safe') {
11
11
  if (domainTaming !== 'safe' && domainTaming !== 'unsafe') {
12
- throw new TypeError(`unrecognized domainTaming ${domainTaming}`);
12
+ throw TypeError(`unrecognized domainTaming ${domainTaming}`);
13
13
  }
14
14
 
15
15
  if (domainTaming === 'unsafe') {
@@ -27,7 +27,7 @@ export function tameDomains(domainTaming = 'safe') {
27
27
  // The domain descriptor on Node.js initially has value: null, which
28
28
  // becomes a get, set pair after domains initialize.
29
29
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_NO_DOMAINS.md
30
- throw new TypeError(
30
+ throw TypeError(
31
31
  `SES failed to lockdown, Node.js domains have been initialized (SES_NO_DOMAINS)`,
32
32
  );
33
33
  }
@@ -30,7 +30,7 @@ import {
30
30
  // list must be updated to match.
31
31
  //
32
32
  // In addition, the standard needs to define four new intrinsics for the safe
33
- // replacement functions. See [./whitelist intrinsics].
33
+ // replacement functions. See [./permits-intrinsics.js].
34
34
  //
35
35
  // Adapted from SES/Caja
36
36
  // Copyright (C) 2011 Google Inc.
@@ -84,7 +84,7 @@ export default function tameFunctionConstructors() {
84
84
  // prototype of functions.
85
85
  // eslint-disable-next-line func-names
86
86
  const InertConstructor = function () {
87
- throw new TypeError(
87
+ throw TypeError(
88
88
  'Function.prototype.constructor is not a valid constructor.',
89
89
  );
90
90
  };
@@ -27,7 +27,7 @@ export const tameFunctionToString = () => {
27
27
 
28
28
  const tamingMethods = {
29
29
  toString() {
30
- const str = functionToString(this, []);
30
+ const str = functionToString(this);
31
31
  if (
32
32
  stringEndsWith(str, nativeSuffix) ||
33
33
  !weaksetHas(virtualizedNativeFunctions, this)
@@ -3,7 +3,7 @@ import { TypeError, freeze } from './commons.js';
3
3
 
4
4
  export const tameHarden = (safeHarden, hardenTaming) => {
5
5
  if (hardenTaming !== 'safe' && hardenTaming !== 'unsafe') {
6
- throw new TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
6
+ throw TypeError(`unrecognized fakeHardenOption ${hardenTaming}`);
7
7
  }
8
8
 
9
9
  if (hardenTaming === 'safe') {
@@ -16,6 +16,12 @@ export const tameHarden = (safeHarden, hardenTaming) => {
16
16
  Object.isSealed = () => true;
17
17
  Reflect.isExtensible = () => false;
18
18
 
19
+ if (safeHarden.isFake) {
20
+ // The "safe" hardener is already a fake hardener.
21
+ // Just use it.
22
+ return safeHarden;
23
+ }
24
+
19
25
  const fakeHarden = arg => arg;
20
26
  fakeHarden.isFake = true;
21
27
  return freeze(fakeHarden);
@@ -19,7 +19,7 @@ const tamedMethods = {
19
19
  // See https://tc39.es/ecma262/#sec-string.prototype.localecompare
20
20
  localeCompare(arg) {
21
21
  if (this === null || this === undefined) {
22
- throw new TypeError(
22
+ throw TypeError(
23
23
  'Cannot localeCompare with null or undefined "this" value',
24
24
  );
25
25
  }
@@ -45,7 +45,7 @@ const numberToString = tamedMethods.toString;
45
45
 
46
46
  export default function tameLocaleMethods(intrinsics, localeTaming = 'safe') {
47
47
  if (localeTaming !== 'safe' && localeTaming !== 'unsafe') {
48
- throw new TypeError(`unrecognized localeTaming ${localeTaming}`);
48
+ throw TypeError(`unrecognized localeTaming ${localeTaming}`);
49
49
  }
50
50
  if (localeTaming === 'unsafe') {
51
51
  return;
@@ -8,7 +8,7 @@ import {
8
8
 
9
9
  export default function tameMathObject(mathTaming = 'safe') {
10
10
  if (mathTaming !== 'safe' && mathTaming !== 'unsafe') {
11
- throw new TypeError(`unrecognized mathTaming ${mathTaming}`);
11
+ throw TypeError(`unrecognized mathTaming ${mathTaming}`);
12
12
  }
13
13
  const originalMath = Math;
14
14
  const initialMath = originalMath; // to follow the naming pattern
@@ -9,12 +9,15 @@ import {
9
9
 
10
10
  export default function tameRegExpConstructor(regExpTaming = 'safe') {
11
11
  if (regExpTaming !== 'safe' && regExpTaming !== 'unsafe') {
12
- throw new TypeError(`unrecognized regExpTaming ${regExpTaming}`);
12
+ throw TypeError(`unrecognized regExpTaming ${regExpTaming}`);
13
13
  }
14
14
  const RegExpPrototype = FERAL_REG_EXP.prototype;
15
15
 
16
16
  const makeRegExpConstructor = (_ = {}) => {
17
17
  // RegExp has non-writable static properties we need to omit.
18
+ /**
19
+ * @param {Parameters<typeof FERAL_REG_EXP>} rest
20
+ */
18
21
  const ResultRegExp = function RegExp(...rest) {
19
22
  if (new.target === undefined) {
20
23
  return FERAL_REG_EXP(...rest);
@@ -22,6 +25,11 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
22
25
  return construct(FERAL_REG_EXP, rest, new.target);
23
26
  };
24
27
 
28
+ const speciesDesc = getOwnPropertyDescriptor(FERAL_REG_EXP, speciesSymbol);
29
+ if (!speciesDesc) {
30
+ throw TypeError('no RegExp[Symbol.species] descriptor');
31
+ }
32
+
25
33
  defineProperties(ResultRegExp, {
26
34
  length: { value: 2 },
27
35
  prototype: {
@@ -30,7 +38,7 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
30
38
  enumerable: false,
31
39
  configurable: false,
32
40
  },
33
- [speciesSymbol]: getOwnPropertyDescriptor(FERAL_REG_EXP, speciesSymbol),
41
+ [speciesSymbol]: speciesDesc,
34
42
  });
35
43
  return ResultRegExp;
36
44
  };
@@ -39,6 +47,7 @@ export default function tameRegExpConstructor(regExpTaming = 'safe') {
39
47
  const SharedRegExp = makeRegExpConstructor();
40
48
 
41
49
  if (regExpTaming !== 'unsafe') {
50
+ // @ts-expect-error Deleted properties must be optional
42
51
  delete RegExpPrototype.compile;
43
52
  }
44
53
  defineProperties(RegExpPrototype, {
@@ -0,0 +1,65 @@
1
+ import {
2
+ Symbol,
3
+ entries,
4
+ fromEntries,
5
+ getOwnPropertyDescriptors,
6
+ defineProperties,
7
+ arrayMap,
8
+ } from './commons.js';
9
+
10
+ /**
11
+ * This taming provides a tamed alternative to the original `Symbol` constructor
12
+ * that starts off identical, except that all its properties are "temporarily"
13
+ * configurable. The original `Symbol` constructor remains unmodified on
14
+ * the start compartment's global. The tamed alternative is used as the shared
15
+ * `Symbol` constructor on constructed compartments.
16
+ *
17
+ * Starting these properties as configurable assumes two succeeding phases of
18
+ * processing: A whitelisting phase, that
19
+ * removes all properties not on the whitelist (which requires them to be
20
+ * configurable) and a global hardening step that freezes all primordials,
21
+ * returning these properties to their expected non-configurable status.
22
+ *
23
+ * The ses shim is constructed to eventually enable vetted shims to run between
24
+ * repair and global hardening. However, such vetted shims would normally
25
+ * run in the start compartment, which continues to use the original unmodified
26
+ * `Symbol`, so they should not normally be affected by the temporary
27
+ * configurability of these properties.
28
+ *
29
+ * Note that the spec refers to the global `Symbol` function as the
30
+ * ["Symbol Constructor"](https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-symbol-constructor)
31
+ * even though it has a call behavior (can be called as a function) and does not
32
+ * not have a construct behavior (cannot be called with `new`). Accordingly,
33
+ * to tame it, we must replace it with a function without a construct
34
+ * behavior.
35
+ */
36
+ export const tameSymbolConstructor = () => {
37
+ const OriginalSymbol = Symbol;
38
+ const SymbolPrototype = OriginalSymbol.prototype;
39
+
40
+ const SharedSymbol = {
41
+ Symbol(description) {
42
+ return OriginalSymbol(description);
43
+ },
44
+ }.Symbol;
45
+
46
+ defineProperties(SymbolPrototype, {
47
+ constructor: {
48
+ value: SharedSymbol,
49
+ // leave other `constructor` attributes as is
50
+ },
51
+ });
52
+
53
+ const originalDescsEntries = entries(
54
+ getOwnPropertyDescriptors(OriginalSymbol),
55
+ );
56
+ const descs = fromEntries(
57
+ arrayMap(originalDescsEntries, ([name, desc]) => [
58
+ name,
59
+ { ...desc, configurable: true },
60
+ ]),
61
+ );
62
+ defineProperties(SharedSymbol, descs);
63
+
64
+ return { '%SharedSymbol%': SharedSymbol };
65
+ };
package/src/transforms.js CHANGED
@@ -71,7 +71,7 @@ export const rejectHtmlComments = src => {
71
71
  }
72
72
  const name = getSourceURL(src);
73
73
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_HTML_COMMENT_REJECTED.md
74
- throw new SyntaxError(
74
+ throw SyntaxError(
75
75
  `Possible HTML comment rejected at ${name}:${lineNumber}. (SES_HTML_COMMENT_REJECTED)`,
76
76
  );
77
77
  };
@@ -147,7 +147,7 @@ export const rejectImportExpressions = src => {
147
147
  }
148
148
  const name = getSourceURL(src);
149
149
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_IMPORT_REJECTED.md
150
- throw new SyntaxError(
150
+ throw SyntaxError(
151
151
  `Possible import expression rejected at ${name}:${lineNumber}. (SES_IMPORT_REJECTED)`,
152
152
  );
153
153
  };
@@ -219,7 +219,7 @@ export const rejectSomeDirectEvalExpressions = src => {
219
219
  }
220
220
  const name = getSourceURL(src);
221
221
  // See https://github.com/endojs/endo/blob/master/packages/ses/error-codes/SES_EVAL_REJECTED.md
222
- throw new SyntaxError(
222
+ throw SyntaxError(
223
223
  `Possible direct eval expression rejected at ${name}:${lineNumber}. (SES_EVAL_REJECTED)`,
224
224
  );
225
225
  };
package/types.d.ts CHANGED
@@ -199,6 +199,7 @@ export interface Assert {
199
199
  ): DetailsToken;
200
200
  Fail(template: TemplateStringsArray | string[], ...args: any): never;
201
201
  quote(payload: any, spaces?: string | number): ToStringable;
202
+ bare(payload: any, spaces?: string | number): ToStringable;
202
203
  makeAssert: MakeAssert;
203
204
  }
204
205