diff --git a/web/view_history.js b/web/view_history.js index eb37673e1..999a38464 100644 --- a/web/view_history.js +++ b/web/view_history.js @@ -31,19 +31,20 @@ class ViewHistory { this._initializedPromise = this._readFromStorage().then(databaseStr => { const database = JSON.parse(databaseStr || "{}"); - if (!("files" in database)) { + let index = -1; + if (!Array.isArray(database.files)) { database.files = []; } else { while (database.files.length >= this.cacheSize) { database.files.shift(); } - } - let index = -1; - for (let i = 0, length = database.files.length; i < length; i++) { - const branch = database.files[i]; - if (branch.fingerprint === this.fingerprint) { - index = i; - break; + + for (let i = 0, ii = database.files.length; i < ii; i++) { + const branch = database.files[i]; + if (branch.fingerprint === this.fingerprint) { + index = i; + break; + } } } if (index === -1) {