Reviewers: rossberg,
Message:
PTAL
Description:
Fix issue with --print-ast and class expressions
Make sure that --pringt-ast works even when the class expression has no
name.
This also updates the printer to print the properties of the class
literal.
BUG=v8:4138
LOG=N
R=rossberg
Please review this at https://codereview.chromium.org/1165613003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+46, -29 lines):
M src/prettyprinter.h
M src/prettyprinter.cc
Index: src/prettyprinter.cc
diff --git a/src/prettyprinter.cc b/src/prettyprinter.cc
index
3a476575718d4dbfb83388252886dfdc2c8b676c..41288b02af38038f055c698f771744e770ce0b25
100644
--- a/src/prettyprinter.cc
+++ b/src/prettyprinter.cc
@@ -1321,7 +1321,50 @@ void
AstPrinter::VisitFunctionLiteral(FunctionLiteral* node) {
void AstPrinter::VisitClassLiteral(ClassLiteral* node) {
IndentedScope indent(this, "CLASS LITERAL");
- PrintLiteralIndented("NAME", node->name(), false);
+ if (node->raw_name() != nullptr) {
+ PrintLiteralIndented("NAME", node->name(), false);
+ }
+ if (node->extends() != nullptr) {
+ PrintIndentedVisit("EXTENDS", node->extends());
+ }
+ PrintProperties(node->properties());
+}
+
+
+void AstPrinter::PrintProperties(
+ ZoneList<ObjectLiteral::Property*>* properties) {
+ for (int i = 0; i < properties->length(); i++) {
+ ObjectLiteral::Property* property = properties->at(i);
+ const char* prop_kind = nullptr;
+ switch (property->kind()) {
+ case ObjectLiteral::Property::CONSTANT:
+ prop_kind = "CONSTANT";
+ break;
+ case ObjectLiteral::Property::COMPUTED:
+ prop_kind = "COMPUTED";
+ break;
+ case ObjectLiteral::Property::MATERIALIZED_LITERAL:
+ prop_kind = "MATERIALIZED_LITERAL";
+ break;
+ case ObjectLiteral::Property::PROTOTYPE:
+ prop_kind = "PROTOTYPE";
+ break;
+ case ObjectLiteral::Property::GETTER:
+ prop_kind = "GETTER";
+ break;
+ case ObjectLiteral::Property::SETTER:
+ prop_kind = "SETTER";
+ break;
+ default:
+ UNREACHABLE();
+ }
+ EmbeddedVector<char, 128> buf;
+ SNPrintF(buf, "PROPERTY%s - %s", property->is_static() ? " -
STATIC" : "",
+ prop_kind);
+ IndentedScope prop(this, buf.start());
+ PrintIndentedVisit("KEY", properties->at(i)->key());
+ PrintIndentedVisit("VALUE", properties->at(i)->value());
+ }
}
@@ -1354,34 +1397,7 @@ void AstPrinter::VisitRegExpLiteral(RegExpLiteral*
node) {
void AstPrinter::VisitObjectLiteral(ObjectLiteral* node) {
IndentedScope indent(this, "OBJ LITERAL");
- for (int i = 0; i < node->properties()->length(); i++) {
- const char* prop_kind = NULL;
- switch (node->properties()->at(i)->kind()) {
- case ObjectLiteral::Property::CONSTANT:
- prop_kind = "PROPERTY - CONSTANT";
- break;
- case ObjectLiteral::Property::COMPUTED:
- prop_kind = "PROPERTY - COMPUTED";
- break;
- case ObjectLiteral::Property::MATERIALIZED_LITERAL:
- prop_kind = "PROPERTY - MATERIALIZED_LITERAL";
- break;
- case ObjectLiteral::Property::PROTOTYPE:
- prop_kind = "PROPERTY - PROTOTYPE";
- break;
- case ObjectLiteral::Property::GETTER:
- prop_kind = "PROPERTY - GETTER";
- break;
- case ObjectLiteral::Property::SETTER:
- prop_kind = "PROPERTY - SETTER";
- break;
- default:
- UNREACHABLE();
- }
- IndentedScope prop(this, prop_kind);
- PrintIndentedVisit("KEY", node->properties()->at(i)->key());
- PrintIndentedVisit("VALUE", node->properties()->at(i)->value());
- }
+ PrintProperties(node->properties());
}
Index: src/prettyprinter.h
diff --git a/src/prettyprinter.h b/src/prettyprinter.h
index
a05b61796a75ccee1b598b407e60861c92c4f6fa..1971cfe8399bc323576e5aa8699afcabae10703f
100644
--- a/src/prettyprinter.h
+++ b/src/prettyprinter.h
@@ -123,6 +123,7 @@ class AstPrinter: public PrettyPrinter {
Variable* var,
Handle<Object> value);
void PrintLabelsIndented(ZoneList<const AstRawString*>* labels);
+ void PrintProperties(ZoneList<ObjectLiteral::Property*>* properties);
void inc_indent() { indent_++; }
void dec_indent() { indent_--; }
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.