Chromium Code Reviews| Index: base/debug/trace_event_impl.cc | 
| diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc | 
| index 9ee9fc802be105ea979576ec239c6275c467a7fc..ac1709dd344c3309327f8c091a53ddca66084a09 100644 | 
| --- a/base/debug/trace_event_impl.cc | 
| +++ b/base/debug/trace_event_impl.cc | 
| @@ -17,6 +17,7 @@ | 
| #include "base/message_loop/message_loop.h" | 
| #include "base/process/process_metrics.h" | 
| #include "base/stl_util.h" | 
| +#include "base/strings/string_number_conversions.h" | 
| #include "base/strings/string_split.h" | 
| #include "base/strings/string_tokenizer.h" | 
| #include "base/strings/string_util.h" | 
| @@ -509,9 +510,28 @@ void TraceEvent::AppendValueAsJSON(unsigned char type, | 
| case TRACE_VALUE_TYPE_INT: | 
| StringAppendF(out, "%" PRId64, static_cast<int64>(value.as_int)); | 
| break; | 
| - case TRACE_VALUE_TYPE_DOUBLE: | 
| - StringAppendF(out, "%f", value.as_double); | 
| + case TRACE_VALUE_TYPE_DOUBLE: { | 
| + std::string real = DoubleToString(value.as_double); | 
| 
 
dsinclair
2013/10/07 14:26:51
Can we add a TODO in here since this is the same a
 
Erik Dahlström (inactive)
2013/10/07 15:00:52
Done.
 
 | 
| + // Ensure that the number has a .0 if there's no decimal or 'e'. This | 
| + // makes sure that when we read the JSON back, it's interpreted as a | 
| + // real rather than an int. | 
| + if (real.find('.') == std::string::npos && | 
| + real.find('e') == std::string::npos && | 
| + real.find('E') == std::string::npos) { | 
| + real.append(".0"); | 
| + } | 
| + // The JSON spec requires that non-integer values in the range (-1,1) | 
| + // have a zero before the decimal point - ".52" is not valid, "0.52" is. | 
| + if (real[0] == '.') { | 
| + real.insert(0, "0"); | 
| + } else if (real.length() > 1 && real[0] == '-' && real[1] == '.') { | 
| + // "-.1" bad "-0.1" good | 
| + real.insert(1, "0"); | 
| + } | 
| + | 
| + StringAppendF(out, "%s", real.c_str()); | 
| break; | 
| + } | 
| case TRACE_VALUE_TYPE_POINTER: | 
| // JSON only supports double and int numbers. | 
| // So as not to lose bits from a 64-bit pointer, output as a hex string. |