Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: Source/bindings/core/v8/ScriptState.h

Issue 1013413002: [bindings] Refactor ScriptStateForTesting, V8TestingScope into V8BindingForTesting.h/cpp (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Combined all testing files into one! Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // This OwnPtr causes a cycle: 110 // This OwnPtr causes a cycle:
111 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState --(OwnPtr)--> V8PerContextData 111 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState --(OwnPtr)--> V8PerContextData
112 // So you must explicitly clear the OwnPtr by calling disposePerContextData( ) 112 // So you must explicitly clear the OwnPtr by calling disposePerContextData( )
113 // once you no longer need V8PerContextData. Otherwise, the v8::Context will leak. 113 // once you no longer need V8PerContextData. Otherwise, the v8::Context will leak.
114 OwnPtr<V8PerContextData> m_perContextData; 114 OwnPtr<V8PerContextData> m_perContextData;
115 115
116 bool m_globalObjectDetached; 116 bool m_globalObjectDetached;
117 Vector<Observer*> m_observers; 117 Vector<Observer*> m_observers;
118 }; 118 };
119 119
120 class ScriptStateForTesting : public ScriptState {
121 public:
122 static PassRefPtr<ScriptStateForTesting> create(v8::Handle<v8::Context>, Pas sRefPtr<DOMWrapperWorld>);
123
124 virtual ExecutionContext* executionContext() const override;
125 virtual void setExecutionContext(ExecutionContext*) override;
126
127 private:
128 ScriptStateForTesting(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
129
130 ExecutionContext* m_executionContext;
131 };
132
133 // ScriptStateProtectingContext keeps the context associated with the ScriptStat e alive. 120 // ScriptStateProtectingContext keeps the context associated with the ScriptStat e alive.
134 // You need to call clear() once you no longer need the context. Otherwise, the context will leak. 121 // You need to call clear() once you no longer need the context. Otherwise, the context will leak.
135 class ScriptStateProtectingContext { 122 class ScriptStateProtectingContext {
136 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); 123 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext);
137 public: 124 public:
138 ScriptStateProtectingContext(ScriptState* scriptState) 125 ScriptStateProtectingContext(ScriptState* scriptState)
139 : m_scriptState(scriptState) 126 : m_scriptState(scriptState)
140 { 127 {
141 if (m_scriptState) 128 if (m_scriptState)
142 m_context.set(m_scriptState->isolate(), m_scriptState->context()); 129 m_context.set(m_scriptState->isolate(), m_scriptState->context());
143 } 130 }
144 131
145 ScriptState* operator->() const { return m_scriptState.get(); } 132 ScriptState* operator->() const { return m_scriptState.get(); }
146 ScriptState* get() const { return m_scriptState.get(); } 133 ScriptState* get() const { return m_scriptState.get(); }
147 void clear() 134 void clear()
148 { 135 {
149 m_scriptState = nullptr; 136 m_scriptState = nullptr;
150 m_context.clear(); 137 m_context.clear();
151 } 138 }
152 139
153 private: 140 private:
154 RefPtr<ScriptState> m_scriptState; 141 RefPtr<ScriptState> m_scriptState;
155 ScopedPersistent<v8::Context> m_context; 142 ScopedPersistent<v8::Context> m_context;
156 }; 143 };
157 144
158 } 145 }
159 146
160 #endif // ScriptState_h 147 #endif // ScriptState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698