Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/storage/mozStorageAsyncStatementParams.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/MozStorageAsyncStatementParamsBinding.h"
14
#include "mozStoragePrivateHelpers.h"
15
16
namespace mozilla {
17
namespace storage {
18
19
////////////////////////////////////////////////////////////////////////////////
20
//// AsyncStatementParams
21
22
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AsyncStatementParams, mWindow)
23
24
0
NS_INTERFACE_TABLE_HEAD(AsyncStatementParams)
25
0
  NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
26
0
  NS_INTERFACE_TABLE(AsyncStatementParams, nsISupports)
27
0
  NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(AsyncStatementParams)
28
0
NS_INTERFACE_MAP_END
29
30
NS_IMPL_CYCLE_COLLECTING_ADDREF(AsyncStatementParams)
31
NS_IMPL_CYCLE_COLLECTING_RELEASE(AsyncStatementParams)
32
33
AsyncStatementParams::AsyncStatementParams(nsPIDOMWindowInner* aWindow, AsyncStatement *aStatement)
34
: mWindow(aWindow),
35
  mStatement(aStatement)
36
0
{
37
0
  NS_ASSERTION(mStatement != nullptr, "mStatement is null");
38
0
}
39
40
JSObject*
41
AsyncStatementParams::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
42
0
{
43
0
  return dom::MozStorageAsyncStatementParams_Binding::Wrap(aCx, this, aGivenProto);
44
0
}
45
46
void
47
AsyncStatementParams::NamedGetter(JSContext* aCx,
48
                                  const nsAString& aName,
49
                                  bool& aFound,
50
                                  JS::MutableHandle<JS::Value> aResult,
51
                                  mozilla::ErrorResult& aRv)
52
0
{
53
0
  if (!mStatement) {
54
0
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
55
0
    return;
56
0
  }
57
0
58
0
  // Unfortunately there's no API that lets us return the parameter value.
59
0
  aFound = false;
60
0
}
61
62
void
63
AsyncStatementParams::NamedSetter(JSContext* aCx,
64
                                  const nsAString& aName,
65
                                  JS::Handle<JS::Value> aValue,
66
                                  mozilla::ErrorResult& aRv)
67
0
{
68
0
  if (!mStatement) {
69
0
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
70
0
    return;
71
0
  }
72
0
73
0
  NS_ConvertUTF16toUTF8 name(aName);
74
0
75
0
  nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
76
0
  if (!variant) {
77
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
78
0
    return;
79
0
  }
80
0
81
0
  aRv = mStatement->BindByName(name, variant);
82
0
}
83
84
void
85
AsyncStatementParams::GetSupportedNames(nsTArray<nsString>& aNames)
86
0
{
87
0
  // We don't know how many params there are, so we can't implement this for
88
0
  // AsyncStatementParams.
89
0
}
90
91
void
92
AsyncStatementParams::IndexedGetter(JSContext* aCx,
93
                                    uint32_t aIndex,
94
                                    bool& aFound,
95
                                    JS::MutableHandle<JS::Value> aResult,
96
                                    mozilla::ErrorResult& aRv)
97
0
{
98
0
  if (!mStatement) {
99
0
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
100
0
    return;
101
0
  }
102
0
103
0
  // Unfortunately there's no API that lets us return the parameter value.
104
0
  aFound = false;
105
0
}
106
107
void
108
AsyncStatementParams::IndexedSetter(JSContext* aCx,
109
                                    uint32_t aIndex,
110
                                    JS::Handle<JS::Value> aValue,
111
                                    mozilla::ErrorResult& aRv)
112
0
{
113
0
  if (!mStatement) {
114
0
    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
115
0
    return;
116
0
  }
117
0
118
0
  nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
119
0
  if (!variant) {
120
0
    aRv.Throw(NS_ERROR_UNEXPECTED);
121
0
    return;
122
0
  }
123
0
124
0
  aRv = mStatement->BindByIndex(aIndex, variant);
125
0
}
126
127
} // namespace storage
128
} // namespace mozilla