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 #ifndef ActiveScriptWrappable_h | 5 #ifndef ActiveScriptWrappable_h |
6 #define ActiveScriptWrappable_h | 6 #define ActiveScriptWrappable_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
10 #include "wtf/Noncopyable.h" | 10 #include "wtf/Noncopyable.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 class Isolate; | 13 class Isolate; |
14 } | 14 } |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 class ScriptWrappable; | 18 class ScriptWrappable; |
19 class ScriptWrappableVisitor; | 19 class ScriptWrappableVisitor; |
20 | 20 |
21 /** | 21 /** |
22 * Classes deriving from ActiveScriptWrappable will be registered in a | 22 * Classes deriving from ActiveScriptWrappable will be registered in a |
23 * thread-specific list. They keep their wrappers and dependant objects alive | 23 * thread-specific list. They keep their wrappers and dependant objects alive |
24 * as long as they have pending activity. | 24 * as long as they have pending activity. |
25 */ | 25 */ |
26 class CORE_EXPORT ActiveScriptWrappableBase : public GarbageCollectedMixin { | 26 class CORE_EXPORT ActiveScriptWrappableBase : public GarbageCollectedMixin { |
27 WTF_MAKE_NONCOPYABLE(ActiveScriptWrappableBase); | 27 WTF_MAKE_NONCOPYABLE(ActiveScriptWrappableBase); |
28 | 28 |
29 public: | 29 public: |
30 explicit ActiveScriptWrappableBase(ScriptWrappable*); | 30 ActiveScriptWrappableBase(); |
31 | 31 |
32 static void traceActiveScriptWrappables(v8::Isolate*, | 32 static void traceActiveScriptWrappables(v8::Isolate*, |
33 ScriptWrappableVisitor*); | 33 ScriptWrappableVisitor*); |
34 | 34 |
35 protected: | 35 protected: |
36 virtual bool isContextDestroyed(ActiveScriptWrappableBase*) const = 0; | 36 virtual bool isContextDestroyed(ActiveScriptWrappableBase*) const = 0; |
37 | 37 virtual bool dispatchHasPendingActivity(ActiveScriptWrappableBase*) const = 0; |
38 private: | 38 virtual ScriptWrappable* toScriptWrappable( |
39 ScriptWrappable* toScriptWrappable() const { return m_scriptWrappable; } | 39 ActiveScriptWrappableBase*) const = 0; |
40 | |
41 ScriptWrappable* m_scriptWrappable; | |
42 }; | 40 }; |
43 | 41 |
44 template <typename T> | 42 template <typename T> |
45 class ActiveScriptWrappable : public ActiveScriptWrappableBase { | 43 class ActiveScriptWrappable : public ActiveScriptWrappableBase { |
46 WTF_MAKE_NONCOPYABLE(ActiveScriptWrappable); | 44 WTF_MAKE_NONCOPYABLE(ActiveScriptWrappable); |
47 | 45 |
48 public: | 46 public: |
49 explicit ActiveScriptWrappable(ScriptWrappable* wrappable) | 47 ActiveScriptWrappable() : ActiveScriptWrappableBase() {} |
sof
2016/12/16 06:36:23
can be removed.
| |
50 : ActiveScriptWrappableBase(wrappable) {} | |
51 | 48 |
52 protected: | 49 protected: |
53 bool isContextDestroyed(ActiveScriptWrappableBase* object) const final { | 50 bool isContextDestroyed(ActiveScriptWrappableBase* object) const final { |
54 return !(static_cast<T*>(object)->T::getExecutionContext)() || | 51 return !(static_cast<T*>(object)->T::getExecutionContext)() || |
55 (static_cast<T*>(object)->T::getExecutionContext)() | 52 (static_cast<T*>(object)->T::getExecutionContext)() |
56 ->isContextDestroyed(); | 53 ->isContextDestroyed(); |
57 } | 54 } |
55 | |
56 bool dispatchHasPendingActivity( | |
57 ActiveScriptWrappableBase* object) const final { | |
58 return static_cast<T*>(object)->T::hasPendingActivity(); | |
59 } | |
60 | |
61 ScriptWrappable* toScriptWrappable( | |
62 ActiveScriptWrappableBase* object) const final { | |
63 return static_cast<T*>(object); | |
64 } | |
58 }; | 65 }; |
59 | 66 |
60 } // namespace blink | 67 } // namespace blink |
61 | 68 |
62 #endif // ActiveScriptWrappable_h | 69 #endif // ActiveScriptWrappable_h |
OLD | NEW |