Bug 1072014 - Log.jsm: Allow logging of falsy arguments. r=Unfocused

This commit is contained in:
Matthew Noorenberghe 2014-09-23 21:38:43 -07:00
parent 9a63c33b35
commit 2bf9e4e38d
2 changed files with 10 additions and 2 deletions

View File

@ -535,7 +535,7 @@ BasicFormatter.prototype = {
*/
formatText: function (message) {
let params = message.params;
if (!params) {
if (typeof(params) == "undefined") {
return message.message || "";
}
// Defensive handling of non-object params
@ -543,7 +543,7 @@ BasicFormatter.prototype = {
let pIsObject = (typeof(params) == 'object' || typeof(params) == 'function');
// if we have params, try and find substitutions.
if (message.params && this.parameterFormatter) {
if (this.parameterFormatter) {
// have we successfully substituted any parameters into the message?
// in the log message
let subDone = false;

View File

@ -457,6 +457,14 @@ add_task(function log_message_with_params() {
'non-object no subst: 1');
do_check_eq(formatMessage("non-object all subst ${}", 2),
'non-object all subst 2');
do_check_eq(formatMessage("false no subst", false),
'false no subst: false');
do_check_eq(formatMessage("null no subst", null),
'null no subst: null');
// If 'params' is undefined and there are no substitutions expected,
// the message should still be output.
do_check_eq(formatMessage("undefined no subst", undefined),
'undefined no subst');
// If 'params' is not an object, no named substitutions can succeed;
// therefore we leave the placeholder and append the formatted params.
do_check_eq(formatMessage("non-object named subst ${junk} space", 3),