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-generator.h" | 8 #include "src/interpreter/bytecode-generator.h" |
9 #include "src/interpreter/interpreter.h" | 9 #include "src/interpreter/interpreter.h" |
10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 ba->length())); | 601 ba->length())); |
602 CHECK_EQ(ba->constant_pool()->length(), snippets[i].constant_count); | 602 CHECK_EQ(ba->constant_pool()->length(), snippets[i].constant_count); |
603 for (int j = 0; j < snippets[i].constant_count; j++) { | 603 for (int j = 0; j < snippets[i].constant_count; j++) { |
604 Handle<String> expected = | 604 Handle<String> expected = |
605 helper.factory()->NewStringFromAsciiChecked(snippets[i].constants[j]); | 605 helper.factory()->NewStringFromAsciiChecked(snippets[i].constants[j]); |
606 CHECK(String::cast(ba->constant_pool()->get(j))->Equals(*expected)); | 606 CHECK(String::cast(ba->constant_pool()->get(j))->Equals(*expected)); |
607 } | 607 } |
608 } | 608 } |
609 } | 609 } |
610 | 610 |
611 | |
612 TEST(IfConditions) { | |
613 InitializedHandleScope handle_scope; | |
614 BytecodeGeneratorHelper helper; | |
615 | |
616 ExpectedSnippet<void*> snippets[] = {{ | |
617 "function f(arg1) { if (false) { return 1; } else { return -1; } }", | |
rmcilroy
2015/09/18 10:42:24
nit - remove arg1
oth
2015/09/23 10:46:56
Done.
| |
618 0, | |
619 2, | |
620 11, | |
621 { | |
622 B(LdaFalse), | |
623 B(JumpIfFalseSmi8), U8(7), | |
624 B(LdaSmi8), U8(1), | |
625 B(Return), | |
626 B(JumpSmi8), U8(5), // TODO(oth): Fix implicit return so dead-jump has | |
627 // a valid target. | |
628 B(LdaSmi8), U8(-1), | |
629 B(Return) | |
630 }}, | |
631 { | |
632 "function f(a) { if (a <= 0) { return 200; } else { return -200; } }", | |
633 kPointerSize, | |
634 2, | |
635 17, | |
636 { | |
637 B(Ldar), R(-5), | |
638 B(Star), R(0), | |
639 B(LdaZero), | |
640 B(TestLessThanEqual), R(0), | |
641 B(JumpIfFalseSmi8), U8(7), | |
642 B(LdaConstant), U8(0), | |
643 B(Return), | |
644 B(JumpSmi8), U8(5), // TODO(oth): Fix implicit return so dead-jump has | |
645 // a valid target. | |
646 B(LdaConstant), U8(1), | |
647 B(Return) | |
648 }}, | |
rmcilroy
2015/09/18 10:42:24
could you add some tests for:
- non-bool values (
oth
2015/09/23 10:46:56
Done. There will be more tests to follow as well i
| |
649 }; | |
650 | |
651 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); | |
652 for (size_t i = 0; i < num_snippets; i++) { | |
653 Handle<BytecodeArray> ba = | |
654 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | |
655 ba->Print(); | |
656 CHECK_EQ(ba->frame_size(), snippets[i].frame_size); | |
657 CHECK_EQ(ba->parameter_count(), snippets[i].parameter_count); | |
658 CHECK_EQ(ba->length(), snippets[i].bytecode_length); | |
659 CHECK(!memcmp(ba->GetFirstBytecodeAddress(), snippets[i].bytecode, | |
660 ba->length())); | |
661 } | |
662 } | |
663 | |
664 | |
611 } // namespace interpreter | 665 } // namespace interpreter |
612 } // namespace internal | 666 } // namespace internal |
613 } // namespance v8 | 667 } // namespance v8 |
OLD | NEW |