From bfb4b0a47455c083225c9239e9d8829e25680656 Mon Sep 17 00:00:00 2001 From: Jacob Flygenring Date: Wed, 28 Nov 2018 14:29:10 +0100 Subject: [PATCH] Extract quota exceeded testing to use an array This improves readability while making it simpler to maintain and extend --- lscache.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lscache.js b/lscache.js index d62a09a..ac87d77 100644 --- a/lscache.js +++ b/lscache.js @@ -45,6 +45,9 @@ // ECMAScript max Date (epoch + 1e8 days) var maxDate = calculateMaxDate(expiryMilliseconds); + // Names to identify exceeded quota errors by + var quotaExceeded = ['QUOTA_EXCEEDED_ERR', 'NS_ERROR_DOM_QUOTA_REACHED', 'QuotaExceededError']; + var cachedStorage; var cachedJSON; var cacheBucket = ''; @@ -90,11 +93,7 @@ // Check to set if the error is us dealing with being out of space function isOutOfSpace(e) { - return e && ( - e.name === 'QUOTA_EXCEEDED_ERR' || - e.name === 'NS_ERROR_DOM_QUOTA_REACHED' || - e.name === 'QuotaExceededError' - ); + return e && quotaExceeded.indexOf(e.name) !== -1; } // Determines if native JSON (de-)serialization is supported in the browser.