Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptState.h

Issue 2640163004: Replace ENABLE(ASSERT) with DCHECK_IS_ON(). (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ScriptState_h 5 #ifndef ScriptState_h
6 #define ScriptState_h 6 #define ScriptState_h
7 7
8 #include "bindings/core/v8/ScopedPersistent.h" 8 #include "bindings/core/v8/ScopedPersistent.h"
9 #include "bindings/core/v8/V8PerContextData.h" 9 #include "bindings/core/v8/V8PerContextData.h"
10 #include "core/CoreExport.h" 10 #include "core/CoreExport.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 // This can return an empty handle if the v8::Context is gone. 149 // This can return an empty handle if the v8::Context is gone.
150 v8::Local<v8::Context> context() const { 150 v8::Local<v8::Context> context() const {
151 return m_context.newLocal(m_isolate); 151 return m_context.newLocal(m_isolate);
152 } 152 }
153 bool contextIsValid() const { 153 bool contextIsValid() const {
154 return !m_context.isEmpty() && m_perContextData; 154 return !m_context.isEmpty() && m_perContextData;
155 } 155 }
156 void detachGlobalObject(); 156 void detachGlobalObject();
157 void clearContext() { return m_context.clear(); } 157 void clearContext() { return m_context.clear(); }
158 #if ENABLE(ASSERT) 158 #if DCHECK_IS_ON()
159 bool isGlobalObjectDetached() const { return m_globalObjectDetached; } 159 bool isGlobalObjectDetached() const { return m_globalObjectDetached; }
160 #endif 160 #endif
161 161
162 V8PerContextData* perContextData() const { return m_perContextData.get(); } 162 V8PerContextData* perContextData() const { return m_perContextData.get(); }
163 void disposePerContextData(); 163 void disposePerContextData();
164 164
165 ScriptValue getFromExtrasExports(const char* name); 165 ScriptValue getFromExtrasExports(const char* name);
166 166
167 protected: 167 protected:
168 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); 168 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>);
169 169
170 private: 170 private:
171 v8::Isolate* m_isolate; 171 v8::Isolate* m_isolate;
172 // This persistent handle is weak. 172 // This persistent handle is weak.
173 ScopedPersistent<v8::Context> m_context; 173 ScopedPersistent<v8::Context> m_context;
174 174
175 // This RefPtr doesn't cause a cycle because all persistent handles that 175 // This RefPtr doesn't cause a cycle because all persistent handles that
176 // DOMWrapperWorld holds are weak. 176 // DOMWrapperWorld holds are weak.
177 RefPtr<DOMWrapperWorld> m_world; 177 RefPtr<DOMWrapperWorld> m_world;
178 178
179 // This std::unique_ptr causes a cycle: 179 // This std::unique_ptr causes a cycle:
180 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState 180 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState
181 // --(std::unique_ptr)--> V8PerContextData 181 // --(std::unique_ptr)--> V8PerContextData
182 // So you must explicitly clear the std::unique_ptr by calling 182 // So you must explicitly clear the std::unique_ptr by calling
183 // disposePerContextData() once you no longer need V8PerContextData. 183 // disposePerContextData() once you no longer need V8PerContextData.
184 // Otherwise, the v8::Context will leak. 184 // Otherwise, the v8::Context will leak.
185 std::unique_ptr<V8PerContextData> m_perContextData; 185 std::unique_ptr<V8PerContextData> m_perContextData;
186 186
187 #if ENABLE(ASSERT) 187 #if DCHECK_IS_ON()
188 bool m_globalObjectDetached; 188 bool m_globalObjectDetached = false;
189 #endif 189 #endif
190 }; 190 };
191 191
192 // ScriptStateProtectingContext keeps the context associated with the 192 // ScriptStateProtectingContext keeps the context associated with the
193 // ScriptState alive. You need to call clear() once you no longer need the 193 // ScriptState alive. You need to call clear() once you no longer need the
194 // context. Otherwise, the context will leak. 194 // context. Otherwise, the context will leak.
195 class ScriptStateProtectingContext { 195 class ScriptStateProtectingContext {
196 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); 196 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext);
197 USING_FAST_MALLOC(ScriptStateProtectingContext); 197 USING_FAST_MALLOC(ScriptStateProtectingContext);
198 198
(...skipping 12 matching lines...) Expand all
211 } 211 }
212 212
213 private: 213 private:
214 RefPtr<ScriptState> m_scriptState; 214 RefPtr<ScriptState> m_scriptState;
215 ScopedPersistent<v8::Context> m_context; 215 ScopedPersistent<v8::Context> m_context;
216 }; 216 };
217 217
218 } // namespace blink 218 } // namespace blink
219 219
220 #endif // ScriptState_h 220 #endif // ScriptState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698