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