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()); |
47 DCHECK(s_scriptForbiddenCount); | 48 DCHECK(s_scriptForbiddenCount); |
48 --s_scriptForbiddenCount; | 49 --s_scriptForbiddenCount; |
49 } | 50 } |
50 static bool isScriptForbidden() { | 51 static bool isScriptForbidden() { |
51 return isMainThread() && s_scriptForbiddenCount; | 52 // Check s_scriptForbiddenCount first to avoid any calls to isMainThread() |
| 53 // since under normal situations where we check this (ex. inside |
| 54 // V8ScriptRunner) the value should always be zero. |
| 55 return s_scriptForbiddenCount && isMainThread(); |
52 } | 56 } |
53 | 57 |
54 private: | 58 private: |
55 static unsigned s_scriptForbiddenCount; | 59 static unsigned s_scriptForbiddenCount; |
56 }; | 60 }; |
57 | 61 |
58 // Scoped disabling of script execution on the main thread, | 62 // Scoped disabling of script execution on the main thread, |
59 // if called on the main thread. | 63 // if called on the main thread. |
60 // | 64 // |
61 // No effect when used by from other threads -- simplifies | 65 // No effect when used by from other threads -- simplifies |
(...skipping 13 matching lines...) Expand all Loading... |
75 ~ScriptForbiddenIfMainThreadScope() { | 79 ~ScriptForbiddenIfMainThreadScope() { |
76 if (m_IsMainThread) | 80 if (m_IsMainThread) |
77 ScriptForbiddenScope::exit(); | 81 ScriptForbiddenScope::exit(); |
78 } | 82 } |
79 bool m_IsMainThread; | 83 bool m_IsMainThread; |
80 }; | 84 }; |
81 | 85 |
82 } // namespace blink | 86 } // namespace blink |
83 | 87 |
84 #endif // ScriptForbiddenScope_h | 88 #endif // ScriptForbiddenScope_h |
OLD | NEW |