LCOV - code coverage report
Current view: top level - toolkit/components/extensions - MatchGlob.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 10 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       5             : 
       6             : #ifndef mozilla_extensions_MatchGlob_h
       7             : #define mozilla_extensions_MatchGlob_h
       8             : 
       9             : #include "mozilla/dom/BindingDeclarations.h"
      10             : #include "mozilla/dom/MatchGlobBinding.h"
      11             : 
      12             : #include "jspubtd.h"
      13             : #include "js/RootingAPI.h"
      14             : 
      15             : #include "nsCOMPtr.h"
      16             : #include "nsCycleCollectionParticipant.h"
      17             : #include "nsISupports.h"
      18             : #include "nsWrapperCache.h"
      19             : 
      20             : namespace mozilla {
      21             : namespace extensions {
      22             : 
      23             : class MatchPattern;
      24             : 
      25             : class MatchGlob final : public nsISupports
      26             :                       , public nsWrapperCache
      27             : {
      28             : public:
      29             :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      30           0 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MatchGlob)
      31             : 
      32             :   static already_AddRefed<MatchGlob>
      33             :   Constructor(dom::GlobalObject& aGlobal, const nsAString& aGlob, bool aAllowQuestion,
      34             :               ErrorResult& aRv);
      35             : 
      36             :   bool Matches(const nsAString& aString) const;
      37             : 
      38           0 :   bool IsWildcard() const
      39             :   {
      40           0 :     return mIsPrefix && mPathLiteral.IsEmpty();
      41             :   }
      42             : 
      43           0 :   void GetGlob(nsAString& aGlob) const
      44             :   {
      45           0 :     aGlob = mGlob;
      46           0 :   }
      47             : 
      48           0 :   nsISupports* GetParentObject() const { return mParent; }
      49             : 
      50             :   virtual JSObject* WrapObject(JSContext* aCx, JS::HandleObject aGivenProto) override;
      51             : 
      52             : protected:
      53             :   virtual ~MatchGlob();
      54             : 
      55             : private:
      56             :   friend class MatchPattern;
      57             : 
      58           0 :   explicit MatchGlob(nsISupports* aParent) : mParent(aParent) {}
      59             : 
      60             :   void Init(JSContext* aCx, const nsAString& aGlob, bool aAllowQuestion, ErrorResult& aRv);
      61             : 
      62             :   nsCOMPtr<nsISupports> mParent;
      63             : 
      64             :   // The original glob string that this glob object represents.
      65             :   nsString mGlob;
      66             : 
      67             :   // The literal path string to match against. If this contains a non-void
      68             :   // value, the glob matches against this exact literal string, rather than
      69             :   // performng a pattern match. If mIsPrefix is true, the literal must appear
      70             :   // at the start of the matched string. If it is false, the the literal must
      71             :   // be exactly equal to the matched string.
      72             :   nsString mPathLiteral;
      73             :   bool mIsPrefix = false;
      74             : 
      75             :   // The regular expression object which is equivalent to this glob pattern.
      76             :   // Used for matching if, and only if, mPathLiteral is non-void.
      77             :   JS::Heap<JSObject*> mRegExp;
      78             : };
      79             : 
      80           0 : class MatchGlobSet final : public nsTArray<RefPtr<MatchGlob>>
      81             : {
      82             : public:
      83             :   // Note: We can't use the nsTArray constructors directly, since the static
      84             :   // analyzer doesn't handle their MOZ_IMPLICIT annotations correctly.
      85           0 :   MatchGlobSet() {}
      86             :   explicit MatchGlobSet(size_type aCapacity) : nsTArray(aCapacity) {}
      87             :   explicit MatchGlobSet(const nsTArray& aOther) : nsTArray(aOther) {}
      88             :   MOZ_IMPLICIT MatchGlobSet(nsTArray&& aOther) : nsTArray(mozilla::Move(aOther)) {}
      89             :   MOZ_IMPLICIT MatchGlobSet(std::initializer_list<RefPtr<MatchGlob>> aIL) : nsTArray(aIL) {}
      90             : 
      91             :   bool Matches(const nsAString& aValue) const;
      92             : };
      93             : 
      94             : } // namespace extensions
      95             : } // namespace mozilla
      96             : 
      97             : #endif // mozilla_extensions_MatchGlob_h
      98             : 

Generated by: LCOV version 1.13