cookie-banner: clean up StorageDetector restore-on-stop
localStorage and sessionStorage share Storage.prototype, so there is only one setItem to wrap and one to restore. The previous code kept a never-assigned originalSessionSetItem field and a dead second if branch that restored from a field already nulled out a few lines above. Collapse the two fields into a single originalSetItem and drop the dead branch. No behavioural change. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -37,8 +37,7 @@ export class StorageDetector implements Detector {
|
||||
private readonly reported: Set<string> = new Set();
|
||||
private readonly pending: Map<string, DetectedStorageEntry> = new Map();
|
||||
private timer: ReturnType<typeof setTimeout> | null = null;
|
||||
private originalLocalSetItem: typeof Storage.prototype.setItem | null = null;
|
||||
private originalSessionSetItem: typeof Storage.prototype.setItem | null = null;
|
||||
private originalSetItem: typeof Storage.prototype.setItem | null = null;
|
||||
private originalIDBOpen: typeof IDBFactory.prototype.open | null = null;
|
||||
|
||||
constructor(baseUrl: URL, bannerId: string) {
|
||||
@@ -61,13 +60,9 @@ export class StorageDetector implements Detector {
|
||||
this.flush();
|
||||
}
|
||||
|
||||
if (this.originalLocalSetItem) {
|
||||
Storage.prototype.setItem = this.originalLocalSetItem;
|
||||
this.originalLocalSetItem = null;
|
||||
}
|
||||
if (this.originalSessionSetItem) {
|
||||
Storage.prototype.setItem = this.originalLocalSetItem ?? this.originalSessionSetItem!;
|
||||
this.originalSessionSetItem = null;
|
||||
if (this.originalSetItem) {
|
||||
Storage.prototype.setItem = this.originalSetItem;
|
||||
this.originalSetItem = null;
|
||||
}
|
||||
if (this.originalIDBOpen) {
|
||||
IDBFactory.prototype.open = this.originalIDBOpen;
|
||||
@@ -77,7 +72,7 @@ export class StorageDetector implements Detector {
|
||||
|
||||
private wrapStorage(): void {
|
||||
const originalSetItem = Storage.prototype.setItem;
|
||||
this.originalLocalSetItem = originalSetItem;
|
||||
this.originalSetItem = originalSetItem;
|
||||
|
||||
const self = this;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user