| 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/ScriptWrappable.h" | 7 #include "bindings/core/v8/ScriptWrappable.h" |
| 8 #include "bindings/core/v8/ScriptWrappableVisitor.h" | 8 #include "bindings/core/v8/ScriptWrappableVisitor.h" |
| 9 #include "wtf/HashSet.h" | 9 #include "bindings/core/v8/V8PerIsolateData.h" |
| 10 #include "wtf/ThreadSpecific.h" | |
| 11 #include "wtf/Threading.h" | |
| 12 | 10 |
| 13 namespace blink { | 11 namespace blink { |
| 14 | 12 |
| 15 namespace { | |
| 16 | |
| 17 using ActiveScriptWrappableSetType = PersistentHeapHashSet<WeakMember<const Acti
veScriptWrappable>>; | |
| 18 | |
| 19 ActiveScriptWrappableSetType& activeScriptWrappables() | |
| 20 { | |
| 21 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<ActiveScriptWrappableSetType>
, activeScriptWrappableSet, new ThreadSpecific<ActiveScriptWrappableSetType>()); | |
| 22 if (!activeScriptWrappableSet.isSet()) | |
| 23 activeScriptWrappableSet->registerAsStaticReference(); | |
| 24 return *activeScriptWrappableSet; | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 ActiveScriptWrappable::ActiveScriptWrappable(ScriptWrappable* self) | 13 ActiveScriptWrappable::ActiveScriptWrappable(ScriptWrappable* self) |
| 30 : m_scriptWrappable(self) | 14 : m_scriptWrappable(self) |
| 31 { | 15 { |
| 32 activeScriptWrappables().add(this); | 16 ASSERT(ThreadState::current()); |
| 17 v8::Isolate* isolate = ThreadState::current()->isolate(); |
| 18 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate); |
| 19 isolateData->addActiveScriptWrappable(this); |
| 33 } | 20 } |
| 34 | 21 |
| 35 ScriptWrappable* ActiveScriptWrappable::toScriptWrappable() const | 22 void ActiveScriptWrappable::traceActiveScriptWrappables(v8::Isolate* isolate, Sc
riptWrappableVisitor* visitor) |
| 36 { | 23 { |
| 37 return m_scriptWrappable; | 24 V8PerIsolateData* isolateData = V8PerIsolateData::from(isolate); |
| 38 } | 25 for (auto activeWrappable : isolateData->activeScriptWrappables()) { |
| 39 | |
| 40 void ActiveScriptWrappable::traceActiveScriptWrappables(ScriptWrappableVisitor*
visitor) | |
| 41 { | |
| 42 for (auto activeWrappable : activeScriptWrappables()) { | |
| 43 if (!activeWrappable->hasPendingActivity()) | 26 if (!activeWrappable->hasPendingActivity()) |
| 44 continue; | 27 continue; |
| 45 | 28 |
| 46 ScriptWrappable* wrappable = activeWrappable->toScriptWrappable(); | 29 ScriptWrappable* wrappable = activeWrappable->toScriptWrappable(); |
| 47 wrappable->wrapperTypeInfo()->traceWrappers(visitor, wrappable); | 30 wrappable->wrapperTypeInfo()->traceWrappers(visitor, wrappable); |
| 48 } | 31 } |
| 49 } | 32 } |
| 50 | 33 |
| 51 } // namespace blink | 34 } // namespace blink |
| OLD | NEW |