| 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 10 matching lines...) Expand all Loading... |
| 21 class LocalFrame; | 21 class LocalFrame; |
| 22 class ScriptValue; | 22 class ScriptValue; |
| 23 | 23 |
| 24 // ScriptState is created when v8::Context is created. | 24 // ScriptState is created when v8::Context is created. |
| 25 // ScriptState is destroyed when v8::Context is garbage-collected and | 25 // ScriptState is destroyed when v8::Context is garbage-collected and |
| 26 // all V8 proxy objects that have references to the ScriptState are destructed. | 26 // all V8 proxy objects that have references to the ScriptState are destructed. |
| 27 class CORE_EXPORT ScriptState : public RefCounted<ScriptState> { | 27 class CORE_EXPORT ScriptState : public RefCounted<ScriptState> { |
| 28 WTF_MAKE_NONCOPYABLE(ScriptState); | 28 WTF_MAKE_NONCOPYABLE(ScriptState); |
| 29 public: | 29 public: |
| 30 class Scope { | 30 class Scope { |
| 31 STACK_ALLOCATED(); |
| 31 public: | 32 public: |
| 32 // You need to make sure that scriptState->context() is not empty before
creating a Scope. | 33 // You need to make sure that scriptState->context() is not empty before
creating a Scope. |
| 33 explicit Scope(ScriptState* scriptState) | 34 explicit Scope(ScriptState* scriptState) |
| 34 : m_handleScope(scriptState->isolate()) | 35 : m_handleScope(scriptState->isolate()) |
| 35 , m_context(scriptState->context()) | 36 , m_context(scriptState->context()) |
| 36 { | 37 { |
| 37 ASSERT(scriptState->contextIsValid()); | 38 ASSERT(scriptState->contextIsValid()); |
| 38 m_context->Enter(); | 39 m_context->Enter(); |
| 39 } | 40 } |
| 40 | 41 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 #if ENABLE(ASSERT) | 134 #if ENABLE(ASSERT) |
| 134 bool m_globalObjectDetached; | 135 bool m_globalObjectDetached; |
| 135 #endif | 136 #endif |
| 136 Vector<Observer*> m_observers; | 137 Vector<Observer*> m_observers; |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 // ScriptStateProtectingContext keeps the context associated with the ScriptStat
e alive. | 140 // ScriptStateProtectingContext keeps the context associated with the ScriptStat
e alive. |
| 140 // You need to call clear() once you no longer need the context. Otherwise, the
context will leak. | 141 // You need to call clear() once you no longer need the context. Otherwise, the
context will leak. |
| 141 class ScriptStateProtectingContext { | 142 class ScriptStateProtectingContext { |
| 142 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); | 143 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); |
| 144 WTF_MAKE_FAST_ALLOCATED(ScriptStateProtectingContext); |
| 143 public: | 145 public: |
| 144 ScriptStateProtectingContext(ScriptState* scriptState) | 146 ScriptStateProtectingContext(ScriptState* scriptState) |
| 145 : m_scriptState(scriptState) | 147 : m_scriptState(scriptState) |
| 146 { | 148 { |
| 147 if (m_scriptState) | 149 if (m_scriptState) |
| 148 m_context.set(m_scriptState->isolate(), m_scriptState->context()); | 150 m_context.set(m_scriptState->isolate(), m_scriptState->context()); |
| 149 } | 151 } |
| 150 | 152 |
| 151 ScriptState* operator->() const { return m_scriptState.get(); } | 153 ScriptState* operator->() const { return m_scriptState.get(); } |
| 152 ScriptState* get() const { return m_scriptState.get(); } | 154 ScriptState* get() const { return m_scriptState.get(); } |
| 153 void clear() | 155 void clear() |
| 154 { | 156 { |
| 155 m_scriptState = nullptr; | 157 m_scriptState = nullptr; |
| 156 m_context.clear(); | 158 m_context.clear(); |
| 157 } | 159 } |
| 158 | 160 |
| 159 private: | 161 private: |
| 160 RefPtr<ScriptState> m_scriptState; | 162 RefPtr<ScriptState> m_scriptState; |
| 161 ScopedPersistent<v8::Context> m_context; | 163 ScopedPersistent<v8::Context> m_context; |
| 162 }; | 164 }; |
| 163 | 165 |
| 164 } | 166 } |
| 165 | 167 |
| 166 #endif // ScriptState_h | 168 #endif // ScriptState_h |
| OLD | NEW |