diff --git a/src/providers/websql.js b/src/providers/websql.js index 6da7038..4101de1 100644 --- a/src/providers/websql.js +++ b/src/providers/websql.js @@ -4,6 +4,7 @@ define(function(require) { var WSQL_VERSION = require('src/constants').WSQL_VERSION; var WSQL_SIZE = require('src/constants').WSQL_SIZE; var WSQL_DESC = require('src/constants').WSQL_DESC; + var u8toArray = require('src/shared').u8toArray; function WebSQLContext(db, isReadOnly) { var that = this; @@ -62,14 +63,7 @@ define(function(require) { if(Object.prototype.toString.call(value) === "[object Uint8Array]") { value = { __isUint8Array: true, - __array: (function() { - var array = []; - var vlen = value.length; - for(var i = 0; i < vlen; i++) { - array[i] = value[i]; - } - return array; - }()) + __array: u8toArray(value) }; } value = JSON.stringify(value); diff --git a/src/shared.js b/src/shared.js index a98d1d4..16d9439 100644 --- a/src/shared.js +++ b/src/shared.js @@ -15,9 +15,22 @@ define(function(require) { function nop() {} + /** + * Convert a Uint8Array to a regular array + */ + function u8toArray(u8) { + var array = []; + var len = u8.length; + for(var i = 0; i < len; i++) { + array[i] = u8[i]; + } + return array; + } + return { guid: guid, hash: hash, + u8toArray: u8toArray, nop: nop };