Bug 1639153 - Part 6.3: Establish dependency from tls for arm callWithABI div/mod...
[gecko.git] / storage / mozStorageStatementParams.cpp
blob64e60eb8702402b846d454eccd71a24a3c27690a
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/MozStorageStatementParamsBinding.h"
14 #include "mozStoragePrivateHelpers.h"
16 namespace mozilla {
17 namespace storage {
19 ////////////////////////////////////////////////////////////////////////////////
20 //// StatementParams
22 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(StatementParams, mWindow)
24 NS_INTERFACE_TABLE_HEAD(StatementParams)
25 NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
26 NS_INTERFACE_TABLE(StatementParams, nsISupports)
27 NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(StatementParams)
28 NS_INTERFACE_MAP_END
30 NS_IMPL_CYCLE_COLLECTING_ADDREF(StatementParams)
31 NS_IMPL_CYCLE_COLLECTING_RELEASE(StatementParams)
33 StatementParams::StatementParams(nsPIDOMWindowInner* aWindow,
34 Statement* aStatement)
35 : mWindow(aWindow), mStatement(aStatement), mParamCount(0) {
36 NS_ASSERTION(mStatement != nullptr, "mStatement is null");
37 (void)mStatement->GetParameterCount(&mParamCount);
40 JSObject* StatementParams::WrapObject(JSContext* aCx,
41 JS::Handle<JSObject*> aGivenProto) {
42 return dom::MozStorageStatementParams_Binding::Wrap(aCx, this, aGivenProto);
45 void StatementParams::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 StatementParams::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 // Check to see if there's a parameter with this name.
69 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
70 if (!variant) {
71 aRv.Throw(NS_ERROR_UNEXPECTED);
72 return;
75 aRv = mStatement->BindByName(name, variant);
78 void StatementParams::GetSupportedNames(nsTArray<nsString>& aNames) {
79 if (!mStatement) {
80 return;
83 for (uint32_t i = 0; i < mParamCount; i++) {
84 // Get the name of our parameter.
85 nsAutoCString name;
86 nsresult rv = mStatement->GetParameterName(i, name);
87 if (NS_WARN_IF(NS_FAILED(rv))) {
88 return;
91 // But drop the first character, which is going to be a ':'.
92 name = Substring(name, 1);
93 aNames.AppendElement(NS_ConvertUTF8toUTF16(name));
97 void StatementParams::IndexedGetter(JSContext* aCx, uint32_t aIndex,
98 bool& aFound,
99 JS::MutableHandle<JS::Value> aResult,
100 mozilla::ErrorResult& aRv) {
101 if (!mStatement) {
102 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
103 return;
106 // Unfortunately there's no API that lets us return the parameter value.
107 aFound = false;
110 void StatementParams::IndexedSetter(JSContext* aCx, uint32_t aIndex,
111 JS::Handle<JS::Value> aValue,
112 mozilla::ErrorResult& aRv) {
113 if (!mStatement) {
114 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
115 return;
118 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
119 if (!variant) {
120 aRv.Throw(NS_ERROR_UNEXPECTED);
121 return;
124 aRv = mStatement->BindByIndex(aIndex, variant);
127 } // namespace storage
128 } // namespace mozilla