Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / bindings / test / TestInterfaceObservableArray.cpp
blobcb8d532eb86cac8ff5fd84fc9af8e29bd0b353b9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/TestInterfaceObservableArray.h"
8 #include "mozilla/dom/TestInterfaceObservableArrayBinding.h"
9 #include "nsPIDOMWindow.h"
10 #include "mozilla/dom/BindingUtils.h"
12 namespace mozilla::dom {
14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TestInterfaceObservableArray, mParent,
15 mSetBooleanCallback,
16 mDeleteBooleanCallback,
17 mSetObjectCallback, mDeleteObjectCallback,
18 mSetInterfaceCallback,
19 mDeleteInterfaceCallback)
21 NS_IMPL_CYCLE_COLLECTING_ADDREF(TestInterfaceObservableArray)
22 NS_IMPL_CYCLE_COLLECTING_RELEASE(TestInterfaceObservableArray)
24 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestInterfaceObservableArray)
25 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
26 NS_INTERFACE_MAP_ENTRY(nsISupports)
27 NS_INTERFACE_MAP_END
29 TestInterfaceObservableArray::TestInterfaceObservableArray(
30 nsPIDOMWindowInner* aParent, const ObservableArrayCallbacks& aCallbacks)
31 : mParent(aParent) {
32 if (aCallbacks.mSetBooleanCallback.WasPassed()) {
33 mSetBooleanCallback = &aCallbacks.mSetBooleanCallback.Value();
35 if (aCallbacks.mDeleteBooleanCallback.WasPassed()) {
36 mDeleteBooleanCallback = &aCallbacks.mDeleteBooleanCallback.Value();
38 if (aCallbacks.mSetObjectCallback.WasPassed()) {
39 mSetObjectCallback = &aCallbacks.mSetObjectCallback.Value();
41 if (aCallbacks.mDeleteObjectCallback.WasPassed()) {
42 mDeleteObjectCallback = &aCallbacks.mDeleteObjectCallback.Value();
44 if (aCallbacks.mSetInterfaceCallback.WasPassed()) {
45 mSetInterfaceCallback = &aCallbacks.mSetInterfaceCallback.Value();
47 if (aCallbacks.mDeleteInterfaceCallback.WasPassed()) {
48 mDeleteInterfaceCallback = &aCallbacks.mDeleteInterfaceCallback.Value();
52 // static
53 already_AddRefed<TestInterfaceObservableArray>
54 TestInterfaceObservableArray::Constructor(
55 const GlobalObject& aGlobal, const ObservableArrayCallbacks& aCallbacks,
56 ErrorResult& aRv) {
57 nsCOMPtr<nsPIDOMWindowInner> window =
58 do_QueryInterface(aGlobal.GetAsSupports());
59 if (!window) {
60 aRv.Throw(NS_ERROR_FAILURE);
61 return nullptr;
64 RefPtr<TestInterfaceObservableArray> r =
65 new TestInterfaceObservableArray(window, aCallbacks);
66 return r.forget();
69 JSObject* TestInterfaceObservableArray::WrapObject(
70 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
71 return TestInterfaceObservableArray_Binding::Wrap(aCx, this, aGivenProto);
74 nsPIDOMWindowInner* TestInterfaceObservableArray::GetParentObject() const {
75 return mParent;
78 void TestInterfaceObservableArray::OnSetObservableArrayObject(
79 JSContext* aCx, JS::Handle<JSObject*> aValue, uint32_t aIndex,
80 ErrorResult& aRv) {
81 if (mSetObjectCallback) {
82 MOZ_KnownLive(mSetObjectCallback)
83 ->Call(aValue, aIndex, aRv, "OnSetObservableArrayObject",
84 CallbackFunction::eRethrowExceptions);
88 void TestInterfaceObservableArray::OnDeleteObservableArrayObject(
89 JSContext* aCx, JS::Handle<JSObject*> aValue, uint32_t aIndex,
90 ErrorResult& aRv) {
91 if (mDeleteObjectCallback) {
92 MOZ_KnownLive(mDeleteObjectCallback)
93 ->Call(aValue, aIndex, aRv, "OnDeleteObservableArrayObject",
94 CallbackFunction::eRethrowExceptions);
98 void TestInterfaceObservableArray::OnSetObservableArrayBoolean(
99 bool aValue, uint32_t aIndex, ErrorResult& aRv) {
100 if (mSetBooleanCallback) {
101 MOZ_KnownLive(mSetBooleanCallback)
102 ->Call(aValue, aIndex, aRv, "OnSetObservableArrayBoolean",
103 CallbackFunction::eRethrowExceptions);
107 void TestInterfaceObservableArray::OnDeleteObservableArrayBoolean(
108 bool aValue, uint32_t aIndex, ErrorResult& aRv) {
109 if (mDeleteBooleanCallback) {
110 MOZ_KnownLive(mDeleteBooleanCallback)
111 ->Call(aValue, aIndex, aRv, "OnDeleteObservableArrayBoolean",
112 CallbackFunction::eRethrowExceptions);
116 void TestInterfaceObservableArray::OnSetObservableArrayInterface(
117 TestInterfaceObservableArray* aValue, uint32_t aIndex, ErrorResult& aRv) {
118 if (mSetInterfaceCallback && aValue) {
119 MOZ_KnownLive(mSetInterfaceCallback)
120 ->Call(*aValue, aIndex, aRv, "OnSetObservableArrayInterface",
121 CallbackFunction::eRethrowExceptions);
125 void TestInterfaceObservableArray::OnDeleteObservableArrayInterface(
126 TestInterfaceObservableArray* aValue, uint32_t aIndex, ErrorResult& aRv) {
127 if (mDeleteInterfaceCallback && aValue) {
128 MOZ_KnownLive(mDeleteInterfaceCallback)
129 ->Call(*aValue, aIndex, aRv, "OnDeleteObservableArrayInterface",
130 CallbackFunction::eRethrowExceptions);
134 bool TestInterfaceObservableArray::BooleanElementAtInternal(uint32_t aIndex,
135 ErrorResult& aRv) {
136 return TestInterfaceObservableArray_Binding::ObservableArrayBooleanHelpers::
137 ElementAt(this, aIndex, aRv);
140 void TestInterfaceObservableArray::ObjectElementAtInternal(
141 JSContext* aCx, uint32_t aIndex, JS::MutableHandle<JSObject*> aValue,
142 ErrorResult& aRv) {
143 TestInterfaceObservableArray_Binding::ObservableArrayObjectHelpers::ElementAt(
144 this, aCx, aIndex, aValue, aRv);
147 already_AddRefed<TestInterfaceObservableArray>
148 TestInterfaceObservableArray::InterfaceElementAtInternal(uint32_t aIndex,
149 ErrorResult& aRv) {
150 return TestInterfaceObservableArray_Binding::ObservableArrayInterfaceHelpers::
151 ElementAt(this, aIndex, aRv);
154 void TestInterfaceObservableArray::BooleanReplaceElementAtInternal(
155 uint32_t aIndex, bool aValue, ErrorResult& aRv) {
156 TestInterfaceObservableArray_Binding::ObservableArrayBooleanHelpers::
157 ReplaceElementAt(this, aIndex, aValue, aRv);
160 void TestInterfaceObservableArray::ObjectReplaceElementAtInternal(
161 JSContext* aCx, uint32_t aIndex, JS::Handle<JSObject*> aValue,
162 ErrorResult& aRv) {
163 TestInterfaceObservableArray_Binding::ObservableArrayObjectHelpers::
164 ReplaceElementAt(this, aIndex, aValue, aRv);
167 void TestInterfaceObservableArray::InterfaceReplaceElementAtInternal(
168 uint32_t aIndex, TestInterfaceObservableArray& aValue, ErrorResult& aRv) {
169 TestInterfaceObservableArray_Binding::ObservableArrayInterfaceHelpers::
170 ReplaceElementAt(this, aIndex, aValue, aRv);
173 void TestInterfaceObservableArray::BooleanAppendElementInternal(
174 bool aValue, ErrorResult& aRv) {
175 TestInterfaceObservableArray_Binding::ObservableArrayBooleanHelpers::
176 AppendElement(this, aValue, aRv);
179 void TestInterfaceObservableArray::ObjectAppendElementInternal(
180 JSContext* aCx, JS::Handle<JSObject*> aValue, ErrorResult& aRv) {
181 TestInterfaceObservableArray_Binding::ObservableArrayObjectHelpers::
182 AppendElement(this, aValue, aRv);
185 void TestInterfaceObservableArray::InterfaceAppendElementInternal(
186 TestInterfaceObservableArray& aValue, ErrorResult& aRv) {
187 TestInterfaceObservableArray_Binding::ObservableArrayInterfaceHelpers::
188 AppendElement(this, aValue, aRv);
191 void TestInterfaceObservableArray::BooleanRemoveLastElementInternal(
192 ErrorResult& aRv) {
193 TestInterfaceObservableArray_Binding::ObservableArrayBooleanHelpers::
194 RemoveLastElement(this, aRv);
197 void TestInterfaceObservableArray::ObjectRemoveLastElementInternal(
198 ErrorResult& aRv) {
199 TestInterfaceObservableArray_Binding::ObservableArrayObjectHelpers::
200 RemoveLastElement(this, aRv);
203 void TestInterfaceObservableArray::InterfaceRemoveLastElementInternal(
204 ErrorResult& aRv) {
205 TestInterfaceObservableArray_Binding::ObservableArrayInterfaceHelpers::
206 RemoveLastElement(this, aRv);
209 uint32_t TestInterfaceObservableArray::BooleanLengthInternal(ErrorResult& aRv) {
210 return TestInterfaceObservableArray_Binding::ObservableArrayBooleanHelpers::
211 Length(this, aRv);
214 uint32_t TestInterfaceObservableArray::ObjectLengthInternal(ErrorResult& aRv) {
215 return TestInterfaceObservableArray_Binding::ObservableArrayObjectHelpers::
216 Length(this, aRv);
219 uint32_t TestInterfaceObservableArray::InterfaceLengthInternal(
220 ErrorResult& aRv) {
221 return TestInterfaceObservableArray_Binding::ObservableArrayInterfaceHelpers::
222 Length(this, aRv);
225 } // namespace mozilla::dom