diff options
| author | Pliable Pixels <pliablepixels@gmail.com> | 2017-09-27 11:39:30 -0400 |
|---|---|---|
| committer | Pliable Pixels <pliablepixels@gmail.com> | 2017-09-27 11:39:30 -0400 |
| commit | e18708f10b04455be151a5a799f0109c34f20a25 (patch) | |
| tree | 9e4559ef0fff8b366474e7768308ddca1e32268a /www/lib/localforage/src/utils | |
| parent | 97a1cb3ae199c7b5455dcba0001efd5b4c32040a (diff) | |
package updates to set up bower correctly #535
Diffstat (limited to 'www/lib/localforage/src/utils')
| -rw-r--r-- | www/lib/localforage/src/utils/idb.js | 32 | ||||
| -rw-r--r-- | www/lib/localforage/src/utils/isIndexedDBValid.js | 33 | ||||
| -rw-r--r-- | www/lib/localforage/src/utils/promise.js | 4 | ||||
| -rw-r--r-- | www/lib/localforage/src/utils/serializer.js | 30 |
4 files changed, 51 insertions, 48 deletions
diff --git a/www/lib/localforage/src/utils/idb.js b/www/lib/localforage/src/utils/idb.js index 47541f6a..f25f2dcd 100644 --- a/www/lib/localforage/src/utils/idb.js +++ b/www/lib/localforage/src/utils/idb.js @@ -1,20 +1,22 @@ function getIDB() { /* global indexedDB,webkitIndexedDB,mozIndexedDB,OIndexedDB,msIndexedDB */ - if (typeof indexedDB !== 'undefined') { - return indexedDB; - } - if (typeof webkitIndexedDB !== 'undefined') { - return webkitIndexedDB; - } - if (typeof mozIndexedDB !== 'undefined') { - return mozIndexedDB; - } - if (typeof OIndexedDB !== 'undefined') { - return OIndexedDB; - } - if (typeof msIndexedDB !== 'undefined') { - return msIndexedDB; - } + try { + if (typeof indexedDB !== 'undefined') { + return indexedDB; + } + if (typeof webkitIndexedDB !== 'undefined') { + return webkitIndexedDB; + } + if (typeof mozIndexedDB !== 'undefined') { + return mozIndexedDB; + } + if (typeof OIndexedDB !== 'undefined') { + return OIndexedDB; + } + if (typeof msIndexedDB !== 'undefined') { + return msIndexedDB; + } + } catch (e) { } } var idb = getIDB(); diff --git a/www/lib/localforage/src/utils/isIndexedDBValid.js b/www/lib/localforage/src/utils/isIndexedDBValid.js index aa14b6d8..f8150875 100644 --- a/www/lib/localforage/src/utils/isIndexedDBValid.js +++ b/www/lib/localforage/src/utils/isIndexedDBValid.js @@ -7,28 +7,25 @@ function isIndexedDBValid() { if (!idb) { return false; } - // We mimic PouchDB here; just UA test for Safari (which, as of - // iOS 8/Yosemite, doesn't properly support IndexedDB). - // IndexedDB support is broken and different from Blink's. - // This is faster than the test case (and it's sync), so we just - // do this. *SIGH* - // http://bl.ocks.org/nolanlawson/raw/c83e9039edf2278047e9/ + // We mimic PouchDB here; // // We test for openDatabase because IE Mobile identifies itself // as Safari. Oh the lulz... - if (typeof openDatabase !== 'undefined' && typeof navigator !== 'undefined' && - navigator.userAgent && - /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)) { - return false; - } + var isSafari = typeof openDatabase !== 'undefined' && + /(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent) && + !/Chrome/.test(navigator.userAgent) && + !/BlackBerry/.test(navigator.platform); + + var hasFetch = typeof fetch === 'function' && + fetch.toString().indexOf('[native code') !== -1; - return idb && - typeof idb.open === 'function' && - // Some Samsung/HTC Android 4.0-4.3 devices - // have older IndexedDB specs; if this isn't available - // their IndexedDB is too old for us to use. - // (Replaces the onupgradeneeded test.) - typeof IDBKeyRange !== 'undefined'; + // Safari <10.1 does not meet our requirements for IDB support (#5572) + // since Safari 10.1 shipped with fetch, we can use that to detect it + return (!isSafari || hasFetch) && + typeof indexedDB !== 'undefined' && + // some outdated implementations of IDB that appear on Samsung + // and HTC Android devices <4.4 are missing IDBKeyRange + typeof IDBKeyRange !== 'undefined'; } catch (e) { return false; } diff --git a/www/lib/localforage/src/utils/promise.js b/www/lib/localforage/src/utils/promise.js index 177a10d0..fe908a82 100644 --- a/www/lib/localforage/src/utils/promise.js +++ b/www/lib/localforage/src/utils/promise.js @@ -1,6 +1,8 @@ // This is CommonJS because lie is an external dependency, so Rollup // can just ignore it. -if (typeof Promise === 'undefined' && typeof require !== 'undefined') { +if (typeof Promise === 'undefined') { + // In the "nopromises" build this will just throw if you don't have + // a global promise object, but it would throw anyway later. require('lie/polyfill'); } export default Promise; diff --git a/www/lib/localforage/src/utils/serializer.js b/www/lib/localforage/src/utils/serializer.js index 08e5fc8f..ddeed301 100644 --- a/www/lib/localforage/src/utils/serializer.js +++ b/www/lib/localforage/src/utils/serializer.js @@ -26,6 +26,8 @@ var TYPE_FLOAT64ARRAY = 'fl64'; var TYPE_SERIALIZED_MARKER_LENGTH = SERIALIZED_MARKER_LENGTH + TYPE_ARRAYBUFFER.length; +var toString = Object.prototype.toString; + function stringToBuffer(serializedString) { // Fill the string into a ArrayBuffer. var bufferLength = serializedString.length * 0.75; @@ -87,18 +89,18 @@ function bufferToString(buffer) { // instructs the `setItem()` callback/promise to be executed). This is how // we store binary data with localStorage. function serialize(value, callback) { - var valueString = ''; + var valueType = ''; if (value) { - valueString = value.toString(); + valueType = toString.call(value); } // Cannot use `value instanceof ArrayBuffer` or such here, as these // checks fail when running the tests using casper.js... // // TODO: See why those tests fail and use a better solution. - if (value && (value.toString() === '[object ArrayBuffer]' || + if (value && (valueType === '[object ArrayBuffer]' || value.buffer && - value.buffer.toString() === '[object ArrayBuffer]')) { + toString.call(value.buffer) === '[object ArrayBuffer]')) { // Convert binary arrays to a string and prefix the string with // a special marker. var buffer; @@ -110,23 +112,23 @@ function serialize(value, callback) { } else { buffer = value.buffer; - if (valueString === '[object Int8Array]') { + if (valueType === '[object Int8Array]') { marker += TYPE_INT8ARRAY; - } else if (valueString === '[object Uint8Array]') { + } else if (valueType === '[object Uint8Array]') { marker += TYPE_UINT8ARRAY; - } else if (valueString === '[object Uint8ClampedArray]') { + } else if (valueType === '[object Uint8ClampedArray]') { marker += TYPE_UINT8CLAMPEDARRAY; - } else if (valueString === '[object Int16Array]') { + } else if (valueType === '[object Int16Array]') { marker += TYPE_INT16ARRAY; - } else if (valueString === '[object Uint16Array]') { + } else if (valueType === '[object Uint16Array]') { marker += TYPE_UINT16ARRAY; - } else if (valueString === '[object Int32Array]') { + } else if (valueType === '[object Int32Array]') { marker += TYPE_INT32ARRAY; - } else if (valueString === '[object Uint32Array]') { + } else if (valueType === '[object Uint32Array]') { marker += TYPE_UINT32ARRAY; - } else if (valueString === '[object Float32Array]') { + } else if (valueType === '[object Float32Array]') { marker += TYPE_FLOAT32ARRAY; - } else if (valueString === '[object Float64Array]') { + } else if (valueType === '[object Float64Array]') { marker += TYPE_FLOAT64ARRAY; } else { callback(new Error('Failed to get type for BinaryArray')); @@ -134,7 +136,7 @@ function serialize(value, callback) { } callback(marker + bufferToString(buffer)); - } else if (valueString === '[object Blob]') { + } else if (valueType === '[object Blob]') { // Conver the blob to a binaryArray and then to a string. var fileReader = new FileReader(); |
