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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_DOMStringList_h
8 #define mozilla_dom_DOMStringList_h
10 #include "nsISupports.h"
12 #include "nsWrapperCache.h"
15 namespace mozilla::dom
{
17 class DOMStringList
: public nsISupports
, public nsWrapperCache
{
19 virtual ~DOMStringList();
22 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
23 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(DOMStringList
)
25 virtual JSObject
* WrapObject(JSContext
* aCx
,
26 JS::Handle
<JSObject
*> aGivenProto
) override
;
27 nsISupports
* GetParentObject() { return nullptr; }
29 void IndexedGetter(uint32_t aIndex
, bool& aFound
, nsAString
& aResult
) {
31 if (aIndex
< mNames
.Length()) {
33 aResult
= mNames
[aIndex
];
39 void Item(uint32_t aIndex
, nsAString
& aResult
) {
41 if (aIndex
< mNames
.Length()) {
42 aResult
= mNames
[aIndex
];
44 aResult
.SetIsVoid(true);
50 return mNames
.Length();
53 bool Contains(const nsAString
& aString
) {
55 return mNames
.Contains(aString
);
58 bool Add(const nsAString
& aName
) {
59 // XXXbz(Bug 1631374) mNames should really be a fallible array; otherwise
60 // this return value is meaningless. return mNames.AppendElement(aName) !=
62 mNames
.AppendElement(aName
);
66 void Clear() { mNames
.Clear(); }
68 nsTArray
<nsString
>& StringArray() { return mNames
; }
70 void CopyList(nsTArray
<nsString
>& aNames
) { aNames
= mNames
.Clone(); }
73 // A method that subclasses can override to modify mNames as needed
74 // before we index into it or return its length or whatnot.
75 virtual void EnsureFresh() {}
77 // XXXbz we really want this to be a fallible array, but we end up passing it
78 // to consumers who declare themselves as taking and nsTArray. :(
79 nsTArray
<nsString
> mNames
;
82 } // namespace mozilla::dom
84 #endif /* mozilla_dom_DOMStringList_h */