Bug 1480951 - Make SessionStore respect sessionStorage.clear(). r=mikedeboer

Differential Revision: https://phabricator.services.mozilla.com/D5066

--HG--
extra : rebase_source : 447e78988d9657247b6870a68dc57bc066905092
This commit is contained in:
Mike Conley 2018-09-05 14:52:00 -04:00
Родитель badaa7a073
Коммит d0b033bcb9
2 изменённых файлов: 25 добавлений и 11 удалений

Просмотреть файл

@ -524,7 +524,15 @@ class SessionStorageListener extends Handler {
if (!this._changes[domain]) {
this._changes[domain] = {};
}
this._changes[domain][key] = newValue;
// If the key isn't defined, then .clear() was called, and we send
// up null for this domain to indicate that storage has been cleared
// for it.
if (!key) {
this._changes[domain] = null;
} else {
this._changes[domain][key] = newValue;
}
this.messageQueue.push("storagechange", () => {
let tmp = this._changes;

Просмотреть файл

@ -77,17 +77,23 @@ var TabStateCacheInternal = {
let storage = data.storage;
for (let domain of Object.keys(change)) {
for (let key of Object.keys(change[domain])) {
let value = change[domain][key];
if (value === null) {
if (storage[domain] && storage[domain][key]) {
delete storage[domain][key];
if (!change[domain]) {
// We were sent null in place of the change object, which means
// we should delete session storage entirely for this domain.
delete storage[domain];
} else {
for (let key of Object.keys(change[domain])) {
let value = change[domain][key];
if (value === null) {
if (storage[domain] && storage[domain][key]) {
delete storage[domain][key];
}
} else {
if (!storage[domain]) {
storage[domain] = {};
}
storage[domain][key] = value;
}
} else {
if (!storage[domain]) {
storage[domain] = {};
}
storage[domain][key] = value;
}
}
}