OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 CheckUncle(&try_catch); | 1641 CheckUncle(&try_catch); |
1642 } | 1642 } |
1643 | 1643 |
1644 | 1644 |
1645 v8::Handle<Value> ThrowFromC(const v8::Arguments& args) { | 1645 v8::Handle<Value> ThrowFromC(const v8::Arguments& args) { |
1646 ApiTestFuzzer::Fuzz(); | 1646 ApiTestFuzzer::Fuzz(); |
1647 return v8::ThrowException(v8_str("konto")); | 1647 return v8::ThrowException(v8_str("konto")); |
1648 } | 1648 } |
1649 | 1649 |
1650 | 1650 |
| 1651 v8::Handle<Value> CCatcher(const v8::Arguments& args) { |
| 1652 if (args.Length() < 1) return v8::Boolean::New(false); |
| 1653 v8::HandleScope scope; |
| 1654 v8::TryCatch try_catch; |
| 1655 v8::Script::Compile(args[0]->ToString())->Run(); |
| 1656 return v8::Boolean::New(try_catch.HasCaught()); |
| 1657 } |
| 1658 |
| 1659 |
1651 THREADED_TEST(APICatch) { | 1660 THREADED_TEST(APICatch) { |
1652 v8::HandleScope scope; | 1661 v8::HandleScope scope; |
1653 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 1662 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
1654 templ->Set(v8_str("ThrowFromC"), | 1663 templ->Set(v8_str("ThrowFromC"), |
1655 v8::FunctionTemplate::New(ThrowFromC)); | 1664 v8::FunctionTemplate::New(ThrowFromC)); |
1656 LocalContext context(0, templ); | 1665 LocalContext context(0, templ); |
1657 CompileRun( | 1666 CompileRun( |
1658 "var thrown = false;" | 1667 "var thrown = false;" |
1659 "try {" | 1668 "try {" |
1660 " ThrowFromC();" | 1669 " ThrowFromC();" |
(...skipping 10 matching lines...) Expand all Loading... |
1671 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 1680 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
1672 templ->Set(v8_str("ThrowFromC"), | 1681 templ->Set(v8_str("ThrowFromC"), |
1673 v8::FunctionTemplate::New(ThrowFromC)); | 1682 v8::FunctionTemplate::New(ThrowFromC)); |
1674 LocalContext context(0, templ); | 1683 LocalContext context(0, templ); |
1675 v8::TryCatch try_catch; | 1684 v8::TryCatch try_catch; |
1676 CompileRun("ThrowFromC();"); | 1685 CompileRun("ThrowFromC();"); |
1677 CHECK(try_catch.HasCaught()); | 1686 CHECK(try_catch.HasCaught()); |
1678 } | 1687 } |
1679 | 1688 |
1680 | 1689 |
| 1690 // Test that a try-finally block doesn't shadow a try-catch block |
| 1691 // when setting up an external handler. |
| 1692 THREADED_TEST(TryCatchInTryFinally) { |
| 1693 v8::HandleScope scope; |
| 1694 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 1695 templ->Set(v8_str("CCatcher"), |
| 1696 v8::FunctionTemplate::New(CCatcher)); |
| 1697 LocalContext context(0, templ); |
| 1698 Local<Value> result = CompileRun("try {" |
| 1699 " try {" |
| 1700 " CCatcher('throw 7;');" |
| 1701 " } finally {" |
| 1702 " }" |
| 1703 "} catch (e) {" |
| 1704 "}"); |
| 1705 CHECK(result->IsTrue()); |
| 1706 } |
| 1707 |
| 1708 |
1681 static void receive_message(v8::Handle<v8::Message> message, | 1709 static void receive_message(v8::Handle<v8::Message> message, |
1682 v8::Handle<v8::Value> data) { | 1710 v8::Handle<v8::Value> data) { |
1683 message_received = true; | 1711 message_received = true; |
1684 } | 1712 } |
1685 | 1713 |
1686 | 1714 |
1687 TEST(APIThrowMessage) { | 1715 TEST(APIThrowMessage) { |
1688 message_received = false; | 1716 message_received = false; |
1689 v8::HandleScope scope; | 1717 v8::HandleScope scope; |
1690 v8::V8::AddMessageListener(receive_message); | 1718 v8::V8::AddMessageListener(receive_message); |
(...skipping 3742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5433 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); | 5461 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); |
5434 } | 5462 } |
5435 // Test CallIC. | 5463 // Test CallIC. |
5436 for (int i = 0; i < 2; i++) { | 5464 for (int i = 0; i < 2; i++) { |
5437 LocalContext context; | 5465 LocalContext context; |
5438 context->Global()->Set(v8_str("tmp"), v8::True()); | 5466 context->Global()->Set(v8_str("tmp"), v8::True()); |
5439 context->Global()->Delete(v8_str("tmp")); | 5467 context->Global()->Delete(v8_str("tmp")); |
5440 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); | 5468 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); |
5441 } | 5469 } |
5442 } | 5470 } |
OLD | NEW |