| 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 // A wrapper isn't kept alive if its ExecutionContext has become |
| 40 // detached, even if hasPendingActivity() returns |true|. This avoids |
| 41 // memory leaks and is acceptable lifetime handling as the HTML spec |
| 42 // requires us to stop almost all DOM activities when the associated |
| 43 // browsing context is detached. |
| 44 // |
| 45 // Consequently, an implementation of hasPendingActivity() is |
| 46 // not required to take the detached state of the associated |
| 47 // ExecutionContext into account (i.e., return |false|.) We probe |
| 48 // the detached state of the ExecutionContext via |
| 49 // |isContextDestroyed()|. |
| 50 // |
| 51 // TODO(haraken): Implement correct lifetime using traceWrapper. |
| 52 if (activeWrappable->isContextDestroyed(activeWrappable)) { |
| 53 continue; |
| 54 } |
| 36 auto wrapperTypeInfo = | 55 auto wrapperTypeInfo = |
| 37 const_cast<WrapperTypeInfo*>(scriptWrappable->wrapperTypeInfo()); | 56 const_cast<WrapperTypeInfo*>(scriptWrappable->wrapperTypeInfo()); |
| 38 visitor->RegisterV8Reference( | 57 visitor->RegisterV8Reference( |
| 39 std::make_pair(wrapperTypeInfo, scriptWrappable)); | 58 std::make_pair(wrapperTypeInfo, scriptWrappable)); |
| 40 } | 59 } |
| 41 } | 60 } |
| 42 | 61 |
| 43 } // namespace blink | 62 } // namespace blink |
| OLD | NEW |