OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_AST_AST_H_ | 5 #ifndef V8_AST_AST_H_ |
6 #define V8_AST_AST_H_ | 6 #define V8_AST_AST_H_ |
7 | 7 |
8 #include "src/ast/ast-value-factory.h" | 8 #include "src/ast/ast-value-factory.h" |
9 #include "src/ast/modules.h" | 9 #include "src/ast/modules.h" |
10 #include "src/ast/variables.h" | 10 #include "src/ast/variables.h" |
(...skipping 2493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2504 Expression* expr_; | 2504 Expression* expr_; |
2505 }; | 2505 }; |
2506 | 2506 |
2507 // Our Yield is different from the JS yield in that it "returns" its argument as | 2507 // Our Yield is different from the JS yield in that it "returns" its argument as |
2508 // is, without wrapping it in an iterator result object. Such wrapping, if | 2508 // is, without wrapping it in an iterator result object. Such wrapping, if |
2509 // desired, must be done beforehand (see the parser). | 2509 // desired, must be done beforehand (see the parser). |
2510 class Yield final : public Expression { | 2510 class Yield final : public Expression { |
2511 public: | 2511 public: |
2512 DECLARE_NODE_TYPE(Yield) | 2512 DECLARE_NODE_TYPE(Yield) |
2513 | 2513 |
| 2514 enum OnException { kOnExceptionThrow, kOnExceptionRethrow }; |
| 2515 |
2514 Expression* generator_object() const { return generator_object_; } | 2516 Expression* generator_object() const { return generator_object_; } |
2515 Expression* expression() const { return expression_; } | 2517 Expression* expression() const { return expression_; } |
| 2518 bool rethrow_on_exception() const { |
| 2519 return on_exception_ == kOnExceptionRethrow; |
| 2520 } |
2516 int yield_id() const { return yield_id_; } | 2521 int yield_id() const { return yield_id_; } |
2517 | 2522 |
2518 void set_generator_object(Expression* e) { generator_object_ = e; } | 2523 void set_generator_object(Expression* e) { generator_object_ = e; } |
2519 void set_expression(Expression* e) { expression_ = e; } | 2524 void set_expression(Expression* e) { expression_ = e; } |
2520 void set_yield_id(int yield_id) { yield_id_ = yield_id; } | 2525 void set_yield_id(int yield_id) { yield_id_ = yield_id; } |
2521 | 2526 |
2522 protected: | 2527 protected: |
2523 Yield(Zone* zone, Expression* generator_object, Expression* expression, | 2528 Yield(Zone* zone, Expression* generator_object, Expression* expression, |
2524 int pos) | 2529 int pos, OnException on_exception) |
2525 : Expression(zone, pos), | 2530 : Expression(zone, pos), |
2526 generator_object_(generator_object), | 2531 generator_object_(generator_object), |
2527 expression_(expression), | 2532 expression_(expression), |
| 2533 on_exception_(on_exception), |
2528 yield_id_(-1) {} | 2534 yield_id_(-1) {} |
2529 | 2535 |
2530 private: | 2536 private: |
2531 Expression* generator_object_; | 2537 Expression* generator_object_; |
2532 Expression* expression_; | 2538 Expression* expression_; |
| 2539 OnException on_exception_; |
2533 int yield_id_; | 2540 int yield_id_; |
2534 }; | 2541 }; |
2535 | 2542 |
2536 | 2543 |
2537 class Throw final : public Expression { | 2544 class Throw final : public Expression { |
2538 public: | 2545 public: |
2539 DECLARE_NODE_TYPE(Throw) | 2546 DECLARE_NODE_TYPE(Throw) |
2540 | 2547 |
2541 Expression* exception() const { return exception_; } | 2548 Expression* exception() const { return exception_; } |
2542 void set_exception(Expression* e) { exception_ = e; } | 2549 void set_exception(Expression* e) { exception_ = e; } |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3392 Assignment* assign = | 3399 Assignment* assign = |
3393 new (local_zone_) Assignment(local_zone_, op, target, value, pos); | 3400 new (local_zone_) Assignment(local_zone_, op, target, value, pos); |
3394 if (assign->is_compound()) { | 3401 if (assign->is_compound()) { |
3395 DCHECK(Token::IsAssignmentOp(op)); | 3402 DCHECK(Token::IsAssignmentOp(op)); |
3396 assign->binary_operation_ = | 3403 assign->binary_operation_ = |
3397 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); | 3404 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); |
3398 } | 3405 } |
3399 return assign; | 3406 return assign; |
3400 } | 3407 } |
3401 | 3408 |
3402 Yield* NewYield(Expression *generator_object, | 3409 Yield* NewYield(Expression* generator_object, Expression* expression, int pos, |
3403 Expression* expression, | 3410 Yield::OnException on_exception) { |
3404 int pos) { | |
3405 if (!expression) expression = NewUndefinedLiteral(pos); | 3411 if (!expression) expression = NewUndefinedLiteral(pos); |
3406 return new (local_zone_) | 3412 return new (local_zone_) |
3407 Yield(local_zone_, generator_object, expression, pos); | 3413 Yield(local_zone_, generator_object, expression, pos, on_exception); |
3408 } | 3414 } |
3409 | 3415 |
3410 Throw* NewThrow(Expression* exception, int pos) { | 3416 Throw* NewThrow(Expression* exception, int pos) { |
3411 return new (local_zone_) Throw(local_zone_, exception, pos); | 3417 return new (local_zone_) Throw(local_zone_, exception, pos); |
3412 } | 3418 } |
3413 | 3419 |
3414 FunctionLiteral* NewFunctionLiteral( | 3420 FunctionLiteral* NewFunctionLiteral( |
3415 const AstRawString* name, Scope* scope, ZoneList<Statement*>* body, | 3421 const AstRawString* name, Scope* scope, ZoneList<Statement*>* body, |
3416 int materialized_literal_count, int expected_property_count, | 3422 int materialized_literal_count, int expected_property_count, |
3417 int parameter_count, | 3423 int parameter_count, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3555 : NULL; \ | 3561 : NULL; \ |
3556 } | 3562 } |
3557 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3563 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3558 #undef DECLARE_NODE_FUNCTIONS | 3564 #undef DECLARE_NODE_FUNCTIONS |
3559 | 3565 |
3560 | 3566 |
3561 } // namespace internal | 3567 } // namespace internal |
3562 } // namespace v8 | 3568 } // namespace v8 |
3563 | 3569 |
3564 #endif // V8_AST_AST_H_ | 3570 #endif // V8_AST_AST_H_ |
OLD | NEW |