Index: src/ast/ast.h |
diff --git a/src/ast/ast.h b/src/ast/ast.h |
index 12e8de97158c3d44c8b6c28f469aec59b3642461..bdc1914f618d4428d3e5c59fd90375fadaf9afec 100644 |
--- a/src/ast/ast.h |
+++ b/src/ast/ast.h |
@@ -693,14 +693,17 @@ class ForStatement final : public IterationStatement { |
class ForEachStatement : public IterationStatement { |
public: |
enum VisitMode { |
- ENUMERATE, // for (each in subject) body; |
- ITERATE // for (each of subject) body; |
+ ENUMERATE, // for (each in subject) body; |
+ ITERATE, // for (each of subject) body; |
+ ASYNC_ITERATE, // for await (each of subject) body; |
}; |
using IterationStatement::Initialize; |
static const char* VisitModeString(VisitMode mode) { |
- return mode == ITERATE ? "for-of" : "for-in"; |
+ static const char* kModeStrings[] = {"for-in", "for-of", "for-await-of"}; |
+ DCHECK(mode >= ENUMERATE && mode <= ASYNC_ITERATE); |
+ return kModeStrings[mode]; |
} |
protected: |
@@ -836,7 +839,6 @@ class ForOfStatement final : public ForEachStatement { |
Expression* assign_each_; |
}; |
- |
class ExpressionStatement final : public Statement { |
public: |
void set_expression(Expression* e) { expression_ = e; } |
@@ -2482,6 +2484,7 @@ class RewritableExpression final : public Expression { |
class Yield final : public Expression { |
public: |
enum OnException { kOnExceptionThrow, kOnExceptionRethrow }; |
+ enum YieldType { kNormal, kAwait, kDelegate }; |
Expression* generator_object() const { return generator_object_; } |
Expression* expression() const { return expression_; } |
@@ -2492,21 +2495,26 @@ class Yield final : public Expression { |
return on_exception() == kOnExceptionRethrow; |
} |
int yield_id() const { return yield_id_; } |
+ YieldType yield_type() const { return YieldTypeField::decode(bit_field_); } |
void set_generator_object(Expression* e) { generator_object_ = e; } |
void set_expression(Expression* e) { expression_ = e; } |
void set_yield_id(int yield_id) { yield_id_ = yield_id; } |
+ void set_yield_type(YieldType type) { |
+ bit_field_ = YieldTypeField::update(bit_field_, type); |
+ } |
private: |
friend class AstNodeFactory; |
Yield(Expression* generator_object, Expression* expression, int pos, |
- OnException on_exception) |
+ OnException on_exception, YieldType yield_type = kNormal) |
: Expression(pos, kYield), |
yield_id_(-1), |
generator_object_(generator_object), |
expression_(expression) { |
- bit_field_ |= OnExceptionField::encode(on_exception); |
+ bit_field_ |= OnExceptionField::encode(on_exception) | |
+ YieldTypeField::encode(yield_type); |
} |
int yield_id_; |
@@ -2515,6 +2523,8 @@ class Yield final : public Expression { |
class OnExceptionField |
: public BitField<OnException, Expression::kNextBitFieldIndex, 1> {}; |
+ class YieldTypeField |
+ : public BitField<YieldType, OnExceptionField::kNext, 2> {}; |
}; |
@@ -2941,6 +2951,10 @@ class EmptyParentheses final : public Expression { |
// validate return value of the Symbol.iterator() call. |
class GetIterator final : public Expression { |
public: |
+ enum Hint { kNormal, kAsync }; |
+ |
+ Hint hint() const { return hint_; } |
+ |
Expression* iterable() const { return iterable_; } |
void set_iterable(Expression* iterable) { iterable_ = iterable; } |
@@ -2952,6 +2966,13 @@ class GetIterator final : public Expression { |
spec->AddSlot(FeedbackVectorSlotKind::LOAD_IC); |
iterator_call_feedback_slot_ = |
spec->AddSlot(FeedbackVectorSlotKind::CALL_IC); |
+ if (hint() == kAsync) { |
+ // Can we just re-use the other slots? |
+ async_iterator_property_feedback_slot_ = |
+ spec->AddSlot(FeedbackVectorSlotKind::LOAD_IC); |
+ async_iterator_call_feedback_slot_ = |
+ spec->AddSlot(FeedbackVectorSlotKind::CALL_IC); |
+ } |
} |
FeedbackVectorSlot IteratorPropertyFeedbackSlot() const { |
@@ -2962,15 +2983,29 @@ class GetIterator final : public Expression { |
return iterator_call_feedback_slot_; |
} |
+ FeedbackVectorSlot AsyncIteratorPropertyFeedbackSlot() const { |
+ return async_iterator_property_feedback_slot_; |
+ } |
+ |
+ FeedbackVectorSlot AsyncIteratorCallFeedbackSlot() const { |
+ return async_iterator_call_feedback_slot_; |
+ } |
+ |
private: |
friend class AstNodeFactory; |
explicit GetIterator(Expression* iterable, int pos) |
- : Expression(pos, kGetIterator), iterable_(iterable) {} |
+ : Expression(pos, kGetIterator), iterable_(iterable), hint_(kNormal) {} |
+ |
+ explicit GetIterator(Expression* iterable, Hint hint, int pos) |
+ : Expression(pos, kGetIterator), iterable_(iterable), hint_(hint) {} |
Expression* iterable_; |
+ Hint hint_; |
FeedbackVectorSlot iterator_property_feedback_slot_; |
FeedbackVectorSlot iterator_call_feedback_slot_; |
+ FeedbackVectorSlot async_iterator_property_feedback_slot_; |
+ FeedbackVectorSlot async_iterator_call_feedback_slot_; |
}; |
// ---------------------------------------------------------------------------- |
@@ -3178,7 +3213,8 @@ class AstNodeFactory final BASE_EMBEDDED { |
case ForEachStatement::ENUMERATE: { |
return new (zone_) ForInStatement(labels, pos); |
} |
- case ForEachStatement::ITERATE: { |
+ case ForEachStatement::ITERATE: |
+ case ForEachStatement::ASYNC_ITERATE: { |
return new (zone_) ForOfStatement(labels, pos); |
} |
} |
@@ -3458,9 +3494,11 @@ class AstNodeFactory final BASE_EMBEDDED { |
} |
Yield* NewYield(Expression* generator_object, Expression* expression, int pos, |
- Yield::OnException on_exception) { |
+ Yield::OnException on_exception, |
+ Yield::YieldType type = Yield::kNormal) { |
if (!expression) expression = NewUndefinedLiteral(pos); |
- return new (zone_) Yield(generator_object, expression, pos, on_exception); |
+ return new (zone_) |
+ Yield(generator_object, expression, pos, on_exception, type); |
} |
Throw* NewThrow(Expression* exception, int pos) { |
@@ -3553,6 +3591,11 @@ class AstNodeFactory final BASE_EMBEDDED { |
return new (zone_) GetIterator(iterable, pos); |
} |
+ GetIterator* NewGetIterator(Expression* iterable, GetIterator::Hint hint, |
+ int pos) { |
+ return new (zone_) GetIterator(iterable, hint, pos); |
+ } |
+ |
Zone* zone() const { return zone_; } |
void set_zone(Zone* zone) { zone_ = zone; } |