mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 965860 - patch 6 - Console.count(), r=khuey
This commit is contained in:
parent
8a87e5bfed
commit
dc67186f99
@ -25,6 +25,9 @@
|
||||
// The maximum allowed number of concurrent timers per page.
|
||||
#define MAX_PAGE_TIMERS 10000
|
||||
|
||||
// The maximum allowed number of concurrent counters per page.
|
||||
#define MAX_PAGE_COUNTERS 10000
|
||||
|
||||
// The maximum stacktrace depth when populating the stacktrace array used for
|
||||
// console.trace().
|
||||
#define DEFAULT_MAX_STACKTRACE_DEPTH 200
|
||||
@ -332,6 +335,8 @@ Console::Assert(JSContext* aCx, bool aCondition,
|
||||
}
|
||||
}
|
||||
|
||||
METHOD(Count, "count")
|
||||
|
||||
void
|
||||
Console::__noSuchMethod__()
|
||||
{
|
||||
@ -566,6 +571,10 @@ Console::ProcessCallData(ConsoleCallData& aData)
|
||||
event.mTimer = StopTimer(cx, aData.mArguments[0], aData.mMonotonicTimer);
|
||||
}
|
||||
|
||||
else if (aData.mMethodName == MethodCount) {
|
||||
event.mCounter = IncreaseCounter(cx, frame, aData.mArguments);
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> eventValue(cx);
|
||||
if (!event.ToObject(cx, JS::NullPtr(), &eventValue)) {
|
||||
Throw(cx, NS_ERROR_FAILURE);
|
||||
@ -929,5 +938,60 @@ Console::ArgumentsToValueList(const nsTArray<JS::Heap<JS::Value>>& aData,
|
||||
}
|
||||
}
|
||||
|
||||
JS::Value
|
||||
Console::IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
|
||||
const nsTArray<JS::Heap<JS::Value>>& aArguments)
|
||||
{
|
||||
ClearException ce(aCx);
|
||||
|
||||
nsAutoString key;
|
||||
nsAutoString label;
|
||||
|
||||
if (!aArguments.IsEmpty()) {
|
||||
JS::Rooted<JS::Value> labelValue(aCx, aArguments[0]);
|
||||
JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, labelValue));
|
||||
|
||||
nsDependentJSString string;
|
||||
if (jsString && string.init(aCx, jsString)) {
|
||||
label = string;
|
||||
key = string;
|
||||
}
|
||||
}
|
||||
|
||||
if (key.IsEmpty()) {
|
||||
key.Append(aFrame.mFilename);
|
||||
key.Append(NS_LITERAL_STRING(":"));
|
||||
key.AppendInt(aFrame.mLineNumber);
|
||||
}
|
||||
|
||||
uint32_t count = 0;
|
||||
if (!mCounterRegistry.Get(key, &count)) {
|
||||
if (mCounterRegistry.Count() >= MAX_PAGE_COUNTERS) {
|
||||
RootedDictionary<ConsoleCounterError> error(aCx);
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
if (!error.ToObject(aCx, JS::NullPtr(), &value)) {
|
||||
return JS::UndefinedValue();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
++count;
|
||||
mCounterRegistry.Put(key, count);
|
||||
|
||||
RootedDictionary<ConsoleCounter> data(aCx);
|
||||
data.mLabel = label;
|
||||
data.mCount = count;
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
if (!data.ToObject(aCx, JS::NullPtr(), &value)) {
|
||||
return JS::UndefinedValue();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -22,6 +22,7 @@ namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ConsoleCallData;
|
||||
class ConsoleStackEntry;
|
||||
|
||||
class Console MOZ_FINAL : public nsITimerCallback
|
||||
, public nsIObserver
|
||||
@ -96,6 +97,9 @@ public:
|
||||
void
|
||||
Assert(JSContext* aCx, bool aCondition, const Sequence<JS::Value>& aData);
|
||||
|
||||
void
|
||||
Count(JSContext* aCx, const Sequence<JS::Value>& aData);
|
||||
|
||||
void
|
||||
__noSuchMethod__();
|
||||
|
||||
@ -115,7 +119,8 @@ private:
|
||||
MethodGroupEnd,
|
||||
MethodTime,
|
||||
MethodTimeEnd,
|
||||
MethodAssert
|
||||
MethodAssert,
|
||||
MethodCount
|
||||
};
|
||||
|
||||
void
|
||||
@ -169,12 +174,17 @@ private:
|
||||
const Sequence<JS::Value>& aData,
|
||||
ErrorResult& aRv);
|
||||
|
||||
JS::Value
|
||||
IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
|
||||
const nsTArray<JS::Heap<JS::Value>>& aArguments);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> mWindow;
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
nsCOMPtr<nsIConsoleAPIStorage> mStorage;
|
||||
|
||||
nsTArray<ConsoleCallData> mQueuedCalls;
|
||||
nsDataHashtable<nsStringHashKey, DOMHighResTimeStamp> mTimerRegistry;
|
||||
nsDataHashtable<nsStringHashKey, uint32_t> mCounterRegistry;
|
||||
|
||||
uint64_t mOuterID;
|
||||
uint64_t mInnerID;
|
||||
|
@ -27,6 +27,8 @@ interface Console {
|
||||
void profileEnd(any... data);
|
||||
|
||||
void assert(boolean condition, any... data);
|
||||
void count(any... data);
|
||||
|
||||
void ___noSuchMethod__();
|
||||
};
|
||||
|
||||
@ -44,6 +46,7 @@ dictionary ConsoleEvent {
|
||||
sequence<ConsoleStackEntry> stacktrace;
|
||||
DOMString groupName = "";
|
||||
any timer = null;
|
||||
any counter = null;
|
||||
};
|
||||
|
||||
// Event for profile operations
|
||||
@ -73,3 +76,12 @@ dictionary ConsoleTimerEnd {
|
||||
dictionary ConsoleTimerError {
|
||||
DOMString error = "maxTimersExceeded";
|
||||
};
|
||||
|
||||
dictionary ConsoleCounter {
|
||||
DOMString label = "";
|
||||
unsigned long count = 0;
|
||||
};
|
||||
|
||||
dictionary ConsoleCounterError {
|
||||
DOMString error = "maxCountersExceeded";
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user