OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "wtf/TypeTraits.h" | 39 #include "wtf/TypeTraits.h" |
40 #include <v8.h> | 40 #include <v8.h> |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 class CORE_EXPORT TraceWrapperBase { | 44 class CORE_EXPORT TraceWrapperBase { |
45 WTF_MAKE_NONCOPYABLE(TraceWrapperBase); | 45 WTF_MAKE_NONCOPYABLE(TraceWrapperBase); |
46 | 46 |
47 public: | 47 public: |
48 TraceWrapperBase() = default; | 48 TraceWrapperBase() = default; |
| 49 virtual bool isScriptWrappable() const { return false; } |
49 | 50 |
50 DECLARE_VIRTUAL_TRACE_WRAPPERS(){}; | 51 DECLARE_VIRTUAL_TRACE_WRAPPERS(){}; |
51 }; | 52 }; |
52 | 53 |
53 // ScriptWrappable provides a way to map from/to C++ DOM implementation to/from | 54 // ScriptWrappable provides a way to map from/to C++ DOM implementation to/from |
54 // JavaScript object (platform object). ToV8() converts a ScriptWrappable to | 55 // JavaScript object (platform object). ToV8() converts a ScriptWrappable to |
55 // a v8::Object and toScriptWrappable() converts a v8::Object back to | 56 // a v8::Object and toScriptWrappable() converts a v8::Object back to |
56 // a ScriptWrappable. v8::Object as platform object is called "wrapper object". | 57 // a ScriptWrappable. v8::Object as platform object is called "wrapper object". |
57 // The wrapepr object for the main world is stored in ScriptWrappable. Wrapper | 58 // The wrapepr object for the main world is stored in ScriptWrappable. Wrapper |
58 // objects for other worlds are stored in DOMWrapperMap. | 59 // objects for other worlds are stored in DOMWrapperMap. |
59 class CORE_EXPORT ScriptWrappable : public TraceWrapperBase { | 60 class CORE_EXPORT ScriptWrappable : public TraceWrapperBase { |
60 WTF_MAKE_NONCOPYABLE(ScriptWrappable); | 61 WTF_MAKE_NONCOPYABLE(ScriptWrappable); |
61 | 62 |
62 public: | 63 public: |
63 ScriptWrappable() {} | 64 ScriptWrappable() {} |
64 | 65 |
| 66 bool isScriptWrappable() const override { return true; } |
| 67 |
65 template <typename T> | 68 template <typename T> |
66 T* toImpl() { | 69 T* toImpl() { |
67 // All ScriptWrappables are managed by the Blink GC heap; check that | 70 // All ScriptWrappables are managed by the Blink GC heap; check that |
68 // |T| is a garbage collected type. | 71 // |T| is a garbage collected type. |
69 static_assert( | 72 static_assert( |
70 sizeof(T) && WTF::IsGarbageCollectedType<T>::value, | 73 sizeof(T) && WTF::IsGarbageCollectedType<T>::value, |
71 "Classes implementing ScriptWrappable must be garbage collected."); | 74 "Classes implementing ScriptWrappable must be garbage collected."); |
72 | 75 |
73 // Check if T* is castable to ScriptWrappable*, which means T doesn't | 76 // Check if T* is castable to ScriptWrappable*, which means T doesn't |
74 // have two or more ScriptWrappable as superclasses. If T has two | 77 // have two or more ScriptWrappable as superclasses. If T has two |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 bool containsWrapper() const { return !m_mainWorldWrapper.IsEmpty(); } | 162 bool containsWrapper() const { return !m_mainWorldWrapper.IsEmpty(); } |
160 | 163 |
161 // Mark wrapper of this ScriptWrappable as alive in V8. Only marks | 164 // Mark wrapper of this ScriptWrappable as alive in V8. Only marks |
162 // wrapper in the main world. To mark wrappers in all worlds call | 165 // wrapper in the main world. To mark wrappers in all worlds call |
163 // ScriptWrappableVisitor::markWrapper(ScriptWrappable*, v8::Isolate*) | 166 // ScriptWrappableVisitor::markWrapper(ScriptWrappable*, v8::Isolate*) |
164 void markWrapper(const WrapperVisitor*) const; | 167 void markWrapper(const WrapperVisitor*) const; |
165 | 168 |
166 private: | 169 private: |
167 // These classes are exceptionally allowed to use mainWorldWrapper(). | 170 // These classes are exceptionally allowed to use mainWorldWrapper(). |
168 friend class DOMDataStore; | 171 friend class DOMDataStore; |
| 172 friend class HeapSnaphotWrapperVisitor; |
169 friend class V8HiddenValue; | 173 friend class V8HiddenValue; |
170 friend class V8PrivateProperty; | 174 friend class V8PrivateProperty; |
171 friend class WebGLRenderingContextBase; | 175 friend class WebGLRenderingContextBase; |
172 | 176 |
173 v8::Local<v8::Object> mainWorldWrapper(v8::Isolate* isolate) const { | 177 v8::Local<v8::Object> mainWorldWrapper(v8::Isolate* isolate) const { |
174 return v8::Local<v8::Object>::New(isolate, m_mainWorldWrapper); | 178 return v8::Local<v8::Object>::New(isolate, m_mainWorldWrapper); |
175 } | 179 } |
176 | 180 |
| 181 // Only use when really necessary, i.e., when passing over this |
| 182 // ScriptWrappable's reference to V8. Should only be needed by GC |
| 183 // infrastructure. |
| 184 const v8::Persistent<v8::Object>* rawMainWorldWrapper() const { |
| 185 return &m_mainWorldWrapper; |
| 186 } |
| 187 |
177 v8::Persistent<v8::Object> m_mainWorldWrapper; | 188 v8::Persistent<v8::Object> m_mainWorldWrapper; |
178 }; | 189 }; |
179 | 190 |
180 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of | 191 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of |
181 // the instance. Also declares a static member of type WrapperTypeInfo, of which | 192 // the instance. Also declares a static member of type WrapperTypeInfo, of which |
182 // the definition is given by the IDL code generator. | 193 // the definition is given by the IDL code generator. |
183 // | 194 // |
184 // All the derived classes of ScriptWrappable, regardless of directly or | 195 // All the derived classes of ScriptWrappable, regardless of directly or |
185 // indirectly, must write this macro in the class definition as long as the | 196 // indirectly, must write this macro in the class definition as long as the |
186 // class has a corresponding .idl file. | 197 // class has a corresponding .idl file. |
(...skipping 19 matching lines...) Expand all Loading... |
206 #define DECLARE_WRAPPERTYPEINFO() \ | 217 #define DECLARE_WRAPPERTYPEINFO() \ |
207 public: \ | 218 public: \ |
208 const WrapperTypeInfo* wrapperTypeInfo() const override; \ | 219 const WrapperTypeInfo* wrapperTypeInfo() const override; \ |
209 \ | 220 \ |
210 private: \ | 221 private: \ |
211 typedef void end_of_define_wrappertypeinfo_not_reached_t | 222 typedef void end_of_define_wrappertypeinfo_not_reached_t |
212 | 223 |
213 } // namespace blink | 224 } // namespace blink |
214 | 225 |
215 #endif // ScriptWrappable_h | 226 #endif // ScriptWrappable_h |
OLD | NEW |