| 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 4609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4620 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4620 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4621 } | 4621 } |
| 4622 } | 4622 } |
| 4623 | 4623 |
| 4624 | 4624 |
| 4625 TEST(TryCatch) { | 4625 TEST(TryCatch) { |
| 4626 InitializedHandleScope handle_scope; | 4626 InitializedHandleScope handle_scope; |
| 4627 BytecodeGeneratorHelper helper; | 4627 BytecodeGeneratorHelper helper; |
| 4628 | 4628 |
| 4629 int closure = Register::function_closure().index(); | 4629 int closure = Register::function_closure().index(); |
| 4630 int context = Register::current_context().index(); |
| 4630 | 4631 |
| 4631 // clang-format off | 4632 // clang-format off |
| 4632 ExpectedSnippet<const char*> snippets[] = { | 4633 ExpectedSnippet<const char*> snippets[] = { |
| 4633 {"try { return 1; } catch(e) { return 2; }", | 4634 {"try { return 1; } catch(e) { return 2; }", |
| 4634 5 * kPointerSize, | 4635 5 * kPointerSize, |
| 4635 1, | 4636 1, |
| 4636 37, | 4637 40, |
| 4637 { | 4638 { |
| 4638 B(StackCheck), // | 4639 B(StackCheck), // |
| 4640 B(Mov), R(context), R(1), // |
| 4639 B(LdaSmi8), U8(1), // | 4641 B(LdaSmi8), U8(1), // |
| 4640 B(Return), // | 4642 B(Return), // |
| 4641 B(Star), R(3), // | 4643 B(Star), R(3), // |
| 4642 B(LdaConstant), U8(0), // | 4644 B(LdaConstant), U8(0), // |
| 4643 B(Star), R(2), // | 4645 B(Star), R(2), // |
| 4644 B(Ldar), R(closure), // | 4646 B(Ldar), R(closure), // |
| 4645 B(Star), R(4), // | 4647 B(Star), R(4), // |
| 4646 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // | 4648 B(CallRuntime), U16(Runtime::kPushCatchContext), R(2), U8(3), // |
| 4647 B(Star), R(1), // | 4649 B(Star), R(1), // |
| 4648 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4650 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4649 /* */ R(0), U8(0), // | 4651 /* */ R(0), U8(0), // |
| 4650 B(Ldar), R(1), // | 4652 B(Ldar), R(1), // |
| 4651 B(PushContext), R(0), // | 4653 B(PushContext), R(0), // |
| 4652 B(LdaSmi8), U8(2), // | 4654 B(LdaSmi8), U8(2), // |
| 4653 B(PopContext), R(0), // | 4655 B(PopContext), R(0), // |
| 4654 B(Return), // | 4656 B(Return), // |
| 4655 // TODO(mstarzinger): Potential optimization, elide next bytes. | 4657 // TODO(mstarzinger): Potential optimization, elide next bytes. |
| 4656 B(LdaUndefined), // | 4658 B(LdaUndefined), // |
| 4657 B(Return), // | 4659 B(Return), // |
| 4658 }, | 4660 }, |
| 4659 1, | 4661 1, |
| 4660 {"e"}, | 4662 {"e"}, |
| 4661 1, | 4663 1, |
| 4662 {{1, 4, 4}}}, | 4664 {{4, 7, 7}}}, |
| 4663 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", | 4665 {"var a; try { a = 1 } catch(e1) {}; try { a = 2 } catch(e2) { a = 3 }", |
| 4664 6 * kPointerSize, | 4666 6 * kPointerSize, |
| 4665 1, | 4667 1, |
| 4666 75, | 4668 81, |
| 4667 { | 4669 { |
| 4668 B(StackCheck), // | 4670 B(StackCheck), // |
| 4671 B(Mov), R(context), R(2), // |
| 4669 B(LdaSmi8), U8(1), // | 4672 B(LdaSmi8), U8(1), // |
| 4670 B(Star), R(0), // | 4673 B(Star), R(0), // |
| 4671 B(Jump), U8(30), // | 4674 B(Jump), U8(30), // |
| 4672 B(Star), R(4), // | 4675 B(Star), R(4), // |
| 4673 B(LdaConstant), U8(0), // | 4676 B(LdaConstant), U8(0), // |
| 4674 B(Star), R(3), // | 4677 B(Star), R(3), // |
| 4675 B(Ldar), R(closure), // | 4678 B(Ldar), R(closure), // |
| 4676 B(Star), R(5), // | 4679 B(Star), R(5), // |
| 4677 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // | 4680 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // |
| 4678 B(Star), R(2), // | 4681 B(Star), R(2), // |
| 4679 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4682 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4680 /* */ R(0), U8(0), // | 4683 /* */ R(0), U8(0), // |
| 4681 B(Ldar), R(2), // | 4684 B(Ldar), R(2), // |
| 4682 B(PushContext), R(1), // | 4685 B(PushContext), R(1), // |
| 4683 B(PopContext), R(1), // | 4686 B(PopContext), R(1), // |
| 4687 B(Mov), R(context), R(2), // |
| 4684 B(LdaSmi8), U8(2), // | 4688 B(LdaSmi8), U8(2), // |
| 4685 B(Star), R(0), // | 4689 B(Star), R(0), // |
| 4686 B(Jump), U8(34), // | 4690 B(Jump), U8(34), // |
| 4687 B(Star), R(4), // | 4691 B(Star), R(4), // |
| 4688 B(LdaConstant), U8(1), // | 4692 B(LdaConstant), U8(1), // |
| 4689 B(Star), R(3), // | 4693 B(Star), R(3), // |
| 4690 B(Ldar), R(closure), // | 4694 B(Ldar), R(closure), // |
| 4691 B(Star), R(5), // | 4695 B(Star), R(5), // |
| 4692 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // | 4696 B(CallRuntime), U16(Runtime::kPushCatchContext), R(3), U8(3), // |
| 4693 B(Star), R(2), // | 4697 B(Star), R(2), // |
| 4694 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4698 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4695 /* */ R(0), U8(0), // | 4699 /* */ R(0), U8(0), // |
| 4696 B(Ldar), R(2), // | 4700 B(Ldar), R(2), // |
| 4697 B(PushContext), R(1), // | 4701 B(PushContext), R(1), // |
| 4698 B(LdaSmi8), U8(3), // | 4702 B(LdaSmi8), U8(3), // |
| 4699 B(Star), R(0), // | 4703 B(Star), R(0), // |
| 4700 B(PopContext), R(1), // | 4704 B(PopContext), R(1), // |
| 4701 B(LdaUndefined), // | 4705 B(LdaUndefined), // |
| 4702 B(Return), // | 4706 B(Return), // |
| 4703 }, | 4707 }, |
| 4704 2, | 4708 2, |
| 4705 {"e1", "e2"}, | 4709 {"e1", "e2"}, |
| 4706 2, | 4710 2, |
| 4707 {{1, 5, 7}, {35, 39, 41}}}, | 4711 {{4, 8, 10}, {41, 45, 47}}}, |
| 4708 }; | 4712 }; |
| 4709 // clang-format on | 4713 // clang-format on |
| 4710 | 4714 |
| 4711 for (size_t i = 0; i < arraysize(snippets); i++) { | 4715 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4712 Handle<BytecodeArray> bytecode_array = | 4716 Handle<BytecodeArray> bytecode_array = |
| 4713 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4717 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4714 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4718 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4715 } | 4719 } |
| 4716 } | 4720 } |
| 4717 | 4721 |
| 4718 | 4722 |
| 4719 TEST(TryFinally) { | 4723 TEST(TryFinally) { |
| 4720 InitializedHandleScope handle_scope; | 4724 InitializedHandleScope handle_scope; |
| 4721 BytecodeGeneratorHelper helper; | 4725 BytecodeGeneratorHelper helper; |
| 4722 | 4726 |
| 4723 int closure = Register::function_closure().index(); | 4727 int closure = Register::function_closure().index(); |
| 4728 int context = Register::current_context().index(); |
| 4724 | 4729 |
| 4725 // clang-format off | 4730 // clang-format off |
| 4726 ExpectedSnippet<const char*> snippets[] = { | 4731 ExpectedSnippet<const char*> snippets[] = { |
| 4727 {"var a = 1; try { a = 2; } finally { a = 3; }", | 4732 {"var a = 1; try { a = 2; } finally { a = 3; }", |
| 4728 4 * kPointerSize, | 4733 4 * kPointerSize, |
| 4729 1, | 4734 1, |
| 4730 48, | 4735 51, |
| 4731 { | 4736 { |
| 4732 B(StackCheck), // | 4737 B(StackCheck), // |
| 4733 B(LdaSmi8), U8(1), // | 4738 B(LdaSmi8), U8(1), // |
| 4734 B(Star), R(0), // | 4739 B(Star), R(0), // |
| 4740 B(Mov), R(context), R(3), // |
| 4735 B(LdaSmi8), U8(2), // | 4741 B(LdaSmi8), U8(2), // |
| 4736 B(Star), R(0), // | 4742 B(Star), R(0), // |
| 4737 B(LdaSmi8), U8(-1), // | 4743 B(LdaSmi8), U8(-1), // |
| 4738 B(Star), R(1), // | 4744 B(Star), R(1), // |
| 4739 B(Jump), U8(7), // | 4745 B(Jump), U8(7), // |
| 4740 B(Star), R(2), // | 4746 B(Star), R(2), // |
| 4741 B(LdaZero), // | 4747 B(LdaZero), // |
| 4742 B(Star), R(1), // | 4748 B(Star), R(1), // |
| 4743 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // | 4749 B(CallRuntime), U16(Runtime::kInterpreterClearPendingMessage), // |
| 4744 /* */ R(0), U8(0), // | 4750 /* */ R(0), U8(0), // |
| 4745 B(Star), R(3), // | 4751 B(Star), R(3), // |
| 4746 B(LdaSmi8), U8(3), // | 4752 B(LdaSmi8), U8(3), // |
| 4747 B(Star), R(0), // | 4753 B(Star), R(0), // |
| 4748 B(CallRuntime), U16(Runtime::kInterpreterSetPendingMessage), // | 4754 B(CallRuntime), U16(Runtime::kInterpreterSetPendingMessage), // |
| 4749 /* */ R(3), U8(1), // | 4755 /* */ R(3), U8(1), // |
| 4750 B(LdaZero), // | 4756 B(LdaZero), // |
| 4751 B(TestEqualStrict), R(1), // | 4757 B(TestEqualStrict), R(1), // |
| 4752 B(JumpIfTrue), U8(4), // | 4758 B(JumpIfTrue), U8(4), // |
| 4753 B(Jump), U8(5), // | 4759 B(Jump), U8(5), // |
| 4754 B(Ldar), R(2), // | 4760 B(Ldar), R(2), // |
| 4755 B(ReThrow), // | 4761 B(ReThrow), // |
| 4756 B(LdaUndefined), // | 4762 B(LdaUndefined), // |
| 4757 B(Return), // | 4763 B(Return), // |
| 4758 }, | 4764 }, |
| 4759 0, | 4765 0, |
| 4760 {}, | 4766 {}, |
| 4761 1, | 4767 1, |
| 4762 {{5, 9, 15}}}, | 4768 {{8, 12, 18}}}, |
| 4763 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", | 4769 {"var a = 1; try { a = 2; } catch(e) { a = 20 } finally { a = 3; }", |
| 4764 9 * kPointerSize, | 4770 9 * kPointerSize, |
| 4765 1, | 4771 1, |
| 4766 82, | 4772 88, |
| 4767 { | 4773 { |
| 4768 B(StackCheck), // | 4774 B(StackCheck), // |
| 4769 B(LdaSmi8), U8(1), // | 4775 B(LdaSmi8), U8(1), // |
| 4770 B(Star), R(0), // | 4776 B(Star), R(0), // |
| 4777 B(Mov), R(context), R(4), // |
| 4778 B(Mov), R(context), R(5), // |
| 4771 B(LdaSmi8), U8(2), // | 4779 B(LdaSmi8), U8(2), // |
| 4772 B(Star), R(0), // | 4780 B(Star), R(0), // |
| 4773 B(Jump), U8(34), // | 4781 B(Jump), U8(34), // |
| 4774 B(Star), R(7), // | 4782 B(Star), R(7), // |
| 4775 B(LdaConstant), U8(0), // | 4783 B(LdaConstant), U8(0), // |
| 4776 B(Star), R(6), // | 4784 B(Star), R(6), // |
| 4777 B(Ldar), R(closure), // | 4785 B(Ldar), R(closure), // |
| 4778 B(Star), R(8), // | 4786 B(Star), R(8), // |
| 4779 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // | 4787 B(CallRuntime), U16(Runtime::kPushCatchContext), R(6), U8(3), // |
| 4780 B(Star), R(5), // | 4788 B(Star), R(5), // |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4803 B(JumpIfTrue), U8(4), // | 4811 B(JumpIfTrue), U8(4), // |
| 4804 B(Jump), U8(5), // | 4812 B(Jump), U8(5), // |
| 4805 B(Ldar), R(3), // | 4813 B(Ldar), R(3), // |
| 4806 B(ReThrow), // | 4814 B(ReThrow), // |
| 4807 B(LdaUndefined), // | 4815 B(LdaUndefined), // |
| 4808 B(Return), // | 4816 B(Return), // |
| 4809 }, | 4817 }, |
| 4810 1, | 4818 1, |
| 4811 {"e"}, | 4819 {"e"}, |
| 4812 2, | 4820 2, |
| 4813 {{5, 43, 49}, {5, 9, 11}}}, | 4821 {{8, 49, 55}, {11, 15, 17}}}, |
| 4814 {"var a; try {" | 4822 {"var a; try {" |
| 4815 " try { a = 1 } catch(e) { a = 2 }" | 4823 " try { a = 1 } catch(e) { a = 2 }" |
| 4816 "} catch(e) { a = 20 } finally { a = 3; }", | 4824 "} catch(e) { a = 20 } finally { a = 3; }", |
| 4817 10 * kPointerSize, | 4825 10 * kPointerSize, |
| 4818 1, | 4826 1, |
| 4819 112, | 4827 121, |
| 4820 { | 4828 { |
| 4821 B(StackCheck), // | 4829 B(StackCheck), // |
| 4830 B(Mov), R(context), R(4), // |
| 4831 B(Mov), R(context), R(5), // |
| 4832 B(Mov), R(context), R(6), // |
| 4822 B(LdaSmi8), U8(1), // | 4833 B(LdaSmi8), U8(1), // |
| 4823 B(Star), R(0), // | 4834 B(Star), R(0), // |
| 4824 B(Jump), U8(34), // | 4835 B(Jump), U8(34), // |
| 4825 B(Star), R(8), // | 4836 B(Star), R(8), // |
| 4826 B(LdaConstant), U8(0), // | 4837 B(LdaConstant), U8(0), // |
| 4827 B(Star), R(7), // | 4838 B(Star), R(7), // |
| 4828 B(Ldar), R(closure), // | 4839 B(Ldar), R(closure), // |
| 4829 B(Star), R(9), // | 4840 B(Star), R(9), // |
| 4830 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // | 4841 B(CallRuntime), U16(Runtime::kPushCatchContext), R(7), U8(3), // |
| 4831 B(Star), R(6), // | 4842 B(Star), R(6), // |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4869 B(JumpIfTrue), U8(4), // | 4880 B(JumpIfTrue), U8(4), // |
| 4870 B(Jump), U8(5), // | 4881 B(Jump), U8(5), // |
| 4871 B(Ldar), R(3), // | 4882 B(Ldar), R(3), // |
| 4872 B(ReThrow), // | 4883 B(ReThrow), // |
| 4873 B(LdaUndefined), // | 4884 B(LdaUndefined), // |
| 4874 B(Return), // | 4885 B(Return), // |
| 4875 }, | 4886 }, |
| 4876 1, | 4887 1, |
| 4877 {"e"}, | 4888 {"e"}, |
| 4878 3, | 4889 3, |
| 4879 {{1, 73, 79}, {1, 39, 41}, {1, 5, 7}}}, | 4890 {{4, 82, 88}, {7, 48, 50}, {10, 14, 16}}}, |
| 4880 }; | 4891 }; |
| 4881 // clang-format on | 4892 // clang-format on |
| 4882 | 4893 |
| 4883 for (size_t i = 0; i < arraysize(snippets); i++) { | 4894 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4884 Handle<BytecodeArray> bytecode_array = | 4895 Handle<BytecodeArray> bytecode_array = |
| 4885 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4896 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4886 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4897 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4887 } | 4898 } |
| 4888 } | 4899 } |
| 4889 | 4900 |
| (...skipping 3447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8337 for (size_t i = 0; i < arraysize(snippets); i++) { | 8348 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 8338 Handle<BytecodeArray> bytecode_array = | 8349 Handle<BytecodeArray> bytecode_array = |
| 8339 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 8350 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 8340 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 8351 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 8341 } | 8352 } |
| 8342 } | 8353 } |
| 8343 | 8354 |
| 8344 } // namespace interpreter | 8355 } // namespace interpreter |
| 8345 } // namespace internal | 8356 } // namespace internal |
| 8346 } // namespace v8 | 8357 } // namespace v8 |
| OLD | NEW |