ses 1.13.1 → 1.15.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.
Files changed (41) hide show
  1. package/README.md +70 -52
  2. package/dist/lockdown.cjs +1346 -948
  3. package/dist/lockdown.mjs +1346 -948
  4. package/dist/lockdown.umd.js +1346 -948
  5. package/dist/lockdown.umd.min.js +1 -1
  6. package/dist/ses-hermes.cjs +1328 -804
  7. package/dist/ses.cjs +1346 -948
  8. package/dist/ses.mjs +1346 -948
  9. package/dist/ses.umd.js +1346 -948
  10. package/dist/ses.umd.min.js +1 -1
  11. package/dist/types.d.cts +115 -141
  12. package/package.json +19 -102
  13. package/src/assert-shim.js +2 -2
  14. package/src/cauterize-property.js +2 -2
  15. package/src/commons.js +111 -50
  16. package/src/compartment.js +25 -8
  17. package/src/enable-property-overrides.js +4 -4
  18. package/src/enablements.js +7 -8
  19. package/src/error/assert.js +126 -101
  20. package/src/error/note-log-args.js +5 -4
  21. package/src/error/stringify-utils.js +2 -2
  22. package/src/error/tame-v8-error-constructor.js +15 -12
  23. package/src/error/types.js +1 -1
  24. package/src/get-anonymous-intrinsics.js +0 -1
  25. package/src/global-object.js +3 -3
  26. package/src/intrinsics.js +8 -8
  27. package/src/lockdown.js +34 -12
  28. package/src/make-hardener.js +4 -4
  29. package/src/module-instance.js +22 -18
  30. package/src/module-link.js +4 -4
  31. package/src/module-load.js +48 -13
  32. package/src/permits-intrinsics.js +8 -8
  33. package/src/permits.js +5 -0
  34. package/src/reporting.js +48 -12
  35. package/src/scope-constants.js +19 -25
  36. package/src/tame-locale-methods.js +2 -2
  37. package/src/tame-regenerator-runtime.js +2 -2
  38. package/src/transforms.js +9 -7
  39. package/types.d.ts +115 -141
  40. package/src/error/README.md +0 -99
  41. package/src/make-lru-cachemap.js +0 -221
