diff --git a/storage/src/mozStorageStatement.cpp b/storage/src/mozStorageStatement.cpp index cf342e3b5713..8ef7500e4e23 100644 --- a/storage/src/mozStorageStatement.cpp +++ b/storage/src/mozStorageStatement.cpp @@ -671,6 +671,9 @@ Statement::BindParameters(mozIStorageBindingParamsArray *aParameters) if (array->getOwner() != this) return NS_ERROR_UNEXPECTED; + if (array->length() == 0) + return NS_ERROR_UNEXPECTED; + mParamsArray = array; mParamsArray->lock(); diff --git a/storage/test/unit/test_statement_executeAsync.js b/storage/test/unit/test_statement_executeAsync.js index 724d7a3cb919..1f672848494b 100644 --- a/storage/test/unit/test_statement_executeAsync.js +++ b/storage/test/unit/test_statement_executeAsync.js @@ -956,6 +956,32 @@ function test_not_right_owning_statement() run_next_test(); } +function test_bind_empty_array() +{ + let stmt = getOpenedDatabase().createStatement( + "INSERT INTO test (id) " + + "VALUES (:int)" + ); + + let paramsArray = stmt.newBindingParamsArray(); + + // We should not be able to bind this array to the statement because it is + // empty. + let exceptionCaught = false; + try { + stmt.bindParameters(paramsArray); + do_throw("we should have an exception!"); + } + catch(e) { + do_check_eq(e.result, Cr.NS_ERROR_UNEXPECTED); + exceptionCaught = true; + } + do_check_true(exceptionCaught); + + // Run the next test. + run_next_test(); +} + function test_multiple_results() { // First, we need to know how many rows we are expecting. @@ -1027,6 +1053,7 @@ var tests = test_bind_bogus_type_by_name, test_bind_params_already_locked, test_bind_params_array_already_locked, + test_bind_empty_array, test_no_binding_params_from_locked_array, test_not_right_owning_array, test_not_right_owning_statement, @@ -1039,7 +1066,14 @@ function run_next_test() if (index < tests.length) { do_test_pending(); print("Running the next test: " + tests[index].name); - tests[index++](); + + // Asynchronous tests means that exceptions don't kill the test. + try { + tests[index++](); + } + catch (e) { + do_throw(e); + } } do_test_finished();