content/base/src/DOMStringList.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef mozilla_dom_DOMStringList_h
     7 #define mozilla_dom_DOMStringList_h
     9 #include "nsISupports.h"
    10 #include "nsTArray.h"
    11 #include "nsWrapperCache.h"
    12 #include "nsString.h"
    14 namespace mozilla {
    15 namespace dom {
    17 class DOMStringList : public nsISupports,
    18                       public nsWrapperCache
    19 {
    20 public:
    21   DOMStringList()
    22   {
    23     SetIsDOMBinding();
    24   }
    25   virtual ~DOMStringList();
    27   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    28   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMStringList)
    30   virtual JSObject* WrapObject(JSContext* aCx);
    31   nsISupports* GetParentObject()
    32   {
    33     return nullptr;
    34   }
    36   void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult)
    37   {
    38     EnsureFresh();
    39     if (aIndex < mNames.Length()) {
    40       aFound = true;
    41       aResult = mNames[aIndex];
    42     } else {
    43       aFound = false;
    44     }
    45   }
    47   void Item(uint32_t aIndex, nsAString& aResult)
    48   {
    49     EnsureFresh();
    50     if (aIndex < mNames.Length()) {
    51       aResult = mNames[aIndex];
    52     } else {
    53       aResult.SetIsVoid(true);
    54     }
    55   }
    57   uint32_t Length()
    58   {
    59     EnsureFresh();
    60     return mNames.Length();
    61   }
    63   bool Contains(const nsAString& aString)
    64   {
    65     EnsureFresh();
    66     return mNames.Contains(aString);
    67   }
    69   bool Add(const nsAString& aName)
    70   {
    71     // XXXbz mNames should really be a fallible array; otherwise this
    72     // return value is meaningless.
    73     return mNames.AppendElement(aName) != nullptr;
    74   }
    76   void Clear()
    77   {
    78     mNames.Clear();
    79   }
    81   nsTArray<nsString>& StringArray()
    82   {
    83     return mNames;
    84   }
    86   void CopyList(nsTArray<nsString>& aNames)
    87   {
    88     aNames = mNames;
    89   }
    91 protected:
    92   // A method that subclasses can override to modify mNames as needed
    93   // before we index into it or return its length or whatnot.
    94   virtual void EnsureFresh()
    95   {
    96   }
    98   // XXXbz we really want this to be a fallible array, but we end up passing it
    99   // to consumers who declare themselves as taking and nsTArray.  :(
   100   nsTArray<nsString> mNames;
   101 };
   103 } // namespace dom
   104 } // namespace mozilla
   106 #endif /* mozilla_dom_DOMStringList_h */

mercurial