1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/Console.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,213 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_dom_Console_h 1.10 +#define mozilla_dom_Console_h 1.11 + 1.12 +#include "mozilla/dom/BindingDeclarations.h" 1.13 +#include "mozilla/dom/UnionConversions.h" 1.14 +#include "mozilla/ErrorResult.h" 1.15 +#include "nsCycleCollectionParticipant.h" 1.16 +#include "nsDataHashtable.h" 1.17 +#include "nsHashKeys.h" 1.18 +#include "nsIObserver.h" 1.19 +#include "nsITimer.h" 1.20 +#include "nsWrapperCache.h" 1.21 + 1.22 +class nsIConsoleAPIStorage; 1.23 + 1.24 +namespace mozilla { 1.25 +namespace dom { 1.26 + 1.27 +class ConsoleCallData; 1.28 +class ConsoleStackEntry; 1.29 + 1.30 +class Console MOZ_FINAL : public nsITimerCallback 1.31 + , public nsIObserver 1.32 + , public nsWrapperCache 1.33 +{ 1.34 +public: 1.35 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.36 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Console, 1.37 + nsITimerCallback) 1.38 + NS_DECL_NSITIMERCALLBACK 1.39 + NS_DECL_NSIOBSERVER 1.40 + 1.41 + Console(nsPIDOMWindow* aWindow); 1.42 + ~Console(); 1.43 + 1.44 + // WebIDL methods 1.45 + nsISupports* GetParentObject() const 1.46 + { 1.47 + return mWindow; 1.48 + } 1.49 + 1.50 + virtual JSObject* 1.51 + WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.52 + 1.53 + void 1.54 + Log(JSContext* aCx, const Sequence<JS::Value>& aData); 1.55 + 1.56 + void 1.57 + Info(JSContext* aCx, const Sequence<JS::Value>& aData); 1.58 + 1.59 + void 1.60 + Warn(JSContext* aCx, const Sequence<JS::Value>& aData); 1.61 + 1.62 + void 1.63 + Error(JSContext* aCx, const Sequence<JS::Value>& aData); 1.64 + 1.65 + void 1.66 + Exception(JSContext* aCx, const Sequence<JS::Value>& aData); 1.67 + 1.68 + void 1.69 + Debug(JSContext* aCx, const Sequence<JS::Value>& aData); 1.70 + 1.71 + void 1.72 + Trace(JSContext* aCx); 1.73 + 1.74 + void 1.75 + Dir(JSContext* aCx, const Sequence<JS::Value>& aData); 1.76 + 1.77 + void 1.78 + Group(JSContext* aCx, const Sequence<JS::Value>& aData); 1.79 + 1.80 + void 1.81 + GroupCollapsed(JSContext* aCx, const Sequence<JS::Value>& aData); 1.82 + 1.83 + void 1.84 + GroupEnd(JSContext* aCx, const Sequence<JS::Value>& aData); 1.85 + 1.86 + void 1.87 + Time(JSContext* aCx, const JS::Handle<JS::Value> aTime); 1.88 + 1.89 + void 1.90 + TimeEnd(JSContext* aCx, const JS::Handle<JS::Value> aTime); 1.91 + 1.92 + void 1.93 + Profile(JSContext* aCx, const Sequence<JS::Value>& aData); 1.94 + 1.95 + void 1.96 + ProfileEnd(JSContext* aCx, const Sequence<JS::Value>& aData); 1.97 + 1.98 + void 1.99 + Assert(JSContext* aCx, bool aCondition, const Sequence<JS::Value>& aData); 1.100 + 1.101 + void 1.102 + Count(JSContext* aCx, const Sequence<JS::Value>& aData); 1.103 + 1.104 + void 1.105 + __noSuchMethod__(); 1.106 + 1.107 +private: 1.108 + enum MethodName 1.109 + { 1.110 + MethodLog, 1.111 + MethodInfo, 1.112 + MethodWarn, 1.113 + MethodError, 1.114 + MethodException, 1.115 + MethodDebug, 1.116 + MethodTrace, 1.117 + MethodDir, 1.118 + MethodGroup, 1.119 + MethodGroupCollapsed, 1.120 + MethodGroupEnd, 1.121 + MethodTime, 1.122 + MethodTimeEnd, 1.123 + MethodAssert, 1.124 + MethodCount 1.125 + }; 1.126 + 1.127 + void 1.128 + Method(JSContext* aCx, MethodName aName, const nsAString& aString, 1.129 + const Sequence<JS::Value>& aData); 1.130 + 1.131 + void 1.132 + AppendCallData(ConsoleCallData* aData); 1.133 + 1.134 + void 1.135 + ProcessCallData(ConsoleCallData* aData); 1.136 + 1.137 + // If the first JS::Value of the array is a string, this method uses it to 1.138 + // format a string. The supported sequences are: 1.139 + // %s - string 1.140 + // %d,%i - integer 1.141 + // %f - double 1.142 + // %o,%O - a JS object. 1.143 + // %c - style string. 1.144 + // The output is an array where any object is a separated item, the rest is 1.145 + // unified in a format string. 1.146 + // Example if the input is: 1.147 + // "string: %s, integer: %d, object: %o, double: %d", 's', 1, window, 0.9 1.148 + // The output will be: 1.149 + // [ "string: s, integer: 1, object: ", window, ", double: 0.9" ] 1.150 + // 1.151 + // The aStyles array is populated with the style strings that the function 1.152 + // finds based the format string. The index of the styles matches the indexes 1.153 + // of elements that need the custom styling from aSequence. For elements with 1.154 + // no custom styling the array is padded with null elements. 1.155 + void 1.156 + ProcessArguments(JSContext* aCx, const nsTArray<JS::Heap<JS::Value>>& aData, 1.157 + Sequence<JS::Value>& aSequence, 1.158 + Sequence<JS::Value>& aStyles); 1.159 + 1.160 + void 1.161 + MakeFormatString(nsCString& aFormat, int32_t aInteger, int32_t aMantissa, 1.162 + char aCh); 1.163 + 1.164 + // Stringify and Concat all the JS::Value in a single string using ' ' as 1.165 + // separator. 1.166 + void 1.167 + ComposeGroupName(JSContext* aCx, const nsTArray<JS::Heap<JS::Value>>& aData, 1.168 + nsAString& aName); 1.169 + 1.170 + JS::Value 1.171 + StartTimer(JSContext* aCx, const JS::Value& aName, 1.172 + DOMHighResTimeStamp aTimestamp); 1.173 + 1.174 + JS::Value 1.175 + StopTimer(JSContext* aCx, const JS::Value& aName, 1.176 + DOMHighResTimeStamp aTimestamp); 1.177 + 1.178 + // The method populates a Sequence from an array of JS::Value. 1.179 + void 1.180 + ArgumentsToValueList(const nsTArray<JS::Heap<JS::Value>>& aData, 1.181 + Sequence<JS::Value>& aSequence); 1.182 + 1.183 + void 1.184 + ProfileMethod(JSContext* aCx, const nsAString& aAction, 1.185 + const Sequence<JS::Value>& aData); 1.186 + 1.187 + JS::Value 1.188 + IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame, 1.189 + const nsTArray<JS::Heap<JS::Value>>& aArguments); 1.190 + 1.191 + void 1.192 + ClearConsoleData(); 1.193 + 1.194 + bool 1.195 + ShouldIncludeStackrace(MethodName aMethodName); 1.196 + 1.197 + nsCOMPtr<nsPIDOMWindow> mWindow; 1.198 + nsCOMPtr<nsITimer> mTimer; 1.199 + nsCOMPtr<nsIConsoleAPIStorage> mStorage; 1.200 + 1.201 + LinkedList<ConsoleCallData> mQueuedCalls; 1.202 + nsDataHashtable<nsStringHashKey, DOMHighResTimeStamp> mTimerRegistry; 1.203 + nsDataHashtable<nsStringHashKey, uint32_t> mCounterRegistry; 1.204 + 1.205 + uint64_t mOuterID; 1.206 + uint64_t mInnerID; 1.207 + 1.208 + friend class ConsoleCallData; 1.209 + friend class ConsoleCallDataRunnable; 1.210 + friend class ConsoleProfileRunnable; 1.211 +}; 1.212 + 1.213 +} // dom namespace 1.214 +} // mozilla namespace 1.215 + 1.216 +#endif /* mozilla_dom_Console_h */