OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 if (scope()->is_function_scope() && scope()->function() != NULL) { | 38 if (scope()->is_function_scope() && scope()->function() != NULL) { |
39 VisitVariableDeclaration(scope()->function()); | 39 VisitVariableDeclaration(scope()->function()); |
40 } | 40 } |
41 | 41 |
42 // Visit declarations within the function scope. | 42 // Visit declarations within the function scope. |
43 VisitDeclarations(scope()->declarations()); | 43 VisitDeclarations(scope()->declarations()); |
44 | 44 |
45 // Visit statements in the function body. | 45 // Visit statements in the function body. |
46 VisitStatements(info->literal()->body()); | 46 VisitStatements(info->literal()->body()); |
47 | 47 |
| 48 // If the last bytecode wasn't a return, then return 'undefined' to avoid |
| 49 // falling off the end. |
| 50 if (!builder_.HasExplicitReturn()) { |
| 51 builder_.LoadUndefined(); |
| 52 builder_.Return(); |
| 53 } |
| 54 |
48 set_scope(nullptr); | 55 set_scope(nullptr); |
49 set_info(nullptr); | 56 set_info(nullptr); |
50 return builder_.ToBytecodeArray(); | 57 return builder_.ToBytecodeArray(); |
51 } | 58 } |
52 | 59 |
53 | 60 |
54 void BytecodeGenerator::VisitBlock(Block* node) { | 61 void BytecodeGenerator::VisitBlock(Block* node) { |
55 if (node->scope() == NULL) { | 62 if (node->scope() == NULL) { |
56 // Visit statements in the same scope, no declarations. | 63 // Visit statements in the same scope, no declarations. |
57 VisitStatements(node->statements()); | 64 VisitStatements(node->statements()); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 415 } |
409 | 416 |
410 | 417 |
411 int BytecodeGenerator::feedback_index(FeedbackVectorICSlot slot) const { | 418 int BytecodeGenerator::feedback_index(FeedbackVectorICSlot slot) const { |
412 return info()->feedback_vector()->GetIndex(slot); | 419 return info()->feedback_vector()->GetIndex(slot); |
413 } | 420 } |
414 | 421 |
415 } // namespace interpreter | 422 } // namespace interpreter |
416 } // namespace internal | 423 } // namespace internal |
417 } // namespace v8 | 424 } // namespace v8 |
OLD | NEW |