| 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; |
| 11 | 11 |
| 12 TEST(Throw) { | 12 TEST(Throw) { |
| 13 i::FLAG_turbo_exceptions = true; | 13 i::FLAG_turbo_exceptions = true; |
| 14 FunctionTester T("(function(a,b) { if (a) { throw b; } else { return b; }})"); | 14 FunctionTester T("(function(a,b) { if (a) { throw b; } else { return b; }})"); |
| 15 | 15 |
| 16 // TODO(mstarzinger) | |
| 17 #if 0 | |
| 18 T.CheckThrows(T.true_value(), T.NewObject("new Error")); | 16 T.CheckThrows(T.true_value(), T.NewObject("new Error")); |
| 19 #endif | |
| 20 T.CheckCall(T.Val(23), T.false_value(), T.Val(23)); | 17 T.CheckCall(T.Val(23), T.false_value(), T.Val(23)); |
| 21 } | 18 } |
| 22 | 19 |
| 23 | 20 |
| 24 TEST(ThrowMessagePosition) { | 21 TEST(ThrowMessagePosition) { |
| 25 i::FLAG_turbo_exceptions = true; | 22 i::FLAG_turbo_exceptions = true; |
| 26 static const char* src = | 23 static const char* src = |
| 27 "(function(a, b) { \n" | 24 "(function(a, b) { \n" |
| 28 " if (a == 1) throw 1; \n" | 25 " if (a == 1) throw 1; \n" |
| 29 " if (a == 2) {throw 2} \n" | 26 " if (a == 2) {throw 2} \n" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 | 46 |
| 50 TEST(ThrowMessageDirectly) { | 47 TEST(ThrowMessageDirectly) { |
| 51 i::FLAG_turbo_exceptions = true; | 48 i::FLAG_turbo_exceptions = true; |
| 52 static const char* src = | 49 static const char* src = |
| 53 "(function(a, b) {" | 50 "(function(a, b) {" |
| 54 " if (a) { throw b; } else { throw new Error(b); }" | 51 " if (a) { throw b; } else { throw new Error(b); }" |
| 55 "})"; | 52 "})"; |
| 56 FunctionTester T(src); | 53 FunctionTester T(src); |
| 57 v8::Handle<v8::Message> message; | 54 v8::Handle<v8::Message> message; |
| 58 | 55 |
| 59 // TODO(mstarzinger) | |
| 60 #if 0 | |
| 61 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); | 56 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); |
| 62 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); | 57 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); |
| 63 | 58 |
| 64 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); | 59 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); |
| 65 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); | 60 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); |
| 66 #endif | |
| 67 } | 61 } |
| 68 | 62 |
| 69 | 63 |
| 70 TEST(ThrowMessageIndirectly) { | 64 TEST(ThrowMessageIndirectly) { |
| 71 i::FLAG_turbo_exceptions = true; | 65 i::FLAG_turbo_exceptions = true; |
| 72 static const char* src = | 66 static const char* src = |
| 73 "(function(a, b) {" | 67 "(function(a, b) {" |
| 74 " try {" | 68 " try {" |
| 75 " if (a) { throw b; } else { throw new Error(b); }" | 69 " if (a) { throw b; } else { throw new Error(b); }" |
| 76 " } finally {" | 70 " } finally {" |
| 77 " try { throw 'clobber'; } catch (e) { 'unclobber'; }" | 71 " try { throw 'clobber'; } catch (e) { 'unclobber'; }" |
| 78 " }" | 72 " }" |
| 79 "})"; | 73 "})"; |
| 80 FunctionTester T(src); | 74 FunctionTester T(src); |
| 81 v8::Handle<v8::Message> message; | 75 v8::Handle<v8::Message> message; |
| 82 | 76 |
| 83 // TODO(mstarzinger) | |
| 84 #if 0 | |
| 85 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); | 77 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); |
| 86 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); | 78 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); |
| 87 | 79 |
| 88 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); | 80 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); |
| 89 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); | 81 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); |
| 90 #endif | |
| 91 } | 82 } |
| 92 | 83 |
| 93 | 84 |
| 94 // TODO(mstarzinger): Increase test coverage by having similar tests within the | 85 // TODO(mstarzinger): Increase test coverage by having similar tests within the |
| 95 // mjsunit suite to also test integration with other components (e.g. OSR). | 86 // mjsunit suite to also test integration with other components (e.g. OSR). |
| 96 | 87 |
| 97 | 88 |
| 98 TEST(Catch) { | 89 TEST(Catch) { |
| 99 i::FLAG_turbo_exceptions = true; | 90 i::FLAG_turbo_exceptions = true; |
| 100 const char* src = | 91 const char* src = |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 " } finally {" | 278 " } finally {" |
| 288 " %DeoptimizeFunction(f);" | 279 " %DeoptimizeFunction(f);" |
| 289 " }" | 280 " }" |
| 290 "})"; | 281 "})"; |
| 291 FunctionTester T(src); | 282 FunctionTester T(src); |
| 292 | 283 |
| 293 #if 0 // TODO(mstarzinger): Enable once we can. | 284 #if 0 // TODO(mstarzinger): Enable once we can. |
| 294 T.CheckThrows(T.NewObject("new Error"), T.Val(1)); | 285 T.CheckThrows(T.NewObject("new Error"), T.Val(1)); |
| 295 #endif | 286 #endif |
| 296 } | 287 } |
| OLD | NEW |