浏览代码

Fix bug in clear and fetch namespace loops.

Afshin Darian 8 年之前
父节点
当前提交
db821c9ac9
共有 2 个文件被更改,包括 6 次插入5 次删除
  1. 0 1
      src/instancerestorer/instancerestorer.ts
  2. 6 4
      src/statedb/statedb.ts

+ 0 - 1
src/instancerestorer/instancerestorer.ts

@@ -273,7 +273,6 @@ class InstanceRestorer implements IInstanceRestorer {
    * calls to `fetch` are guaranteed to return after restoration is complete.
    */
   fetch(): Promise<IInstanceRestorer.ILayout> {
-    (window as any).restorer = this;
     const blank: IInstanceRestorer.ILayout = {
       currentWidget: null,
       fresh: true,

+ 6 - 4
src/statedb/statedb.ts

@@ -44,8 +44,9 @@ class StateDB implements IStateDB {
    */
   clear(): Promise<void> {
     const prefix = `${this.namespace}:`;
-    while (window.localStorage.length) {
-      let key = window.localStorage.key(window.localStorage.length - 1);
+    let i = window.localStorage.length;
+    while (i) {
+      let key = window.localStorage.key(--i);
       if (key.indexOf(prefix) === 0) {
         window.localStorage.removeItem(key);
       }
@@ -99,8 +100,9 @@ class StateDB implements IStateDB {
     const prefix = `${this.namespace}:${namespace}:`;
     const regex = new RegExp(`^${this.namespace}\:`);
     let items: IStateItem[] = [];
-    while (window.localStorage.length) {
-      let key = window.localStorage.key(window.localStorage.length - 1);
+    let i = window.localStorage.length;
+    while (i) {
+      let key = window.localStorage.key(--i);
       if (key.indexOf(prefix) === 0) {
         try {
           items.push({