Bug 1346326 - implement new console.count semantics; r?baku
Bug 1346326 points out that the console.count spec has changed to
void count(optional DOMString label = "default");
This patch implements the same behavior, but does not change the webidl,
on the theory that perhaps something relies on the current "any..."
type.
MozReview-Commit-ID: 9RQKAZ4AVtT
--- a/devtools/client/webconsole/test/browser_webconsole_count.js
+++ b/devtools/client/webconsole/test/browser_webconsole_count.js
@@ -16,32 +16,35 @@ function test() {
function* runner() {
const {tab} = yield loadTab(TEST_URI);
const hud = yield openConsole(tab);
BrowserTestUtils.synthesizeMouseAtCenter("#local", {}, gBrowser.selectedBrowser);
let messages = [];
[
"start",
- "<no label>: 2",
+ "default: 1",
+ "default: 2",
+ "default: 3",
+ "default: 4",
"console.count() testcounter: 1",
"console.count() testcounter: 2",
"console.count() testcounter: 3",
"console.count() testcounter: 4",
"end"
].forEach(function (msg) {
messages.push({
text: msg,
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG
});
});
messages.push({
name: "Three local counts with no label and count=1",
- text: "<no label>: 1",
+ text: "default: 1",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
count: 3
});
yield waitForMessages({
webconsole: hud,
messages: messages
});
@@ -59,17 +62,17 @@ function test() {
messages.push({
text: msg,
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG
});
});
messages.push({
name: "Two external counts with no label and count=1",
- text: "<no label>: 1",
+ text: "default: 1",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
count: 2
});
yield waitForMessages({
webconsole: hud,
messages: messages
});
--- a/dom/console/Console.cpp
+++ b/dom/console/Console.cpp
@@ -56,16 +56,19 @@
// This tags are used in the Structured Clone Algorithm to move js values from
// worker thread to main thread
#define CONSOLE_TAG_BLOB JS_SCTAG_USER_MIN
// This value is taken from ConsoleAPIStorage.js
#define STORAGE_MAX_EVENTS 1000
+// Default label for console.count.
+#define COUNT_DEFAULT_LABEL "default"
+
using namespace mozilla::dom::exceptions;
using namespace mozilla::dom::workers;
namespace mozilla {
namespace dom {
struct
ConsoleStructuredCloneData
@@ -1359,22 +1362,17 @@ Console::MethodInternal(JSContext* aCx,
else if (aMethodName == MethodTimeEnd && !aData.IsEmpty()) {
callData->mStopTimerStatus = StopTimer(aCx, aData[0],
monotonicTimer,
callData->mStopTimerLabel,
&callData->mStopTimerDuration);
}
else if (aMethodName == MethodCount) {
- ConsoleStackEntry frame;
- if (callData->mTopStackFrame) {
- frame = *callData->mTopStackFrame;
- }
-
- callData->mCountValue = IncreaseCounter(aCx, frame, aData,
+ callData->mCountValue = IncreaseCounter(aCx, aData,
callData->mCountLabel);
}
if (NS_IsMainThread()) {
callData->SetIDs(mOuterID, mInnerID);
ProcessCallData(aCx, callData, aData);
// Just because we don't want to expose
@@ -2114,52 +2112,50 @@ Console::ArgumentsToValueList(const Sequ
return false;
}
}
return true;
}
uint32_t
-Console::IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
- const Sequence<JS::Value>& aArguments,
+Console::IncreaseCounter(JSContext* aCx, const Sequence<JS::Value>& aArguments,
nsAString& aCountLabel)
{
AssertIsOnOwningThread();
ClearException ce(aCx);
- nsAutoString key;
nsAutoString label;
- if (!aArguments.IsEmpty()) {
+ if (aArguments.IsEmpty()) {
+ label.AssignLiteral(COUNT_DEFAULT_LABEL);
+ } else {
JS::Rooted<JS::Value> labelValue(aCx, aArguments[0]);
- JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, labelValue));
-
- nsAutoJSString string;
- if (jsString && string.init(aCx, jsString)) {
- label = string;
- key = string;
+
+ if (labelValue.isUndefined()) {
+ label.AssignLiteral(COUNT_DEFAULT_LABEL);
+ } else {
+ JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, labelValue));
+
+ nsAutoJSString string;
+ if (jsString && string.init(aCx, jsString)) {
+ label = string;
+ }
}
}
- if (key.IsEmpty()) {
- key.Append(aFrame.mFilename);
- key.Append(':');
- key.AppendInt(aFrame.mLineNumber);
- }
-
uint32_t count = 0;
- if (!mCounterRegistry.Get(key, &count) &&
+ if (!mCounterRegistry.Get(label, &count) &&
mCounterRegistry.Count() >= MAX_PAGE_COUNTERS) {
return MAX_PAGE_COUNTERS;
}
++count;
- mCounterRegistry.Put(key, count);
+ mCounterRegistry.Put(label, count);
aCountLabel = label;
return count;
}
JS::Value
Console::CreateCounterValue(JSContext* aCx, const nsAString& aCountLabel,
uint32_t aCountValue) const
--- a/dom/console/Console.h
+++ b/dom/console/Console.h
@@ -315,22 +315,20 @@ private:
ArgumentsToValueList(const Sequence<JS::Value>& aData,
Sequence<JS::Value>& aSequence) const;
// This method follows the same pattern as StartTimer: its runs on the owning
// thread and populate aCountLabel, used by CreateCounterValue. Returns
// MAX_PAGE_COUNTERS in case of error, otherwise the incremented counter
// value.
// * aCx - the JSContext rooting aData.
- // * aFrame - the first frame of ConsoleCallData.
// * aData - the arguments received by the console.count() method.
// * aCountLabel - the label that will be populated by this method.
uint32_t
- IncreaseCounter(JSContext* aCx, const ConsoleStackEntry& aFrame,
- const Sequence<JS::Value>& aData,
+ IncreaseCounter(JSContext* aCx, const Sequence<JS::Value>& aData,
nsAString& aCountLabel);
// This method generates a ConsoleCounter dictionary as JS::Value. If
// aCountValue is == MAX_PAGE_COUNTERS it generates a ConsoleCounterError
// instead. See IncreaseCounter.
// * aCx - this is the context that will root the returned value.
// * aCountLabel - this label must be what IncreaseCounter received as
// aTimerLabel.
--- a/dom/console/tests/test_bug659625.html
+++ b/dom/console/tests/test_bug659625.html
@@ -49,16 +49,31 @@ https://bugzilla.mozilla.org/show_bug.cg
clearAndCheckStorage();
console.count("count-label");
console.count("count-label");
ok(storage.getEvents().length === 3,
"2 new console events registered for 2 count calls");
clearAndCheckStorage();
+ // For bug 1346326.
+ console.count("default");
+ console.count();
+ console.count(undefined);
+ let events = storage.getEvents();
+ // Drop the event from the previous "clear".
+ events.splice(0, 1);
+ is(events.length, 3,
+ "3 new console events registered for 3 'default' count calls");
+ for (let i = 0; i < events.length; ++i) {
+ is(events[i].counter.count, i + 1, "check counter for event " + i);
+ is(events[i].counter.label, "default", "check label for event " + i);
+ }
+ clearAndCheckStorage();
+
console.group("group-label")
console.log("group-log");
ok(storage.getEvents().length === 3,
"2 new console events registered for group + log");
clearAndCheckStorage();
console.groupCollapsed("group-collapsed")
console.log("group-collapsed-log");