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/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 3474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3485 {"a"}}, | 3485 {"a"}}, |
3486 }; | 3486 }; |
3487 | 3487 |
3488 for (size_t i = 0; i < arraysize(snippets); i++) { | 3488 for (size_t i = 0; i < arraysize(snippets); i++) { |
3489 Handle<BytecodeArray> bytecode_array = | 3489 Handle<BytecodeArray> bytecode_array = |
3490 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 3490 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
3491 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3491 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
3492 } | 3492 } |
3493 } | 3493 } |
3494 | 3494 |
| 3495 |
| 3496 TEST(Conditional) { |
| 3497 InitializedHandleScope handle_scope; |
| 3498 BytecodeGeneratorHelper helper; |
| 3499 |
| 3500 ExpectedSnippet<int> snippets[] = { |
| 3501 {"return 1 ? 2 : 3;", |
| 3502 0, |
| 3503 1, |
| 3504 12, |
| 3505 { |
| 3506 B(LdaSmi8), U8(1), // |
| 3507 B(ToBoolean), // |
| 3508 B(JumpIfFalse), U8(6), // |
| 3509 B(LdaSmi8), U8(2), // |
| 3510 B(Jump), U8(4), // |
| 3511 B(LdaSmi8), U8(3), // |
| 3512 B(Return), // |
| 3513 }}, |
| 3514 {"return 1 ? 2 ? 3 : 4 : 5;", |
| 3515 0, |
| 3516 1, |
| 3517 21, |
| 3518 { |
| 3519 B(LdaSmi8), U8(1), // |
| 3520 B(ToBoolean), // |
| 3521 B(JumpIfFalse), U8(15), // |
| 3522 B(LdaSmi8), U8(2), // |
| 3523 B(ToBoolean), // |
| 3524 B(JumpIfFalse), U8(6), // |
| 3525 B(LdaSmi8), U8(3), // |
| 3526 B(Jump), U8(4), // |
| 3527 B(LdaSmi8), U8(4), // |
| 3528 B(Jump), U8(4), // |
| 3529 B(LdaSmi8), U8(5), // |
| 3530 B(Return), // |
| 3531 }}, |
| 3532 }; |
| 3533 |
| 3534 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 3535 Handle<BytecodeArray> bytecode_array = |
| 3536 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 3537 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 3538 } |
| 3539 } |
| 3540 |
3495 } // namespace interpreter | 3541 } // namespace interpreter |
3496 } // namespace internal | 3542 } // namespace internal |
3497 } // namespace v8 | 3543 } // namespace v8 |
OLD | NEW |