Bug 1697672 [wpt PR 28012] - Disable SVG composited animation if effective zoom is...
[gecko.git] / storage / mozStorageStatementParams.cpp
blob23e651d4416a85d5454015e9e1135414211665f9
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 "mozStorageStatementParams.h"
9 #include "nsJSUtils.h"
10 #include "nsMemory.h"
11 #include "nsString.h"
13 #include "jsapi.h"
15 #include "mozilla/ErrorResult.h"
16 #include "mozilla/dom/MozStorageStatementParamsBinding.h"
17 #include "mozStoragePrivateHelpers.h"
18 #include "mozStorageStatement.h"
20 namespace mozilla {
21 namespace storage {
23 ////////////////////////////////////////////////////////////////////////////////
24 //// StatementParams
26 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(StatementParams, mWindow)
28 NS_INTERFACE_TABLE_HEAD(StatementParams)
29 NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
30 NS_INTERFACE_TABLE(StatementParams, nsISupports)
31 NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(StatementParams)
32 NS_INTERFACE_MAP_END
34 NS_IMPL_CYCLE_COLLECTING_ADDREF(StatementParams)
35 NS_IMPL_CYCLE_COLLECTING_RELEASE(StatementParams)
37 StatementParams::StatementParams(nsPIDOMWindowInner* aWindow,
38 Statement* aStatement)
39 : mWindow(aWindow), mStatement(aStatement), mParamCount(0) {
40 NS_ASSERTION(mStatement != nullptr, "mStatement is null");
41 (void)mStatement->GetParameterCount(&mParamCount);
44 JSObject* StatementParams::WrapObject(JSContext* aCx,
45 JS::Handle<JSObject*> aGivenProto) {
46 return dom::MozStorageStatementParams_Binding::Wrap(aCx, this, aGivenProto);
49 void StatementParams::NamedGetter(JSContext* aCx, const nsAString& aName,
50 bool& aFound,
51 JS::MutableHandle<JS::Value> aResult,
52 mozilla::ErrorResult& aRv) {
53 if (!mStatement) {
54 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
55 return;
58 // Unfortunately there's no API that lets us return the parameter value.
59 aFound = false;
62 void StatementParams::NamedSetter(JSContext* aCx, const nsAString& aName,
63 JS::Handle<JS::Value> aValue,
64 mozilla::ErrorResult& aRv) {
65 if (!mStatement) {
66 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
67 return;
70 NS_ConvertUTF16toUTF8 name(aName);
72 // Check to see if there's a parameter with this name.
73 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
74 if (!variant) {
75 aRv.Throw(NS_ERROR_UNEXPECTED);
76 return;
79 aRv = mStatement->BindByName(name, variant);
82 void StatementParams::GetSupportedNames(nsTArray<nsString>& aNames) {
83 if (!mStatement) {
84 return;
87 for (uint32_t i = 0; i < mParamCount; i++) {
88 // Get the name of our parameter.
89 nsAutoCString name;
90 nsresult rv = mStatement->GetParameterName(i, name);
91 if (NS_WARN_IF(NS_FAILED(rv))) {
92 return;
95 // But drop the first character, which is going to be a ':'.
96 name = Substring(name, 1);
97 aNames.AppendElement(NS_ConvertUTF8toUTF16(name));
101 void StatementParams::IndexedGetter(JSContext* aCx, uint32_t aIndex,
102 bool& aFound,
103 JS::MutableHandle<JS::Value> aResult,
104 mozilla::ErrorResult& aRv) {
105 if (!mStatement) {
106 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
107 return;
110 // Unfortunately there's no API that lets us return the parameter value.
111 aFound = false;
114 void StatementParams::IndexedSetter(JSContext* aCx, uint32_t aIndex,
115 JS::Handle<JS::Value> aValue,
116 mozilla::ErrorResult& aRv) {
117 if (!mStatement) {
118 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
119 return;
122 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
123 if (!variant) {
124 aRv.Throw(NS_ERROR_UNEXPECTED);
125 return;
128 aRv = mStatement->BindByIndex(aIndex, variant);
131 } // namespace storage
132 } // namespace mozilla