1 // Copyright 2013 the V8 project 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.
5 #ifndef V8_ASSERT_SCOPE_H_
6 #define V8_ASSERT_SCOPE_H_
9 #include "src/base/macros.h"
14 // Forward declarations.
16 class PerThreadAssertData;
19 enum PerThreadAssertType {
20 HEAP_ALLOCATION_ASSERT,
21 HANDLE_ALLOCATION_ASSERT,
22 HANDLE_DEREFERENCE_ASSERT,
23 DEFERRED_HANDLE_DEREFERENCE_ASSERT,
24 CODE_DEPENDENCY_CHANGE_ASSERT,
25 LAST_PER_THREAD_ASSERT_TYPE
29 enum PerIsolateAssertType {
30 JAVASCRIPT_EXECUTION_ASSERT,
31 JAVASCRIPT_EXECUTION_THROWS,
32 DEOPTIMIZATION_ASSERT,
37 template <PerThreadAssertType kType, bool kAllow>
38 class PerThreadAssertScope {
40 PerThreadAssertScope();
41 ~PerThreadAssertScope();
43 static bool IsAllowed();
46 PerThreadAssertData* data_;
49 DISALLOW_COPY_AND_ASSIGN(PerThreadAssertScope);
53 template <PerIsolateAssertType type, bool allow>
54 class PerIsolateAssertScope {
56 explicit PerIsolateAssertScope(Isolate* isolate);
57 ~PerIsolateAssertScope();
59 static bool IsAllowed(Isolate* isolate);
67 DISALLOW_COPY_AND_ASSIGN(PerIsolateAssertScope);
71 template <PerThreadAssertType type, bool allow>
73 class PerThreadAssertScopeDebugOnly : public
74 PerThreadAssertScope<type, allow> {
76 class PerThreadAssertScopeDebugOnly {
78 PerThreadAssertScopeDebugOnly() { }
83 template <PerIsolateAssertType type, bool allow>
85 class PerIsolateAssertScopeDebugOnly : public
86 PerIsolateAssertScope<type, allow> {
88 explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate)
89 : PerIsolateAssertScope<type, allow>(isolate) { }
91 class PerIsolateAssertScopeDebugOnly {
93 explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) { }
97 // Per-thread assert scopes.
99 // Scope to document where we do not expect handles to be created.
100 typedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, false>
101 DisallowHandleAllocation;
103 // Scope to introduce an exception to DisallowHandleAllocation.
104 typedef PerThreadAssertScopeDebugOnly<HANDLE_ALLOCATION_ASSERT, true>
105 AllowHandleAllocation;
107 // Scope to document where we do not expect any allocation and GC.
108 typedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, false>
109 DisallowHeapAllocation;
111 // Scope to introduce an exception to DisallowHeapAllocation.
112 typedef PerThreadAssertScopeDebugOnly<HEAP_ALLOCATION_ASSERT, true>
115 // Scope to document where we do not expect any handle dereferences.
116 typedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, false>
117 DisallowHandleDereference;
119 // Scope to introduce an exception to DisallowHandleDereference.
120 typedef PerThreadAssertScopeDebugOnly<HANDLE_DEREFERENCE_ASSERT, true>
121 AllowHandleDereference;
123 // Scope to document where we do not expect deferred handles to be dereferenced.
124 typedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, false>
125 DisallowDeferredHandleDereference;
127 // Scope to introduce an exception to DisallowDeferredHandleDereference.
128 typedef PerThreadAssertScopeDebugOnly<DEFERRED_HANDLE_DEREFERENCE_ASSERT, true>
129 AllowDeferredHandleDereference;
131 // Scope to document where we do not expect deferred handles to be dereferenced.
132 typedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, false>
133 DisallowCodeDependencyChange;
135 // Scope to introduce an exception to DisallowDeferredHandleDereference.
136 typedef PerThreadAssertScopeDebugOnly<CODE_DEPENDENCY_CHANGE_ASSERT, true>
137 AllowCodeDependencyChange;
140 // Per-isolate assert scopes.
142 // Scope to document where we do not expect javascript execution.
143 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, false>
144 DisallowJavascriptExecution;
146 // Scope to introduce an exception to DisallowJavascriptExecution.
147 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, true>
148 AllowJavascriptExecution;
150 // Scope in which javascript execution leads to exception being thrown.
151 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, false>
152 ThrowOnJavascriptExecution;
154 // Scope to introduce an exception to ThrowOnJavascriptExecution.
155 typedef PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, true>
156 NoThrowOnJavascriptExecution;
158 // Scope to document where we do not expect deoptimization.
159 typedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, false>
160 DisallowDeoptimization;
162 // Scope to introduce an exception to DisallowDeoptimization.
163 typedef PerIsolateAssertScopeDebugOnly<DEOPTIMIZATION_ASSERT, true>
166 // Scope to document where we do not expect deoptimization.
167 typedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, false>
170 // Scope to introduce an exception to DisallowDeoptimization.
171 typedef PerIsolateAssertScopeDebugOnly<COMPILATION_ASSERT, true>
173 } } // namespace v8::internal
175 #endif // V8_ASSERT_SCOPE_H_