Bug 1336944 - Change Sqlite.jsm to bind TypedArrays as Blobs, not common Arrays. r=Gijs a=gchang
authorMarco Bonardo <mbonardo@mozilla.com>
Mon, 06 Feb 2017 19:30:19 +0100
changeset 376023 eae7e45deb55defb86c7c30fdfcf20c5d017b98d
parent 376022 e13bac1442d27da93a2fd572b06621ac713b0fbf
child 376024 522951ff7046fd2bdf3916c973fbfde27be0af31
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, gchang
bugs1336944
milestone53.0a2
Bug 1336944 - Change Sqlite.jsm to bind TypedArrays as Blobs, not common Arrays. r=Gijs a=gchang Currently an Array is bound as a blob. Unfortunately this occupies the best javascript code path to bind an array to an IN clause in the future. We would like Arrays to bind to IN lists, while still keeping a nice interface to bind blobs. This patch makes Uint8Array bind to blob, while Array is left available for future use. MozReview-Commit-ID: 7xzumBs8JTe
browser/components/migration/tests/unit/test_Chrome_passwords.js
toolkit/modules/Sqlite.jsm
toolkit/modules/tests/xpcshell/test_sqlite.js
--- a/browser/components/migration/tests/unit/test_Chrome_passwords.js
+++ b/browser/components/migration/tests/unit/test_Chrome_passwords.js
@@ -75,17 +75,17 @@ const TEST_LOGINS = [
     timesUsed: 1,
   },
 ];
 
 var crypto = new OSCrypto();
 var dbConn;
 
 function promiseSetPassword(login) {
-  let passwordValue = crypto.stringToArray(crypto.encryptData(login.password));
+  let passwordValue = new Uint8Array(crypto.stringToArray(crypto.encryptData(login.password)));
   return dbConn.execute(`UPDATE logins
                          SET password_value = :password_value
                          WHERE rowid = :rowid
                         `, { password_value: passwordValue,
                              rowid: login.id });
 }
 
 function checkLoginsAreEqual(passwordManagerLogin, chromeLogin, id) {
--- a/toolkit/modules/Sqlite.jsm
+++ b/toolkit/modules/Sqlite.jsm
@@ -675,17 +675,18 @@ ConnectionData.prototype = Object.freeze
    * reflection.
    */
   _bindParameters(statement, params) {
     if (!params) {
       return;
     }
 
     function bindParam(obj, key, val) {
-      let isBlob = Array.isArray(val);
+      let isBlob = val && typeof val == "object" &&
+                   val.constructor.name == "Uint8Array";
       let args = [key, val].concat(isBlob ? [val.length] : []);
       let methodName =
         `bind${isBlob ? "Blob" : ""}By${typeof key == "number" ? "Index" : "Name"}`;
       obj[methodName](...args);
     }
 
     if (Array.isArray(params)) {
       // It's an array of separate params.
--- a/toolkit/modules/tests/xpcshell/test_sqlite.js
+++ b/toolkit/modules/tests/xpcshell/test_sqlite.js
@@ -1099,25 +1099,25 @@ add_task(function* test_datatypes() {
                      real_col    REAL    NOT NULL,
                      numeric_col NUMERIC NOT NULL
                    )`);
   const bindings = [
     {
       null_col: null,
       integer_col: 12345,
       text_col: "qwerty",
-      blob_col: new Array(256).fill(undefined).map( (value, index) => index % 256 ),
+      blob_col: new Uint8Array(256).map( (value, index) => index % 256 ),
       real_col: 3.14159265359,
       numeric_col: true
     },
     {
       null_col: null,
       integer_col: -12345,
       text_col: "",
-      blob_col: new Array(256 * 2).fill(undefined).map( (value, index) => index % 256 ),
+      blob_col: new Uint8Array(256 * 2).map( (value, index) => index % 256 ),
       real_col: Number.NEGATIVE_INFINITY,
       numeric_col: false
     }
   ];
 
   yield c.execute(`INSERT INTO datatypes VALUES (
                      :null_col,
                      :integer_col,