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

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

Issue 2386173002: reflow comments in Source/bindings/core/v8 (Closed)
Patch Set: Created 4 years, 2 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 14 matching lines...) Expand all
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 29
30 public: 30 public:
31 class Scope { 31 class Scope {
32 STACK_ALLOCATED(); 32 STACK_ALLOCATED();
33 33
34 public: 34 public:
35 // You need to make sure that scriptState->context() is not empty before cre ating a Scope. 35 // You need to make sure that scriptState->context() is not empty before
36 // creating a Scope.
36 explicit Scope(ScriptState* scriptState) 37 explicit Scope(ScriptState* scriptState)
37 : m_handleScope(scriptState->isolate()), 38 : m_handleScope(scriptState->isolate()),
38 m_context(scriptState->context()) { 39 m_context(scriptState->context()) {
39 ASSERT(scriptState->contextIsValid()); 40 ASSERT(scriptState->contextIsValid());
40 m_context->Enter(); 41 m_context->Enter();
41 } 42 }
42 43
43 ~Scope() { m_context->Exit(); } 44 ~Scope() { m_context->Exit(); }
44 45
45 private: 46 private:
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 ScriptValue getFromExtrasExports(const char* name); 128 ScriptValue getFromExtrasExports(const char* name);
128 129
129 protected: 130 protected:
130 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>); 131 ScriptState(v8::Local<v8::Context>, PassRefPtr<DOMWrapperWorld>);
131 132
132 private: 133 private:
133 v8::Isolate* m_isolate; 134 v8::Isolate* m_isolate;
134 // This persistent handle is weak. 135 // This persistent handle is weak.
135 ScopedPersistent<v8::Context> m_context; 136 ScopedPersistent<v8::Context> m_context;
136 137
137 // This RefPtr doesn't cause a cycle because all persistent handles that DOMWr apperWorld holds are weak. 138 // This RefPtr doesn't cause a cycle because all persistent handles that
139 // DOMWrapperWorld holds are weak.
138 RefPtr<DOMWrapperWorld> m_world; 140 RefPtr<DOMWrapperWorld> m_world;
139 141
140 // This std::unique_ptr causes a cycle: 142 // This std::unique_ptr causes a cycle:
141 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState -- (std::unique_ptr)--> V8PerContextData 143 // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState
142 // So you must explicitly clear the std::unique_ptr by calling disposePerConte xtData() 144 // --(std::unique_ptr)--> V8PerContextData
143 // once you no longer need V8PerContextData. Otherwise, the v8::Context will l eak. 145 // So you must explicitly clear the std::unique_ptr by calling
146 // disposePerContextData() once you no longer need V8PerContextData.
147 // Otherwise, the v8::Context will leak.
144 std::unique_ptr<V8PerContextData> m_perContextData; 148 std::unique_ptr<V8PerContextData> m_perContextData;
145 149
146 #if ENABLE(ASSERT) 150 #if ENABLE(ASSERT)
147 bool m_globalObjectDetached; 151 bool m_globalObjectDetached;
148 #endif 152 #endif
149 }; 153 };
150 154
151 // ScriptStateProtectingContext keeps the context associated with the ScriptStat e alive. 155 // ScriptStateProtectingContext keeps the context associated with the
152 // You need to call clear() once you no longer need the context. Otherwise, the context will leak. 156 // ScriptState alive. You need to call clear() once you no longer need the
157 // context. Otherwise, the context will leak.
153 class ScriptStateProtectingContext { 158 class ScriptStateProtectingContext {
154 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext); 159 WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext);
155 USING_FAST_MALLOC(ScriptStateProtectingContext); 160 USING_FAST_MALLOC(ScriptStateProtectingContext);
156 161
157 public: 162 public:
158 ScriptStateProtectingContext(ScriptState* scriptState) 163 ScriptStateProtectingContext(ScriptState* scriptState)
159 : m_scriptState(scriptState) { 164 : m_scriptState(scriptState) {
160 if (m_scriptState) 165 if (m_scriptState)
161 m_context.set(m_scriptState->isolate(), m_scriptState->context()); 166 m_context.set(m_scriptState->isolate(), m_scriptState->context());
162 } 167 }
163 168
164 ScriptState* operator->() const { return m_scriptState.get(); } 169 ScriptState* operator->() const { return m_scriptState.get(); }
165 ScriptState* get() const { return m_scriptState.get(); } 170 ScriptState* get() const { return m_scriptState.get(); }
166 void clear() { 171 void clear() {
167 m_scriptState = nullptr; 172 m_scriptState = nullptr;
168 m_context.clear(); 173 m_context.clear();
169 } 174 }
170 175
171 private: 176 private:
172 RefPtr<ScriptState> m_scriptState; 177 RefPtr<ScriptState> m_scriptState;
173 ScopedPersistent<v8::Context> m_context; 178 ScopedPersistent<v8::Context> m_context;
174 }; 179 };
175 180
176 } // namespace blink 181 } // namespace blink
177 182
178 #endif // ScriptState_h 183 #endif // ScriptState_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698