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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 bool has_dot = scanner()->ContainsDot(); | 497 bool has_dot = scanner()->ContainsDot(); |
498 double value = scanner()->DoubleValue(); | 498 double value = scanner()->DoubleValue(); |
499 return factory()->NewNumberLiteral(value, pos, has_dot); | 499 return factory()->NewNumberLiteral(value, pos, has_dot); |
500 } | 500 } |
501 default: | 501 default: |
502 DCHECK(false); | 502 DCHECK(false); |
503 } | 503 } |
504 return NULL; | 504 return NULL; |
505 } | 505 } |
506 | 506 |
507 Expression* Parser::GetIterator(Expression* iterable, int pos) { | |
508 Expression* iterator_symbol_literal = | |
509 factory()->NewSymbolLiteral("iterator_symbol", kNoSourcePosition); | |
510 Expression* prop = | |
511 factory()->NewProperty(iterable, iterator_symbol_literal, pos); | |
512 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(0, zone()); | |
513 return factory()->NewCall(prop, args, pos); | |
514 } | |
515 | |
516 void Parser::MarkTailPosition(Expression* expression) { | 507 void Parser::MarkTailPosition(Expression* expression) { |
517 expression->MarkTail(); | 508 expression->MarkTail(); |
518 } | 509 } |
519 | 510 |
520 Expression* Parser::NewV8Intrinsic(const AstRawString* name, | 511 Expression* Parser::NewV8Intrinsic(const AstRawString* name, |
521 ZoneList<Expression*>* args, int pos, | 512 ZoneList<Expression*>* args, int pos, |
522 bool* ok) { | 513 bool* ok) { |
523 if (extension_ != nullptr) { | 514 if (extension_ != nullptr) { |
524 // The extension structures are only accessible while parsing the | 515 // The extension structures are only accessible while parsing the |
525 // very first time, not when reparsing because of lazy compilation. | 516 // very first time, not when reparsing because of lazy compilation. |
(...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2071 | 2062 |
2072 Variable* iterator = NewTemporary(ast_value_factory()->dot_iterator_string()); | 2063 Variable* iterator = NewTemporary(ast_value_factory()->dot_iterator_string()); |
2073 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); | 2064 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); |
2074 Variable* completion = NewTemporary(avfactory->empty_string()); | 2065 Variable* completion = NewTemporary(avfactory->empty_string()); |
2075 | 2066 |
2076 // iterator = iterable[Symbol.iterator]() | 2067 // iterator = iterable[Symbol.iterator]() |
2077 Expression* assign_iterator; | 2068 Expression* assign_iterator; |
2078 { | 2069 { |
2079 assign_iterator = factory()->NewAssignment( | 2070 assign_iterator = factory()->NewAssignment( |
2080 Token::ASSIGN, factory()->NewVariableProxy(iterator), | 2071 Token::ASSIGN, factory()->NewVariableProxy(iterator), |
2081 GetIterator(iterable, iterable->position()), iterable->position()); | 2072 factory()->NewGetIterator(iterable, iterable->position()), |
2073 iterable->position()); | |
2082 } | 2074 } |
2083 | 2075 |
2084 // !%_IsJSReceiver(result = iterator.next()) && | 2076 // !%_IsJSReceiver(result = iterator.next()) && |
2085 // %ThrowIteratorResultNotAnObject(result) | 2077 // %ThrowIteratorResultNotAnObject(result) |
2086 Expression* next_result; | 2078 Expression* next_result; |
2087 { | 2079 { |
2088 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); | 2080 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); |
2089 next_result = | 2081 next_result = |
2090 BuildIteratorNextResult(iterator_proxy, result, next_result_pos); | 2082 BuildIteratorNextResult(iterator_proxy, result, next_result_pos); |
2091 } | 2083 } |
(...skipping 2470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4562 // | 4554 // |
4563 // do { | 4555 // do { |
4564 // const kNext = 0; | 4556 // const kNext = 0; |
4565 // const kReturn = 1; | 4557 // const kReturn = 1; |
4566 // const kThrow = 2; | 4558 // const kThrow = 2; |
4567 // | 4559 // |
4568 // let input = function.sent; | 4560 // let input = function.sent; |
4569 // let mode = kNext; | 4561 // let mode = kNext; |
4570 // let output = undefined; | 4562 // let output = undefined; |
4571 // | 4563 // |
4572 // let iterator = iterable[Symbol.iterator](); | 4564 // let iterator = GetIterator(iterable); |
4573 // if (!IS_RECEIVER(iterator)) throw MakeTypeError(kSymbolIteratorInvalid); | |
4574 // | 4565 // |
4575 // while (true) { | 4566 // while (true) { |
4576 // // From the generator to the iterator: | 4567 // // From the generator to the iterator: |
4577 // // Forward input according to resume mode and obtain output. | 4568 // // Forward input according to resume mode and obtain output. |
4578 // switch (mode) { | 4569 // switch (mode) { |
4579 // case kNext: | 4570 // case kNext: |
4580 // output = iterator.next(input); | 4571 // output = iterator.next(input); |
4581 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); | 4572 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); |
4582 // break; | 4573 // break; |
4583 // case kReturn: | 4574 // case kReturn: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4666 Variable* var_output = NewTemporary(ast_value_factory()->empty_string()); | 4657 Variable* var_output = NewTemporary(ast_value_factory()->empty_string()); |
4667 Statement* initialize_output; | 4658 Statement* initialize_output; |
4668 { | 4659 { |
4669 Expression* output_proxy = factory()->NewVariableProxy(var_output); | 4660 Expression* output_proxy = factory()->NewVariableProxy(var_output); |
4670 Expression* assignment = | 4661 Expression* assignment = |
4671 factory()->NewAssignment(Token::ASSIGN, output_proxy, | 4662 factory()->NewAssignment(Token::ASSIGN, output_proxy, |
4672 factory()->NewUndefinedLiteral(nopos), nopos); | 4663 factory()->NewUndefinedLiteral(nopos), nopos); |
4673 initialize_output = factory()->NewExpressionStatement(assignment, nopos); | 4664 initialize_output = factory()->NewExpressionStatement(assignment, nopos); |
4674 } | 4665 } |
4675 | 4666 |
4676 // let iterator = iterable[Symbol.iterator]; | 4667 // let iterator = iterable[Symbol.iterator]; |
adamk
2016/12/06 18:49:05
Please update this comment to to match the full de
caitp
2016/12/06 19:00:44
Acknowledged.
| |
4677 Variable* var_iterator = NewTemporary(ast_value_factory()->empty_string()); | 4668 Variable* var_iterator = NewTemporary(ast_value_factory()->empty_string()); |
4678 Statement* get_iterator; | 4669 Statement* get_iterator; |
4679 { | 4670 { |
4680 Expression* iterator = GetIterator(iterable, nopos); | 4671 Expression* iterator = factory()->NewGetIterator(iterable, nopos); |
4681 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator); | 4672 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator); |
4682 Expression* assignment = factory()->NewAssignment( | 4673 Expression* assignment = factory()->NewAssignment( |
4683 Token::ASSIGN, iterator_proxy, iterator, nopos); | 4674 Token::ASSIGN, iterator_proxy, iterator, nopos); |
4684 get_iterator = factory()->NewExpressionStatement(assignment, nopos); | 4675 get_iterator = factory()->NewExpressionStatement(assignment, nopos); |
4685 } | 4676 } |
4686 | 4677 |
4687 // if (!IS_RECEIVER(iterator)) throw MakeTypeError(kSymbolIteratorInvalid); | |
4688 Statement* validate_iterator; | |
4689 { | |
4690 Expression* is_receiver_call; | |
4691 { | |
4692 auto args = new (zone()) ZoneList<Expression*>(1, zone()); | |
4693 args->Add(factory()->NewVariableProxy(var_iterator), zone()); | |
4694 is_receiver_call = | |
4695 factory()->NewCallRuntime(Runtime::kInlineIsJSReceiver, args, nopos); | |
4696 } | |
4697 | |
4698 Statement* throw_call; | |
4699 { | |
4700 Expression* call = | |
4701 NewThrowTypeError(MessageTemplate::kSymbolIteratorInvalid, | |
4702 ast_value_factory()->empty_string(), nopos); | |
4703 throw_call = factory()->NewExpressionStatement(call, nopos); | |
4704 } | |
4705 | |
4706 validate_iterator = factory()->NewIfStatement( | |
4707 is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call, | |
4708 nopos); | |
4709 } | |
4710 | |
4711 // output = iterator.next(input); | 4678 // output = iterator.next(input); |
4712 Statement* call_next; | 4679 Statement* call_next; |
4713 { | 4680 { |
4714 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator); | 4681 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator); |
4715 Expression* literal = | 4682 Expression* literal = |
4716 factory()->NewStringLiteral(ast_value_factory()->next_string(), nopos); | 4683 factory()->NewStringLiteral(ast_value_factory()->next_string(), nopos); |
4717 Expression* next_property = | 4684 Expression* next_property = |
4718 factory()->NewProperty(iterator_proxy, literal, nopos); | 4685 factory()->NewProperty(iterator_proxy, literal, nopos); |
4719 Expression* input_proxy = factory()->NewVariableProxy(var_input); | 4686 Expression* input_proxy = factory()->NewVariableProxy(var_input); |
4720 auto args = new (zone()) ZoneList<Expression*>(1, zone()); | 4687 auto args = new (zone()) ZoneList<Expression*>(1, zone()); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5005 | 4972 |
5006 loop->Initialize(factory()->NewBooleanLiteral(true, nopos), loop_body); | 4973 loop->Initialize(factory()->NewBooleanLiteral(true, nopos), loop_body); |
5007 } | 4974 } |
5008 | 4975 |
5009 // do { ... } | 4976 // do { ... } |
5010 DoExpression* yield_star; | 4977 DoExpression* yield_star; |
5011 { | 4978 { |
5012 // The rewriter needs to process the get_value statement only, hence we | 4979 // The rewriter needs to process the get_value statement only, hence we |
5013 // put the preceding statements into an init block. | 4980 // put the preceding statements into an init block. |
5014 | 4981 |
5015 Block* do_block_ = factory()->NewBlock(nullptr, 7, true, nopos); | 4982 Block* do_block_ = factory()->NewBlock(nullptr, 6, true, nopos); |
5016 do_block_->statements()->Add(initialize_input, zone()); | 4983 do_block_->statements()->Add(initialize_input, zone()); |
5017 do_block_->statements()->Add(initialize_mode, zone()); | 4984 do_block_->statements()->Add(initialize_mode, zone()); |
5018 do_block_->statements()->Add(initialize_output, zone()); | 4985 do_block_->statements()->Add(initialize_output, zone()); |
5019 do_block_->statements()->Add(get_iterator, zone()); | 4986 do_block_->statements()->Add(get_iterator, zone()); |
5020 do_block_->statements()->Add(validate_iterator, zone()); | |
5021 do_block_->statements()->Add(loop, zone()); | 4987 do_block_->statements()->Add(loop, zone()); |
5022 do_block_->statements()->Add(maybe_return_value, zone()); | 4988 do_block_->statements()->Add(maybe_return_value, zone()); |
5023 | 4989 |
5024 Block* do_block = factory()->NewBlock(nullptr, 2, false, nopos); | 4990 Block* do_block = factory()->NewBlock(nullptr, 2, false, nopos); |
5025 do_block->statements()->Add(do_block_, zone()); | 4991 do_block->statements()->Add(do_block_, zone()); |
5026 do_block->statements()->Add(get_value, zone()); | 4992 do_block->statements()->Add(get_value, zone()); |
5027 | 4993 |
5028 Variable* dot_result = | 4994 Variable* dot_result = |
5029 NewTemporary(ast_value_factory()->dot_result_string()); | 4995 NewTemporary(ast_value_factory()->dot_result_string()); |
5030 yield_star = factory()->NewDoExpression(do_block, dot_result, nopos); | 4996 yield_star = factory()->NewDoExpression(do_block, dot_result, nopos); |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5476 | 5442 |
5477 return final_loop; | 5443 return final_loop; |
5478 } | 5444 } |
5479 | 5445 |
5480 #undef CHECK_OK | 5446 #undef CHECK_OK |
5481 #undef CHECK_OK_VOID | 5447 #undef CHECK_OK_VOID |
5482 #undef CHECK_FAILED | 5448 #undef CHECK_FAILED |
5483 | 5449 |
5484 } // namespace internal | 5450 } // namespace internal |
5485 } // namespace v8 | 5451 } // namespace v8 |
OLD | NEW |