| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 void disposeWrapper(const v8::WeakCallbackInfo<ScriptWrappable>& data) | 173 void disposeWrapper(const v8::WeakCallbackInfo<ScriptWrappable>& data) |
| 174 { | 174 { |
| 175 auto scriptWrappable = reinterpret_cast<ScriptWrappable*>(data.GetIntern
alField(v8DOMWrapperObjectIndex)); | 175 auto scriptWrappable = reinterpret_cast<ScriptWrappable*>(data.GetIntern
alField(v8DOMWrapperObjectIndex)); |
| 176 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptWrappable == this); | 176 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptWrappable == this); |
| 177 RELEASE_ASSERT(containsWrapper()); | 177 RELEASE_ASSERT(containsWrapper()); |
| 178 m_wrapper.Reset(); | 178 m_wrapper.Reset(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 static void firstWeakCallback(const v8::WeakCallbackInfo<ScriptWrappable>& d
ata) | 181 static void firstWeakCallback(const v8::WeakCallbackInfo<ScriptWrappable>& d
ata) |
| 182 { | 182 { |
| 183 data.GetParameter()->disposeWrapper(data); | 183 auto scriptWrappable = data.GetParameter(); |
| 184 data.SetSecondPassCallback(secondWeakCallback); | 184 scriptWrappable->disposeWrapper(data); |
| 185 |
| 186 auto wrapperTypeInfo = reinterpret_cast<WrapperTypeInfo*>(data.GetIntern
alField(v8DOMWrapperTypeIndex)); |
| 187 if (wrapperTypeInfo->isGarbageCollected()) { |
| 188 // derefObject() for garbage collected objects is very cheap, so |
| 189 // we don't delay derefObject to the second pass. |
| 190 // |
| 191 // More importantly, we've already disposed the wrapper at this |
| 192 // moment, so the ScriptWrappable may have already been collected |
| 193 // by GC by the second pass. We shouldn't use a pointer to the |
| 194 // ScriptWrappable in secondWeakCallback in case of garbage |
| 195 // collected objects. Thus calls derefObject right now. |
| 196 wrapperTypeInfo->derefObject(scriptWrappable); |
| 197 } else { |
| 198 // For reference counted objects, let's delay the destruction of |
| 199 // the object to the second pass. |
| 200 data.SetSecondPassCallback(secondWeakCallback); |
| 201 } |
| 185 } | 202 } |
| 186 | 203 |
| 187 static void secondWeakCallback(const v8::WeakCallbackInfo<ScriptWrappable>&
data) | 204 static void secondWeakCallback(const v8::WeakCallbackInfo<ScriptWrappable>&
data) |
| 188 { | 205 { |
| 189 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed | 206 // FIXME: I noticed that 50%~ of minor GC cycle times can be consumed |
| 190 // inside data.GetParameter()->deref(), which causes Node destructions.
We should | 207 // inside data.GetParameter()->deref(), which causes Node destructions.
We should |
| 191 // make Node destructions incremental. | 208 // make Node destructions incremental. |
| 192 auto scriptWrappable = reinterpret_cast<ScriptWrappable*>(data.GetIntern
alField(v8DOMWrapperObjectIndex)); | 209 auto scriptWrappable = reinterpret_cast<ScriptWrappable*>(data.GetIntern
alField(v8DOMWrapperObjectIndex)); |
| 193 auto typeInfo = reinterpret_cast<WrapperTypeInfo*>(data.GetInternalField
(v8DOMWrapperTypeIndex)); | 210 auto wrapperTypeInfo = reinterpret_cast<WrapperTypeInfo*>(data.GetIntern
alField(v8DOMWrapperTypeIndex)); |
| 194 typeInfo->derefObject(scriptWrappable); | 211 wrapperTypeInfo->derefObject(scriptWrappable); |
| 195 } | 212 } |
| 196 | 213 |
| 197 v8::Persistent<v8::Object> m_wrapper; | 214 v8::Persistent<v8::Object> m_wrapper; |
| 198 }; | 215 }; |
| 199 | 216 |
| 200 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of | 217 // Defines 'wrapperTypeInfo' virtual method which returns the WrapperTypeInfo of |
| 201 // the instance. Also declares a static member of type WrapperTypeInfo, of which | 218 // the instance. Also declares a static member of type WrapperTypeInfo, of which |
| 202 // the definition is given by the IDL code generator. | 219 // the definition is given by the IDL code generator. |
| 203 // | 220 // |
| 204 // All the derived classes of ScriptWrappable, regardless of directly or | 221 // All the derived classes of ScriptWrappable, regardless of directly or |
| 205 // indirectly, must write this macro in the class definition as long as the | 222 // indirectly, must write this macro in the class definition as long as the |
| 206 // class has a corresponding .idl file. | 223 // class has a corresponding .idl file. |
| 207 #define DEFINE_WRAPPERTYPEINFO() \ | 224 #define DEFINE_WRAPPERTYPEINFO() \ |
| 208 public: \ | 225 public: \ |
| 209 const WrapperTypeInfo* wrapperTypeInfo() const override \ | 226 const WrapperTypeInfo* wrapperTypeInfo() const override \ |
| 210 { \ | 227 { \ |
| 211 return &s_wrapperTypeInfo; \ | 228 return &s_wrapperTypeInfo; \ |
| 212 } \ | 229 } \ |
| 213 private: \ | 230 private: \ |
| 214 static const WrapperTypeInfo& s_wrapperTypeInfo | 231 static const WrapperTypeInfo& s_wrapperTypeInfo |
| 215 | 232 |
| 216 // Defines 'wrapperTypeInfo' virtual method, which should never be called. | 233 // Defines 'wrapperTypeInfo' virtual method, which should never be called. |
| 217 // | 234 // |
| (...skipping 27 matching lines...) Expand all Loading... |
| 245 // in X's cpp code, and instantiate X, i.e. "template class X;". | 262 // in X's cpp code, and instantiate X, i.e. "template class X;". |
| 246 #define DECLARE_WRAPPERTYPEINFO() \ | 263 #define DECLARE_WRAPPERTYPEINFO() \ |
| 247 public: \ | 264 public: \ |
| 248 const WrapperTypeInfo* wrapperTypeInfo() const override; \ | 265 const WrapperTypeInfo* wrapperTypeInfo() const override; \ |
| 249 private: \ | 266 private: \ |
| 250 typedef void end_of_define_wrappertypeinfo_not_reached_t | 267 typedef void end_of_define_wrappertypeinfo_not_reached_t |
| 251 | 268 |
| 252 } // namespace blink | 269 } // namespace blink |
| 253 | 270 |
| 254 #endif // ScriptWrappable_h | 271 #endif // ScriptWrappable_h |
| OLD | NEW |