mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Catch possible exceptions when accessing window.localStorage
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/899 This is a code review of previous commits related to the above issue.
This commit is contained in:
parent
39dc88b8f5
commit
08d370d32e
1 changed files with 14 additions and 15 deletions
|
|
@ -246,23 +246,22 @@ vAPI.localStorage = {
|
||||||
this.cache = new Promise(resolve => {
|
this.cache = new Promise(resolve => {
|
||||||
browser.storage.local.get('localStorage', bin => {
|
browser.storage.local.get('localStorage', bin => {
|
||||||
this.cache = undefined;
|
this.cache = undefined;
|
||||||
if (
|
try {
|
||||||
bin instanceof Object === false ||
|
if (
|
||||||
bin.localStorage instanceof Object === false
|
bin instanceof Object === false ||
|
||||||
) {
|
bin.localStorage instanceof Object === false
|
||||||
this.cache = {};
|
) {
|
||||||
const ls = self.localStorage;
|
this.cache = {};
|
||||||
for ( let i = 0; i < ls.length; i++ ) {
|
const ls = self.localStorage;
|
||||||
const key = ls.key(i);
|
for ( let i = 0; i < ls.length; i++ ) {
|
||||||
this.cache[key] = ls.getItem(key);
|
const key = ls.key(i);
|
||||||
}
|
this.cache[key] = ls.getItem(key);
|
||||||
//ls.clear();
|
}
|
||||||
browser.storage.local.set({ localStorage: this.cache });
|
browser.storage.local.set({ localStorage: this.cache });
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
this.cache = bin.localStorage;
|
this.cache = bin.localStorage;
|
||||||
} catch(ex) {
|
|
||||||
}
|
}
|
||||||
|
} catch(ex) {
|
||||||
}
|
}
|
||||||
if ( this.cache instanceof Object === false ) {
|
if ( this.cache instanceof Object === false ) {
|
||||||
this.cache = {};
|
this.cache = {};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue