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"
17 #include "nsWrapperCache.h"
19 class nsIConsoleAPIStorage
;
24 class ConsoleCallData
;
25 struct ConsoleStackEntry
;
27 class Console MOZ_FINAL
: public nsITimerCallback
29 , public nsWrapperCache
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Console
,
37 NS_DECL_NSITIMERCALLBACK
40 explicit Console(nsPIDOMWindow
* aWindow
);
43 nsISupports
* GetParentObject() const
49 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
52 Log(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
55 Info(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
58 Warn(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
61 Error(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
64 Exception(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
67 Debug(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
70 Table(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
73 Trace(JSContext
* aCx
);
76 Dir(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
79 Group(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
82 GroupCollapsed(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
85 GroupEnd(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
88 Time(JSContext
* aCx
, const JS::Handle
<JS::Value
> aTime
);
91 TimeEnd(JSContext
* aCx
, const JS::Handle
<JS::Value
> aTime
);
94 Profile(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
97 ProfileEnd(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
100 Assert(JSContext
* aCx
, bool aCondition
, const Sequence
<JS::Value
>& aData
);
103 Count(JSContext
* aCx
, const Sequence
<JS::Value
>& aData
);
121 MethodGroupCollapsed
,
130 Method(JSContext
* aCx
, MethodName aName
, const nsAString
& aString
,
131 const Sequence
<JS::Value
>& aData
);
134 AppendCallData(ConsoleCallData
* aData
);
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:
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.
158 ProcessArguments(JSContext
* aCx
, const nsTArray
<JS::Heap
<JS::Value
>>& aData
,
159 Sequence
<JS::Value
>& aSequence
,
160 Sequence
<JS::Value
>& aStyles
);
163 MakeFormatString(nsCString
& aFormat
, int32_t aInteger
, int32_t aMantissa
,
166 // Stringify and Concat all the JS::Value in a single string using ' ' as
169 ComposeGroupName(JSContext
* aCx
, const nsTArray
<JS::Heap
<JS::Value
>>& aData
,
173 StartTimer(JSContext
* aCx
, const JS::Value
& aName
,
174 DOMHighResTimeStamp aTimestamp
);
177 StopTimer(JSContext
* aCx
, const JS::Value
& aName
,
178 DOMHighResTimeStamp aTimestamp
);
180 // The method populates a Sequence from an array of JS::Value.
182 ArgumentsToValueList(const nsTArray
<JS::Heap
<JS::Value
>>& aData
,
183 Sequence
<JS::Value
>& aSequence
);
186 ProfileMethod(JSContext
* aCx
, const nsAString
& aAction
,
187 const Sequence
<JS::Value
>& aData
);
190 IncreaseCounter(JSContext
* aCx
, const ConsoleStackEntry
& aFrame
,
191 const nsTArray
<JS::Heap
<JS::Value
>>& aArguments
);
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
;
210 friend class ConsoleCallData
;
211 friend class ConsoleCallDataRunnable
;
212 friend class ConsoleProfileRunnable
;
216 } // mozilla namespace
218 #endif /* mozilla_dom_Console_h */