Commit c7b4febc authored by Matt Gardner's avatar Matt Gardner Committed by Commit Bot

Escape source name with '--trace-turbo'

Bug: https://bugs.chromium.org/p/v8/issues/detail?id=8441

Change-Id: I3b5f8c8f4439d0169f0cc5a91922ca961522f134
Bug: v8:8441
Reviewed-on: https://chromium-review.googlesource.com/c/1419078Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58910}
parent 4b90359c
......@@ -62,6 +62,30 @@ std::ostream& operator<<(std::ostream& out, const NodeOriginAsJSON& asJSON) {
return out;
}
class JSONEscaped {
public:
explicit JSONEscaped(const std::ostringstream& os) : str_(os.str()) {}
friend std::ostream& operator<<(std::ostream& os, const JSONEscaped& e) {
for (char c : e.str_) PipeCharacter(os, c);
return os;
}
private:
static std::ostream& PipeCharacter(std::ostream& os, char c) {
if (c == '"') return os << "\\\"";
if (c == '\\') return os << "\\\\";
if (c == '\b') return os << "\\b";
if (c == '\f') return os << "\\f";
if (c == '\n') return os << "\\n";
if (c == '\r') return os << "\\r";
if (c == '\t') return os << "\\t";
return os << c;
}
const std::string str_;
};
void JsonPrintFunctionSource(std::ostream& os, int source_id,
std::unique_ptr<char[]> function_name,
Handle<Script> script, Isolate* isolate,
......@@ -78,7 +102,9 @@ void JsonPrintFunctionSource(std::ostream& os, int source_id,
Object source_name = script->name();
os << ", \"sourceName\": \"";
if (source_name->IsString()) {
os << String::cast(source_name)->ToCString().get();
std::ostringstream escaped_name;
escaped_name << String::cast(source_name)->ToCString().get();
os << JSONEscaped(escaped_name);
}
os << "\"";
{
......@@ -239,30 +265,6 @@ static const char* SafeMnemonic(Node* node) {
return node == nullptr ? "null" : node->op()->mnemonic();
}
class JSONEscaped {
public:
explicit JSONEscaped(const std::ostringstream& os) : str_(os.str()) {}
friend std::ostream& operator<<(std::ostream& os, const JSONEscaped& e) {
for (char c : e.str_) PipeCharacter(os, c);
return os;
}
private:
static std::ostream& PipeCharacter(std::ostream& os, char c) {
if (c == '"') return os << "\\\"";
if (c == '\\') return os << "\\\\";
if (c == '\b') return os << "\\b";
if (c == '\f') return os << "\\f";
if (c == '\n') return os << "\\n";
if (c == '\r') return os << "\\r";
if (c == '\t') return os << "\\t";
return os << c;
}
const std::string str_;
};
class JSONGraphNodeWriter {
public:
JSONGraphNodeWriter(std::ostream& os, Zone* zone, const Graph* graph,
......
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