@@ -1,221 +0,0 @@
1
- // @ts-check
2
- /* eslint-disable @endo/no-polymorphic-call */
3
-
4
- // eslint-disable-next-line no-restricted-globals
5
- const { isSafeInteger } = Number;
6
- // eslint-disable-next-line no-restricted-globals
7
- const { freeze } = Object;
8
- // eslint-disable-next-line no-restricted-globals
9
- const { toStringTag: toStringTagSymbol } = Symbol;
10
-
11
- /**
12
- * @template Data
13
- * @typedef {object} DoublyLinkedCell
14
- * A cell of a doubly-linked ring, i.e., a doubly-linked circular list.
15
- * DoublyLinkedCells are not frozen, and so should be closely encapsulated by
16
- * any abstraction that uses them.
17
- * @property {DoublyLinkedCell<Data>} next
18
- * @property {DoublyLinkedCell<Data>} prev
19
- * @property {Data} data
20
- */
21
-
22
- /**
23
- * Makes a new self-linked cell. There are two reasons to do so:
24
- * * To make the head sigil of a new initially-empty doubly-linked ring.
25
- * * To make a non-sigil cell to be `spliceAfter`ed.
26
- *
27
- * @template Data
28
- * @param {Data} data
29
- * @returns {DoublyLinkedCell<Data>}
30
- */
31
- const makeSelfCell = data => {
32
- /** @type {Partial<DoublyLinkedCell<Data>>} */
33
- const incompleteCell = {
34
- next: undefined,
35
- prev: undefined,
36
- data,
37
- };
38
- const selfCell = /** @type {DoublyLinkedCell<Data>} */ (incompleteCell);
39
- selfCell.next = selfCell;
40
- selfCell.prev = selfCell;
41
- // Not frozen!
42
- return selfCell;
43
- };
44
-
45
- /**
46
- * Splices a self-linked non-sigil cell into a ring after `prev`.
47
- * `prev` could be the head sigil, or it could be some other non-sigil
48
- * cell within a ring.
49
- *
50
- * @template Data
51
- * @param {DoublyLinkedCell<Data>} prev
52
- * @param {DoublyLinkedCell<Data>} selfCell
53
- */
54
- const spliceAfter = (prev, selfCell) => {
55
- if (prev === selfCell) {
56
- // eslint-disable-next-line no-restricted-globals
57
- throw TypeError('Cannot splice a cell into itself');
58
- }
59
- if (selfCell.next !== selfCell || selfCell.prev !== selfCell) {
60
- // eslint-disable-next-line no-restricted-globals
61
- throw TypeError('Expected self-linked cell');
62
- }
63
- const cell = selfCell;
64
- // rename variable cause it isn't self-linked after this point.
65
-
66
- const next = prev.next;
67
- cell.prev = prev;
68
- cell.next = next;
69
- prev.next = cell;
70
- next.prev = cell;
71
- // Not frozen!
72
- return cell;
73
- };
74
-
75
- /**
76
- * @template Data
77
- * @param {DoublyLinkedCell<Data>} cell
78
- * No-op if the cell is self-linked.
79
- */
80
- const spliceOut = cell => {
81
- const { prev, next } = cell;
82
- prev.next = next;
83
- next.prev = prev;
84
- cell.prev = cell;
85
- cell.next = cell;
86
- };
87
-
88
- /**
89
- * The LRUCacheMap is used within the implementation of `assert` and so
90
- * at a layer below SES or harden. Thus, we give it a `WeakMap`-like interface
91
- * rather than a `WeakMapStore`-like interface. To work before `lockdown`,
92
- * the implementation must use `freeze` manually, but still exhaustively.
93
- *
94
- * It implements the WeakMap interface, and holds its keys weakly. Cached
95
- * values are only held while the key is held by the user and the key/value
96
- * bookkeeping cell has not been pushed off the end of the cache by `budget`
97
- * number of more recently referenced cells. If the key is dropped by the user,
98
- * the value will no longer be held by the cache, but the bookkeeping cell
99
- * itself will stay in memory.
100
- *
101
- * @template {{}} K
102
- * @template {unknown} V
103
- * @param {number} keysBudget
104
- * @returns {WeakMap<K,V>}
105
- */
106
- export const makeLRUCacheMap = keysBudget => {
107
- if (!isSafeInteger(keysBudget) || keysBudget < 0) {
108
- // eslint-disable-next-line no-restricted-globals
109
- throw TypeError('keysBudget must be a safe non-negative integer number');
110
- }
111
- /** @typedef {DoublyLinkedCell<WeakMap<K, V> | undefined>} LRUCacheCell */
112
- /** @type {WeakMap<K, LRUCacheCell>} */
113
- // eslint-disable-next-line no-restricted-globals
114
- const keyToCell = new WeakMap();
115
- let size = 0; // `size` must remain <= `keysBudget`
116
- // As a sigil, `head` uniquely is not in the `keyToCell` map.
117
- /** @type {LRUCacheCell} */
118
- const head = makeSelfCell(undefined);
119
-
120
- const touchCell = key => {
121
- const cell = keyToCell.get(key);
122
- if (cell === undefined || cell.data === undefined) {
123
- // Either the key was GCed, or the cell was condemned.
124
- return undefined;
125
- }
126
- // Becomes most recently used
127
- spliceOut(cell);
128
- spliceAfter(head, cell);
129
- return cell;
130
- };
131
-
132
- /**
133
- * @param {K} key
134
- */
135
- const has = key => touchCell(key) !== undefined;
136
- freeze(has);
137
-
138
- /**
139
- * @param {K} key
140
- */
141
- // UNTIL https://github.com/endojs/endo/issues/1514
142
- // Prefer: const get = key => touchCell(key)?.data?.get(key);
143
- const get = key => {
144
- const cell = touchCell(key);
145
- return cell && cell.data && cell.data.get(key);
146
- };
147
- freeze(get);
148
-
149
- /**
150
- * @param {K} key
151
- * @param {V} value
152
- */
153
- const set = (key, value) => {
154
- if (keysBudget < 1) {
155
- // eslint-disable-next-line no-use-before-define
156
- return lruCacheMap; // Implements WeakMap.set
157
- }
158
-
159
- let cell = touchCell(key);
160
- if (cell === undefined) {
161
- cell = makeSelfCell(undefined);
162
- spliceAfter(head, cell); // start most recently used
163
- }
164
- if (!cell.data) {
165
- // Either a fresh cell or a reused condemned cell.
166
- size += 1;
167
- // Add its data.
168
- // eslint-disable-next-line no-restricted-globals
169
- cell.data = new WeakMap();
170
- // Advertise the cell for this key.
171
- keyToCell.set(key, cell);
172
- while (size > keysBudget) {
173
- const condemned = head.prev;
174
- spliceOut(condemned); // Drop least recently used
175
- condemned.data = undefined;
176
- size -= 1;
177
- }
178
- }
179
-
180
- // Update the data.
181
- cell.data.set(key, value);
182
-
183
- // eslint-disable-next-line no-use-before-define
184
- return lruCacheMap; // Implements WeakMap.set
185
- };
186
- freeze(set);
187
-
188
- // "delete" is a keyword.
189
- /**
190
- * @param {K} key
191
- */
192
- const deleteIt = key => {
193
- const cell = keyToCell.get(key);
194
- if (cell === undefined) {
195
- return false;
196
- }
197
- spliceOut(cell);
198
- keyToCell.delete(key);
199
- if (cell.data === undefined) {
200
- // Already condemned.
201
- return false;
202
- }
203
-
204
- cell.data = undefined;
205
- size -= 1;
206
- return true;
207
- };
208
- freeze(deleteIt);
209
-
210
- const lruCacheMap = freeze({
211
- has,
212
- get,
213
- set,
214
- delete: deleteIt,
215
- // eslint-disable-next-line jsdoc/check-types
216
- [/** @type {typeof Symbol.toStringTag} */ (toStringTagSymbol)]:
217
- 'LRUCacheMap',
218
- });
219
- return lruCacheMap;
220
- };
221
- freeze(makeLRUCacheMap);