Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/storage/mozStorageStatementParams.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#include "nsJSUtils.h"
8
#include "nsMemory.h"
9
#include "nsString.h"
10
11
#include "jsapi.h"
12
13
#include "mozilla/dom/MozStorageStatementParamsBinding.h"
14
#include "mozStoragePrivateHelpers.h"
15
16
namespace mozilla {
17
namespace storage {
18
19
////////////////////////////////////////////////////////////////////////////////
20
//// StatementParams
21
22
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(StatementParams, mWindow)
23
24
0
NS_INTERFACE_TABLE_HEAD(StatementParams)
25
0
  NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
26
0
  NS_INTERFACE_TABLE(StatementParams, nsISupports)
27
0
  NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(StatementParams)
28
0
NS_INTERFACE_MAP_END
29
30
NS_IMPL_CYCLE_COLLECTING_ADDREF(StatementParams)
31
NS_IMPL_CYCLE_COLLECTING_RELEASE(StatementParams)
32
33
StatementParams::StatementParams(nsPIDOMWindowInner* aWindow, Statement *aStatement)
34
: mWindow(aWindow),
35
  mStatement(aStatement),
36
  mParamCount(0)
37
0
{
38
0
  NS_ASSERTION(mStatement != nullptr, "mStatement is null");
39
0
  (void)mStatement->GetParameterCount(&mParamCount);
40
0
}
41
42
JSObject*
43
StatementParams::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
44
0
{
45
0
  return dom::MozStorageStatementParams_Binding::Wrap(aCx, this, aGivenProto);
46
0
}
47
48
void
49
StatementParams::NamedGetter(JSContext* aCx,
50
                             const nsAString& aName,
51
                             bool& aFound,
52
                             JS::MutableHandle<JS::Value> aResult,
53
                             mozilla::ErrorResult& aRv)
54
0
{
55
0
  if (!mStatement) {
56
0
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
57
0
    return;
58
0
  }
59
0
60
0
  // Unfortunately there's no API that lets us return the parameter value.
61
0
  aFound = false;
62
0
}
63
64
void
65
StatementParams::NamedSetter(JSContext* aCx,
66
                             const nsAString& aName,
67
                             JS::Handle<JS::Value> aValue,
68
                             mozilla::ErrorResult& aRv)
69
0
{
70
0
  if (!mStatement) {
71
0
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
72
0
    return;
73
0
  }
74
0
75
0
  NS_ConvertUTF16toUTF8 name(aName);
76
0
77
0
  // Check to see if there's a parameter with this name.
78
0
  nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
79
0
  if (!variant) {
80
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
81
0
    return;
82
0
  }
83
0
84
0
  aRv = mStatement->BindByName(name, variant);
85
0
}
86
87
void
88
StatementParams::GetSupportedNames(nsTArray<nsString>& aNames)
89
0
{
90
0
  if (!mStatement) {
91
0
    return;
92
0
  }
93
0
94
0
  for (uint32_t i = 0; i < mParamCount; i++) {
95
0
    // Get the name of our parameter.
96
0
    nsAutoCString name;
97
0
    nsresult rv = mStatement->GetParameterName(i, name);
98
0
    if (NS_WARN_IF(NS_FAILED(rv))) {
99
0
      return;
100
0
    }
101
0
102
0
    // But drop the first character, which is going to be a ':'.
103
0
    name = Substring(name, 1);
104
0
    aNames.AppendElement(NS_ConvertUTF8toUTF16(name));
105
0
  }
106
0
}
107
108
void
109
StatementParams::IndexedGetter(JSContext* aCx,
110
                               uint32_t aIndex,
111
                               bool& aFound,
112
                               JS::MutableHandle<JS::Value> aResult,
113
                               mozilla::ErrorResult& aRv)
114
0
{
115
0
  if (!mStatement) {
116
0
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
117
0
    return;
118
0
  }
119
0
120
0
  // Unfortunately there's no API that lets us return the parameter value.
121
0
  aFound = false;
122
0
}
123
124
void
125
StatementParams::IndexedSetter(JSContext* aCx,
126
                               uint32_t aIndex,
127
                               JS::Handle<JS::Value> aValue,
128
                               mozilla::ErrorResult& aRv)
129
0
{
130
0
  if (!mStatement) {
131
0
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
132
0
    return;
133
0
  }
134
0
135
0
  nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
136
0
  if (!variant) {
137
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
138
0
    return;
139
0
  }
140
0
141
0
  aRv = mStatement->BindByIndex(aIndex, variant);
142
0
}
143
144
} // namespace storage
145
} // namespace mozilla