Bug 1750884 - Add style_traits::ToCss for AtomIdent r=emilio
[gecko.git] / storage / mozStorageAsyncStatementParams.cpp
blobbd52173f412a21cde178c54f8b5450eb812945cb
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 "nsMemory.h"
11 #include "nsString.h"
13 #include "jsapi.h"
15 #include "mozilla/ErrorResult.h"
16 #include "mozilla/dom/MozStorageAsyncStatementParamsBinding.h"
17 #include "mozStorageAsyncStatement.h"
18 #include "mozStoragePrivateHelpers.h"
20 namespace mozilla {
21 namespace storage {
23 ////////////////////////////////////////////////////////////////////////////////
24 //// AsyncStatementParams
26 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AsyncStatementParams, mWindow)
28 NS_INTERFACE_TABLE_HEAD(AsyncStatementParams)
29 NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
30 NS_INTERFACE_TABLE(AsyncStatementParams, nsISupports)
31 NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(AsyncStatementParams)
32 NS_INTERFACE_MAP_END
34 NS_IMPL_CYCLE_COLLECTING_ADDREF(AsyncStatementParams)
35 NS_IMPL_CYCLE_COLLECTING_RELEASE(AsyncStatementParams)
37 AsyncStatementParams::AsyncStatementParams(nsPIDOMWindowInner* aWindow,
38 AsyncStatement* aStatement)
39 : mWindow(aWindow), mStatement(aStatement) {
40 NS_ASSERTION(mStatement != nullptr, "mStatement is null");
43 JSObject* AsyncStatementParams::WrapObject(JSContext* aCx,
44 JS::Handle<JSObject*> aGivenProto) {
45 return dom::MozStorageAsyncStatementParams_Binding::Wrap(aCx, this,
46 aGivenProto);
49 void AsyncStatementParams::NamedGetter(JSContext* aCx, const nsAString& aName,
50 bool& aFound,
51 JS::MutableHandle<JS::Value> aResult,
52 mozilla::ErrorResult& aRv) {
53 if (!mStatement) {
54 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
55 return;
58 // Unfortunately there's no API that lets us return the parameter value.
59 aFound = false;
62 void AsyncStatementParams::NamedSetter(JSContext* aCx, const nsAString& aName,
63 JS::Handle<JS::Value> aValue,
64 mozilla::ErrorResult& aRv) {
65 if (!mStatement) {
66 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
67 return;
70 NS_ConvertUTF16toUTF8 name(aName);
72 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
73 if (!variant) {
74 aRv.Throw(NS_ERROR_UNEXPECTED);
75 return;
78 aRv = mStatement->BindByName(name, variant);
81 void AsyncStatementParams::GetSupportedNames(nsTArray<nsString>& aNames) {
82 // We don't know how many params there are, so we can't implement this for
83 // AsyncStatementParams.
86 void AsyncStatementParams::IndexedGetter(JSContext* aCx, uint32_t aIndex,
87 bool& aFound,
88 JS::MutableHandle<JS::Value> aResult,
89 mozilla::ErrorResult& aRv) {
90 if (!mStatement) {
91 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
92 return;
95 // Unfortunately there's no API that lets us return the parameter value.
96 aFound = false;
99 void AsyncStatementParams::IndexedSetter(JSContext* aCx, uint32_t aIndex,
100 JS::Handle<JS::Value> aValue,
101 mozilla::ErrorResult& aRv) {
102 if (!mStatement) {
103 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
104 return;
107 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
108 if (!variant) {
109 aRv.Throw(NS_ERROR_UNEXPECTED);
110 return;
113 aRv = mStatement->BindByIndex(aIndex, variant);
116 } // namespace storage
117 } // namespace mozilla