Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| OLD | NEW |