(store, key)
| 10 | }; |
| 11 | |
| 12 | const fillStorage = (store, key) => { |
| 13 | // double the attempted string until we fail |
| 14 | // then a binary search to find the exact point of failure |
| 15 | const maxPow = 30; |
| 16 | let pow = 0; |
| 17 | for (; pow < maxPow; pow++) { |
| 18 | try { |
| 19 | store.setItem(key, longString(pow)); |
| 20 | } catch (e) { |
| 21 | break; |
| 22 | } |
| 23 | } |
| 24 | pow--; |
| 25 | let s = longString(pow); |
| 26 | for (pow--; pow >= 0; pow--) { |
| 27 | const s2 = s + longString(pow); |
| 28 | try { |
| 29 | store.setItem(key, s2); |
| 30 | s = s2; |
| 31 | } catch (e) { |
| 32 | // s remains as is, next time we'll add half as much |
| 33 | } |
| 34 | } |
| 35 | // finally a sanity check that nothing more can be added |
| 36 | try { |
| 37 | store.setItem(key + '+', 'a'); |
| 38 | } catch (e) { |
| 39 | return; |
| 40 | } |
| 41 | throw new Error('Something still fits in the store?'); |
| 42 | }; |
| 43 | |
| 44 | const clearStores = () => { |
| 45 | window.localStorage.clear(); |
no test coverage detected
searching dependent graphs…