From 35717fcad1b04dcf3c6d05c7e84be9ae8be297b6 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Wed, 17 Jan 2018 09:19:36 -0800 Subject: [PATCH] Bug 1431105 - Prefix in Console when used by JSM, r=bgrins, r=smaug --- .../test/fixtures/stubs/consoleApi.js | 48 +++++++++++++++++++ dom/console/Console.cpp | 9 ++-- dom/console/Console.h | 2 +- dom/console/ConsoleInstance.cpp | 2 +- dom/console/tests/test_jsm.xul | 3 ++ dom/webidl/Console.webidl | 1 + 6 files changed, 59 insertions(+), 6 deletions(-) diff --git a/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js b/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js index b5f56e96df00..fecfcd0f9146 100644 --- a/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js +++ b/devtools/client/webconsole/new-console-output/test/fixtures/stubs/consoleApi.js @@ -1507,6 +1507,7 @@ stubPackets.set("console.log('foobar', 'test')", { "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924471, @@ -1533,6 +1534,7 @@ stubPackets.set("console.log(undefined)", { "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924479, @@ -1557,6 +1559,7 @@ stubPackets.set("console.warn('danger, will robinson!')", { "groupName": "", "level": "warn", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924487, @@ -1583,6 +1586,7 @@ stubPackets.set("console.log(NaN)", { "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924495, @@ -1609,6 +1613,7 @@ stubPackets.set("console.log(null)", { "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924501, @@ -1633,6 +1638,7 @@ stubPackets.set("console.log('鼬')", { "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924506, @@ -1655,6 +1661,7 @@ stubPackets.set("console.clear()", { "groupName": "", "level": "clear", "lineNumber": 1, + "prefix": "", "private": false, "timeStamp": 1502884924512, "timer": null, @@ -1682,6 +1689,7 @@ stubPackets.set("console.count('bar')", { "groupName": "", "level": "count", "lineNumber": 1, + "prefix": "", "private": false, "timeStamp": 1502884924515, "timer": null, @@ -1729,6 +1737,7 @@ stubPackets.set("console.assert(false, {message: 'foobar'})", { "groupName": "", "level": "assert", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924521, @@ -1761,6 +1770,7 @@ stubPackets.set("console.log('hello \nfrom \rthe \"string world!')", { "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924528, @@ -1785,6 +1795,7 @@ stubPackets.set("console.log('úṇĩçödê țĕșť')", { "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924586, @@ -1821,6 +1832,7 @@ stubPackets.set("console.dirxml(window)", { "groupName": "", "level": "dirxml", "lineNumber": 1, + "prefix": "", "private": false, "timeStamp": 1502884924596, "timer": null, @@ -1863,6 +1875,7 @@ stubPackets.set("console.log('myarray', ['red', 'green', 'blue'])", { "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924604, @@ -1897,6 +1910,7 @@ stubPackets.set("console.log('myregex', /a.b.c/)", { "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924610, @@ -1938,6 +1952,7 @@ stubPackets.set("console.table(['red', 'green', 'blue']);", { "groupName": "", "level": "table", "lineNumber": 1, + "prefix": "", "private": false, "timeStamp": 1502884924612, "timer": null, @@ -1998,6 +2013,7 @@ stubPackets.set("console.log('myobject', {red: 'redValue', green: 'greenValue', "groupName": "", "level": "log", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924614, @@ -2022,6 +2038,7 @@ stubPackets.set("console.debug('debug message');", { "groupName": "", "level": "debug", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924621, @@ -2046,6 +2063,7 @@ stubPackets.set("console.info('info message');", { "groupName": "", "level": "info", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924625, @@ -2070,6 +2088,7 @@ stubPackets.set("console.error('error message');", { "groupName": "", "level": "error", "lineNumber": 1, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924628, @@ -2125,6 +2144,7 @@ stubPackets.set("console.log('mymap')", { "groupName": "", "level": "log", "lineNumber": 5, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924631, @@ -2166,6 +2186,7 @@ stubPackets.set("console.log('myset')", { "groupName": "", "level": "log", "lineNumber": 2, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924746, @@ -2188,6 +2209,7 @@ stubPackets.set("console.trace()", { "groupName": "", "level": "trace", "lineNumber": 3, + "prefix": "", "private": false, "timeStamp": 1502884924752, "timer": null, @@ -2232,6 +2254,7 @@ stubPackets.set("console.time('bar')", { "groupName": "", "level": "time", "lineNumber": 2, + "prefix": "", "private": false, "timeStamp": 1502884924757, "timer": { @@ -2258,6 +2281,7 @@ stubPackets.set("timerAlreadyExists", { "groupName": "", "level": "time", "lineNumber": 3, + "prefix": "", "private": false, "timeStamp": 1502884924758, "timer": { @@ -2285,6 +2309,7 @@ stubPackets.set("console.timeEnd('bar')", { "groupName": "", "level": "timeEnd", "lineNumber": 4, + "prefix": "", "private": false, "timeStamp": 1502884924759, "timer": { @@ -2312,6 +2337,7 @@ stubPackets.set("timerDoesntExist", { "groupName": "", "level": "timeEnd", "lineNumber": 5, + "prefix": "", "private": false, "timeStamp": 1502884924759, "timer": { @@ -2339,6 +2365,7 @@ stubPackets.set("console.table('bar')", { "groupName": "", "level": "table", "lineNumber": 2, + "prefix": "", "private": false, "timeStamp": 1502884924801, "timer": null, @@ -2380,6 +2407,7 @@ stubPackets.set("console.table(['a', 'b', 'c'])", { "groupName": "", "level": "table", "lineNumber": 2, + "prefix": "", "private": false, "timeStamp": 1502884924859, "timer": null, @@ -2404,6 +2432,7 @@ stubPackets.set("console.group('bar')", { "groupName": "bar", "level": "group", "lineNumber": 2, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924863, @@ -2426,6 +2455,7 @@ stubPackets.set("console.groupEnd('bar')", { "groupName": "bar", "level": "groupEnd", "lineNumber": 3, + "prefix": "", "private": false, "timeStamp": 1502884924864, "timer": null, @@ -2450,6 +2480,7 @@ stubPackets.set("console.groupCollapsed('foo')", { "groupName": "foo", "level": "groupCollapsed", "lineNumber": 2, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924870, @@ -2472,6 +2503,7 @@ stubPackets.set("console.groupEnd('foo')", { "groupName": "foo", "level": "groupEnd", "lineNumber": 3, + "prefix": "", "private": false, "timeStamp": 1502884924871, "timer": null, @@ -2494,6 +2526,7 @@ stubPackets.set("console.group()", { "groupName": "", "level": "group", "lineNumber": 2, + "prefix": "", "private": false, "styles": [], "timeStamp": 1502884924878, @@ -2516,6 +2549,7 @@ stubPackets.set("console.groupEnd()", { "groupName": "", "level": "groupEnd", "lineNumber": 3, + "prefix": "", "private": false, "timeStamp": 1502884924879, "timer": null, @@ -2541,6 +2575,7 @@ stubPackets.set("console.log(%cfoobar)", { "groupName": "", "level": "log", "lineNumber": 2, + "prefix": "", "private": false, "styles": [ "color:blue;font-size:1.3em;background:url('http://example.com/test');position:absolute;top:10px", @@ -2569,6 +2604,7 @@ stubPackets.set("console.group(%cfoo%cbar)", { "groupName": "foo bar", "level": "group", "lineNumber": 2, + "prefix": "", "private": false, "styles": [ "color:blue;font-size:1.3em;background:url('http://example.com/test');position:absolute;top:10px", @@ -2594,6 +2630,7 @@ stubPackets.set("console.groupEnd(%cfoo%cbar)", { "groupName": "foo bar", "level": "groupEnd", "lineNumber": 6, + "prefix": "", "private": false, "timeStamp": 1502884924887, "timer": null, @@ -2619,6 +2656,7 @@ stubPackets.set("console.groupCollapsed(%cfoo%cbaz)", { "groupName": "foo baz", "level": "groupCollapsed", "lineNumber": 2, + "prefix": "", "private": false, "styles": [ "color:blue;font-size:1.3em;background:url('http://example.com/test');position:absolute;top:10px", @@ -2644,6 +2682,7 @@ stubPackets.set("console.groupEnd(%cfoo%cbaz)", { "groupName": "foo baz", "level": "groupEnd", "lineNumber": 6, + "prefix": "", "private": false, "timeStamp": 1502884924893, "timer": null, @@ -2709,6 +2748,7 @@ stubPackets.set("console.dir({C, M, Y, K})", { "groupName": "", "level": "dir", "lineNumber": 1, + "prefix": "", "private": false, "timeStamp": 1502884924899, "timer": null, @@ -2736,6 +2776,7 @@ stubPackets.set("console.count | default: 1", { "groupName": "", "level": "count", "lineNumber": 2, + "prefix": "", "private": false, "timeStamp": 1511365913333, "timer": null, @@ -2763,6 +2804,7 @@ stubPackets.set("console.count | default: 2", { "groupName": "", "level": "count", "lineNumber": 3, + "prefix": "", "private": false, "timeStamp": 1511365913334, "timer": null, @@ -2790,6 +2832,7 @@ stubPackets.set("console.count | test counter: 1", { "groupName": "", "level": "count", "lineNumber": 4, + "prefix": "", "private": false, "timeStamp": 1511365913334, "timer": null, @@ -2817,6 +2860,7 @@ stubPackets.set("console.count | test counter: 2", { "groupName": "", "level": "count", "lineNumber": 5, + "prefix": "", "private": false, "timeStamp": 1511365913334, "timer": null, @@ -2844,6 +2888,7 @@ stubPackets.set("console.count | default: 3", { "groupName": "", "level": "count", "lineNumber": 6, + "prefix": "", "private": false, "timeStamp": 1511365913334, "timer": null, @@ -2866,6 +2911,7 @@ stubPackets.set("console.count | clear", { "groupName": "", "level": "clear", "lineNumber": 7, + "prefix": "", "private": false, "timeStamp": 1511365913334, "timer": null, @@ -2893,6 +2939,7 @@ stubPackets.set("console.count | default: 4", { "groupName": "", "level": "count", "lineNumber": 8, + "prefix": "", "private": false, "timeStamp": 1511365913335, "timer": null, @@ -2920,6 +2967,7 @@ stubPackets.set("console.count | test counter: 3", { "groupName": "", "level": "count", "lineNumber": 9, + "prefix": "", "private": false, "timeStamp": 1511365913335, "timer": null, diff --git a/dom/console/Console.cpp b/dom/console/Console.cpp index 6abeea731a84..4e60a0b139ab 100644 --- a/dom/console/Console.cpp +++ b/dom/console/Console.cpp @@ -1537,6 +1537,7 @@ Console::PopulateConsoleNotificationInTheTargetScope(JSContext* aCx, event.mConsoleID = mConsoleID; event.mLevel = aData->mMethodString; event.mFilename = frame.mFilename; + event.mPrefix = mPrefix; nsCOMPtr filenameURI; nsAutoCString pass; @@ -2602,8 +2603,8 @@ Console::MaybeExecuteDumpFunction(JSContext* aCx, message.Append(aMethodName); message.AppendLiteral(": "); - if (!mDumpPrefix.IsEmpty()) { - message.Append(mDumpPrefix); + if (!mPrefix.IsEmpty()) { + message.Append(mPrefix); message.AppendLiteral(": "); } @@ -2640,8 +2641,8 @@ Console::MaybeExecuteDumpFunctionForTrace(JSContext* aCx, nsIStackFrame* aStack) nsAutoString message; message.AssignLiteral("console.trace:\n"); - if (!mDumpPrefix.IsEmpty()) { - message.Append(mDumpPrefix); + if (!mPrefix.IsEmpty()) { + message.Append(mPrefix); message.AppendLiteral(": "); } diff --git a/dom/console/Console.h b/dom/console/Console.h index 0f06c4fa469b..6bddeecb6879 100644 --- a/dom/console/Console.h +++ b/dom/console/Console.h @@ -444,7 +444,7 @@ private: nsString mPassedInnerID; RefPtr mDumpFunction; bool mDumpToStdout; - nsString mDumpPrefix; + nsString mPrefix; bool mChromeInstance; ConsoleLogLevel mMaxLogLevel; diff --git a/dom/console/ConsoleInstance.cpp b/dom/console/ConsoleInstance.cpp index dba879d24c11..91984b6362af 100644 --- a/dom/console/ConsoleInstance.cpp +++ b/dom/console/ConsoleInstance.cpp @@ -79,7 +79,7 @@ ConsoleInstance::ConsoleInstance(const ConsoleInstanceOptions& aOptions) mConsole->mDumpToStdout = true; } - mConsole->mDumpPrefix = aOptions.mPrefix; + mConsole->mPrefix = aOptions.mPrefix; // Let's inform that this is a custom instance. mConsole->mChromeInstance = true; diff --git a/dom/console/tests/test_jsm.xul b/dom/console/tests/test_jsm.xul index a4393bccdf82..35743912c30d 100644 --- a/dom/console/tests/test_jsm.xul +++ b/dom/console/tests/test_jsm.xul @@ -38,6 +38,7 @@ consoleListener.prototype = { is(obj.ID, "jsm", "ID and InnerID are correctly set."); is(obj.arguments[0], "Hello world!", "Message matches"); is(obj.consoleID, "", "No consoleID for console API"); + is(obj.prefix, "", "prefix is empty by default"); // We want to see 2 messages from this innerID, the first is generated // by console.log, the second one from createInstance().log(); @@ -46,11 +47,13 @@ consoleListener.prototype = { is(obj.ID, "jsm", "ID and InnerID are correctly set."); is(obj.arguments[0], "Hello world!", "Message matches"); is(obj.consoleID, "wow", "consoleID is set by consoleInstance"); + is(obj.prefix, "_PREFIX_", "prefix is set by consoleInstance"); ++this.count; } else if (obj.innerID == "LEVEL") { // Nothing special... just we don't want to see 'invisible' messages. is(obj.ID, "jsm", "ID and InnerID are correctly set."); is(obj.arguments[0], "Hello world!", "Message matches"); + is(obj.prefix, "", "prefix is empty by default"); ++this.count; } diff --git a/dom/webidl/Console.webidl b/dom/webidl/Console.webidl index c95316d21d57..46532be3092e 100644 --- a/dom/webidl/Console.webidl +++ b/dom/webidl/Console.webidl @@ -78,6 +78,7 @@ dictionary ConsoleEvent { DOMString groupName = ""; any timer = null; any counter = null; + DOMString prefix = ""; }; // Event for profile operations