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/. */
13 #include "mozilla/dom/MozStorageAsyncStatementParamsBinding.h"
14 #include "mozStoragePrivateHelpers.h"
19 ////////////////////////////////////////////////////////////////////////////////
20 //// AsyncStatementParams
22 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AsyncStatementParams
, mWindow
)
24 NS_INTERFACE_TABLE_HEAD(AsyncStatementParams
)
25 NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
26 NS_INTERFACE_TABLE(AsyncStatementParams
, nsISupports
)
27 NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(AsyncStatementParams
)
30 NS_IMPL_CYCLE_COLLECTING_ADDREF(AsyncStatementParams
)
31 NS_IMPL_CYCLE_COLLECTING_RELEASE(AsyncStatementParams
)
33 AsyncStatementParams::AsyncStatementParams(nsPIDOMWindowInner
* aWindow
,
34 AsyncStatement
* aStatement
)
35 : mWindow(aWindow
), mStatement(aStatement
) {
36 NS_ASSERTION(mStatement
!= nullptr, "mStatement is null");
39 JSObject
* AsyncStatementParams::WrapObject(JSContext
* aCx
,
40 JS::Handle
<JSObject
*> aGivenProto
) {
41 return dom::MozStorageAsyncStatementParams_Binding::Wrap(aCx
, this,
45 void AsyncStatementParams::NamedGetter(JSContext
* aCx
, const nsAString
& aName
,
47 JS::MutableHandle
<JS::Value
> aResult
,
48 mozilla::ErrorResult
& aRv
) {
50 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
54 // Unfortunately there's no API that lets us return the parameter value.
58 void AsyncStatementParams::NamedSetter(JSContext
* aCx
, const nsAString
& aName
,
59 JS::Handle
<JS::Value
> aValue
,
60 mozilla::ErrorResult
& aRv
) {
62 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
66 NS_ConvertUTF16toUTF8
name(aName
);
68 nsCOMPtr
<nsIVariant
> variant(convertJSValToVariant(aCx
, aValue
));
70 aRv
.Throw(NS_ERROR_UNEXPECTED
);
74 aRv
= mStatement
->BindByName(name
, variant
);
77 void AsyncStatementParams::GetSupportedNames(nsTArray
<nsString
>& aNames
) {
78 // We don't know how many params there are, so we can't implement this for
79 // AsyncStatementParams.
82 void AsyncStatementParams::IndexedGetter(JSContext
* aCx
, uint32_t aIndex
,
84 JS::MutableHandle
<JS::Value
> aResult
,
85 mozilla::ErrorResult
& aRv
) {
87 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
91 // Unfortunately there's no API that lets us return the parameter value.
95 void AsyncStatementParams::IndexedSetter(JSContext
* aCx
, uint32_t aIndex
,
96 JS::Handle
<JS::Value
> aValue
,
97 mozilla::ErrorResult
& aRv
) {
99 aRv
.Throw(NS_ERROR_NOT_INITIALIZED
);
103 nsCOMPtr
<nsIVariant
> variant(convertJSValToVariant(aCx
, aValue
));
105 aRv
.Throw(NS_ERROR_UNEXPECTED
);
109 aRv
= mStatement
->BindByIndex(aIndex
, variant
);
112 } // namespace storage
113 } // namespace mozilla