Index: src/ast.h |
diff --git a/src/ast.h b/src/ast.h |
index 2ffa473be67aa03571b411beb80a788e3de41264..e1945b01cbec25a7f3c8cc1d8344e13c9cdf403f 100644 |
--- a/src/ast.h |
+++ b/src/ast.h |
@@ -90,6 +90,7 @@ namespace internal { |
V(WhileStatement) \ |
V(ForStatement) \ |
V(ForInStatement) \ |
+ V(ForOfStatement) \ |
V(TryCatchStatement) \ |
V(TryFinallyStatement) \ |
V(DebuggerStatement) |
@@ -874,47 +875,79 @@ class ForStatement: public IterationStatement { |
}; |
-class ForInStatement: public IterationStatement { |
+class ForEachStatement: public IterationStatement { |
public: |
- DECLARE_NODE_TYPE(ForInStatement) |
+ enum VisitMode { |
+ ENUMERATE, // for (each in subject) body; |
+ ITERATE // for (each of subject) body; |
+ }; |
- void Initialize(Expression* each, Expression* enumerable, Statement* body) { |
+ void Initialize(Expression* each, Expression* subject, Statement* body) { |
IterationStatement::Initialize(body); |
each_ = each; |
- enumerable_ = enumerable; |
- for_in_type_ = SLOW_FOR_IN; |
+ subject_ = subject; |
} |
Expression* each() const { return each_; } |
- Expression* enumerable() const { return enumerable_; } |
+ Expression* subject() const { return subject_; } |
virtual BailoutId ContinueId() const { return EntryId(); } |
virtual BailoutId StackCheckId() const { return body_id_; } |
BailoutId BodyId() const { return body_id_; } |
BailoutId PrepareId() const { return prepare_id_; } |
- TypeFeedbackId ForInFeedbackId() const { return reuse(PrepareId()); } |
- void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
- enum ForInType { FAST_FOR_IN, SLOW_FOR_IN }; |
- ForInType for_in_type() const { return for_in_type_; } |
- |
protected: |
- ForInStatement(Isolate* isolate, ZoneStringList* labels) |
+ ForEachStatement(Isolate* isolate, ZoneStringList* labels) |
: IterationStatement(isolate, labels), |
each_(NULL), |
- enumerable_(NULL), |
+ subject_(NULL), |
body_id_(GetNextId(isolate)), |
prepare_id_(GetNextId(isolate)) { |
} |
private: |
Expression* each_; |
- Expression* enumerable_; |
+ Expression* subject_; |
+ const BailoutId body_id_; |
+ const BailoutId prepare_id_; |
+}; |
+ |
+ |
+class ForInStatement: public ForEachStatement { |
+ public: |
+ DECLARE_NODE_TYPE(ForInStatement) |
+ |
+ Expression* enumerable() const { |
+ return subject(); |
+ } |
+ |
+ TypeFeedbackId ForInFeedbackId() const { return reuse(PrepareId()); } |
+ void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
+ enum ForInType { FAST_FOR_IN, SLOW_FOR_IN }; |
+ ForInType for_in_type() const { return for_in_type_; } |
+ |
+ protected: |
+ ForInStatement(Isolate* isolate, ZoneStringList* labels) |
+ : ForEachStatement(isolate, labels), |
+ for_in_type_(SLOW_FOR_IN) { |
+ } |
ForInType for_in_type_; |
+}; |
- const BailoutId body_id_; |
- const BailoutId prepare_id_; |
+ |
+class ForOfStatement: public ForEachStatement { |
+ public: |
+ DECLARE_NODE_TYPE(ForOfStatement) |
+ |
+ Expression* iterable() const { |
+ return subject(); |
+ } |
+ |
+ protected: |
+ ForOfStatement(Isolate* isolate, ZoneStringList* labels) |
+ : ForEachStatement(isolate, labels) { |
+ } |
}; |
@@ -2853,10 +2886,25 @@ class AstNodeFactory BASE_EMBEDDED { |
STATEMENT_WITH_LABELS(DoWhileStatement) |
STATEMENT_WITH_LABELS(WhileStatement) |
STATEMENT_WITH_LABELS(ForStatement) |
- STATEMENT_WITH_LABELS(ForInStatement) |
STATEMENT_WITH_LABELS(SwitchStatement) |
#undef STATEMENT_WITH_LABELS |
+ ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, |
+ ZoneStringList* labels) { |
+ switch (visit_mode) { |
+ case ForEachStatement::ENUMERATE: { |
+ ForInStatement* stmt = new(zone_) ForInStatement(isolate_, labels); |
+ VISIT_AND_RETURN(ForInStatement, stmt); |
+ } |
+ case ForEachStatement::ITERATE: { |
+ ForOfStatement* stmt = new(zone_) ForOfStatement(isolate_, labels); |
+ VISIT_AND_RETURN(ForOfStatement, stmt); |
+ } |
+ } |
+ UNREACHABLE(); |
+ return NULL; |
+ } |
+ |
ModuleStatement* NewModuleStatement(VariableProxy* proxy, Block* body) { |
ModuleStatement* stmt = new(zone_) ModuleStatement(proxy, body); |
VISIT_AND_RETURN(ModuleStatement, stmt) |