Bug 1441336 - Use addon permissions for PerformanceTiming properties r=bz,kmag
[gecko.git] / storage / mozStorageAsyncStatementParams.cpp
blob692324eeafed8205944ea866709c50f2effa8163
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, AsyncStatement *aStatement)
34 : mWindow(aWindow),
35 mStatement(aStatement)
37 NS_ASSERTION(mStatement != nullptr, "mStatement is null");
40 JSObject*
41 AsyncStatementParams::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
43 return dom::MozStorageAsyncStatementParamsBinding::Wrap(aCx, this, aGivenProto);
46 void
47 AsyncStatementParams::NamedGetter(JSContext* aCx,
48 const nsAString& aName,
49 bool& aFound,
50 JS::MutableHandle<JS::Value> aResult,
51 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
63 AsyncStatementParams::NamedSetter(JSContext* aCx,
64 const nsAString& aName,
65 JS::Handle<JS::Value> aValue,
66 mozilla::ErrorResult& aRv)
68 if (!mStatement) {
69 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
70 return;
73 NS_ConvertUTF16toUTF8 name(aName);
75 nsCOMPtr<nsIVariant> variant(convertJSValToVariant(aCx, aValue));
76 if (!variant) {
77 aRv.Throw(NS_ERROR_UNEXPECTED);
78 return;
81 aRv = mStatement->BindByName(name, variant);
84 void
85 AsyncStatementParams::GetSupportedNames(nsTArray<nsString>& aNames)
87 // We don't know how many params there are, so we can't implement this for
88 // AsyncStatementParams.
91 void
92 AsyncStatementParams::IndexedGetter(JSContext* aCx,
93 uint32_t aIndex,
94 bool& aFound,
95 JS::MutableHandle<JS::Value> aResult,
96 mozilla::ErrorResult& aRv)
98 if (!mStatement) {
99 aRv.Throw(NS_ERROR_NOT_INITIALIZED);
100 return;
103 // Unfortunately there's no API that lets us return the parameter value.
104 aFound = false;
107 void
108 AsyncStatementParams::IndexedSetter(JSContext* aCx,
109 uint32_t aIndex,
110 JS::Handle<JS::Value> aValue,
111 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