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

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

mercurial