| 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 "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 Loading... |
| 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 DCHECK_IS_ON() |
| 159 bool isGlobalObjectDetached() const { return m_globalObjectDetached; } |
| 160 #endif |
| 158 | 161 |
| 159 V8PerContextData* perContextData() const { return m_perContextData.get(); } | 162 V8PerContextData* perContextData() const { return m_perContextData.get(); } |
| 160 void disposePerContextData(); | 163 void disposePerContextData(); |
| 161 | 164 |
| 162 ScriptValue getFromExtrasExports(const char* name); | 165 ScriptValue getFromExtrasExports(const char* name); |
| 163 | 166 |
| 164 protected: | 167 protected: |
| 165 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); | 168 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); |
| 166 | 169 |
| 167 private: | 170 private: |
| 168 v8::Isolate* m_isolate; | 171 v8::Isolate* m_isolate; |
| 169 // This persistent handle is weak. | 172 // This persistent handle is weak. |
| 170 ScopedPersistent<v8::Context> m_context; | 173 ScopedPersistent<v8::Context> m_context; |
| 171 | 174 |
| 172 // 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 |
| 173 // DOMWrapperWorld holds are weak. | 176 // DOMWrapperWorld holds are weak. |
| 174 RefPtr<DOMWrapperWorld> m_world; | 177 RefPtr<DOMWrapperWorld> m_world; |
| 175 | 178 |
| 176 // This std::unique_ptr causes a cycle: | 179 // This std::unique_ptr causes a cycle: |
| 177 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState | 180 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState |
| 178 // --(std::unique_ptr)--> V8PerContextData | 181 // --(std::unique_ptr)--> V8PerContextData |
| 179 // So you must explicitly clear the std::unique_ptr by calling | 182 // So you must explicitly clear the std::unique_ptr by calling |
| 180 // disposePerContextData() once you no longer need V8PerContextData. | 183 // disposePerContextData() once you no longer need V8PerContextData. |
| 181 // Otherwise, the v8::Context will leak. | 184 // Otherwise, the v8::Context will leak. |
| 182 std::unique_ptr<V8PerContextData> m_perContextData; | 185 std::unique_ptr<V8PerContextData> m_perContextData; |
| 186 |
| 187 #if DCHECK_IS_ON() |
| 188 bool m_globalObjectDetached = false; |
| 189 #endif |
| 183 }; | 190 }; |
| 184 | 191 |
| 185 // ScriptStateProtectingContext keeps the context associated with the | 192 // ScriptStateProtectingContext keeps the context associated with the |
| 186 // 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 |
| 187 // context. Otherwise, the context will leak. | 194 // context. Otherwise, the context will leak. |
| 188 class ScriptStateProtectingContext { | 195 class ScriptStateProtectingContext { |
| 189 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); | 196 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); |
| 190 USING_FAST_MALLOC(ScriptStateProtectingContext); | 197 USING_FAST_MALLOC(ScriptStateProtectingContext); |
| 191 | 198 |
| 192 public: | 199 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 204 } | 211 } |
| 205 | 212 |
| 206 private: | 213 private: |
| 207 RefPtr<ScriptState> m_scriptState; | 214 RefPtr<ScriptState> m_scriptState; |
| 208 ScopedPersistent<v8::Context> m_context; | 215 ScopedPersistent<v8::Context> m_context; |
| 209 }; | 216 }; |
| 210 | 217 |
| 211 } // namespace blink | 218 } // namespace blink |
| 212 | 219 |
| 213 #endif // ScriptState_h | 220 #endif // ScriptState_h |
| OLD | NEW |