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"
18 class DOMStringList
: public nsISupports
, public nsWrapperCache
{
20 virtual ~DOMStringList();
23 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
24 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMStringList
)
26 virtual JSObject
* WrapObject(JSContext
* aCx
,
27 JS::Handle
<JSObject
*> aGivenProto
) override
;
28 nsISupports
* GetParentObject() { return nullptr; }
30 void IndexedGetter(uint32_t aIndex
, bool& aFound
, nsAString
& aResult
) {
32 if (aIndex
< mNames
.Length()) {
34 aResult
= mNames
[aIndex
];
40 void Item(uint32_t aIndex
, nsAString
& aResult
) {
42 if (aIndex
< mNames
.Length()) {
43 aResult
= mNames
[aIndex
];
45 aResult
.SetIsVoid(true);
51 return mNames
.Length();
54 bool Contains(const nsAString
& aString
) {
56 return mNames
.Contains(aString
);
59 bool Add(const nsAString
& aName
) {
60 // XXXbz mNames should really be a fallible array; otherwise this
61 // return value is meaningless.
62 return mNames
.AppendElement(aName
) != nullptr;
65 void Clear() { mNames
.Clear(); }
67 nsTArray
<nsString
>& StringArray() { return mNames
; }
69 void CopyList(nsTArray
<nsString
>& aNames
) { aNames
= mNames
; }
72 // A method that subclasses can override to modify mNames as needed
73 // before we index into it or return its length or whatnot.
74 virtual void EnsureFresh() {}
76 // XXXbz we really want this to be a fallible array, but we end up passing it
77 // to consumers who declare themselves as taking and nsTArray. :(
78 nsTArray
<nsString
> mNames
;
82 } // namespace mozilla
84 #endif /* mozilla_dom_DOMStringList_h */