OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 #include "src/assert-scope.h" | 5 #include "src/assert-scope.h" |
6 | 6 |
7 #include "src/base/lazy-instance.h" | 7 #include "src/base/lazy-instance.h" |
8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 PerThreadAssertData::SetCurrent(data_); | 76 PerThreadAssertData::SetCurrent(data_); |
77 } | 77 } |
78 data_->IncrementLevel(); | 78 data_->IncrementLevel(); |
79 old_state_ = data_->Get(kType); | 79 old_state_ = data_->Get(kType); |
80 data_->Set(kType, kAllow); | 80 data_->Set(kType, kAllow); |
81 } | 81 } |
82 | 82 |
83 | 83 |
84 template <PerThreadAssertType kType, bool kAllow> | 84 template <PerThreadAssertType kType, bool kAllow> |
85 PerThreadAssertScope<kType, kAllow>::~PerThreadAssertScope() { | 85 PerThreadAssertScope<kType, kAllow>::~PerThreadAssertScope() { |
86 DCHECK_NOT_NULL(data_); | 86 if (data_ == nullptr) return; |
87 data_->Set(kType, old_state_); | 87 data_->Set(kType, old_state_); |
88 if (data_->DecrementLevel()) { | 88 if (data_->DecrementLevel()) { |
89 PerThreadAssertData::SetCurrent(NULL); | 89 PerThreadAssertData::SetCurrent(NULL); |
90 delete data_; | 90 delete data_; |
91 } | 91 } |
rmcilroy
2017/01/17 10:41:31
Could you just call Release here rather than dupli
Leszek Swirski
2017/01/17 12:11:49
Not directly, because of the DCHECK, but extracted
Leszek Swirski
2017/01/17 12:17:18
Ignore me, I'm an idiot. Done.
| |
92 } | 92 } |
93 | 93 |
94 template <PerThreadAssertType kType, bool kAllow> | |
95 void PerThreadAssertScope<kType, kAllow>::Release() { | |
96 DCHECK_NOT_NULL(data_); | |
97 data_->Set(kType, old_state_); | |
98 if (data_->DecrementLevel()) { | |
99 PerThreadAssertData::SetCurrent(NULL); | |
100 delete data_; | |
101 } | |
102 data_ = nullptr; | |
103 } | |
94 | 104 |
95 // static | 105 // static |
96 template <PerThreadAssertType kType, bool kAllow> | 106 template <PerThreadAssertType kType, bool kAllow> |
97 bool PerThreadAssertScope<kType, kAllow>::IsAllowed() { | 107 bool PerThreadAssertScope<kType, kAllow>::IsAllowed() { |
98 PerThreadAssertData* data = PerThreadAssertData::GetCurrent(); | 108 PerThreadAssertData* data = PerThreadAssertData::GetCurrent(); |
99 return data == NULL || data->Get(kType); | 109 return data == NULL || data->Get(kType); |
100 } | 110 } |
101 | 111 |
102 | 112 |
103 template <PerIsolateAssertType kType, bool kAllow> | 113 template <PerIsolateAssertType kType, bool kAllow> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 template class PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, true>; | 155 template class PerIsolateAssertScope<JAVASCRIPT_EXECUTION_ASSERT, true>; |
146 template class PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, false>; | 156 template class PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, false>; |
147 template class PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, true>; | 157 template class PerIsolateAssertScope<JAVASCRIPT_EXECUTION_THROWS, true>; |
148 template class PerIsolateAssertScope<DEOPTIMIZATION_ASSERT, false>; | 158 template class PerIsolateAssertScope<DEOPTIMIZATION_ASSERT, false>; |
149 template class PerIsolateAssertScope<DEOPTIMIZATION_ASSERT, true>; | 159 template class PerIsolateAssertScope<DEOPTIMIZATION_ASSERT, true>; |
150 template class PerIsolateAssertScope<COMPILATION_ASSERT, false>; | 160 template class PerIsolateAssertScope<COMPILATION_ASSERT, false>; |
151 template class PerIsolateAssertScope<COMPILATION_ASSERT, true>; | 161 template class PerIsolateAssertScope<COMPILATION_ASSERT, true>; |
152 | 162 |
153 } // namespace internal | 163 } // namespace internal |
154 } // namespace v8 | 164 } // namespace v8 |
OLD | NEW |