Skip to content

Commit

Permalink
fixup! fix(ses): avoid holding deep stacks strongly
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Mar 21, 2023
1 parent 46fa2e4 commit 9f408cb
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/ses/src/error/note-log-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const { isSafeInteger } = Number;
* * To make the head sigil of a new initially-empty doubly-linked ring.
* * To make a non-sigil cell to be `spliceAfter`ed.
*
* TODO: It would be nice to use `template {object} K`, but that only works with noImplicitAny.
*
* @template Data
* @param {Data} data
* @returns {DoublyLinkedCell<Data>}
Expand Down Expand Up @@ -100,20 +98,20 @@ const spliceOut = cell => {
* the value will no longer be held by the cache, but the bookkeeping cell
* itself vill stay in memory until it has cycled off the end of the cache.
*
* @template {object} K
* @template V
* @template {{}} K
* @template {unknown} V
* @param {number} budget
* @returns {WeakMap<K,V>}
*/
export const makeLRUCacheMap = budget => {
if (!isSafeInteger(budget) || budget < 0) {
throw new TypeError('budget must be a safe non-negative integer number');
}
/** @type {WeakMap<object, DoublyLinkedCell<WeakMap<object, V> | undefined>} */
/** @type {WeakMap<K, DoublyLinkedCell<WeakMap<K, V> | undefined>>} */
const keyToCell = new WeakMap();
let size = 0; // `size` must remain <= `budget`
// As a sigil, `head` uniquely is not in the `keyToCell` map.
/** @type {DoublyLinkedCell<WeakMap<object, V> | undefined>} */
/** @type {DoublyLinkedCell<WeakMap<K, V> | undefined>} */
const head = makeSelfCell(undefined);

const touchCell = key => {
Expand Down Expand Up @@ -151,7 +149,7 @@ export const makeLRUCacheMap = budget => {
*/
const set = (key, value) => {
if (budget >= 1) {
/** @type {DoublyLinkedCell<WeakMap<object, V> | undefined> | undefined} */
/** @type {DoublyLinkedCell<WeakMap<K, V> | undefined> | undefined} */
let cell = touchCell(key);
if (cell === undefined) {
if (size >= budget) {
Expand Down

0 comments on commit 9f408cb

Please sign in to comment.