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 "wtf/HashSet.h" | 8 #include "wtf/HashSet.h" |
9 #include "wtf/ThreadSpecific.h" | 9 #include "wtf/ThreadSpecific.h" |
10 #include "wtf/Threading.h" | 10 #include "wtf/Threading.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 using ActiveScriptWrappableSetType = HashSet<const ActiveScriptWrappable*>; | 16 using ActiveScriptWrappableSetType = PersistentHeapHashSet<WeakMember<const Acti veScriptWrappable>>; |
17 | 17 |
18 ActiveScriptWrappableSetType& activeScriptWrappables() | 18 ActiveScriptWrappableSetType& activeScriptWrappables() |
19 { | 19 { |
20 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<ActiveScriptWrappableSetType> , activeScriptWrappableSet, new ThreadSpecific<ActiveScriptWrappableSetType>()); | 20 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<ActiveScriptWrappableSetType> , activeScriptWrappableSet, new ThreadSpecific<ActiveScriptWrappableSetType>()); |
haraken
2016/05/10 07:10:27
Not directly related to this CL, shall we move the
sof
2016/05/10 15:46:04
That would avoid ThreadSpecific<> , which would be
| |
21 if (!activeScriptWrappableSet.isSet()) | |
22 activeScriptWrappableSet->registerAsStaticReference(); | |
21 return *activeScriptWrappableSet; | 23 return *activeScriptWrappableSet; |
22 } | 24 } |
23 | 25 |
24 } // namespace | 26 } // namespace |
25 | 27 |
26 ActiveScriptWrappable::ActiveScriptWrappable(ScriptWrappable* self) | 28 ActiveScriptWrappable::ActiveScriptWrappable(ScriptWrappable* self) |
27 : m_scriptWrappable(self) | 29 : m_scriptWrappable(self) |
28 { | 30 { |
29 activeScriptWrappables().add(this); | 31 activeScriptWrappables().add(this); |
30 } | 32 } |
31 | 33 |
32 ActiveScriptWrappable::~ActiveScriptWrappable() | |
33 { | |
34 activeScriptWrappables().remove(this); | |
35 } | |
36 | |
37 ScriptWrappable* ActiveScriptWrappable::toScriptWrappable() const | 34 ScriptWrappable* ActiveScriptWrappable::toScriptWrappable() const |
38 { | 35 { |
39 return m_scriptWrappable; | 36 return m_scriptWrappable; |
40 } | 37 } |
41 | 38 |
42 void ActiveScriptWrappable::traceActiveScriptWrappables(ScriptWrappableVisitor* visitor) | 39 void ActiveScriptWrappable::traceActiveScriptWrappables(ScriptWrappableVisitor* visitor) |
43 { | 40 { |
44 for (auto activeWrappable : activeScriptWrappables()) { | 41 for (auto activeWrappable : activeScriptWrappables()) { |
45 if (!activeWrappable->hasPendingActivity()) | 42 if (!activeWrappable->hasPendingActivity()) |
46 continue; | 43 continue; |
47 | 44 |
48 visitor->traceWrappers(activeWrappable->toScriptWrappable()); | 45 visitor->traceWrappers(activeWrappable->toScriptWrappable()); |
49 } | 46 } |
50 } | 47 } |
51 | 48 |
52 } // namespace blink | 49 } // namespace blink |
OLD | NEW |