Bug 1516570 [wpt PR 14678] - Fix key code for NUMPAD4 and NUMPAD5, a=testonly
[gecko.git] / storage / mozStorageAsyncStatementParams.cpp
blob6c3600e83c3c23f456c33989f5446be0b84fd742
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 "nsJSUtils.h"
8 #include "nsMemory.h"
9 #include "nsString.h"
11 #include "jsapi.h"
13 #include "mozilla/dom/MozStorageAsyncStatementParamsBinding.h"
14 #include "mozStoragePrivateHelpers.h"
16 namespace mozilla {
17 namespace storage {
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)
28 NS_INTERFACE_MAP_END
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,
42 aGivenProto);
45 void AsyncStatementParams::NamedGetter(JSContext* aCx, const nsAString& aName,
46 bool& aFound,
47 JS::MutableHandle<JS::Value> aResult,
48 mozilla::ErrorResult& aRv) {
49 if (!mStatement) {
50 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
51 return;
54 // Unfortunately there's no API that lets us return the parameter value.
55 aFound = false;
58 void AsyncStatementParams::NamedSetter(JSContext* aCx, const nsAString& aName,
59 JS::Handle<JS::Value> aValue,
60 mozilla::ErrorResult& aRv) {
61 if (!mStatement) {
62 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
63 return;
66 NS_ConvertUTF16toUTF8 name(aName);
68 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
69 if (!variant) {
70 aRv.Throw(NS_ERROR_UNEXPECTED);
71 return;
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,
83 bool& aFound,
84 JS::MutableHandle<JS::Value> aResult,
85 mozilla::ErrorResult& aRv) {
86 if (!mStatement) {
87 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
88 return;
91 // Unfortunately there's no API that lets us return the parameter value.
92 aFound = false;
95 void AsyncStatementParams::IndexedSetter(JSContext* aCx, uint32_t aIndex,
96 JS::Handle<JS::Value> aValue,
97 mozilla::ErrorResult& aRv) {
98 if (!mStatement) {
99 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
100 return;
103 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
104 if (!variant) {
105 aRv.Throw(NS_ERROR_UNEXPECTED);
106 return;
109 aRv = mStatement->BindByIndex(aIndex, variant);
112 } // namespace storage
113 } // namespace mozilla