OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 #import "base/mac/scoped_nsexception_enabler.h" | 5 #import "base/mac/scoped_nsexception_enabler.h" |
6 | 6 |
7 #import "base/lazy_instance.h" | 7 #import "base/lazy_instance.h" |
8 #import "base/threading/thread_local.h" | 8 #import "base/threading/thread_local.h" |
9 | 9 |
10 // To make the |g_exceptionsAllowed| declaration readable. | 10 // To make the |g_exceptionsAllowed| declaration readable. |
11 using base::LazyInstance; | 11 using base::LazyInstance; |
12 using base::LeakyLazyInstanceTraits; | |
13 using base::ThreadLocalBoolean; | 12 using base::ThreadLocalBoolean; |
14 | 13 |
15 // When C++ exceptions are disabled, the C++ library defines |try| and | 14 // When C++ exceptions are disabled, the C++ library defines |try| and |
16 // |catch| so as to allow exception-expecting C++ code to build properly when | 15 // |catch| so as to allow exception-expecting C++ code to build properly when |
17 // language support for exceptions is not present. These macros interfere | 16 // language support for exceptions is not present. These macros interfere |
18 // with the use of |@try| and |@catch| in Objective-C files such as this one. | 17 // with the use of |@try| and |@catch| in Objective-C files such as this one. |
19 // Undefine these macros here, after everything has been #included, since | 18 // Undefine these macros here, after everything has been #included, since |
20 // there will be no C++ uses and only Objective-C uses from this point on. | 19 // there will be no C++ uses and only Objective-C uses from this point on. |
21 #undef try | 20 #undef try |
22 #undef catch | 21 #undef catch |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 // Whether to allow NSExceptions to be raised on the current thread. | 25 // Whether to allow NSExceptions to be raised on the current thread. |
27 LazyInstance<ThreadLocalBoolean, LeakyLazyInstanceTraits<ThreadLocalBoolean> > | 26 LazyInstance<ThreadLocalBoolean>::Leaky |
28 g_exceptionsAllowed = LAZY_INSTANCE_INITIALIZER; | 27 g_exceptionsAllowed = LAZY_INSTANCE_INITIALIZER; |
29 | 28 |
30 } // namespace | 29 } // namespace |
31 | 30 |
32 namespace base { | 31 namespace base { |
33 namespace mac { | 32 namespace mac { |
34 | 33 |
35 bool GetNSExceptionsAllowed() { | 34 bool GetNSExceptionsAllowed() { |
36 return g_exceptionsAllowed.Get().Get(); | 35 return g_exceptionsAllowed.Get().Get(); |
37 } | 36 } |
(...skipping 17 matching lines...) Expand all Loading... |
55 was_enabled_ = GetNSExceptionsAllowed(); | 54 was_enabled_ = GetNSExceptionsAllowed(); |
56 SetNSExceptionsAllowed(true); | 55 SetNSExceptionsAllowed(true); |
57 } | 56 } |
58 | 57 |
59 ScopedNSExceptionEnabler::~ScopedNSExceptionEnabler() { | 58 ScopedNSExceptionEnabler::~ScopedNSExceptionEnabler() { |
60 SetNSExceptionsAllowed(was_enabled_); | 59 SetNSExceptionsAllowed(was_enabled_); |
61 } | 60 } |
62 | 61 |
63 } // namespace mac | 62 } // namespace mac |
64 } // namespace base | 63 } // namespace base |
OLD | NEW |