| 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 13 matching lines...) Expand all Loading... |
| 24 "(function(a, b) { \n" | 24 "(function(a, b) { \n" |
| 25 " if (a == 1) throw 1; \n" | 25 " if (a == 1) throw 1; \n" |
| 26 " if (a == 2) {throw 2} \n" | 26 " if (a == 2) {throw 2} \n" |
| 27 " if (a == 3) {0;throw 3}\n" | 27 " if (a == 3) {0;throw 3}\n" |
| 28 " throw 4; \n" | 28 " throw 4; \n" |
| 29 "}) "; | 29 "}) "; |
| 30 FunctionTester T(src); | 30 FunctionTester T(src); |
| 31 v8::Handle<v8::Message> message; | 31 v8::Handle<v8::Message> message; |
| 32 | 32 |
| 33 message = T.CheckThrowsReturnMessage(T.Val(1), T.undefined()); | 33 message = T.CheckThrowsReturnMessage(T.Val(1), T.undefined()); |
| 34 CHECK(!message.IsEmpty()); | |
| 35 CHECK_EQ(2, message->GetLineNumber()); | 34 CHECK_EQ(2, message->GetLineNumber()); |
| 36 CHECK_EQ(40, message->GetStartPosition()); | 35 CHECK_EQ(40, message->GetStartPosition()); |
| 37 | 36 |
| 38 message = T.CheckThrowsReturnMessage(T.Val(2), T.undefined()); | 37 message = T.CheckThrowsReturnMessage(T.Val(2), T.undefined()); |
| 39 CHECK(!message.IsEmpty()); | |
| 40 CHECK_EQ(3, message->GetLineNumber()); | 38 CHECK_EQ(3, message->GetLineNumber()); |
| 41 CHECK_EQ(67, message->GetStartPosition()); | 39 CHECK_EQ(67, message->GetStartPosition()); |
| 42 | 40 |
| 43 message = T.CheckThrowsReturnMessage(T.Val(3), T.undefined()); | 41 message = T.CheckThrowsReturnMessage(T.Val(3), T.undefined()); |
| 44 CHECK(!message.IsEmpty()); | |
| 45 CHECK_EQ(4, message->GetLineNumber()); | 42 CHECK_EQ(4, message->GetLineNumber()); |
| 46 CHECK_EQ(95, message->GetStartPosition()); | 43 CHECK_EQ(95, message->GetStartPosition()); |
| 47 } | 44 } |
| 48 | 45 |
| 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 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); | 56 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); |
| 60 CHECK(!message.IsEmpty()); | |
| 61 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); | 57 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); |
| 62 | 58 |
| 63 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); | 59 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); |
| 64 CHECK(!message.IsEmpty()); | |
| 65 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); | 60 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); |
| 66 } | 61 } |
| 67 | 62 |
| 68 | 63 |
| 69 TEST(ThrowMessageIndirectly) { | 64 TEST(ThrowMessageIndirectly) { |
| 70 i::FLAG_turbo_exceptions = true; | 65 i::FLAG_turbo_exceptions = true; |
| 71 static const char* src = | 66 static const char* src = |
| 72 "(function(a, b) {" | 67 "(function(a, b) {" |
| 73 " try {" | 68 " try {" |
| 74 " if (a) { throw b; } else { throw new Error(b); }" | 69 " if (a) { throw b; } else { throw new Error(b); }" |
| 75 " } finally {" | 70 " } finally {" |
| 76 " try { throw 'clobber'; } catch (e) { 'unclobber'; }" | 71 " try { throw 'clobber'; } catch (e) { 'unclobber'; }" |
| 77 " }" | 72 " }" |
| 78 "})"; | 73 "})"; |
| 79 FunctionTester T(src); | 74 FunctionTester T(src); |
| 80 v8::Handle<v8::Message> message; | 75 v8::Handle<v8::Message> message; |
| 81 | 76 |
| 82 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); | 77 message = T.CheckThrowsReturnMessage(T.false_value(), T.Val("Wat?")); |
| 83 CHECK(!message.IsEmpty()); | |
| 84 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); | 78 CHECK(message->Get()->Equals(v8_str("Uncaught Error: Wat?"))); |
| 85 | 79 |
| 86 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); | 80 message = T.CheckThrowsReturnMessage(T.true_value(), T.Val("Kaboom!")); |
| 87 CHECK(!message.IsEmpty()); | |
| 88 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); | 81 CHECK(message->Get()->Equals(v8_str("Uncaught Kaboom!"))); |
| 89 } | 82 } |
| 90 | 83 |
| 91 | 84 |
| 92 // TODO(mstarzinger): Increase test coverage by having similar tests within the | 85 // TODO(mstarzinger): Increase test coverage by having similar tests within the |
| 93 // 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). |
| 94 | 87 |
| 95 | 88 |
| 96 TEST(Catch) { | 89 TEST(Catch) { |
| 97 i::FLAG_turbo_exceptions = true; | 90 i::FLAG_turbo_exceptions = true; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 " } finally {" | 284 " } finally {" |
| 292 " %DeoptimizeFunction(f);" | 285 " %DeoptimizeFunction(f);" |
| 293 " }" | 286 " }" |
| 294 "})"; | 287 "})"; |
| 295 FunctionTester T(src); | 288 FunctionTester T(src); |
| 296 | 289 |
| 297 #if 0 // TODO(mstarzinger): Enable once we can. | 290 #if 0 // TODO(mstarzinger): Enable once we can. |
| 298 T.CheckThrows(T.NewObject("new Error"), T.Val(1)); | 291 T.CheckThrows(T.NewObject("new Error"), T.Val(1)); |
| 299 #endif | 292 #endif |
| 300 } | 293 } |
| OLD | NEW |