dom/base/Console.h

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:5fcae17c1696
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_dom_Console_h
7 #define mozilla_dom_Console_h
8
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"
18
19 class nsIConsoleAPIStorage;
20
21 namespace mozilla {
22 namespace dom {
23
24 class ConsoleCallData;
25 class ConsoleStackEntry;
26
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
37
38 Console(nsPIDOMWindow* aWindow);
39 ~Console();
40
41 // WebIDL methods
42 nsISupports* GetParentObject() const
43 {
44 return mWindow;
45 }
46
47 virtual JSObject*
48 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
49
50 void
51 Log(JSContext* aCx, const Sequence<JS::Value>& aData);
52
53 void
54 Info(JSContext* aCx, const Sequence<JS::Value>& aData);
55
56 void
57 Warn(JSContext* aCx, const Sequence<JS::Value>& aData);
58
59 void
60 Error(JSContext* aCx, const Sequence<JS::Value>& aData);
61
62 void
63 Exception(JSContext* aCx, const Sequence<JS::Value>& aData);
64
65 void
66 Debug(JSContext* aCx, const Sequence<JS::Value>& aData);
67
68 void
69 Trace(JSContext* aCx);
70
71 void
72 Dir(JSContext* aCx, const Sequence<JS::Value>& aData);
73
74 void
75 Group(JSContext* aCx, const Sequence<JS::Value>& aData);
76
77 void
78 GroupCollapsed(JSContext* aCx, const Sequence<JS::Value>& aData);
79
80 void
81 GroupEnd(JSContext* aCx, const Sequence<JS::Value>& aData);
82
83 void
84 Time(JSContext* aCx, const JS::Handle<JS::Value> aTime);
85
86 void
87 TimeEnd(JSContext* aCx, const JS::Handle<JS::Value> aTime);
88
89 void
90 Profile(JSContext* aCx, const Sequence<JS::Value>& aData);
91
92 void
93 ProfileEnd(JSContext* aCx, const Sequence<JS::Value>& aData);
94
95 void
96 Assert(JSContext* aCx, bool aCondition, const Sequence<JS::Value>& aData);
97
98 void
99 Count(JSContext* aCx, const Sequence<JS::Value>& aData);
100
101 void
102 __noSuchMethod__();
103
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 };
123
124 void
125 Method(JSContext* aCx, MethodName aName, const nsAString& aString,
126 const Sequence<JS::Value>& aData);
127
128 void
129 AppendCallData(ConsoleCallData* aData);
130
131 void
132 ProcessCallData(ConsoleCallData* aData);
133
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);
156
157 void
158 MakeFormatString(nsCString& aFormat, int32_t aInteger, int32_t aMantissa,
159 char aCh);
160
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);
166
167 JS::Value
168 StartTimer(JSContext* aCx, const JS::Value& aName,
169 DOMHighResTimeStamp aTimestamp);
170
171 JS::Value
172 StopTimer(JSContext* aCx, const JS::Value& aName,
173 DOMHighResTimeStamp aTimestamp);
174
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);
179
180 void
181 ProfileMethod(JSContext* aCx, const nsAString& aAction,
182 const Sequence<JS::Value>& aData);
183
184 JS::Value
185 IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
186 const nsTArray<JS::Heap<JS::Value>>& aArguments);
187
188 void
189 ClearConsoleData();
190
191 bool
192 ShouldIncludeStackrace(MethodName aMethodName);
193
194 nsCOMPtr<nsPIDOMWindow> mWindow;
195 nsCOMPtr<nsITimer> mTimer;
196 nsCOMPtr<nsIConsoleAPIStorage> mStorage;
197
198 LinkedList<ConsoleCallData> mQueuedCalls;
199 nsDataHashtable<nsStringHashKey, DOMHighResTimeStamp> mTimerRegistry;
200 nsDataHashtable<nsStringHashKey, uint32_t> mCounterRegistry;
201
202 uint64_t mOuterID;
203 uint64_t mInnerID;
204
205 friend class ConsoleCallData;
206 friend class ConsoleCallDataRunnable;
207 friend class ConsoleProfileRunnable;
208 };
209
210 } // dom namespace
211 } // mozilla namespace
212
213 #endif /* mozilla_dom_Console_h */

mercurial