From f8239567d1c6d217de6a7135632bda987c741ef6 Mon Sep 17 00:00:00 2001 From: Marco Bonardo Date: Mon, 6 Feb 2017 19:30:19 +0100 Subject: [PATCH] Bug 1336944 - Change Sqlite.jsm to bind TypedArrays as Blobs, not common Arrays. r=Gijs 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 --HG-- extra : rebase_source : e9f63f06892d9db801951243648eddd148646426 --- .../components/migration/tests/unit/test_Chrome_passwords.js | 2 +- toolkit/modules/Sqlite.jsm | 3 ++- toolkit/modules/tests/xpcshell/test_sqlite.js | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/browser/components/migration/tests/unit/test_Chrome_passwords.js b/browser/components/migration/tests/unit/test_Chrome_passwords.js index 25c164bc9f87..a9281fdea4bb 100644 --- a/browser/components/migration/tests/unit/test_Chrome_passwords.js +++ b/browser/components/migration/tests/unit/test_Chrome_passwords.js @@ -80,7 +80,7 @@ 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 diff --git a/toolkit/modules/Sqlite.jsm b/toolkit/modules/Sqlite.jsm index 665d9d61e6bf..932fbe7cd2d6 100644 --- a/toolkit/modules/Sqlite.jsm +++ b/toolkit/modules/Sqlite.jsm @@ -680,7 +680,8 @@ ConnectionData.prototype = Object.freeze({ } 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"}`; diff --git a/toolkit/modules/tests/xpcshell/test_sqlite.js b/toolkit/modules/tests/xpcshell/test_sqlite.js index 3da420f1d84f..f5bcf572c505 100644 --- a/toolkit/modules/tests/xpcshell/test_sqlite.js +++ b/toolkit/modules/tests/xpcshell/test_sqlite.js @@ -1103,7 +1103,7 @@ add_task(function* test_datatypes() { 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 }, @@ -1111,7 +1111,7 @@ add_task(function* test_datatypes() { 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 }