OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef ScriptForbiddenScope_h | 5 #ifndef ScriptForbiddenScope_h |
6 #define ScriptForbiddenScope_h | 6 #define ScriptForbiddenScope_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
10 #include "wtf/AutoReset.h" | 10 #include "wtf/AutoReset.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 private: | 38 private: |
39 Optional<AutoReset<unsigned>> m_change; | 39 Optional<AutoReset<unsigned>> m_change; |
40 }; | 40 }; |
41 | 41 |
42 static void enter() { | 42 static void enter() { |
43 DCHECK(isMainThread()); | 43 DCHECK(isMainThread()); |
44 ++s_scriptForbiddenCount; | 44 ++s_scriptForbiddenCount; |
45 } | 45 } |
46 static void exit() { | 46 static void exit() { |
47 DCHECK(isMainThread()); | |
48 DCHECK(s_scriptForbiddenCount); | 47 DCHECK(s_scriptForbiddenCount); |
49 --s_scriptForbiddenCount; | 48 --s_scriptForbiddenCount; |
50 } | 49 } |
51 static bool isScriptForbidden() { | 50 static bool isScriptForbidden() { |
52 // Check s_scriptForbiddenCount first to avoid any calls to isMainThread() | 51 return isMainThread() && s_scriptForbiddenCount; |
53 // since under normal situations where we check this (ex. inside | |
54 // V8ScriptRunner) the value should always be zero. | |
55 return s_scriptForbiddenCount && isMainThread(); | |
56 } | 52 } |
57 | 53 |
58 private: | 54 private: |
59 static unsigned s_scriptForbiddenCount; | 55 static unsigned s_scriptForbiddenCount; |
60 }; | 56 }; |
61 | 57 |
62 // Scoped disabling of script execution on the main thread, | 58 // Scoped disabling of script execution on the main thread, |
63 // if called on the main thread. | 59 // if called on the main thread. |
64 // | 60 // |
65 // No effect when used by from other threads -- simplifies | 61 // No effect when used by from other threads -- simplifies |
(...skipping 13 matching lines...) Expand all Loading... |
79 ~ScriptForbiddenIfMainThreadScope() { | 75 ~ScriptForbiddenIfMainThreadScope() { |
80 if (m_IsMainThread) | 76 if (m_IsMainThread) |
81 ScriptForbiddenScope::exit(); | 77 ScriptForbiddenScope::exit(); |
82 } | 78 } |
83 bool m_IsMainThread; | 79 bool m_IsMainThread; |
84 }; | 80 }; |
85 | 81 |
86 } // namespace blink | 82 } // namespace blink |
87 | 83 |
88 #endif // ScriptForbiddenScope_h | 84 #endif // ScriptForbiddenScope_h |
OLD | NEW |