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/TestInterfaceIterableDouble.h"
8 #include "mozilla/dom/TestInterfaceJSMaplikeSetlikeIterableBinding.h"
9 #include "nsPIDOMWindow.h"
10 #include "mozilla/dom/BindingUtils.h"
12 namespace mozilla::dom
{
14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TestInterfaceIterableDouble
, mParent
)
16 NS_IMPL_CYCLE_COLLECTING_ADDREF(TestInterfaceIterableDouble
)
17 NS_IMPL_CYCLE_COLLECTING_RELEASE(TestInterfaceIterableDouble
)
19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestInterfaceIterableDouble
)
20 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
21 NS_INTERFACE_MAP_ENTRY(nsISupports
)
24 TestInterfaceIterableDouble::TestInterfaceIterableDouble(
25 nsPIDOMWindowInner
* aParent
)
27 mValues
.AppendElement(std::pair
<nsString
, nsString
>(u
"a"_ns
, u
"b"_ns
));
28 mValues
.AppendElement(std::pair
<nsString
, nsString
>(u
"c"_ns
, u
"d"_ns
));
29 mValues
.AppendElement(std::pair
<nsString
, nsString
>(u
"e"_ns
, u
"f"_ns
));
33 already_AddRefed
<TestInterfaceIterableDouble
>
34 TestInterfaceIterableDouble::Constructor(const GlobalObject
& aGlobal
,
36 nsCOMPtr
<nsPIDOMWindowInner
> window
=
37 do_QueryInterface(aGlobal
.GetAsSupports());
39 aRv
.Throw(NS_ERROR_FAILURE
);
43 RefPtr
<TestInterfaceIterableDouble
> r
=
44 new TestInterfaceIterableDouble(window
);
48 JSObject
* TestInterfaceIterableDouble::WrapObject(
49 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
50 return TestInterfaceIterableDouble_Binding::Wrap(aCx
, this, aGivenProto
);
53 nsPIDOMWindowInner
* TestInterfaceIterableDouble::GetParentObject() const {
57 size_t TestInterfaceIterableDouble::GetIterableLength() {
58 return mValues
.Length();
61 nsAString
& TestInterfaceIterableDouble::GetKeyAtIndex(uint32_t aIndex
) {
62 MOZ_ASSERT(aIndex
< mValues
.Length());
63 return mValues
.ElementAt(aIndex
).first
;
66 nsAString
& TestInterfaceIterableDouble::GetValueAtIndex(uint32_t aIndex
) {
67 MOZ_ASSERT(aIndex
< mValues
.Length());
68 return mValues
.ElementAt(aIndex
).second
;
71 } // namespace mozilla::dom