| 7 | this.cache = cache || {}; |
| 8 | }, |
| 9 | get(pattern) { |
| 10 | if (pattern in this.cache) { |
| 11 | return this.cache[pattern]; |
| 12 | } else { |
| 13 | let result; |
| 14 | // We use try/catch to ensure that a broken regexp doesn't wholly cripple Vimium. |
| 15 | try { |
| 16 | result = new RegExp("^" + pattern.replace(/\*/g, ".*") + "$"); |
| 17 | } catch { |
| 18 | if (!globalThis.isUnitTests) { |
| 19 | console.log(`bad regexp in exclusion rule: ${pattern}`); |
| 20 | } |
| 21 | result = /^$/; // Match the empty string. |
| 22 | } |
| 23 | this.cache[pattern] = result; |
| 24 | return result; |
| 25 | } |
| 26 | }, |
| 27 | }; |
| 28 | |
| 29 | // Make RegexpCache, which is required on the page popup, accessible via the Exclusions object. |