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"
15 #include "mozilla/ErrorResult.h"
16 #include "mozilla/dom/MozStorageAsyncStatementParamsBinding.h"
17 #include "mozStorageAsyncStatement.h"
18 #include "mozStoragePrivateHelpers.h"
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
)
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,
49 void AsyncStatementParams::NamedGetter(JSContext
* aCx
, const nsAString
& aName
,
51 JS::MutableHandle
<JS::Value
> aResult
,
52 mozilla::ErrorResult
& aRv
) {
54 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
58 // Unfortunately there's no API that lets us return the parameter value.
62 void AsyncStatementParams::NamedSetter(JSContext
* aCx
, const nsAString
& aName
,
63 JS::Handle
<JS::Value
> aValue
,
64 mozilla::ErrorResult
& aRv
) {
66 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
70 NS_ConvertUTF16toUTF8
name(aName
);
72 nsCOMPtr
<nsIVariant
> variant(convertJSValToVariant(aCx
, aValue
));
74 aRv
.Throw(NS_ERROR_UNEXPECTED
);
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
,
88 JS::MutableHandle
<JS::Value
> aResult
,
89 mozilla::ErrorResult
& aRv
) {
91 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
95 // Unfortunately there's no API that lets us return the parameter value.
99 void AsyncStatementParams::IndexedSetter(JSContext
* aCx
, uint32_t aIndex
,
100 JS::Handle
<JS::Value
> aValue
,
101 mozilla::ErrorResult
& aRv
) {
103 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
107 nsCOMPtr
<nsIVariant
> variant(convertJSValToVariant(aCx
, aValue
));
109 aRv
.Throw(NS_ERROR_UNEXPECTED
);
113 aRv
= mStatement
->BindByIndex(aIndex
, variant
);
116 } // namespace storage
117 } // namespace mozilla