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

Side by Side Diff: Source/WebCore/bindings/dart/DartIsolate.cpp

Issue 9837116: DOM wrappers that are not retained from Dart should be collected. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012, Google Inc. 1 // Copyright 2012, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 12 matching lines...) Expand all
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "DartIsolate.h" 31 #include "DartIsolate.h"
32 32
33 #include "DartController.h" 33 #include "DartDebugServer.h"
34 #include "DartUtilities.h"
34 35
35 namespace WebCore { 36 namespace WebCore {
36 37
37 class DartIsolateLink { 38 class DartIsolateLink {
38 public: 39 public:
39 static void push(DartIsolate* isolate) 40 static void push(DartIsolate* isolate)
40 { 41 {
41 DartIsolateLink* link = new DartIsolateLink; 42 DartIsolateLink* link = new DartIsolateLink;
42 link->m_isolate = isolate; 43 link->m_isolate = isolate;
43 link->m_previous = s_current; 44 link->m_previous = s_current;
(...skipping 29 matching lines...) Expand all
73 } 74 }
74 75
75 DartIsolate::DartIsolate(Dart_Isolate isolate) 76 DartIsolate::DartIsolate(Dart_Isolate isolate)
76 : m_isolate(isolate) 77 : m_isolate(isolate)
77 { 78 {
78 isolateMap().set(m_isolate, this); 79 isolateMap().set(m_isolate, this);
79 } 80 }
80 81
81 DartIsolate::~DartIsolate() 82 DartIsolate::~DartIsolate()
82 { 83 {
83 DartController::shutdownIsolate(this); 84 Dart_Isolate currentIsolate = Dart_CurrentIsolate();
85 if (currentIsolate)
86 Dart_ExitIsolate();
87
88 Dart_EnterIsolate(m_isolate);
89 for (WeakCallbackMap::iterator it = m_weakCallbackMap.begin(); it != m_weakC allbackMap.end(); ++it)
90 (*it->second.weakCallback)(it->first, it->second.peer);
91 Dart_ShutdownIsolate();
92
93 *DartUtilities::recursionForIsolate(m_isolate) = 0;
94 DartUtilities::unregisterIsolate(m_isolate);
95 DartDebugServer::shared().unregisterIsolate(this);
96
84 isolateMap().remove(m_isolate); 97 isolateMap().remove(m_isolate);
85 m_isolate = 0; 98 m_isolate = 0;
99
100 if (currentIsolate)
101 Dart_EnterIsolate(currentIsolate);
86 } 102 }
87 103
88 PassRefPtr<DartIsolate> DartIsolate::current() 104 PassRefPtr<DartIsolate> DartIsolate::current()
89 { 105 {
90 return DartIsolateLink::current(); 106 return DartIsolateLink::current();
91 } 107 }
92 108
93 PassRefPtr<DartIsolate> DartIsolate::forIsolate(Dart_Isolate isolate) 109 PassRefPtr<DartIsolate> DartIsolate::forIsolate(Dart_Isolate isolate)
94 { 110 {
95 ASSERT(isolateMap().contains(isolate)); 111 ASSERT(isolateMap().contains(isolate));
(...skipping 16 matching lines...) Expand all
112 ASSERT(m_isolate == Dart_CurrentIsolate()); 128 ASSERT(m_isolate == Dart_CurrentIsolate());
113 DartIsolateLink::pop(); 129 DartIsolateLink::pop();
114 DartIsolate* previous = DartIsolateLink::current(); 130 DartIsolate* previous = DartIsolateLink::current();
115 if (previous == this) 131 if (previous == this)
116 return; 132 return;
117 Dart_ExitIsolate(); 133 Dart_ExitIsolate();
118 if (previous) 134 if (previous)
119 Dart_EnterIsolate(previous->m_isolate); 135 Dart_EnterIsolate(previous->m_isolate);
120 } 136 }
121 137
138 Dart_Handle DartIsolate::createWeakPersistentHandle(Dart_Handle object, void* pe er, Dart_WeakPersistentHandleFinalizer weakCallback)
139 {
140 Dart_Handle persistentHandle = Dart_NewWeakPersistentHandle(object, peer, &D artIsolate::weakCallbackWrapper);
Anton Muhin 2012/03/28 18:03:23 as another option which might be more natural: as
podivilov 2012/03/28 18:20:05 That would require creating the Peer in the heap a
Anton Muhin 2012/03/28 18:25:54 What's the problem w/ it? Allocating small object
141 ASSERT(!m_weakCallbackMap.contains(persistentHandle));
142 m_weakCallbackMap.set(persistentHandle, WeakCallbackData(peer, weakCallback) );
143 return persistentHandle;
122 } 144 }
145
146 void DartIsolate::weakCallbackWrapper(Dart_Handle persistentHandle, void* peer)
147 {
148 DartIsolate* isolate = current().get();
149 ASSERT(isolate->m_weakCallbackMap.contains(persistentHandle));
150 WeakCallbackData weakCallbackData = isolate->m_weakCallbackMap.take(persiste ntHandle);
151 ASSERT(weakCallbackData.peer == peer);
152 (*weakCallbackData.weakCallback)(persistentHandle, peer);
Anton Muhin 2012/03/28 18:03:23 you allow 0 weak callback in ctor, so check here a
podivilov 2012/03/28 18:20:05 0 is not allowed. Default ctor is used for denotin
153 }
154
155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698