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 5413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5424 // | 5424 // |
5425 // completion = kNormalCompletion; | 5425 // completion = kNormalCompletion; |
5426 // try { | 5426 // try { |
5427 // try { | 5427 // try { |
5428 // #loop; | 5428 // #loop; |
5429 // } catch(e) { | 5429 // } catch(e) { |
5430 // if (completion === kAbruptCompletion) completion = kThrowCompletion; | 5430 // if (completion === kAbruptCompletion) completion = kThrowCompletion; |
5431 // %ReThrow(e); | 5431 // %ReThrow(e); |
5432 // } | 5432 // } |
5433 // } finally { | 5433 // } finally { |
5434 // if (!(completion === kNormalCompletion || IS_UNDEFINED(#iterator))) { | 5434 // if (!(completion === kNormalCompletion)) { |
neis
2016/11/28 14:52:51
See below.
| |
5435 // #BuildIteratorCloseForCompletion(#iterator, completion) | 5435 // #BuildIteratorCloseForCompletion(#iterator, completion) |
5436 // } | 5436 // } |
5437 // } | 5437 // } |
5438 // | 5438 // |
5439 // Note that the loop's body and its assign_each already contain appropriate | 5439 // Note that the loop's body and its assign_each already contain appropriate |
5440 // assignments to completion (see InitializeForOfStatement). | 5440 // assignments to completion (see InitializeForOfStatement). |
5441 // | 5441 // |
5442 | 5442 |
5443 const int nopos = kNoSourcePosition; | 5443 const int nopos = kNoSourcePosition; |
5444 | 5444 |
5445 // !(completion === kNormalCompletion || IS_UNDEFINED(#iterator)) | 5445 // !(completion === kNormalCompletion) |
5446 Expression* closing_condition; | 5446 Expression* closing_condition; |
5447 { | 5447 { |
5448 Expression* lhs = factory()->NewCompareOperation( | 5448 Expression* cmp = factory()->NewCompareOperation( |
5449 Token::EQ_STRICT, factory()->NewVariableProxy(var_completion), | 5449 Token::EQ_STRICT, factory()->NewVariableProxy(var_completion), |
5450 factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos); | 5450 factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), nopos); |
5451 Expression* rhs = factory()->NewCompareOperation( | 5451 closing_condition = factory()->NewUnaryOperation(Token::NOT, cmp, nopos); |
neis
2016/11/28 14:52:51
You can use NE_STRICT (!==) instead of negating EQ
| |
5452 Token::EQ_STRICT, factory()->NewVariableProxy(loop->iterator()), | |
5453 factory()->NewUndefinedLiteral(nopos), nopos); | |
5454 closing_condition = factory()->NewUnaryOperation( | |
5455 Token::NOT, factory()->NewBinaryOperation(Token::OR, lhs, rhs, nopos), | |
5456 nopos); | |
5457 } | 5452 } |
5458 | 5453 |
5459 Block* final_loop = factory()->NewBlock(nullptr, 2, false, nopos); | 5454 Block* final_loop = factory()->NewBlock(nullptr, 2, false, nopos); |
5460 { | 5455 { |
5461 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); | 5456 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); |
5462 try_block->statements()->Add(loop, zone()); | 5457 try_block->statements()->Add(loop, zone()); |
5463 | 5458 |
5464 // The scope in which the parser creates this loop. | 5459 // The scope in which the parser creates this loop. |
5465 Scope* loop_scope = scope()->outer_scope(); | 5460 Scope* loop_scope = scope()->outer_scope(); |
5466 DCHECK_EQ(loop_scope->scope_type(), BLOCK_SCOPE); | 5461 DCHECK_EQ(loop_scope->scope_type(), BLOCK_SCOPE); |
5467 DCHECK_EQ(scope()->scope_type(), BLOCK_SCOPE); | 5462 DCHECK_EQ(scope()->scope_type(), BLOCK_SCOPE); |
5468 | 5463 |
5469 FinalizeIteratorUse(loop_scope, var_completion, closing_condition, | 5464 FinalizeIteratorUse(loop_scope, var_completion, closing_condition, |
5470 loop->iterator(), try_block, final_loop); | 5465 loop->iterator(), try_block, final_loop); |
5471 } | 5466 } |
5472 | 5467 |
5473 return final_loop; | 5468 return final_loop; |
5474 } | 5469 } |
5475 | 5470 |
5476 #undef CHECK_OK | 5471 #undef CHECK_OK |
5477 #undef CHECK_OK_VOID | 5472 #undef CHECK_OK_VOID |
5478 #undef CHECK_FAILED | 5473 #undef CHECK_FAILED |
5479 | 5474 |
5480 } // namespace internal | 5475 } // namespace internal |
5481 } // namespace v8 | 5476 } // namespace v8 |
OLD | NEW |