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

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

Issue 538933002: ScriptState::contextIsEmpty shouldn't return true for a context whose global object is detached (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/core/v8/ScriptDebugServer.cpp ('k') | Source/bindings/core/v8/ScriptState.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "wtf/RefCounted.h" 10 #include "wtf/RefCounted.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 contextIsValue() 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;
jochen (gone - plz use gerrit) 2014/09/04 08:37:39 you can have several pointers to the same context,
haraken 2014/09/04 08:39:23 ScriptState and v8::Context have the 1:1 relations
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
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
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptDebugServer.cpp ('k') | Source/bindings/core/v8/ScriptState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698