Fixed printing of JS code.

This is a fix/improvement for r23478 ("Fix disassembly redirection from stdout
into a file.").

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/554223002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23792 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d1283420
......@@ -189,7 +189,7 @@ void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
function->end_position() - function->start_position() + 1;
for (int i = 0; i < source_len; i++) {
if (stream.HasMore()) {
os << AsUC16(stream.GetNext());
os << AsReversiblyEscapedUC16(stream.GetNext());
}
}
os << "\n\n";
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <algorithm>
#include <cctype>
#include <cmath>
#include "src/base/platform/platform.h" // For isinf/isnan with MSVC
......@@ -165,9 +166,10 @@ OFStream& OFStream::flush() {
OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c) {
char buf[10];
const char* format = (0x20 <= c.value && c.value <= 0x7F) && (c.value != 0x52)
? "%c"
: (c.value <= 0xff) ? "\\x%02x" : "\\u%04x";
const char* format =
(std::isprint(c.value) || std::isspace(c.value)) && c.value != '\\'
? "%c"
: (c.value <= 0xff) ? "\\x%02x" : "\\u%04x";
snprintf(buf, sizeof(buf), format, c.value);
return os << buf;
}
......@@ -175,9 +177,8 @@ OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c) {
OStream& operator<<(OStream& os, const AsUC16& c) {
char buf[10];
const char* format = (0x20 <= c.value && c.value <= 0x7F)
? "%c"
: (c.value <= 0xff) ? "\\x%02x" : "\\u%04x";
const char* format =
std::isprint(c.value) ? "%c" : (c.value <= 0xff) ? "\\x%02x" : "\\u%04x";
snprintf(buf, sizeof(buf), format, c.value);
return os << buf;
}
......
......@@ -130,8 +130,8 @@ struct AsReversiblyEscapedUC16 {
};
// Writes the given character to the output escaping everything outside
// of printable ASCII range. Additionally escapes '\' making escaping
// Writes the given character to the output escaping everything outside of
// printable/space ASCII range. Additionally escapes '\' making escaping
// reversible.
OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment