| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/mac/call_with_eh_frame.h" | |
| 6 | |
| 7 #import <Foundation/Foundation.h> | |
| 8 | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace base { | |
| 12 namespace mac { | |
| 13 namespace { | |
| 14 | |
| 15 class CallWithEHFrameTest : public testing::Test { | |
| 16 protected: | |
| 17 void ThrowException() { [NSArray arrayWithObject:nil]; } | |
| 18 }; | |
| 19 | |
| 20 // Catching from within the EHFrame is allowed. | |
| 21 TEST_F(CallWithEHFrameTest, CatchExceptionHigher) { | |
| 22 bool __block saw_exception = false; | |
| 23 base::mac::CallWithEHFrame(^{ | |
| 24 @try { | |
| 25 ThrowException(); | |
| 26 } @catch (NSException* exception) { | |
| 27 saw_exception = true; | |
| 28 } | |
| 29 }); | |
| 30 EXPECT_TRUE(saw_exception); | |
| 31 } | |
| 32 | |
| 33 // Trying to catch an exception outside the EHFrame is blocked. | |
| 34 TEST_F(CallWithEHFrameTest, CatchExceptionLower) { | |
| 35 auto catch_exception_lower = ^{ | |
| 36 bool saw_exception = false; | |
| 37 @try { | |
| 38 base::mac::CallWithEHFrame(^{ | |
| 39 ThrowException(); | |
| 40 }); | |
| 41 } @catch (NSException* exception) { | |
| 42 saw_exception = true; | |
| 43 } | |
| 44 ASSERT_FALSE(saw_exception); | |
| 45 }; | |
| 46 EXPECT_DEATH(catch_exception_lower(), ""); | |
| 47 } | |
| 48 | |
| 49 } // namespace | |
| 50 } // namespace mac | |
| 51 } // namespace base | |
| OLD | NEW |