dom/base/Console.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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_Console_h
     7 #define mozilla_dom_Console_h
     9 #include "mozilla/dom/BindingDeclarations.h"
    10 #include "mozilla/dom/UnionConversions.h"
    11 #include "mozilla/ErrorResult.h"
    12 #include "nsCycleCollectionParticipant.h"
    13 #include "nsDataHashtable.h"
    14 #include "nsHashKeys.h"
    15 #include "nsIObserver.h"
    16 #include "nsITimer.h"
    17 #include "nsWrapperCache.h"
    19 class nsIConsoleAPIStorage;
    21 namespace mozilla {
    22 namespace dom {
    24 class ConsoleCallData;
    25 class ConsoleStackEntry;
    27 class Console MOZ_FINAL : public nsITimerCallback
    28                         , public nsIObserver
    29                         , public nsWrapperCache
    30 {
    31 public:
    32   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    33   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Console,
    34                                                          nsITimerCallback)
    35   NS_DECL_NSITIMERCALLBACK
    36   NS_DECL_NSIOBSERVER
    38   Console(nsPIDOMWindow* aWindow);
    39   ~Console();
    41   // WebIDL methods
    42   nsISupports* GetParentObject() const
    43   {
    44     return mWindow;
    45   }
    47   virtual JSObject*
    48   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    50   void
    51   Log(JSContext* aCx, const Sequence<JS::Value>& aData);
    53   void
    54   Info(JSContext* aCx, const Sequence<JS::Value>& aData);
    56   void
    57   Warn(JSContext* aCx, const Sequence<JS::Value>& aData);
    59   void
    60   Error(JSContext* aCx, const Sequence<JS::Value>& aData);
    62   void
    63   Exception(JSContext* aCx, const Sequence<JS::Value>& aData);
    65   void
    66   Debug(JSContext* aCx, const Sequence<JS::Value>& aData);
    68   void
    69   Trace(JSContext* aCx);
    71   void
    72   Dir(JSContext* aCx, const Sequence<JS::Value>& aData);
    74   void
    75   Group(JSContext* aCx, const Sequence<JS::Value>& aData);
    77   void
    78   GroupCollapsed(JSContext* aCx, const Sequence<JS::Value>& aData);
    80   void
    81   GroupEnd(JSContext* aCx, const Sequence<JS::Value>& aData);
    83   void
    84   Time(JSContext* aCx, const JS::Handle<JS::Value> aTime);
    86   void
    87   TimeEnd(JSContext* aCx, const JS::Handle<JS::Value> aTime);
    89   void
    90   Profile(JSContext* aCx, const Sequence<JS::Value>& aData);
    92   void
    93   ProfileEnd(JSContext* aCx, const Sequence<JS::Value>& aData);
    95   void
    96   Assert(JSContext* aCx, bool aCondition, const Sequence<JS::Value>& aData);
    98   void
    99   Count(JSContext* aCx, const Sequence<JS::Value>& aData);
   101   void
   102   __noSuchMethod__();
   104 private:
   105   enum MethodName
   106   {
   107     MethodLog,
   108     MethodInfo,
   109     MethodWarn,
   110     MethodError,
   111     MethodException,
   112     MethodDebug,
   113     MethodTrace,
   114     MethodDir,
   115     MethodGroup,
   116     MethodGroupCollapsed,
   117     MethodGroupEnd,
   118     MethodTime,
   119     MethodTimeEnd,
   120     MethodAssert,
   121     MethodCount
   122   };
   124   void
   125   Method(JSContext* aCx, MethodName aName, const nsAString& aString,
   126          const Sequence<JS::Value>& aData);
   128   void
   129   AppendCallData(ConsoleCallData* aData);
   131   void
   132   ProcessCallData(ConsoleCallData* aData);
   134   // If the first JS::Value of the array is a string, this method uses it to
   135   // format a string. The supported sequences are:
   136   //   %s    - string
   137   //   %d,%i - integer
   138   //   %f    - double
   139   //   %o,%O - a JS object.
   140   //   %c    - style string.
   141   // The output is an array where any object is a separated item, the rest is
   142   // unified in a format string.
   143   // Example if the input is:
   144   //   "string: %s, integer: %d, object: %o, double: %d", 's', 1, window, 0.9
   145   // The output will be:
   146   //   [ "string: s, integer: 1, object: ", window, ", double: 0.9" ]
   147   //
   148   // The aStyles array is populated with the style strings that the function
   149   // finds based the format string. The index of the styles matches the indexes
   150   // of elements that need the custom styling from aSequence. For elements with
   151   // no custom styling the array is padded with null elements.
   152   void
   153   ProcessArguments(JSContext* aCx, const nsTArray<JS::Heap<JS::Value>>& aData,
   154                    Sequence<JS::Value>& aSequence,
   155                    Sequence<JS::Value>& aStyles);
   157   void
   158   MakeFormatString(nsCString& aFormat, int32_t aInteger, int32_t aMantissa,
   159                    char aCh);
   161   // Stringify and Concat all the JS::Value in a single string using ' ' as
   162   // separator.
   163   void
   164   ComposeGroupName(JSContext* aCx, const nsTArray<JS::Heap<JS::Value>>& aData,
   165                    nsAString& aName);
   167   JS::Value
   168   StartTimer(JSContext* aCx, const JS::Value& aName,
   169              DOMHighResTimeStamp aTimestamp);
   171   JS::Value
   172   StopTimer(JSContext* aCx, const JS::Value& aName,
   173             DOMHighResTimeStamp aTimestamp);
   175   // The method populates a Sequence from an array of JS::Value.
   176   void
   177   ArgumentsToValueList(const nsTArray<JS::Heap<JS::Value>>& aData,
   178                        Sequence<JS::Value>& aSequence);
   180   void
   181   ProfileMethod(JSContext* aCx, const nsAString& aAction,
   182                 const Sequence<JS::Value>& aData);
   184   JS::Value
   185   IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
   186                    const nsTArray<JS::Heap<JS::Value>>& aArguments);
   188   void
   189   ClearConsoleData();
   191   bool
   192   ShouldIncludeStackrace(MethodName aMethodName);
   194   nsCOMPtr<nsPIDOMWindow> mWindow;
   195   nsCOMPtr<nsITimer> mTimer;
   196   nsCOMPtr<nsIConsoleAPIStorage> mStorage;
   198   LinkedList<ConsoleCallData> mQueuedCalls;
   199   nsDataHashtable<nsStringHashKey, DOMHighResTimeStamp> mTimerRegistry;
   200   nsDataHashtable<nsStringHashKey, uint32_t> mCounterRegistry;
   202   uint64_t mOuterID;
   203   uint64_t mInnerID;
   205   friend class ConsoleCallData;
   206   friend class ConsoleCallDataRunnable;
   207   friend class ConsoleProfileRunnable;
   208 };
   210 } // dom namespace
   211 } // mozilla namespace
   213 #endif /* mozilla_dom_Console_h */

mercurial