Bug 1885565 - Part 1: Add mozac_ic_avatar_circle_24 to ui-icons r=android-reviewers...
[gecko.git] / storage / mozStorageAsyncStatementParams.cpp
blobcb8601504e0b58b1b6416382d4a43358dff6f583
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 "mozStorageAsyncStatementParams.h"
9 #include "nsJSUtils.h"
10 #include "nsString.h"
12 #include "jsapi.h"
14 #include "mozilla/ErrorResult.h"
15 #include "mozilla/dom/MozStorageAsyncStatementParamsBinding.h"
16 #include "mozStorageAsyncStatement.h"
17 #include "mozStoragePrivateHelpers.h"
19 namespace mozilla {
20 namespace storage {
22 ////////////////////////////////////////////////////////////////////////////////
23 //// AsyncStatementParams
25 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AsyncStatementParams, mWindow)
27 NS_INTERFACE_TABLE_HEAD(AsyncStatementParams)
28 NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
29 NS_INTERFACE_TABLE(AsyncStatementParams, nsISupports)
30 NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(AsyncStatementParams)
31 NS_INTERFACE_MAP_END
33 NS_IMPL_CYCLE_COLLECTING_ADDREF(AsyncStatementParams)
34 NS_IMPL_CYCLE_COLLECTING_RELEASE(AsyncStatementParams)
36 AsyncStatementParams::AsyncStatementParams(nsPIDOMWindowInner* aWindow,
37 AsyncStatement* aStatement)
38 : mWindow(aWindow), mStatement(aStatement) {
39 NS_ASSERTION(mStatement != nullptr, "mStatement is null");
42 JSObject* AsyncStatementParams::WrapObject(JSContext* aCx,
43 JS::Handle<JSObject*> aGivenProto) {
44 return dom::MozStorageAsyncStatementParams_Binding::Wrap(aCx, this,
45 aGivenProto);
48 void AsyncStatementParams::NamedGetter(JSContext* aCx, const nsAString& aName,
49 bool& aFound,
50 JS::MutableHandle<JS::Value> aResult,
51 mozilla::ErrorResult& aRv) {
52 if (!mStatement) {
53 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
54 return;
57 // Unfortunately there's no API that lets us return the parameter value.
58 aFound = false;
61 void AsyncStatementParams::NamedSetter(JSContext* aCx, const nsAString& aName,
62 JS::Handle<JS::Value> aValue,
63 mozilla::ErrorResult& aRv) {
64 if (!mStatement) {
65 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
66 return;
69 NS_ConvertUTF16toUTF8 name(aName);
71 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
72 if (!variant) {
73 aRv.Throw(NS_ERROR_UNEXPECTED);
74 return;
77 aRv = mStatement->BindByName(name, variant);
80 void AsyncStatementParams::GetSupportedNames(nsTArray<nsString>& aNames) {
81 // We don't know how many params there are, so we can't implement this for
82 // AsyncStatementParams.
85 void AsyncStatementParams::IndexedGetter(JSContext* aCx, uint32_t aIndex,
86 bool& aFound,
87 JS::MutableHandle<JS::Value> aResult,
88 mozilla::ErrorResult& aRv) {
89 if (!mStatement) {
90 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
91 return;
94 // Unfortunately there's no API that lets us return the parameter value.
95 aFound = false;
98 void AsyncStatementParams::IndexedSetter(JSContext* aCx, uint32_t aIndex,
99 JS::Handle<JS::Value> aValue,
100 mozilla::ErrorResult& aRv) {
101 if (!mStatement) {
102 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
103 return;
106 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
107 if (!variant) {
108 aRv.Throw(NS_ERROR_UNEXPECTED);
109 return;
112 aRv = mStatement->BindByIndex(aIndex, variant);
115 } // namespace storage
116 } // namespace mozilla