| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/ast.h" | 7 #include "src/ast.h" |
| 8 #include "src/ast-numbering.h" | 8 #include "src/ast-numbering.h" |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 129 } |
| 130 | 130 |
| 131 | 131 |
| 132 void BreakableStatementChecker::VisitWhileStatement(WhileStatement* stmt) { | 132 void BreakableStatementChecker::VisitWhileStatement(WhileStatement* stmt) { |
| 133 // Mark while statements breakable if the condition expression is. | 133 // Mark while statements breakable if the condition expression is. |
| 134 Visit(stmt->cond()); | 134 Visit(stmt->cond()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 | 137 |
| 138 void BreakableStatementChecker::VisitForStatement(ForStatement* stmt) { | 138 void BreakableStatementChecker::VisitForStatement(ForStatement* stmt) { |
| 139 // We set positions for both init and condition, if they exist. | 139 // Mark for statements breakable if the condition expression is. |
| 140 if (stmt->cond() != NULL || stmt->init() != NULL) is_breakable_ = true; | 140 if (stmt->cond() != NULL) { |
| 141 Visit(stmt->cond()); |
| 142 } |
| 141 } | 143 } |
| 142 | 144 |
| 143 | 145 |
| 144 void BreakableStatementChecker::VisitForInStatement(ForInStatement* stmt) { | 146 void BreakableStatementChecker::VisitForInStatement(ForInStatement* stmt) { |
| 145 // For-in is breakable because we set the position for the enumerable. | 147 // Mark for in statements breakable if the enumerable expression is. |
| 146 is_breakable_ = true; | 148 Visit(stmt->enumerable()); |
| 147 } | 149 } |
| 148 | 150 |
| 149 | 151 |
| 150 void BreakableStatementChecker::VisitForOfStatement(ForOfStatement* stmt) { | 152 void BreakableStatementChecker::VisitForOfStatement(ForOfStatement* stmt) { |
| 151 // For-of is breakable because we set the position for the next() call. | 153 // For-of is breakable because of the next() call. |
| 152 is_breakable_ = true; | 154 is_breakable_ = true; |
| 153 } | 155 } |
| 154 | 156 |
| 155 | 157 |
| 156 void BreakableStatementChecker::VisitTryCatchStatement( | 158 void BreakableStatementChecker::VisitTryCatchStatement( |
| 157 TryCatchStatement* stmt) { | 159 TryCatchStatement* stmt) { |
| 158 // Mark try catch as breakable to avoid adding a break slot in front of it. | 160 // Mark try catch as breakable to avoid adding a break slot in front of it. |
| 159 is_breakable_ = true; | 161 is_breakable_ = true; |
| 160 } | 162 } |
| 161 | 163 |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 void FullCodeGenerator::VisitForStatement(ForStatement* stmt) { | 1338 void FullCodeGenerator::VisitForStatement(ForStatement* stmt) { |
| 1337 Comment cmnt(masm_, "[ ForStatement"); | 1339 Comment cmnt(masm_, "[ ForStatement"); |
| 1338 Label test, body; | 1340 Label test, body; |
| 1339 | 1341 |
| 1340 Iteration loop_statement(this, stmt); | 1342 Iteration loop_statement(this, stmt); |
| 1341 | 1343 |
| 1342 // Set statement position for a break slot before entering the for-body. | 1344 // Set statement position for a break slot before entering the for-body. |
| 1343 SetStatementPosition(stmt); | 1345 SetStatementPosition(stmt); |
| 1344 | 1346 |
| 1345 if (stmt->init() != NULL) { | 1347 if (stmt->init() != NULL) { |
| 1346 SetStatementPosition(stmt->init()); | |
| 1347 Visit(stmt->init()); | 1348 Visit(stmt->init()); |
| 1348 } | 1349 } |
| 1349 | 1350 |
| 1350 increment_loop_depth(); | 1351 increment_loop_depth(); |
| 1351 // Emit the test at the bottom of the loop (even if empty). | 1352 // Emit the test at the bottom of the loop (even if empty). |
| 1352 __ jmp(&test); | 1353 __ jmp(&test); |
| 1353 | 1354 |
| 1354 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); | 1355 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
| 1355 __ bind(&body); | 1356 __ bind(&body); |
| 1356 Visit(stmt->body()); | 1357 Visit(stmt->body()); |
| 1357 | 1358 |
| 1358 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); | 1359 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); |
| 1359 __ bind(loop_statement.continue_label()); | 1360 __ bind(loop_statement.continue_label()); |
| 1360 if (stmt->next() != NULL) { | 1361 if (stmt->next() != NULL) { |
| 1361 SetStatementPosition(stmt->next()); | |
| 1362 Visit(stmt->next()); | 1362 Visit(stmt->next()); |
| 1363 } | 1363 } |
| 1364 | 1364 |
| 1365 // Emit the statement position here as this is where the for | 1365 // Emit the statement position here as this is where the for |
| 1366 // statement code starts. | 1366 // statement code starts. |
| 1367 SetStatementPosition(stmt); | 1367 SetStatementPosition(stmt); |
| 1368 | 1368 |
| 1369 // Check stack before looping. | 1369 // Check stack before looping. |
| 1370 EmitBackEdgeBookkeeping(stmt, &body); | 1370 EmitBackEdgeBookkeeping(stmt, &body); |
| 1371 | 1371 |
| 1372 __ bind(&test); | 1372 __ bind(&test); |
| 1373 if (stmt->cond() != NULL) { | 1373 if (stmt->cond() != NULL) { |
| 1374 SetExpressionPosition(stmt->cond()); | |
| 1375 VisitForControl(stmt->cond(), | 1374 VisitForControl(stmt->cond(), |
| 1376 &body, | 1375 &body, |
| 1377 loop_statement.break_label(), | 1376 loop_statement.break_label(), |
| 1378 loop_statement.break_label()); | 1377 loop_statement.break_label()); |
| 1379 } else { | 1378 } else { |
| 1380 __ jmp(&body); | 1379 __ jmp(&body); |
| 1381 } | 1380 } |
| 1382 | 1381 |
| 1383 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | 1382 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 1384 __ bind(loop_statement.break_label()); | 1383 __ bind(loop_statement.break_label()); |
| 1385 decrement_loop_depth(); | 1384 decrement_loop_depth(); |
| 1386 } | 1385 } |
| 1387 | 1386 |
| 1388 | 1387 |
| 1389 void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { | |
| 1390 Comment cmnt(masm_, "[ ForOfStatement"); | |
| 1391 SetStatementPosition(stmt); | |
| 1392 | |
| 1393 Iteration loop_statement(this, stmt); | |
| 1394 increment_loop_depth(); | |
| 1395 | |
| 1396 // var iterator = iterable[Symbol.iterator](); | |
| 1397 VisitForEffect(stmt->assign_iterator()); | |
| 1398 | |
| 1399 // Loop entry. | |
| 1400 __ bind(loop_statement.continue_label()); | |
| 1401 | |
| 1402 // result = iterator.next() | |
| 1403 SetExpressionPosition(stmt->next_result()); | |
| 1404 VisitForEffect(stmt->next_result()); | |
| 1405 | |
| 1406 // if (result.done) break; | |
| 1407 Label result_not_done; | |
| 1408 VisitForControl(stmt->result_done(), loop_statement.break_label(), | |
| 1409 &result_not_done, &result_not_done); | |
| 1410 __ bind(&result_not_done); | |
| 1411 | |
| 1412 // each = result.value | |
| 1413 VisitForEffect(stmt->assign_each()); | |
| 1414 | |
| 1415 // Generate code for the body of the loop. | |
| 1416 Visit(stmt->body()); | |
| 1417 | |
| 1418 // Check stack before looping. | |
| 1419 PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); | |
| 1420 EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label()); | |
| 1421 __ jmp(loop_statement.continue_label()); | |
| 1422 | |
| 1423 // Exit and decrement the loop depth. | |
| 1424 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | |
| 1425 __ bind(loop_statement.break_label()); | |
| 1426 decrement_loop_depth(); | |
| 1427 } | |
| 1428 | |
| 1429 | |
| 1430 void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { | 1388 void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { |
| 1431 Comment cmnt(masm_, "[ TryCatchStatement"); | 1389 Comment cmnt(masm_, "[ TryCatchStatement"); |
| 1432 SetStatementPosition(stmt); | 1390 SetStatementPosition(stmt); |
| 1433 // The try block adds a handler to the exception handler chain before | 1391 // The try block adds a handler to the exception handler chain before |
| 1434 // entering, and removes it again when exiting normally. If an exception | 1392 // entering, and removes it again when exiting normally. If an exception |
| 1435 // is thrown during execution of the try block, the handler is consumed | 1393 // is thrown during execution of the try block, the handler is consumed |
| 1436 // and control is passed to the catch block with the exception in the | 1394 // and control is passed to the catch block with the exception in the |
| 1437 // result register. | 1395 // result register. |
| 1438 | 1396 |
| 1439 Label try_entry, handler_entry, exit; | 1397 Label try_entry, handler_entry, exit; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1789 } | 1747 } |
| 1790 return true; | 1748 return true; |
| 1791 } | 1749 } |
| 1792 #endif // DEBUG | 1750 #endif // DEBUG |
| 1793 | 1751 |
| 1794 | 1752 |
| 1795 #undef __ | 1753 #undef __ |
| 1796 | 1754 |
| 1797 | 1755 |
| 1798 } } // namespace v8::internal | 1756 } } // namespace v8::internal |
| OLD | NEW |