| 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" |
| 11 #include "wtf/RefCounted.h" | 11 #include "wtf/RefCounted.h" |
| 12 #include <memory> |
| 12 #include <v8-debug.h> | 13 #include <v8-debug.h> |
| 13 #include <v8.h> | 14 #include <v8.h> |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 class LocalDOMWindow; | 18 class LocalDOMWindow; |
| 18 class DOMWrapperWorld; | 19 class DOMWrapperWorld; |
| 19 class ExecutionContext; | 20 class ExecutionContext; |
| 20 class LocalFrame; | 21 class LocalFrame; |
| 21 class ScriptValue; | 22 class ScriptValue; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); | 109 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); |
| 109 | 110 |
| 110 private: | 111 private: |
| 111 v8::Isolate* m_isolate; | 112 v8::Isolate* m_isolate; |
| 112 // This persistent handle is weak. | 113 // This persistent handle is weak. |
| 113 ScopedPersistent<v8::Context> m_context; | 114 ScopedPersistent<v8::Context> m_context; |
| 114 | 115 |
| 115 // This RefPtr doesn't cause a cycle because all persistent handles that DOM
WrapperWorld holds are weak. | 116 // This RefPtr doesn't cause a cycle because all persistent handles that DOM
WrapperWorld holds are weak. |
| 116 RefPtr<DOMWrapperWorld> m_world; | 117 RefPtr<DOMWrapperWorld> m_world; |
| 117 | 118 |
| 118 // This OwnPtr causes a cycle: | 119 // This std::unique_ptr causes a cycle: |
| 119 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState
--(OwnPtr)--> V8PerContextData | 120 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState
--(std::unique_ptr)--> V8PerContextData |
| 120 // So you must explicitly clear the OwnPtr by calling disposePerContextData(
) | 121 // So you must explicitly clear the std::unique_ptr by calling disposePerCon
textData() |
| 121 // once you no longer need V8PerContextData. Otherwise, the v8::Context will
leak. | 122 // once you no longer need V8PerContextData. Otherwise, the v8::Context will
leak. |
| 122 OwnPtr<V8PerContextData> m_perContextData; | 123 std::unique_ptr<V8PerContextData> m_perContextData; |
| 123 | 124 |
| 124 #if ENABLE(ASSERT) | 125 #if ENABLE(ASSERT) |
| 125 bool m_globalObjectDetached; | 126 bool m_globalObjectDetached; |
| 126 #endif | 127 #endif |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 // ScriptStateProtectingContext keeps the context associated with the ScriptStat
e alive. | 130 // ScriptStateProtectingContext keeps the context associated with the ScriptStat
e alive. |
| 130 // You need to call clear() once you no longer need the context. Otherwise, the
context will leak. | 131 // You need to call clear() once you no longer need the context. Otherwise, the
context will leak. |
| 131 class ScriptStateProtectingContext { | 132 class ScriptStateProtectingContext { |
| 132 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); | 133 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 148 } | 149 } |
| 149 | 150 |
| 150 private: | 151 private: |
| 151 RefPtr<ScriptState> m_scriptState; | 152 RefPtr<ScriptState> m_scriptState; |
| 152 ScopedPersistent<v8::Context> m_context; | 153 ScopedPersistent<v8::Context> m_context; |
| 153 }; | 154 }; |
| 154 | 155 |
| 155 } // namespace blink | 156 } // namespace blink |
| 156 | 157 |
| 157 #endif // ScriptState_h | 158 #endif // ScriptState_h |
| OLD | NEW |