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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ActiveScriptWrappable.cpp

Issue 2577053002: ActiveScriptWrappable: GC wrappers in detached ExecutionContexts. (Closed)
Patch Set: enable TraceWrappables for testing purposes Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "bindings/core/v8/ActiveScriptWrappable.h" 5 #include "bindings/core/v8/ActiveScriptWrappable.h"
6 6
7 #include "bindings/core/v8/DOMDataStore.h"
7 #include "bindings/core/v8/ScriptWrappable.h" 8 #include "bindings/core/v8/ScriptWrappable.h"
8 #include "bindings/core/v8/ScriptWrappableVisitor.h" 9 #include "bindings/core/v8/ScriptWrappableVisitor.h"
10 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8PerIsolateData.h" 11 #include "bindings/core/v8/V8PerIsolateData.h"
12 #include "core/dom/ExecutionContext.h"
10 13
11 namespace blink { 14 namespace blink {
12 15
13 ActiveScriptWrappable::ActiveScriptWrappable(ScriptWrappable* self) 16 ActiveScriptWrappableBase::ActiveScriptWrappableBase(ScriptWrappable* self)
14 : m_scriptWrappable(self) { 17 : m_scriptWrappable(self) {
15 ASSERT(ThreadState::current()); 18 ASSERT(ThreadState::current());
16 v8::Isolate* isolate = ThreadState::current()->isolate(); 19 v8::Isolate* isolate = ThreadState::current()->isolate();
17 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate); 20 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate);
18 isolateData->addActiveScriptWrappable(this); 21 isolateData->addActiveScriptWrappable(this);
19 } 22 }
20 23
21 void ActiveScriptWrappable::traceActiveScriptWrappables( 24 void ActiveScriptWrappableBase::traceActiveScriptWrappables(
22 v8::Isolate* isolate, 25 v8::Isolate* isolate,
23 ScriptWrappableVisitor* visitor) { 26 ScriptWrappableVisitor* visitor) {
24 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate); 27 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate);
25 auto activeScriptWrappables = isolateData->activeScriptWrappables(); 28 auto activeScriptWrappables = isolateData->activeScriptWrappables();
26 if (!activeScriptWrappables) { 29 if (!activeScriptWrappables) {
27 return; 30 return;
28 } 31 }
29 32
30 for (auto activeWrappable : *activeScriptWrappables) { 33 for (auto activeWrappable : *activeScriptWrappables) {
31 auto scriptWrappable = activeWrappable->toScriptWrappable(); 34 auto scriptWrappable = activeWrappable->toScriptWrappable();
32 if (!scriptWrappable->hasPendingActivity()) { 35 if (!scriptWrappable->hasPendingActivity()) {
33 continue; 36 continue;
34 } 37 }
35 38
39 // Do not keep the wrapper alive if the ExecutionContext
40 // has become detached, irrespective of what hasPendingActivity()
41 // returns. This is done to avoid memory leaks. see
Michael Lippautz 2016/12/15 13:57:31 nit: Mind copying over the comment? This part of M
sof 2016/12/15 15:33:02 Blended in that comment. Even though we invoke has
42 // MajorGCWrapperVisitor::VisitPersistentHandle() comment.
43 if (activeWrappable->isContextDestroyed(activeWrappable)) {
44 continue;
45 }
36 auto wrapperTypeInfo = 46 auto wrapperTypeInfo =
37 const_cast<WrapperTypeInfo*>(scriptWrappable->wrapperTypeInfo()); 47 const_cast<WrapperTypeInfo*>(scriptWrappable->wrapperTypeInfo());
38 visitor->RegisterV8Reference( 48 visitor->RegisterV8Reference(
39 std::make_pair(wrapperTypeInfo, scriptWrappable)); 49 std::make_pair(wrapperTypeInfo, scriptWrappable));
40 } 50 }
41 } 51 }
42 52
43 } // namespace blink 53 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698