| 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 "wtf/RefCounted.h" | 10 #include "wtf/RefCounted.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 static ScriptState* forMainWorld(LocalFrame*); | 67 static ScriptState* forMainWorld(LocalFrame*); |
| 68 | 68 |
| 69 v8::Isolate* isolate() const { return m_isolate; } | 69 v8::Isolate* isolate() const { return m_isolate; } |
| 70 DOMWrapperWorld& world() const { return *m_world; } | 70 DOMWrapperWorld& world() const { return *m_world; } |
| 71 LocalDOMWindow* domWindow() const; | 71 LocalDOMWindow* domWindow() const; |
| 72 virtual ExecutionContext* executionContext() const; | 72 virtual ExecutionContext* executionContext() const; |
| 73 virtual void setExecutionContext(ExecutionContext*); | 73 virtual void setExecutionContext(ExecutionContext*); |
| 74 | 74 |
| 75 // This can return an empty handle if the v8::Context is gone. | 75 // This can return an empty handle if the v8::Context is gone. |
| 76 v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolat
e); } | 76 v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolat
e); } |
| 77 bool contextIsEmpty() const { return m_context.isEmpty(); } | 77 bool contextIsValid() const { return m_context.isEmpty() || m_globalObjectDe
tached; } |
| 78 void detachGlobalObject(); |
| 78 void clearContext() { return m_context.clear(); } | 79 void clearContext() { return m_context.clear(); } |
| 79 | 80 |
| 80 V8PerContextData* perContextData() const { return m_perContextData.get(); } | 81 V8PerContextData* perContextData() const { return m_perContextData.get(); } |
| 81 void disposePerContextData() { m_perContextData = nullptr; } | 82 void disposePerContextData() { m_perContextData = nullptr; } |
| 82 | 83 |
| 83 bool evalEnabled() const; | 84 bool evalEnabled() const; |
| 84 void setEvalEnabled(bool); | 85 void setEvalEnabled(bool); |
| 85 ScriptValue getFromGlobalObject(const char* name); | 86 ScriptValue getFromGlobalObject(const char* name); |
| 86 | 87 |
| 87 protected: | 88 protected: |
| 88 ScriptState(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>); | 89 ScriptState(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>); |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 v8::Isolate* m_isolate; | 92 v8::Isolate* m_isolate; |
| 92 // This persistent handle is weak. | 93 // This persistent handle is weak. |
| 93 ScopedPersistent<v8::Context> m_context; | 94 ScopedPersistent<v8::Context> m_context; |
| 94 | 95 |
| 95 // This RefPtr doesn't cause a cycle because all persistent handles that DOM
WrapperWorld holds are weak. | 96 // This RefPtr doesn't cause a cycle because all persistent handles that DOM
WrapperWorld holds are weak. |
| 96 RefPtr<DOMWrapperWorld> m_world; | 97 RefPtr<DOMWrapperWorld> m_world; |
| 97 | 98 |
| 98 // This OwnPtr causes a cycle: | 99 // This OwnPtr causes a cycle: |
| 99 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState
--(OwnPtr)--> V8PerContextData | 100 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState
--(OwnPtr)--> V8PerContextData |
| 100 // So you must explicitly clear the OwnPtr by calling disposePerContextData(
) | 101 // So you must explicitly clear the OwnPtr by calling disposePerContextData(
) |
| 101 // once you no longer need V8PerContextData. Otherwise, the v8::Context will
leak. | 102 // once you no longer need V8PerContextData. Otherwise, the v8::Context will
leak. |
| 102 OwnPtr<V8PerContextData> m_perContextData; | 103 OwnPtr<V8PerContextData> m_perContextData; |
| 104 |
| 105 bool m_globalObjectDetached; |
| 103 }; | 106 }; |
| 104 | 107 |
| 105 class ScriptStateForTesting : public ScriptState { | 108 class ScriptStateForTesting : public ScriptState { |
| 106 public: | 109 public: |
| 107 static PassRefPtr<ScriptStateForTesting> create(v8::Handle<v8::Context>, Pas
sRefPtr<DOMWrapperWorld>); | 110 static PassRefPtr<ScriptStateForTesting> create(v8::Handle<v8::Context>, Pas
sRefPtr<DOMWrapperWorld>); |
| 108 | 111 |
| 109 virtual ExecutionContext* executionContext() const OVERRIDE; | 112 virtual ExecutionContext* executionContext() const OVERRIDE; |
| 110 virtual void setExecutionContext(ExecutionContext*) OVERRIDE; | 113 virtual void setExecutionContext(ExecutionContext*) OVERRIDE; |
| 111 | 114 |
| 112 private: | 115 private: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 136 } | 139 } |
| 137 | 140 |
| 138 private: | 141 private: |
| 139 RefPtr<ScriptState> m_scriptState; | 142 RefPtr<ScriptState> m_scriptState; |
| 140 ScopedPersistent<v8::Context> m_context; | 143 ScopedPersistent<v8::Context> m_context; |
| 141 }; | 144 }; |
| 142 | 145 |
| 143 } | 146 } |
| 144 | 147 |
| 145 #endif // ScriptState_h | 148 #endif // ScriptState_h |
| OLD | NEW |