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/TestInterfaceIterableDoubleUnion.h"
8 #include "mozilla/dom/TestInterfaceJSMaplikeSetlikeIterableBinding.h"
9 #include "mozilla/dom/UnionTypes.h"
10 #include "nsPIDOMWindow.h"
11 #include "mozilla/dom/BindingUtils.h"
13 namespace mozilla::dom
{
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TestInterfaceIterableDoubleUnion
, mParent
)
17 NS_IMPL_CYCLE_COLLECTING_ADDREF(TestInterfaceIterableDoubleUnion
)
18 NS_IMPL_CYCLE_COLLECTING_RELEASE(TestInterfaceIterableDoubleUnion
)
20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestInterfaceIterableDoubleUnion
)
21 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
22 NS_INTERFACE_MAP_ENTRY(nsISupports
)
25 TestInterfaceIterableDoubleUnion::TestInterfaceIterableDoubleUnion(
26 nsPIDOMWindowInner
* aParent
)
30 mValues
.AppendElement(std::pair
<nsString
, OwningStringOrLong
>(u
"long"_ns
, a
));
31 a
.SetAsString() = u
"a"_ns
;
32 mValues
.AppendElement(
33 std::pair
<nsString
, OwningStringOrLong
>(u
"string"_ns
, a
));
37 already_AddRefed
<TestInterfaceIterableDoubleUnion
>
38 TestInterfaceIterableDoubleUnion::Constructor(const GlobalObject
& aGlobal
,
40 nsCOMPtr
<nsPIDOMWindowInner
> window
=
41 do_QueryInterface(aGlobal
.GetAsSupports());
43 aRv
.Throw(NS_ERROR_FAILURE
);
47 RefPtr
<TestInterfaceIterableDoubleUnion
> r
=
48 new TestInterfaceIterableDoubleUnion(window
);
52 JSObject
* TestInterfaceIterableDoubleUnion::WrapObject(
53 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
54 return TestInterfaceIterableDoubleUnion_Binding::Wrap(aCx
, this, aGivenProto
);
57 nsPIDOMWindowInner
* TestInterfaceIterableDoubleUnion::GetParentObject() const {
61 size_t TestInterfaceIterableDoubleUnion::GetIterableLength() {
62 return mValues
.Length();
65 nsAString
& TestInterfaceIterableDoubleUnion::GetKeyAtIndex(uint32_t aIndex
) {
66 MOZ_ASSERT(aIndex
< mValues
.Length());
67 return mValues
.ElementAt(aIndex
).first
;
70 OwningStringOrLong
& TestInterfaceIterableDoubleUnion::GetValueAtIndex(
72 MOZ_ASSERT(aIndex
< mValues
.Length());
73 return mValues
.ElementAt(aIndex
).second
;
76 } // namespace mozilla::dom