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

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

Issue 2732153002: Revert of Prepare WindowProxy for using v8::Context::NewRemoteContext(). (Closed)
Patch Set: Created 3 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 <memory> 8 #include <memory>
9 9
10 #include "bindings/core/v8/ScopedPersistent.h" 10 #include "bindings/core/v8/ScopedPersistent.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 // This can return an empty handle if the v8::Context is gone. 150 // This can return an empty handle if the v8::Context is gone.
151 v8::Local<v8::Context> context() const { 151 v8::Local<v8::Context> context() const {
152 return m_context.newLocal(m_isolate); 152 return m_context.newLocal(m_isolate);
153 } 153 }
154 bool contextIsValid() const { 154 bool contextIsValid() const {
155 return !m_context.isEmpty() && m_perContextData; 155 return !m_context.isEmpty() && m_perContextData;
156 } 156 }
157 void detachGlobalObject(); 157 void detachGlobalObject();
158 void clearContext() { return m_context.clear(); } 158 void clearContext() { return m_context.clear(); }
159 #if DCHECK_IS_ON()
160 bool isGlobalObjectDetached() const { return m_globalObjectDetached; }
161 #endif
159 162
160 V8PerContextData* perContextData() const { return m_perContextData.get(); } 163 V8PerContextData* perContextData() const { return m_perContextData.get(); }
161 void disposePerContextData(); 164 void disposePerContextData();
162 165
163 ScriptValue getFromExtrasExports(const char* name); 166 ScriptValue getFromExtrasExports(const char* name);
164 167
165 protected: 168 protected:
166 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); 169 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>);
167 170
168 private: 171 private:
169 v8::Isolate* m_isolate; 172 v8::Isolate* m_isolate;
170 // This persistent handle is weak. 173 // This persistent handle is weak.
171 ScopedPersistent<v8::Context> m_context; 174 ScopedPersistent<v8::Context> m_context;
172 175
173 // This RefPtr doesn't cause a cycle because all persistent handles that 176 // This RefPtr doesn't cause a cycle because all persistent handles that
174 // DOMWrapperWorld holds are weak. 177 // DOMWrapperWorld holds are weak.
175 RefPtr<DOMWrapperWorld> m_world; 178 RefPtr<DOMWrapperWorld> m_world;
176 179
177 // This std::unique_ptr causes a cycle: 180 // This std::unique_ptr causes a cycle:
178 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState 181 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState
179 // --(std::unique_ptr)--> V8PerContextData 182 // --(std::unique_ptr)--> V8PerContextData
180 // So you must explicitly clear the std::unique_ptr by calling 183 // So you must explicitly clear the std::unique_ptr by calling
181 // disposePerContextData() once you no longer need V8PerContextData. 184 // disposePerContextData() once you no longer need V8PerContextData.
182 // Otherwise, the v8::Context will leak. 185 // Otherwise, the v8::Context will leak.
183 std::unique_ptr<V8PerContextData> m_perContextData; 186 std::unique_ptr<V8PerContextData> m_perContextData;
187
188 #if DCHECK_IS_ON()
189 bool m_globalObjectDetached = false;
190 #endif
184 }; 191 };
185 192
186 // ScriptStateProtectingContext keeps the context associated with the 193 // ScriptStateProtectingContext keeps the context associated with the
187 // ScriptState alive. You need to call clear() once you no longer need the 194 // ScriptState alive. You need to call clear() once you no longer need the
188 // context. Otherwise, the context will leak. 195 // context. Otherwise, the context will leak.
189 class ScriptStateProtectingContext { 196 class ScriptStateProtectingContext {
190 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); 197 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext);
191 USING_FAST_MALLOC(ScriptStateProtectingContext); 198 USING_FAST_MALLOC(ScriptStateProtectingContext);
192 199
193 public: 200 public:
(...skipping 11 matching lines...) Expand all
205 } 212 }
206 213
207 private: 214 private:
208 RefPtr<ScriptState> m_scriptState; 215 RefPtr<ScriptState> m_scriptState;
209 ScopedPersistent<v8::Context> m_context; 216 ScopedPersistent<v8::Context> m_context;
210 }; 217 };
211 218
212 } // namespace blink 219 } // namespace blink
213 220
214 #endif // ScriptState_h 221 #endif // ScriptState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698