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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); | 53 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); |
54 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); | 54 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); |
55 | 55 |
56 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); | 56 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); |
57 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); | 57 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 TEST(ThrowMessageIndirectly) { | 61 TEST(ThrowMessageIndirectly) { |
62 i::FLAG_turbo_try_catch = true; | |
63 i::FLAG_turbo_try_finally = true; | 62 i::FLAG_turbo_try_finally = true; |
64 static const char* src = | 63 static const char* src = |
65 "(function(a, b) {" | 64 "(function(a, b) {" |
66 " try {" | 65 " try {" |
67 " if (a) { throw b; } else { throw new Error(b); }" | 66 " if (a) { throw b; } else { throw new Error(b); }" |
68 " } finally {" | 67 " } finally {" |
69 " try { throw 'clobber'; } catch (e) { 'unclobber'; }" | 68 " try { throw 'clobber'; } catch (e) { 'unclobber'; }" |
70 " }" | 69 " }" |
71 "})"; | 70 "})"; |
72 FunctionTester T(src); | 71 FunctionTester T(src); |
73 v8::Handle<v8::Message> message; | 72 v8::Handle<v8::Message> message; |
74 | 73 |
75 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); | 74 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); |
76 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); | 75 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); |
77 | 76 |
78 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); | 77 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); |
79 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); | 78 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); |
80 } | 79 } |
81 | 80 |
82 | 81 |
83 TEST(Catch) { | 82 TEST(Catch) { |
84 i::FLAG_turbo_try_catch = true; | |
85 const char* src = | 83 const char* src = |
86 "(function(a,b) {" | 84 "(function(a,b) {" |
87 " var r = '-';" | 85 " var r = '-';" |
88 " try {" | 86 " try {" |
89 " r += 'A-';" | 87 " r += 'A-';" |
90 " throw 'B-';" | 88 " throw 'B-';" |
91 " } catch (e) {" | 89 " } catch (e) {" |
92 " r += e;" | 90 " r += e;" |
93 " }" | 91 " }" |
94 " return r;" | 92 " return r;" |
95 "})"; | 93 "})"; |
96 FunctionTester T(src); | 94 FunctionTester T(src); |
97 | 95 |
98 T.CheckCall(T.Val("-A-B-")); | 96 T.CheckCall(T.Val("-A-B-")); |
99 } | 97 } |
100 | 98 |
101 | 99 |
102 TEST(CatchNested) { | 100 TEST(CatchNested) { |
103 i::FLAG_turbo_try_catch = true; | |
104 const char* src = | 101 const char* src = |
105 "(function(a,b) {" | 102 "(function(a,b) {" |
106 " var r = '-';" | 103 " var r = '-';" |
107 " try {" | 104 " try {" |
108 " r += 'A-';" | 105 " r += 'A-';" |
109 " throw 'C-';" | 106 " throw 'C-';" |
110 " } catch (e) {" | 107 " } catch (e) {" |
111 " try {" | 108 " try {" |
112 " throw 'B-';" | 109 " throw 'B-';" |
113 " } catch (e) {" | 110 " } catch (e) {" |
114 " r += e;" | 111 " r += e;" |
115 " }" | 112 " }" |
116 " r += e;" | 113 " r += e;" |
117 " }" | 114 " }" |
118 " return r;" | 115 " return r;" |
119 "})"; | 116 "})"; |
120 FunctionTester T(src); | 117 FunctionTester T(src); |
121 | 118 |
122 T.CheckCall(T.Val("-A-B-C-")); | 119 T.CheckCall(T.Val("-A-B-C-")); |
123 } | 120 } |
124 | 121 |
125 | 122 |
126 TEST(CatchBreak) { | 123 TEST(CatchBreak) { |
127 i::FLAG_turbo_try_catch = true; | |
128 const char* src = | 124 const char* src = |
129 "(function(a,b) {" | 125 "(function(a,b) {" |
130 " var r = '-';" | 126 " var r = '-';" |
131 " L: try {" | 127 " L: try {" |
132 " r += 'A-';" | 128 " r += 'A-';" |
133 " if (a) break L;" | 129 " if (a) break L;" |
134 " r += 'B-';" | 130 " r += 'B-';" |
135 " throw 'C-';" | 131 " throw 'C-';" |
136 " } catch (e) {" | 132 " } catch (e) {" |
137 " if (b) break L;" | 133 " if (b) break L;" |
138 " r += e;" | 134 " r += e;" |
139 " }" | 135 " }" |
140 " r += 'D-';" | 136 " r += 'D-';" |
141 " return r;" | 137 " return r;" |
142 "})"; | 138 "})"; |
143 FunctionTester T(src); | 139 FunctionTester T(src); |
144 | 140 |
145 T.CheckCall(T.Val("-A-D-"), T.true_value(), T.false_value()); | 141 T.CheckCall(T.Val("-A-D-"), T.true_value(), T.false_value()); |
146 T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value()); | 142 T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value()); |
147 T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value()); | 143 T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value()); |
148 } | 144 } |
149 | 145 |
150 | 146 |
151 TEST(CatchCall) { | 147 TEST(CatchCall) { |
152 i::FLAG_turbo_try_catch = true; | |
153 const char* src = | 148 const char* src = |
154 "(function(fun) {" | 149 "(function(fun) {" |
155 " var r = '-';" | 150 " var r = '-';" |
156 " try {" | 151 " try {" |
157 " r += 'A-';" | 152 " r += 'A-';" |
158 " return r + 'B-' + fun();" | 153 " return r + 'B-' + fun();" |
159 " } catch (e) {" | 154 " } catch (e) {" |
160 " r += e;" | 155 " r += e;" |
161 " }" | 156 " }" |
162 " return r;" | 157 " return r;" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 "})"; | 201 "})"; |
207 FunctionTester T(src); | 202 FunctionTester T(src); |
208 | 203 |
209 T.CheckCall(T.Val("-A-"), T.true_value(), T.false_value()); | 204 T.CheckCall(T.Val("-A-"), T.true_value(), T.false_value()); |
210 T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value()); | 205 T.CheckCall(T.Val("-A-B-D-"), T.false_value(), T.true_value()); |
211 T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value()); | 206 T.CheckCall(T.Val("-A-B-C-D-"), T.false_value(), T.false_value()); |
212 } | 207 } |
213 | 208 |
214 | 209 |
215 TEST(DeoptTry) { | 210 TEST(DeoptTry) { |
216 i::FLAG_turbo_try_catch = true; | |
217 const char* src = | 211 const char* src = |
218 "(function f(a) {" | 212 "(function f(a) {" |
219 " try {" | 213 " try {" |
220 " %DeoptimizeFunction(f);" | 214 " %DeoptimizeFunction(f);" |
221 " throw a;" | 215 " throw a;" |
222 " } catch (e) {" | 216 " } catch (e) {" |
223 " return e + 1;" | 217 " return e + 1;" |
224 " }" | 218 " }" |
225 "})"; | 219 "})"; |
226 FunctionTester T(src); | 220 FunctionTester T(src); |
227 | 221 |
228 T.CheckCall(T.Val(2), T.Val(1)); | 222 T.CheckCall(T.Val(2), T.Val(1)); |
229 } | 223 } |
230 | 224 |
231 | 225 |
232 TEST(DeoptCatch) { | 226 TEST(DeoptCatch) { |
233 i::FLAG_turbo_try_catch = true; | |
234 const char* src = | 227 const char* src = |
235 "(function f(a) {" | 228 "(function f(a) {" |
236 " try {" | 229 " try {" |
237 " throw a;" | 230 " throw a;" |
238 " } catch (e) {" | 231 " } catch (e) {" |
239 " %DeoptimizeFunction(f);" | 232 " %DeoptimizeFunction(f);" |
240 " return e + 1;" | 233 " return e + 1;" |
241 " }" | 234 " }" |
242 "})"; | 235 "})"; |
243 FunctionTester T(src); | 236 FunctionTester T(src); |
(...skipping 28 matching lines...) Expand all Loading... |
272 " } finally {" | 265 " } finally {" |
273 " %DeoptimizeFunction(f);" | 266 " %DeoptimizeFunction(f);" |
274 " }" | 267 " }" |
275 "})"; | 268 "})"; |
276 FunctionTester T(src); | 269 FunctionTester T(src); |
277 | 270 |
278 #if 0 // TODO(mstarzinger): Enable once we can. | 271 #if 0 // TODO(mstarzinger): Enable once we can. |
279 T.CheckThrows(T.NewObject("new Error"), T.Val(1)); | 272 T.CheckThrows(T.NewObject("new Error"), T.Val(1)); |
280 #endif | 273 #endif |
281 } | 274 } |
OLD | NEW |