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 2670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2681 }; | 2681 }; |
2682 | 2682 |
2683 for (size_t i = 0; i < arraysize(snippets); i++) { | 2683 for (size_t i = 0; i < arraysize(snippets); i++) { |
2684 Handle<BytecodeArray> bytecode_array = | 2684 Handle<BytecodeArray> bytecode_array = |
2685 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 2685 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
2686 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 2686 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2687 } | 2687 } |
2688 } | 2688 } |
2689 | 2689 |
2690 | 2690 |
| 2691 TEST(Throw) { |
| 2692 InitializedHandleScope handle_scope; |
| 2693 BytecodeGeneratorHelper helper; |
| 2694 |
| 2695 // TODO(rmcilroy): modify tests when we have real try catch support. |
| 2696 ExpectedSnippet<const char*> snippets[] = { |
| 2697 {"throw 1;", |
| 2698 0, |
| 2699 1, |
| 2700 3, |
| 2701 { |
| 2702 B(LdaSmi8), U8(1), // |
| 2703 B(Throw), // |
| 2704 }, |
| 2705 0}, |
| 2706 {"throw 'Error';", |
| 2707 0, |
| 2708 1, |
| 2709 3, |
| 2710 { |
| 2711 B(LdaConstant), U8(0), // |
| 2712 B(Throw), // |
| 2713 }, |
| 2714 1, |
| 2715 {"Error"}}, |
| 2716 {"if ('test') { throw 'Error'; };", |
| 2717 0, |
| 2718 1, |
| 2719 10, |
| 2720 { |
| 2721 B(LdaConstant), U8(0), // |
| 2722 B(ToBoolean), // |
| 2723 B(JumpIfFalse), U8(5), // |
| 2724 B(LdaConstant), U8(1), // |
| 2725 B(Throw), // |
| 2726 B(LdaUndefined), // |
| 2727 B(Return), // |
| 2728 }, |
| 2729 2, |
| 2730 {"test", "Error"}}, |
| 2731 }; |
| 2732 |
| 2733 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 2734 Handle<BytecodeArray> bytecode_array = |
| 2735 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 2736 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 2737 } |
| 2738 } |
| 2739 |
| 2740 |
2691 TEST(CallNew) { | 2741 TEST(CallNew) { |
2692 InitializedHandleScope handle_scope; | 2742 InitializedHandleScope handle_scope; |
2693 BytecodeGeneratorHelper helper; | 2743 BytecodeGeneratorHelper helper; |
2694 | 2744 |
2695 ExpectedSnippet<InstanceType> snippets[] = { | 2745 ExpectedSnippet<InstanceType> snippets[] = { |
2696 {"function bar() { this.value = 0; }\n" | 2746 {"function bar() { this.value = 0; }\n" |
2697 "function f() { return new bar(); }\n" | 2747 "function f() { return new bar(); }\n" |
2698 "f()", | 2748 "f()", |
2699 kPointerSize, | 2749 kPointerSize, |
2700 1, | 2750 1, |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2954 for (size_t i = 0; i < arraysize(snippets); i++) { | 3004 for (size_t i = 0; i < arraysize(snippets); i++) { |
2955 Handle<BytecodeArray> bytecode_array = | 3005 Handle<BytecodeArray> bytecode_array = |
2956 helper.MakeBytecodeForFunction(snippets[i].code_snippet); | 3006 helper.MakeBytecodeForFunction(snippets[i].code_snippet); |
2957 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 3007 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
2958 } | 3008 } |
2959 } | 3009 } |
2960 | 3010 |
2961 } // namespace interpreter | 3011 } // namespace interpreter |
2962 } // namespace internal | 3012 } // namespace internal |
2963 } // namespace v8 | 3013 } // namespace v8 |
OLD | NEW |