[tbb-commits] [tor-browser/tor-browser-45.1.0esr-6.0-1] Bug 18619: If indexedDB disabled, use in-memory db for asyncStorage.js

gk at torproject.org gk at torproject.org
Tue May 17 13:22:03 UTC 2016


commit 847b5368b573508a66c7ba38a2148fe36289fe23
Author: Arthur Edelstein <arthuredelstein at gmail.com>
Date:   Mon May 16 11:00:16 2016 -0700

    Bug 18619: If indexedDB disabled, use in-memory db for asyncStorage.js
---
 devtools/shared/async-storage.js | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/devtools/shared/async-storage.js b/devtools/shared/async-storage.js
index 7bd05b6..4eb2889 100644
--- a/devtools/shared/async-storage.js
+++ b/devtools/shared/async-storage.js
@@ -42,10 +42,37 @@
 const {Cc, Ci, Cu, Cr} = require("chrome");
 const {indexedDB} = require("sdk/indexed-db");
 const Promise = require("promise");
+const prefs = require("sdk/preferences/service");
+
+// Substitute memory-only "database" when "dom.indexedDB.enabled" is false.
+// Match the API and behavior of the indexedDB-based version.
+const memoryDB = function () {
+  let dbMap = new Map();
+  return {
+    getItem : k => {
+      let value = dbMap.get(k);
+      // Match the behavior of indexedDB-based implementation
+      // when an item is not present.
+      if (value === undefined) {
+        value = null;
+      }
+      return Promise.resolve(value);
+    },
+    setItem : (k, v) => Promise.resolve(dbMap.set(k, v)),
+    removeItem : k => Promise.resolve(dbMap.delete(k)),
+    clear : () => Promise.resolve(dbMap.clear()),
+    length : () => Promise.resolve(dbMap.size),
+    key : n => Promise.resolve(Array.from(dbMap.keys())[n])
+  };
+};
 
 module.exports = (function() {
   "use strict";
 
+  if (!prefs.get('dom.indexedDB.enabled', true)) {
+    return memoryDB();
+  }
+
   var DBNAME = "devtools-async-storage";
   var DBVERSION = 1;
   var STORENAME = "keyvaluepairs";



More information about the tbb-commits mailing list