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"
14 #include "mozilla/ErrorResult.h"
15 #include "mozilla/dom/MozStorageAsyncStatementParamsBinding.h"
16 #include "mozStorageAsyncStatement.h"
17 #include "mozStoragePrivateHelpers.h"
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
)
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,
48 void AsyncStatementParams::NamedGetter(JSContext
* aCx
, const nsAString
& aName
,
50 JS::MutableHandle
<JS::Value
> aResult
,
51 mozilla::ErrorResult
& aRv
) {
53 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
57 // Unfortunately there's no API that lets us return the parameter value.
61 void AsyncStatementParams::NamedSetter(JSContext
* aCx
, const nsAString
& aName
,
62 JS::Handle
<JS::Value
> aValue
,
63 mozilla::ErrorResult
& aRv
) {
65 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
69 NS_ConvertUTF16toUTF8
name(aName
);
71 nsCOMPtr
<nsIVariant
> variant(convertJSValToVariant(aCx
, aValue
));
73 aRv
.Throw(NS_ERROR_UNEXPECTED
);
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
,
87 JS::MutableHandle
<JS::Value
> aResult
,
88 mozilla::ErrorResult
& aRv
) {
90 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
94 // Unfortunately there's no API that lets us return the parameter value.
98 void AsyncStatementParams::IndexedSetter(JSContext
* aCx
, uint32_t aIndex
,
99 JS::Handle
<JS::Value
> aValue
,
100 mozilla::ErrorResult
& aRv
) {
102 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
106 nsCOMPtr
<nsIVariant
> variant(convertJSValToVariant(aCx
, aValue
));
108 aRv
.Throw(NS_ERROR_UNEXPECTED
);
112 aRv
= mStatement
->BindByIndex(aIndex
, variant
);
115 } // namespace storage
116 } // namespace mozilla