| 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 ScriptState_h | 5 #ifndef ScriptState_h |
| 6 #define ScriptState_h | 6 #define ScriptState_h |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "bindings/core/v8/ScopedPersistent.h" | 10 #include "bindings/core/v8/ScopedPersistent.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 // This can return an empty handle if the v8::Context is gone. | 150 // This can return an empty handle if the v8::Context is gone. |
| 151 v8::Local<v8::Context> context() const { | 151 v8::Local<v8::Context> context() const { |
| 152 return m_context.newLocal(m_isolate); | 152 return m_context.newLocal(m_isolate); |
| 153 } | 153 } |
| 154 bool contextIsValid() const { | 154 bool contextIsValid() const { |
| 155 return !m_context.isEmpty() && m_perContextData; | 155 return !m_context.isEmpty() && m_perContextData; |
| 156 } | 156 } |
| 157 void detachGlobalObject(); | 157 void detachGlobalObject(); |
| 158 void clearContext() { return m_context.clear(); } | 158 void clearContext() { return m_context.clear(); } |
| 159 #if DCHECK_IS_ON() | |
| 160 bool isGlobalObjectDetached() const { return m_globalObjectDetached; } | |
| 161 #endif | |
| 162 | 159 |
| 163 V8PerContextData* perContextData() const { return m_perContextData.get(); } | 160 V8PerContextData* perContextData() const { return m_perContextData.get(); } |
| 164 void disposePerContextData(); | 161 void disposePerContextData(); |
| 165 | 162 |
| 166 ScriptValue getFromExtrasExports(const char* name); | 163 ScriptValue getFromExtrasExports(const char* name); |
| 167 | 164 |
| 168 protected: | 165 protected: |
| 169 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); | 166 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); |
| 170 | 167 |
| 171 private: | 168 private: |
| 172 v8::Isolate* m_isolate; | 169 v8::Isolate* m_isolate; |
| 173 // This persistent handle is weak. | 170 // This persistent handle is weak. |
| 174 ScopedPersistent<v8::Context> m_context; | 171 ScopedPersistent<v8::Context> m_context; |
| 175 | 172 |
| 176 // This RefPtr doesn't cause a cycle because all persistent handles that | 173 // This RefPtr doesn't cause a cycle because all persistent handles that |
| 177 // DOMWrapperWorld holds are weak. | 174 // DOMWrapperWorld holds are weak. |
| 178 RefPtr<DOMWrapperWorld> m_world; | 175 RefPtr<DOMWrapperWorld> m_world; |
| 179 | 176 |
| 180 // This std::unique_ptr causes a cycle: | 177 // This std::unique_ptr causes a cycle: |
| 181 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState | 178 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState |
| 182 // --(std::unique_ptr)--> V8PerContextData | 179 // --(std::unique_ptr)--> V8PerContextData |
| 183 // So you must explicitly clear the std::unique_ptr by calling | 180 // So you must explicitly clear the std::unique_ptr by calling |
| 184 // disposePerContextData() once you no longer need V8PerContextData. | 181 // disposePerContextData() once you no longer need V8PerContextData. |
| 185 // Otherwise, the v8::Context will leak. | 182 // Otherwise, the v8::Context will leak. |
| 186 std::unique_ptr<V8PerContextData> m_perContextData; | 183 std::unique_ptr<V8PerContextData> m_perContextData; |
| 187 | |
| 188 #if DCHECK_IS_ON() | |
| 189 bool m_globalObjectDetached = false; | |
| 190 #endif | |
| 191 }; | 184 }; |
| 192 | 185 |
| 193 // ScriptStateProtectingContext keeps the context associated with the | 186 // ScriptStateProtectingContext keeps the context associated with the |
| 194 // ScriptState alive. You need to call clear() once you no longer need the | 187 // ScriptState alive. You need to call clear() once you no longer need the |
| 195 // context. Otherwise, the context will leak. | 188 // context. Otherwise, the context will leak. |
| 196 class ScriptStateProtectingContext { | 189 class ScriptStateProtectingContext { |
| 197 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); | 190 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); |
| 198 USING_FAST_MALLOC(ScriptStateProtectingContext); | 191 USING_FAST_MALLOC(ScriptStateProtectingContext); |
| 199 | 192 |
| 200 public: | 193 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 212 } | 205 } |
| 213 | 206 |
| 214 private: | 207 private: |
| 215 RefPtr<ScriptState> m_scriptState; | 208 RefPtr<ScriptState> m_scriptState; |
| 216 ScopedPersistent<v8::Context> m_context; | 209 ScopedPersistent<v8::Context> m_context; |
| 217 }; | 210 }; |
| 218 | 211 |
| 219 } // namespace blink | 212 } // namespace blink |
| 220 | 213 |
| 221 #endif // ScriptState_h | 214 #endif // ScriptState_h |
| OLD | NEW |