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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // to the existing wrapper. | 98 // to the existing wrapper. |
99 bool setWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo
, v8::Local<v8::Object>& wrapper) WARN_UNUSED_RETURN | 99 bool setWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo
, v8::Local<v8::Object>& wrapper) WARN_UNUSED_RETURN |
100 { | 100 { |
101 ASSERT(!wrapper.IsEmpty()); | 101 ASSERT(!wrapper.IsEmpty()); |
102 if (UNLIKELY(containsWrapper())) { | 102 if (UNLIKELY(containsWrapper())) { |
103 wrapper = newLocalWrapper(isolate); | 103 wrapper = newLocalWrapper(isolate); |
104 return false; | 104 return false; |
105 } | 105 } |
106 m_wrapper.Reset(isolate, wrapper); | 106 m_wrapper.Reset(isolate, wrapper); |
107 wrapperTypeInfo->configureWrapper(&m_wrapper); | 107 wrapperTypeInfo->configureWrapper(&m_wrapper); |
108 m_wrapper.SetWeak(this, &firstWeakCallback, v8::WeakCallbackType::kInter
nalFields); | 108 m_wrapper.SetWeak(); |
109 ASSERT(containsWrapper()); | 109 ASSERT(containsWrapper()); |
110 return true; | 110 return true; |
111 } | 111 } |
112 | 112 |
113 v8::Local<v8::Object> newLocalWrapper(v8::Isolate* isolate) const | 113 v8::Local<v8::Object> newLocalWrapper(v8::Isolate* isolate) const |
114 { | 114 { |
115 return v8::Local<v8::Object>::New(isolate, m_wrapper); | 115 return v8::Local<v8::Object>::New(isolate, m_wrapper); |
116 } | 116 } |
117 | 117 |
118 bool isEqualTo(const v8::Local<v8::Object>& other) const | 118 bool isEqualTo(const v8::Local<v8::Object>& other) const |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // With Oilpan we don't need a ScriptWrappable destructor. | 162 // With Oilpan we don't need a ScriptWrappable destructor. |
163 // | 163 // |
164 // 'RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!containsWrapper())' is not nee
ded | 164 // 'RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!containsWrapper())' is not nee
ded |
165 // because Oilpan is not using reference counting at all. If containsWrapper
() is true, | 165 // because Oilpan is not using reference counting at all. If containsWrapper
() is true, |
166 // it means that ScriptWrappable still has a wrapper. In this case, the dest
ructor | 166 // it means that ScriptWrappable still has a wrapper. In this case, the dest
ructor |
167 // must not be called since the wrapper has a persistent handle back to this
ScriptWrappable object. | 167 // must not be called since the wrapper has a persistent handle back to this
ScriptWrappable object. |
168 // Assuming that Oilpan's GC is correct (If we cannot assume this, a lot of
more things are | 168 // Assuming that Oilpan's GC is correct (If we cannot assume this, a lot of
more things are |
169 // already broken), we must not hit the RELEASE_ASSERT. | 169 // already broken), we must not hit the RELEASE_ASSERT. |
170 | 170 |
171 private: | 171 private: |
172 void disposeWrapper(const v8::WeakCallbackInfo<ScriptWrappable>& data) | |
173 { | |
174 auto scriptWrappable = reinterpret_cast<ScriptWrappable*>(data.GetIntern
alField(v8DOMWrapperObjectIndex)); | |
175 SECURITY_CHECK(scriptWrappable == this); | |
176 RELEASE_ASSERT(containsWrapper()); | |
177 m_wrapper.Reset(); | |
178 } | |
179 | |
180 static void firstWeakCallback(const v8::WeakCallbackInfo<ScriptWrappable>& d
ata) | |
181 { | |
182 auto scriptWrappable = data.GetParameter(); | |
183 scriptWrappable->disposeWrapper(data); | |
184 | |
185 auto wrapperTypeInfo = reinterpret_cast<WrapperTypeInfo*>(data.GetIntern
alField(v8DOMWrapperTypeIndex)); | |
186 wrapperTypeInfo->wrapperDestroyed(); | |
187 } | |
188 | |
189 v8::Persistent<v8::Object> m_wrapper; | 172 v8::Persistent<v8::Object> m_wrapper; |
190 }; | 173 }; |
191 | 174 |
192 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of | 175 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of |
193 // the instance. Also declares a static member of type WrapperTypeInfo, of which | 176 // the instance. Also declares a static member of type WrapperTypeInfo, of which |
194 // the definition is given by the IDL code generator. | 177 // the definition is given by the IDL code generator. |
195 // | 178 // |
196 // All the derived classes of ScriptWrappable, regardless of directly or | 179 // All the derived classes of ScriptWrappable, regardless of directly or |
197 // indirectly, must write this macro in the class definition as long as the | 180 // indirectly, must write this macro in the class definition as long as the |
198 // class has a corresponding .idl file. | 181 // class has a corresponding .idl file. |
(...skipping 18 matching lines...) Expand all Loading... |
217 // in X's cpp code, and instantiate X, i.e. "template class X;". | 200 // in X's cpp code, and instantiate X, i.e. "template class X;". |
218 #define DECLARE_WRAPPERTYPEINFO() \ | 201 #define DECLARE_WRAPPERTYPEINFO() \ |
219 public: \ | 202 public: \ |
220 const WrapperTypeInfo* wrapperTypeInfo() const override; \ | 203 const WrapperTypeInfo* wrapperTypeInfo() const override; \ |
221 private: \ | 204 private: \ |
222 typedef void end_of_define_wrappertypeinfo_not_reached_t | 205 typedef void end_of_define_wrappertypeinfo_not_reached_t |
223 | 206 |
224 } // namespace blink | 207 } // namespace blink |
225 | 208 |
226 #endif // ScriptWrappable_h | 209 #endif // ScriptWrappable_h |
OLD | NEW |