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

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

Issue 2578193004: Remove ActiveScriptWrappableBase::m_scriptWrappable (Closed)
Patch Set: temp 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/DOMDataStore.h"
8 #include "bindings/core/v8/ScriptWrappable.h" 8 #include "bindings/core/v8/ScriptWrappable.h"
9 #include "bindings/core/v8/ScriptWrappableVisitor.h" 9 #include "bindings/core/v8/ScriptWrappableVisitor.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
11 #include "bindings/core/v8/V8PerIsolateData.h" 11 #include "bindings/core/v8/V8PerIsolateData.h"
12 #include "core/dom/ExecutionContext.h" 12 #include "core/dom/ExecutionContext.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 ActiveScriptWrappableBase::ActiveScriptWrappableBase(ScriptWrappable* self) 16 ActiveScriptWrappableBase::ActiveScriptWrappableBase() {
17 : m_scriptWrappable(self) {
18 ASSERT(ThreadState::current()); 17 ASSERT(ThreadState::current());
19 v8::Isolate* isolate = ThreadState::current()->isolate(); 18 v8::Isolate* isolate = ThreadState::current()->isolate();
20 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate); 19 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate);
21 isolateData->addActiveScriptWrappable(this); 20 isolateData->addActiveScriptWrappable(this);
22 } 21 }
23 22
24 void ActiveScriptWrappableBase::traceActiveScriptWrappables( 23 void ActiveScriptWrappableBase::traceActiveScriptWrappables(
25 v8::Isolate* isolate, 24 v8::Isolate* isolate,
26 ScriptWrappableVisitor* visitor) { 25 ScriptWrappableVisitor* visitor) {
27 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate); 26 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate);
28 auto activeScriptWrappables = isolateData->activeScriptWrappables(); 27 auto activeScriptWrappables = isolateData->activeScriptWrappables();
29 if (!activeScriptWrappables) { 28 if (!activeScriptWrappables) {
30 return; 29 return;
31 } 30 }
32 31
33 for (auto activeWrappable : *activeScriptWrappables) { 32 for (auto activeWrappable : *activeScriptWrappables) {
34 auto scriptWrappable = activeWrappable->toScriptWrappable(); 33 if (!activeWrappable->dispatchHasPendingActivity(activeWrappable)) {
35 if (!scriptWrappable->hasPendingActivity()) {
36 continue; 34 continue;
37 } 35 }
38 36
39 // A wrapper isn't kept alive after its ExecutionContext becomes 37 // A wrapper isn't kept alive after its ExecutionContext becomes
40 // detached, even if hasPendingActivity() returns |true|. This measure 38 // detached, even if hasPendingActivity() returns |true|. This measure
41 // avoids memory leaks and has proven not to be too eager wrt 39 // avoids memory leaks and has proven not to be too eager wrt
42 // garbage collection of objects belonging to discarded browser contexts 40 // garbage collection of objects belonging to discarded browser contexts
43 // ( https://html.spec.whatwg.org/#a-browsing-context-is-discarded ) 41 // ( https://html.spec.whatwg.org/#a-browsing-context-is-discarded )
44 // 42 //
45 // Consequently, an implementation of hasPendingActivity() is 43 // Consequently, an implementation of hasPendingActivity() is
46 // not required to take the detached state of the associated 44 // not required to take the detached state of the associated
47 // ExecutionContext into account (i.e., return |false|.) We probe 45 // ExecutionContext into account (i.e., return |false|.) We probe
48 // the detached state of the ExecutionContext via 46 // the detached state of the ExecutionContext via
49 // |isContextDestroyed()|. 47 // |isContextDestroyed()|.
50 // 48 //
51 // TODO(haraken): Implement correct lifetime using traceWrapper. 49 // TODO(haraken): Implement correct lifetime using traceWrapper.
52 if (activeWrappable->isContextDestroyed(activeWrappable)) { 50 if (activeWrappable->isContextDestroyed(activeWrappable)) {
53 continue; 51 continue;
54 } 52 }
53
54 auto scriptWrappable = activeWrappable->toScriptWrappable(activeWrappable);
55 auto wrapperTypeInfo = 55 auto wrapperTypeInfo =
56 const_cast<WrapperTypeInfo*>(scriptWrappable->wrapperTypeInfo()); 56 const_cast<WrapperTypeInfo*>(scriptWrappable->wrapperTypeInfo());
57 visitor->RegisterV8Reference( 57 visitor->RegisterV8Reference(
58 std::make_pair(wrapperTypeInfo, scriptWrappable)); 58 std::make_pair(wrapperTypeInfo, scriptWrappable));
59 } 59 }
60 } 60 }
61 61
62 } // namespace blink 62 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698