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

Unified Diff: src/ast/prettyprinter.cc

Issue 1491923003: Improve rendering of callsite with non-function target. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix tests Created 5 years 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 | « src/ast/prettyprinter.h ('k') | src/parsing/parser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/prettyprinter.cc
diff --git a/src/ast/prettyprinter.cc b/src/ast/prettyprinter.cc
index 00b31168ea5c31c445fff69570f2982ae44a0972..8317d9497764a4cd00ee91580feb3a1be46f05b7 100644
--- a/src/ast/prettyprinter.cc
+++ b/src/ast/prettyprinter.cc
@@ -13,13 +13,14 @@
namespace v8 {
namespace internal {
-CallPrinter::CallPrinter(Isolate* isolate) {
+CallPrinter::CallPrinter(Isolate* isolate, bool is_builtin) {
output_ = NULL;
size_ = 0;
pos_ = 0;
position_ = 0;
found_ = false;
done_ = false;
+ is_builtin_ = is_builtin;
InitializeAstVisitor(isolate);
}
@@ -192,8 +193,9 @@ void CallPrinter::VisitForInStatement(ForInStatement* node) {
void CallPrinter::VisitForOfStatement(ForOfStatement* node) {
Find(node->each());
- Find(node->iterable());
+ Find(node->assign_iterator());
Find(node->body());
+ Find(node->next_result());
}
@@ -239,13 +241,13 @@ void CallPrinter::VisitConditional(Conditional* node) {
void CallPrinter::VisitLiteral(Literal* node) {
- PrintLiteral(node->value(), true);
+ PrintLiteral(*node->value(), true);
}
void CallPrinter::VisitRegExpLiteral(RegExpLiteral* node) {
Print("/");
- PrintLiteral(node->pattern(), false);
+ PrintLiteral(*node->pattern(), false);
Print("/");
if (node->flags() & RegExp::kGlobal) Print("g");
if (node->flags() & RegExp::kIgnoreCase) Print("i");
@@ -273,7 +275,12 @@ void CallPrinter::VisitArrayLiteral(ArrayLiteral* node) {
void CallPrinter::VisitVariableProxy(VariableProxy* node) {
- PrintLiteral(node->name(), false);
+ if (is_builtin_) {
+ // Variable names of builtins are meaningless due to minification.
+ Print("(var)");
+ } else {
+ PrintLiteral(*node->name(), false);
+ }
}
@@ -295,7 +302,7 @@ void CallPrinter::VisitProperty(Property* node) {
if (literal != NULL && literal->value()->IsInternalizedString()) {
Find(node->obj(), true);
Print(".");
- PrintLiteral(literal->value(), false);
+ PrintLiteral(*literal->value(), false);
} else {
Find(node->obj(), true);
Print("[");
@@ -307,7 +314,15 @@ void CallPrinter::VisitProperty(Property* node) {
void CallPrinter::VisitCall(Call* node) {
bool was_found = !found_ && node->position() == position_;
- if (was_found) found_ = true;
+ if (was_found) {
+ // Bail out if the error is caused by a direct call to a variable in builtin
+ // code. The variable name is meaningless due to minification.
+ if (is_builtin_ && node->expression()->IsVariableProxy()) {
+ done_ = true;
+ return;
+ }
+ found_ = true;
+ }
Find(node->expression(), true);
if (!was_found) Print("(...)");
FindArguments(node->arguments());
@@ -317,7 +332,15 @@ void CallPrinter::VisitCall(Call* node) {
void CallPrinter::VisitCallNew(CallNew* node) {
bool was_found = !found_ && node->position() == position_;
- if (was_found) found_ = true;
+ if (was_found) {
+ // Bail out if the error is caused by a direct call to a variable in builtin
+ // code. The variable name is meaningless due to minification.
+ if (is_builtin_ && node->expression()->IsVariableProxy()) {
+ done_ = true;
+ return;
+ }
+ found_ = true;
+ }
Find(node->expression(), was_found);
FindArguments(node->arguments());
if (was_found) done_ = true;
@@ -413,14 +436,11 @@ void CallPrinter::FindArguments(ZoneList<Expression*>* arguments) {
}
-void CallPrinter::PrintLiteral(Handle<Object> value, bool quote) {
- Object* object = *value;
+void CallPrinter::PrintLiteral(Object* value, bool quote) {
+ Object* object = value;
if (object->IsString()) {
- String* string = String::cast(object);
if (quote) Print("\"");
- for (int i = 0; i < string->length(); i++) {
- Print("%c", string->Get(i));
- }
+ Print("%s", String::cast(object)->ToCString().get());
if (quote) Print("\"");
} else if (object->IsNull()) {
Print("null");
@@ -432,12 +452,15 @@ void CallPrinter::PrintLiteral(Handle<Object> value, bool quote) {
Print("undefined");
} else if (object->IsNumber()) {
Print("%g", object->Number());
+ } else if (object->IsSymbol()) {
+ // Symbols can only occur as literals if they were inserted by the parser.
+ PrintLiteral(Symbol::cast(object)->name(), false);
}
}
void CallPrinter::PrintLiteral(const AstRawString* value, bool quote) {
- PrintLiteral(value->string(), quote);
+ PrintLiteral(*value->string(), quote);
}
« no previous file with comments | « src/ast/prettyprinter.h ('k') | src/parsing/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698