Bumping manifests a=b2g-bump
[gecko.git] / dom / base / Console.h
blob07c940174b8e8d4915f74e328ca54ffb2259d6d8
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 struct ConsoleStackEntry;
27 class Console MOZ_FINAL : public nsITimerCallback
28 , public nsIObserver
29 , public nsWrapperCache
31 ~Console();
33 public:
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Console,
36 nsITimerCallback)
37 NS_DECL_NSITIMERCALLBACK
38 NS_DECL_NSIOBSERVER
40 explicit Console(nsPIDOMWindow* aWindow);
42 // WebIDL methods
43 nsISupports* GetParentObject() const
45 return mWindow;
48 virtual JSObject*
49 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
51 void
52 Log(JSContext* aCx, const Sequence<JS::Value>& aData);
54 void
55 Info(JSContext* aCx, const Sequence<JS::Value>& aData);
57 void
58 Warn(JSContext* aCx, const Sequence<JS::Value>& aData);
60 void
61 Error(JSContext* aCx, const Sequence<JS::Value>& aData);
63 void
64 Exception(JSContext* aCx, const Sequence<JS::Value>& aData);
66 void
67 Debug(JSContext* aCx, const Sequence<JS::Value>& aData);
69 void
70 Table(JSContext* aCx, const Sequence<JS::Value>& aData);
72 void
73 Trace(JSContext* aCx);
75 void
76 Dir(JSContext* aCx, const Sequence<JS::Value>& aData);
78 void
79 Group(JSContext* aCx, const Sequence<JS::Value>& aData);
81 void
82 GroupCollapsed(JSContext* aCx, const Sequence<JS::Value>& aData);
84 void
85 GroupEnd(JSContext* aCx, const Sequence<JS::Value>& aData);
87 void
88 Time(JSContext* aCx, const JS::Handle<JS::Value> aTime);
90 void
91 TimeEnd(JSContext* aCx, const JS::Handle<JS::Value> aTime);
93 void
94 Profile(JSContext* aCx, const Sequence<JS::Value>& aData);
96 void
97 ProfileEnd(JSContext* aCx, const Sequence<JS::Value>& aData);
99 void
100 Assert(JSContext* aCx, bool aCondition, const Sequence<JS::Value>& aData);
102 void
103 Count(JSContext* aCx, const Sequence<JS::Value>& aData);
105 void
106 __noSuchMethod__();
108 private:
109 enum MethodName
111 MethodLog,
112 MethodInfo,
113 MethodWarn,
114 MethodError,
115 MethodException,
116 MethodDebug,
117 MethodTable,
118 MethodTrace,
119 MethodDir,
120 MethodGroup,
121 MethodGroupCollapsed,
122 MethodGroupEnd,
123 MethodTime,
124 MethodTimeEnd,
125 MethodAssert,
126 MethodCount
129 void
130 Method(JSContext* aCx, MethodName aName, const nsAString& aString,
131 const Sequence<JS::Value>& aData);
133 void
134 AppendCallData(ConsoleCallData* aData);
136 void
137 ProcessCallData(ConsoleCallData* aData);
139 // If the first JS::Value of the array is a string, this method uses it to
140 // format a string. The supported sequences are:
141 // %s - string
142 // %d,%i - integer
143 // %f - double
144 // %o,%O - a JS object.
145 // %c - style string.
146 // The output is an array where any object is a separated item, the rest is
147 // unified in a format string.
148 // Example if the input is:
149 // "string: %s, integer: %d, object: %o, double: %d", 's', 1, window, 0.9
150 // The output will be:
151 // [ "string: s, integer: 1, object: ", window, ", double: 0.9" ]
153 // The aStyles array is populated with the style strings that the function
154 // finds based the format string. The index of the styles matches the indexes
155 // of elements that need the custom styling from aSequence. For elements with
156 // no custom styling the array is padded with null elements.
157 void
158 ProcessArguments(JSContext* aCx, const nsTArray<JS::Heap<JS::Value>>& aData,
159 Sequence<JS::Value>& aSequence,
160 Sequence<JS::Value>& aStyles);
162 void
163 MakeFormatString(nsCString& aFormat, int32_t aInteger, int32_t aMantissa,
164 char aCh);
166 // Stringify and Concat all the JS::Value in a single string using ' ' as
167 // separator.
168 void
169 ComposeGroupName(JSContext* aCx, const nsTArray<JS::Heap<JS::Value>>& aData,
170 nsAString& aName);
172 JS::Value
173 StartTimer(JSContext* aCx, const JS::Value& aName,
174 DOMHighResTimeStamp aTimestamp);
176 JS::Value
177 StopTimer(JSContext* aCx, const JS::Value& aName,
178 DOMHighResTimeStamp aTimestamp);
180 // The method populates a Sequence from an array of JS::Value.
181 void
182 ArgumentsToValueList(const nsTArray<JS::Heap<JS::Value>>& aData,
183 Sequence<JS::Value>& aSequence);
185 void
186 ProfileMethod(JSContext* aCx, const nsAString& aAction,
187 const Sequence<JS::Value>& aData);
189 JS::Value
190 IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
191 const nsTArray<JS::Heap<JS::Value>>& aArguments);
193 void
194 ClearConsoleData();
196 bool
197 ShouldIncludeStackrace(MethodName aMethodName);
199 nsCOMPtr<nsPIDOMWindow> mWindow;
200 nsCOMPtr<nsITimer> mTimer;
201 nsCOMPtr<nsIConsoleAPIStorage> mStorage;
203 LinkedList<ConsoleCallData> mQueuedCalls;
204 nsDataHashtable<nsStringHashKey, DOMHighResTimeStamp> mTimerRegistry;
205 nsDataHashtable<nsStringHashKey, uint32_t> mCounterRegistry;
207 uint64_t mOuterID;
208 uint64_t mInnerID;
210 friend class ConsoleCallData;
211 friend class ConsoleCallDataRunnable;
212 friend class ConsoleProfileRunnable;
215 } // dom namespace
216 } // mozilla namespace
218 #endif /* mozilla_dom_Console_h */