Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1490)

Unified Diff: src/ostreams.cc

Issue 2224913002: [turbolizer] Output correct JSON when source contains a backslash. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/interpreter/bytecode_expectations/RegExpLiterals.golden » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ostreams.cc
diff --git a/src/ostreams.cc b/src/ostreams.cc
index 45f41bb012089fd52a8beb14d4e6e4ad37cabb9f..a0a548b6070dafbc6f45f8a4c970bef1a4ba5220 100644
--- a/src/ostreams.cc
+++ b/src/ostreams.cc
@@ -61,6 +61,14 @@ std::ostream& PrintUC16(std::ostream& os, uint16_t c, bool (*pred)(uint16_t)) {
return os << buf;
}
+std::ostream& PrintUC16ForJSON(std::ostream& os, uint16_t c,
+ bool (*pred)(uint16_t)) {
+ // JSON does not allow \x99; must use \u0099.
+ char buf[10];
+ const char* format = pred(c) ? "%c" : "\\u%04x";
+ snprintf(buf, sizeof(buf), format, c);
+ return os << buf;
+}
std::ostream& PrintUC32(std::ostream& os, int32_t c, bool (*pred)(uint16_t)) {
if (c <= String::kMaxUtf16CodeUnit) {
@@ -84,7 +92,7 @@ std::ostream& operator<<(std::ostream& os, const AsEscapedUC16ForJSON& c) {
if (c.value == '\r') return os << "\\r";
if (c.value == '\t') return os << "\\t";
if (c.value == '\"') return os << "\\\"";
- return PrintUC16(os, c.value, IsOK);
+ return PrintUC16ForJSON(os, c.value, IsOK);
}
« no previous file with comments | « no previous file | test/cctest/interpreter/bytecode_expectations/RegExpLiterals.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698