| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "bindings/core/v8/ActiveScriptWrappable.h" | |
| 6 | |
| 7 #include "bindings/core/v8/DOMDataStore.h" | |
| 8 #include "bindings/core/v8/ScriptWrappable.h" | |
| 9 #include "bindings/core/v8/ScriptWrappableVisitor.h" | |
| 10 #include "bindings/core/v8/V8Binding.h" | |
| 11 #include "bindings/core/v8/V8PerIsolateData.h" | |
| 12 #include "core/dom/ExecutionContext.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 ActiveScriptWrappableBase::ActiveScriptWrappableBase() { | |
| 17 DCHECK(ThreadState::Current()); | |
| 18 v8::Isolate* isolate = ThreadState::Current()->GetIsolate(); | |
| 19 V8PerIsolateData* isolate_data = V8PerIsolateData::From(isolate); | |
| 20 isolate_data->AddActiveScriptWrappable(this); | |
| 21 } | |
| 22 | |
| 23 void ActiveScriptWrappableBase::TraceActiveScriptWrappables( | |
| 24 v8::Isolate* isolate, | |
| 25 ScriptWrappableVisitor* visitor) { | |
| 26 V8PerIsolateData* isolate_data = V8PerIsolateData::From(isolate); | |
| 27 auto active_script_wrappables = isolate_data->ActiveScriptWrappables(); | |
| 28 if (!active_script_wrappables) { | |
| 29 return; | |
| 30 } | |
| 31 | |
| 32 for (auto active_wrappable : *active_script_wrappables) { | |
| 33 if (!active_wrappable->DispatchHasPendingActivity(active_wrappable)) { | |
| 34 continue; | |
| 35 } | |
| 36 | |
| 37 // A wrapper isn't kept alive after its ExecutionContext becomes | |
| 38 // detached, even if hasPendingActivity() returns |true|. This measure | |
| 39 // avoids memory leaks and has proven not to be too eager wrt | |
| 40 // garbage collection of objects belonging to discarded browser contexts | |
| 41 // ( https://html.spec.whatwg.org/#a-browsing-context-is-discarded ) | |
| 42 // | |
| 43 // Consequently, an implementation of hasPendingActivity() is | |
| 44 // not required to take the detached state of the associated | |
| 45 // ExecutionContext into account (i.e., return |false|.) We probe | |
| 46 // the detached state of the ExecutionContext via | |
| 47 // |isContextDestroyed()|. | |
| 48 // | |
| 49 // TODO(haraken): Implement correct lifetime using traceWrapper. | |
| 50 if (active_wrappable->IsContextDestroyed(active_wrappable)) { | |
| 51 continue; | |
| 52 } | |
| 53 | |
| 54 auto script_wrappable = | |
| 55 active_wrappable->ToScriptWrappable(active_wrappable); | |
| 56 auto wrapper_type_info = | |
| 57 const_cast<WrapperTypeInfo*>(script_wrappable->GetWrapperTypeInfo()); | |
| 58 visitor->RegisterV8Reference( | |
| 59 std::make_pair(wrapper_type_info, script_wrappable)); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 } // namespace blink | |
| OLD | NEW |