OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "test/cctest/compiler/function-tester.h" | 7 #include "test/cctest/compiler/function-tester.h" |
8 | 8 |
9 using namespace v8::internal; | 9 using namespace v8::internal; |
10 using namespace v8::internal::compiler; | 10 using namespace v8::internal::compiler; |
(...skipping 25 matching lines...) Expand all Loading... |
36 message = T.CheckThrowsReturnMessage(T.Val(2), T.undefined()); | 36 message = T.CheckThrowsReturnMessage(T.Val(2), T.undefined()); |
37 CHECK(!message.IsEmpty()); | 37 CHECK(!message.IsEmpty()); |
38 CHECK_EQ(3, message->GetLineNumber()); | 38 CHECK_EQ(3, message->GetLineNumber()); |
39 CHECK_EQ(67, message->GetStartPosition()); | 39 CHECK_EQ(67, message->GetStartPosition()); |
40 | 40 |
41 message = T.CheckThrowsReturnMessage(T.Val(3), T.undefined()); | 41 message = T.CheckThrowsReturnMessage(T.Val(3), T.undefined()); |
42 CHECK(!message.IsEmpty()); | 42 CHECK(!message.IsEmpty()); |
43 CHECK_EQ(4, message->GetLineNumber()); | 43 CHECK_EQ(4, message->GetLineNumber()); |
44 CHECK_EQ(95, message->GetStartPosition()); | 44 CHECK_EQ(95, message->GetStartPosition()); |
45 } | 45 } |
| 46 |
| 47 |
| 48 // TODO(mstarzinger): Increase test coverage by having similar tests within the |
| 49 // mjsunit suite to also test integration with other components (e.g. OSR). |
| 50 |
| 51 |
| 52 TEST(Catch) { |
| 53 i::FLAG_turbo_exceptions = true; |
| 54 const char* src = |
| 55 "(function(a,b) {" |
| 56 " var r = '-';" |
| 57 " try {" |
| 58 " r += 'A-';" |
| 59 " throw 'B-';" |
| 60 " } catch (e) {" |
| 61 " r += e;" |
| 62 " }" |
| 63 " return r;" |
| 64 "})"; |
| 65 FunctionTester T(src); |
| 66 |
| 67 T.CheckCall(T.Val("-A-B-")); |
| 68 } |
| 69 |
| 70 |
| 71 TEST(CatchNested) { |
| 72 i::FLAG_turbo_exceptions = true; |
| 73 const char* src = |
| 74 "(function(a,b) {" |
| 75 " var r = '-';" |
| 76 " try {" |
| 77 " r += 'A-';" |
| 78 " throw 'C-';" |
| 79 " } catch (e) {" |
| 80 " try {" |
| 81 " throw 'B-';" |
| 82 " } catch (e) {" |
| 83 " r += e;" |
| 84 " }" |
| 85 " r += e;" |
| 86 " }" |
| 87 " return r;" |
| 88 "})"; |
| 89 FunctionTester T(src); |
| 90 |
| 91 T.CheckCall(T.Val("-A-B-C-")); |
| 92 } |
| 93 |
| 94 |
| 95 TEST(CatchBreak) { |
| 96 i::FLAG_turbo_exceptions = true; |
| 97 const char* src = |
| 98 "(function(a,b) {" |
| 99 " var r = '-';" |
| 100 " L: try {" |
| 101 " r += 'A-';" |
| 102 " if (a) break L;" |
| 103 " r += 'B-';" |
| 104 " throw 'C-';" |
| 105 " } catch (e) {" |
| 106 " if (b) break L;" |
| 107 " r += e;" |
| 108 " }" |
| 109 " r += 'D-';" |
| 110 " return r;" |
| 111 "})"; |
| 112 FunctionTester T(src); |
| 113 |
| 114 T.CheckCall(T.Val("-A-D-"), T.true_value(), T.false_value()); |
| 115 T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value()); |
| 116 T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value()); |
| 117 } |
| 118 |
| 119 |
| 120 TEST(Finally) { |
| 121 i::FLAG_turbo_exceptions = true; |
| 122 const char* src = |
| 123 "(function(a,b) {" |
| 124 " var r = '-';" |
| 125 " try {" |
| 126 " r += 'A-';" |
| 127 " } finally {" |
| 128 " r += 'B-';" |
| 129 " }" |
| 130 " return r;" |
| 131 "})"; |
| 132 FunctionTester T(src); |
| 133 |
| 134 T.CheckCall(T.Val("-A-B-")); |
| 135 } |
| 136 |
| 137 |
| 138 TEST(FinallyBreak) { |
| 139 i::FLAG_turbo_exceptions = true; |
| 140 const char* src = |
| 141 "(function(a,b) {" |
| 142 " var r = '-';" |
| 143 " L: try {" |
| 144 " r += 'A-';" |
| 145 " if (a) return r;" |
| 146 " r += 'B-';" |
| 147 " if (b) break L;" |
| 148 " r += 'C-';" |
| 149 " } finally {" |
| 150 " r += 'D-';" |
| 151 " }" |
| 152 " return r;" |
| 153 "})"; |
| 154 FunctionTester T(src); |
| 155 |
| 156 T.CheckCall(T.Val("-A-"), T.true_value(), T.false_value()); |
| 157 T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value()); |
| 158 T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value()); |
| 159 } |
OLD | NEW |