Skip to content

Commit 6a8f74e

Browse files
Fixed printing of JS code.
This is a fix/improvement for r23478 ("Fix disassembly redirection from stdout into a file."). [email protected] Review URL: https://codereview.chromium.org/554223002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23792 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent 7a76052 commit 6a8f74e

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/codegen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
189189
function->end_position() - function->start_position() + 1;
190190
for (int i = 0; i < source_len; i++) {
191191
if (stream.HasMore()) {
192-
os << AsUC16(stream.GetNext());
192+
os << AsReversiblyEscapedUC16(stream.GetNext());
193193
}
194194
}
195195
os << "\n\n";

src/ostreams.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#include <algorithm>
6+
#include <cctype>
67
#include <cmath>
78

89
#include "src/base/platform/platform.h" // For isinf/isnan with MSVC
@@ -165,19 +166,19 @@ OFStream& OFStream::flush() {
165166

166167
OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c) {
167168
char buf[10];
168-
const char* format = (0x20 <= c.value && c.value <= 0x7F) && (c.value != 0x52)
169-
? "%c"
170-
: (c.value <= 0xff) ? "\\x%02x" : "\\u%04x";
169+
const char* format =
170+
(std::isprint(c.value) || std::isspace(c.value)) && c.value != '\\'
171+
? "%c"
172+
: (c.value <= 0xff) ? "\\x%02x" : "\\u%04x";
171173
snprintf(buf, sizeof(buf), format, c.value);
172174
return os << buf;
173175
}
174176

175177

176178
OStream& operator<<(OStream& os, const AsUC16& c) {
177179
char buf[10];
178-
const char* format = (0x20 <= c.value && c.value <= 0x7F)
179-
? "%c"
180-
: (c.value <= 0xff) ? "\\x%02x" : "\\u%04x";
180+
const char* format =
181+
std::isprint(c.value) ? "%c" : (c.value <= 0xff) ? "\\x%02x" : "\\u%04x";
181182
snprintf(buf, sizeof(buf), format, c.value);
182183
return os << buf;
183184
}

src/ostreams.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ struct AsReversiblyEscapedUC16 {
130130
};
131131

132132

133-
// Writes the given character to the output escaping everything outside
134-
// of printable ASCII range. Additionally escapes '\' making escaping
133+
// Writes the given character to the output escaping everything outside of
134+
// printable/space ASCII range. Additionally escapes '\' making escaping
135135
// reversible.
136136
OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c);
137137

0 commit comments

Comments
 (0)