diff options
Diffstat (limited to 'www/lib/localforage/src/drivers')
| -rw-r--r-- | www/lib/localforage/src/drivers/indexeddb.js | 17 | ||||
| -rw-r--r-- | www/lib/localforage/src/drivers/websql.js | 12 |
2 files changed, 20 insertions, 9 deletions
diff --git a/www/lib/localforage/src/drivers/indexeddb.js b/www/lib/localforage/src/drivers/indexeddb.js index 2dd52554..51f936dc 100644 --- a/www/lib/localforage/src/drivers/indexeddb.js +++ b/www/lib/localforage/src/drivers/indexeddb.js @@ -2,6 +2,7 @@ import createBlob from '../utils/createBlob'; import idb from '../utils/idb'; import Promise from '../utils/promise'; import executeCallback from '../utils/executeCallback'; +import executeTwoCallbacks from '../utils/executeTwoCallbacks'; // Some code originally from async_storage.js in // [Gaia](https://github.com/mozilla-b2g/gaia). @@ -9,6 +10,7 @@ import executeCallback from '../utils/executeCallback'; var DETECT_BLOB_SUPPORT_STORE = 'local-forage-detect-blob-support'; var supportsBlobs; var dbContexts; +var toString = Object.prototype.toString; // Transform a binary string to an array buffer, because otherwise // weird stuff happens when you try to work with the binary string directly. @@ -38,10 +40,11 @@ function _binStringToArrayBuffer(bin) { // FileReader bug: https://code.google.com/p/chromium/issues/detail?id=447836 // // Code borrowed from PouchDB. See: -// https://github.com/pouchdb/pouchdb/blob/9c25a23/src/adapters/idb/blobSupport.js +// https://github.com/pouchdb/pouchdb/blob/master/packages/node_modules/pouchdb-adapter-idb/src/blobSupport.js // -function _checkBlobSupportWithoutCaching(txn) { +function _checkBlobSupportWithoutCaching(idb) { return new Promise(function(resolve) { + var txn = idb.transaction(DETECT_BLOB_SUPPORT_STORE, 'readwrite'); var blob = createBlob(['']); txn.objectStore(DETECT_BLOB_SUPPORT_STORE).put(blob, 'key'); @@ -154,7 +157,8 @@ function _getConnection(dbInfo, upgradeNeeded) { }; } - openreq.onerror = function() { + openreq.onerror = function(e) { + e.preventDefault(); reject(openreq.error); }; @@ -254,7 +258,7 @@ function _fullyReady(callback) { } }); - promise.then(callback, callback); + executeTwoCallbacks(promise, callback, callback); return promise; } @@ -448,7 +452,7 @@ function setItem(key, value, callback) { var dbInfo; self.ready().then(function() { dbInfo = self._dbInfo; - if (value instanceof Blob) { + if (toString.call(value) === '[object Blob]') { return _checkBlobSupport(dbInfo.db).then(function(blobSupport) { if (blobSupport) { return value; @@ -460,6 +464,7 @@ function setItem(key, value, callback) { }).then(function(value) { var transaction = dbInfo.db.transaction(dbInfo.storeName, 'readwrite'); var store = transaction.objectStore(dbInfo.storeName); + var req = store.put(value, key); // The reason we don't _save_ null is because IE 10 does // not support saving the `null` type in IndexedDB. How @@ -486,8 +491,6 @@ function setItem(key, value, callback) { var err = req.error ? req.error : req.transaction.error; reject(err); }; - - var req = store.put(value, key); }).catch(reject); }); diff --git a/www/lib/localforage/src/drivers/websql.js b/www/lib/localforage/src/drivers/websql.js index 04e6df2d..e99398b8 100644 --- a/www/lib/localforage/src/drivers/websql.js +++ b/www/lib/localforage/src/drivers/websql.js @@ -137,7 +137,7 @@ function iterate(iterator, callback) { return promise; } -function setItem(key, value, callback) { +function _setItem(key, value, callback, retriesLeft) { var self = this; // Cast the key to a string, as that's all we can set as a key. @@ -183,7 +183,11 @@ function setItem(key, value, callback) { // more storage on Safari, this error will // be called. // - // TODO: Try to re-run the transaction. + // Try to re-run the transaction. + if (retriesLeft > 0) { + resolve(_setItem.apply(self, [key, originalValue, callback, retriesLeft - 1])); + return; + } reject(sqlError); } }); @@ -196,6 +200,10 @@ function setItem(key, value, callback) { return promise; } +function setItem(key, value, callback) { + return _setItem.apply(this, [key, value, callback, 1]); +} + function removeItem(key, callback) { var self = this; |
