filterStyles: code cosmetics and a bug fix

This commit is contained in:
tophf 2017-09-03 18:16:00 +03:00
parent e69b6482b7
commit d843b4e23f

View File

@ -160,15 +160,16 @@ function filterStyles({
) { ) {
return cachedStyles.list; return cachedStyles.list;
} }
const blankHash = asHash && {
disableAll: prefs.get('disableAll'),
exposeIframes: prefs.get('exposeIframes'),
};
if (matchUrl && !URLS.supported(matchUrl)) { if (matchUrl && !URLS.supported(matchUrl)) {
return asHash ? {} : []; return asHash ? {} : [];
} }
const blankHash = asHash && {
disableAll: prefs.get('disableAll'),
exposeIframes: prefs.get('exposeIframes'),
};
// add \t after url to prevent collisions (not sure it can actually happen though) // add \t after url to prevent collisions (not sure it can actually happen though)
const cacheKey = ' ' + enabled + url + '\t' + id + matchUrl + '\t' + asHash + strictRegexp; const cacheKey = ' ' + enabled + url + '\t' + id + matchUrl + '\t' + asHash + strictRegexp;
const cached = cachedStyles.filters.get(cacheKey); const cached = cachedStyles.filters.get(cacheKey);
@ -216,8 +217,8 @@ function filterStylesInternal({
const styles = id === null const styles = id === null
? cachedStyles.list ? cachedStyles.list
: [cachedStyles.byId.get(id)]; : [cachedStyles.byId.get(id)];
const filtered = asHash ? {} : []; const filtered = asHash ? blankHash : [];
if (!styles) { if (!styles[0]) {
// may happen when users [accidentally] reopen an old URL // may happen when users [accidentally] reopen an old URL
// of edit.html with a non-existent style id parameter // of edit.html with a non-existent style id parameter
return filtered; return filtered;
@ -259,9 +260,7 @@ function filterStylesInternal({
cleanupCachedFilters(); cleanupCachedFilters();
} }
return asHash return filtered;
? Object.assign(blankHash, filtered)
: filtered;
} }