Bug 1766606 [wpt PR 33809] - Update wpt metadata, a=testonly
[gecko.git] / storage / mozStorageBindingParamsArray.cpp
blob1913d4473344c7a6ae2fbdc8ed44e7043a0bebb5
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozStorageBindingParamsArray.h"
8 #include "mozStorageBindingParams.h"
9 #include "StorageBaseStatementInternal.h"
11 namespace mozilla {
12 namespace storage {
14 ////////////////////////////////////////////////////////////////////////////////
15 //// BindingParamsArray
17 BindingParamsArray::BindingParamsArray(
18 StorageBaseStatementInternal* aOwningStatement)
19 : mOwningStatement(aOwningStatement), mLocked(false) {}
21 void BindingParamsArray::lock() {
22 NS_ASSERTION(mLocked == false, "Array has already been locked!");
23 mLocked = true;
25 // We also no longer need to hold a reference to our statement since it owns
26 // us.
27 mOwningStatement = nullptr;
30 const StorageBaseStatementInternal* BindingParamsArray::getOwner() const {
31 return mOwningStatement;
34 NS_IMPL_ISUPPORTS(BindingParamsArray, mozIStorageBindingParamsArray)
36 ///////////////////////////////////////////////////////////////////////////////
37 //// mozIStorageBindingParamsArray
39 NS_IMETHODIMP
40 BindingParamsArray::NewBindingParams(mozIStorageBindingParams** _params) {
41 NS_ENSURE_FALSE(mLocked, NS_ERROR_UNEXPECTED);
43 nsCOMPtr<mozIStorageBindingParams> params(
44 mOwningStatement->newBindingParams(this));
45 NS_ENSURE_TRUE(params, NS_ERROR_UNEXPECTED);
47 params.forget(_params);
48 return NS_OK;
51 NS_IMETHODIMP
52 BindingParamsArray::AddParams(mozIStorageBindingParams* aParameters) {
53 NS_ENSURE_FALSE(mLocked, NS_ERROR_UNEXPECTED);
55 BindingParams* params = static_cast<BindingParams*>(aParameters);
57 // Check to make sure that this set of parameters was created with us.
58 if (params->getOwner() != this) return NS_ERROR_UNEXPECTED;
60 mArray.AppendElement(params);
62 // Lock the parameters only after we've successfully added them.
63 params->lock();
65 return NS_OK;
68 NS_IMETHODIMP
69 BindingParamsArray::GetLength(uint32_t* _length) {
70 *_length = length();
71 return NS_OK;
74 } // namespace storage
75 } // namespace mozilla