V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
assert-scope.h
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.
4 
5 #ifndef V8_ASSERT_SCOPE_H_
6 #define V8_ASSERT_SCOPE_H_
7 
8 #include <stdint.h>
9 
10 #include "src/base/macros.h"
11 #include "src/globals.h"
12 #include "src/pointer-with-payload.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 // Forward declarations.
18 class Isolate;
19 class PerThreadAssertData;
20 
21 template <>
23  static constexpr int value = 1;
24 };
25 
26 enum PerThreadAssertType {
27  HEAP_ALLOCATION_ASSERT,
28  HANDLE_ALLOCATION_ASSERT,
29  HANDLE_DEREFERENCE_ASSERT,
30  DEFERRED_HANDLE_DEREFERENCE_ASSERT,
31  CODE_DEPENDENCY_CHANGE_ASSERT,
32  LAST_PER_THREAD_ASSERT_TYPE
33 };
34 
35 enum PerIsolateAssertType {
36  JAVASCRIPT_EXECUTION_ASSERT,
37  JAVASCRIPT_EXECUTION_THROWS,
38  JAVASCRIPT_EXECUTION_DUMP,
39  DEOPTIMIZATION_ASSERT,
40  COMPILATION_ASSERT,
41  NO_EXCEPTION_ASSERT
42 };
43 
44 template <PerThreadAssertType kType, bool kAllow>
46  public:
47  V8_EXPORT_PRIVATE PerThreadAssertScope();
48  V8_EXPORT_PRIVATE ~PerThreadAssertScope();
49 
50  V8_EXPORT_PRIVATE static bool IsAllowed();
51 
52  void Release();
53 
54  private:
56 
57  V8_INLINE void set_data(PerThreadAssertData* data) {
58  data_and_old_state_.SetPointer(data);
59  }
60 
61  V8_INLINE PerThreadAssertData* data() const {
62  return data_and_old_state_.GetPointer();
63  }
64 
65  V8_INLINE void set_old_state(bool old_state) {
66  return data_and_old_state_.SetPayload(old_state);
67  }
68 
69  V8_INLINE bool old_state() const { return data_and_old_state_.GetPayload(); }
70 
71  DISALLOW_COPY_AND_ASSIGN(PerThreadAssertScope);
72 };
73 
74 
75 template <PerIsolateAssertType type, bool allow>
77  public:
78  explicit PerIsolateAssertScope(Isolate* isolate);
80 
81  static bool IsAllowed(Isolate* isolate);
82 
83  private:
84  class DataBit;
85 
86  Isolate* isolate_;
87  uint32_t old_data_;
88 
89  DISALLOW_COPY_AND_ASSIGN(PerIsolateAssertScope);
90 };
91 
92 
93 template <PerThreadAssertType type, bool allow>
94 #ifdef DEBUG
95 class PerThreadAssertScopeDebugOnly : public
96  PerThreadAssertScope<type, allow> {
97 #else
99  public:
100  PerThreadAssertScopeDebugOnly() { // NOLINT (modernize-use-equals-default)
101  // Define a constructor to avoid unused variable warnings.
102  }
103  void Release() {}
104 #endif
105 };
106 
107 
108 template <PerIsolateAssertType type, bool allow>
109 #ifdef DEBUG
110 class PerIsolateAssertScopeDebugOnly : public
111  PerIsolateAssertScope<type, allow> {
112  public:
113  explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate)
114  : PerIsolateAssertScope<type, allow>(isolate) { }
115 #else
117  public:
118  explicit PerIsolateAssertScopeDebugOnly(Isolate* isolate) { }
119 #endif
120 };
121 
122 // Per-thread assert scopes.
123 
124 // Scope to document where we do not expect handles to be created.
127 
128 // Scope to introduce an exception to DisallowHandleAllocation.
131 
132 // Scope to document where we do not expect any allocation and GC.
135 #ifdef DEBUG
136 #define DISALLOW_HEAP_ALLOCATION(name) DisallowHeapAllocation name
137 #else
138 #define DISALLOW_HEAP_ALLOCATION(name)
139 #endif
140 
141 // Scope to introduce an exception to DisallowHeapAllocation.
144 
145 // Scope to document where we do not expect any handle dereferences.
148 
149 // Scope to introduce an exception to DisallowHandleDereference.
152 
153 // Scope to document where we do not expect deferred handles to be dereferenced.
156 
157 // Scope to introduce an exception to DisallowDeferredHandleDereference.
160 
161 // Scope to document where we do not expect deferred handles to be dereferenced.
164 
165 // Scope to introduce an exception to DisallowDeferredHandleDereference.
168 
170  DisallowHeapAllocation no_heap_allocation_;
171  DisallowHandleAllocation no_handle_allocation_;
172  DisallowHandleDereference no_handle_dereference_;
173  DisallowCodeDependencyChange no_dependency_change_;
174 };
175 
176 // Per-isolate assert scopes.
177 
178 // Scope to document where we do not expect javascript execution.
181 
182 // Scope to introduce an exception to DisallowJavascriptExecution.
185 
186 // Scope to document where we do not expect javascript execution (debug only)
189 
190 // Scope to introduce an exception to DisallowJavascriptExecutionDebugOnly.
193 
194 // Scope in which javascript execution leads to exception being thrown.
197 
198 // Scope to introduce an exception to ThrowOnJavascriptExecution.
201 
202 // Scope in which javascript execution causes dumps.
205 
206 // Scope in which javascript execution causes dumps.
209 
210 // Scope to document where we do not expect deoptimization.
213 
214 // Scope to introduce an exception to DisallowDeoptimization.
217 
218 // Scope to document where we do not expect deoptimization.
221 
222 // Scope to introduce an exception to DisallowDeoptimization.
225 
226 // Scope to document where we do not expect exceptions.
229 
230 // Scope to introduce an exception to DisallowExceptions.
233 } // namespace internal
234 } // namespace v8
235 
236 #endif // V8_ASSERT_SCOPE_H_
Definition: libplatform.h:13