Changeset 135305 in webkit
- Timestamp:
- Nov 20, 2012, 11:59:14 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r135281 r135305 1 2012-11-20 Elliott Sprehn <esprehn@chromium.org> 2 3 Store MutationObserver callback in a hidden property for V8 4 https://bugs.webkit.org/show_bug.cgi?id=102555 5 6 Reviewed by Adam Barth. 7 8 Test for reference cycle leaks with mutation observers. There doesn't seem 9 to be a way to check this for v8, but if you manually run you can see if it 10 leaks observers. 11 12 * ManualTests/leak-cycle-observer-wrapper.html: Added. 13 1 14 2012-11-20 Carlos Garcia Campos <cgarcia@igalia.com> 2 15 -
trunk/Source/WebCore/ChangeLog
r135303 r135305 1 2012-11-20 Elliott Sprehn <esprehn@chromium.org> 2 3 Store MutationObserver callback in a hidden property for V8 4 https://bugs.webkit.org/show_bug.cgi?id=102555 5 6 Reviewed by Adam Barth. 7 8 To prevent circular reference leaks we should store the MutationObserver 9 callback in a hidden property on the wrapper of the observer. 10 11 This is done by extending the code generator to support a new owner 12 argument to ::create() that lets you set the owner of the callback where 13 the hidden property should be stored. 14 15 Test: ManualTests/leak-cycle-observer-wrapper.html 16 17 * bindings/scripts/CodeGeneratorV8.pm: 18 (GenerateCallbackHeader): 19 (GenerateCallbackImplementation): 20 * bindings/scripts/test/V8/V8TestCallback.cpp: rebaselined. 21 * bindings/scripts/test/V8/V8TestCallback.h: rebaselined. 22 * bindings/v8/V8HiddenPropertyName.h: 23 * bindings/v8/custom/V8MutationObserverCustom.cpp: 24 (WebCore::V8MutationObserver::constructorCallback): 25 1 26 2012-11-20 Abhishek Arya <inferno@chromium.org> 2 27 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
r135239 r135305 3247 3247 push(@headerContent, <<END); 3248 3248 public: 3249 static PassRefPtr<${v8InterfaceName}> create(v8:: Local<v8::Value> value, ScriptExecutionContext* context)3249 static PassRefPtr<${v8InterfaceName}> create(v8::Handle<v8::Value> value, ScriptExecutionContext* context, v8::Handle<v8::Object> owner = v8::Handle<v8::Object>()) 3250 3250 { 3251 3251 ASSERT(value->IsObject()); 3252 3252 ASSERT(context); 3253 return adoptRef(new ${v8InterfaceName}(value->ToObject(), context ));3253 return adoptRef(new ${v8InterfaceName}(value->ToObject(), context, owner)); 3254 3254 } 3255 3255 … … 3283 3283 3284 3284 private: 3285 ${v8InterfaceName}(v8::Local<v8::Object>, ScriptExecutionContext*); 3286 3285 ${v8InterfaceName}(v8::Handle<v8::Object>, ScriptExecutionContext*, v8::Handle<v8::Object>); 3286 3287 static void weakCallback(v8::Persistent<v8::Value> wrapper, void* parameter) 3288 { 3289 ${v8InterfaceName}* object = static_cast<${v8InterfaceName}*>(parameter); 3290 object->m_callback.Dispose(); 3291 object->m_callback.Clear(); 3292 } 3293 3294 // FIXME: m_callback should be a ScopedPersistent. 3287 3295 v8::Persistent<v8::Object> m_callback; 3288 3296 WorldContextHandle m_worldContext; … … 3315 3323 push(@implContent, "namespace WebCore {\n\n"); 3316 3324 push(@implContent, <<END); 3317 ${v8InterfaceName}::${v8InterfaceName}(v8:: Local<v8::Object> callback, ScriptExecutionContext* context)3325 ${v8InterfaceName}::${v8InterfaceName}(v8::Handle<v8::Object> callback, ScriptExecutionContext* context, v8::Handle<v8::Object> owner) 3318 3326 : ActiveDOMCallback(context) 3319 3327 , m_callback(v8::Persistent<v8::Object>::New(callback)) 3320 3328 , m_worldContext(UseCurrentWorld) 3321 3329 { 3330 if (!owner.IsEmpty()) { 3331 owner->SetHiddenValue(V8HiddenPropertyName::callback(), callback); 3332 m_callback.MakeWeak(this, &${v8InterfaceName}::weakCallback); 3333 } 3322 3334 } 3323 3335 3324 3336 ${v8InterfaceName}::~${v8InterfaceName}() 3325 3337 { 3326 m_callback.Dispose(); 3338 if (!m_callback.IsEmpty()) 3339 m_callback.Dispose(); 3327 3340 } 3328 3341 -
trunk/Source/WebCore/bindings/scripts/test/V8/V8TestCallback.cpp
r127972 r135305 40 40 namespace WebCore { 41 41 42 V8TestCallback::V8TestCallback(v8:: Local<v8::Object> callback, ScriptExecutionContext* context)42 V8TestCallback::V8TestCallback(v8::Handle<v8::Object> callback, ScriptExecutionContext* context, v8::Handle<v8::Object> owner) 43 43 : ActiveDOMCallback(context) 44 44 , m_callback(v8::Persistent<v8::Object>::New(callback)) 45 45 , m_worldContext(UseCurrentWorld) 46 46 { 47 if (!owner.IsEmpty()) { 48 owner->SetHiddenValue(V8HiddenPropertyName::callback(), callback); 49 m_callback.MakeWeak(this, &V8TestCallback::weakCallback); 50 } 47 51 } 48 52 49 53 V8TestCallback::~V8TestCallback() 50 54 { 51 m_callback.Dispose(); 55 if (!m_callback.IsEmpty()) 56 m_callback.Dispose(); 52 57 } 53 58 -
trunk/Source/WebCore/bindings/scripts/test/V8/V8TestCallback.h
r114502 r135305 36 36 class V8TestCallback : public TestCallback, public ActiveDOMCallback { 37 37 public: 38 static PassRefPtr<V8TestCallback> create(v8:: Local<v8::Value> value, ScriptExecutionContext* context)38 static PassRefPtr<V8TestCallback> create(v8::Handle<v8::Value> value, ScriptExecutionContext* context, v8::Handle<v8::Object> owner = v8::Handle<v8::Object>()) 39 39 { 40 40 ASSERT(value->IsObject()); 41 41 ASSERT(context); 42 return adoptRef(new V8TestCallback(value->ToObject(), context ));42 return adoptRef(new V8TestCallback(value->ToObject(), context, owner)); 43 43 } 44 44 … … 56 56 57 57 private: 58 V8TestCallback(v8:: Local<v8::Object>, ScriptExecutionContext*);58 V8TestCallback(v8::Handle<v8::Object>, ScriptExecutionContext*, v8::Handle<v8::Object>); 59 59 60 static void weakCallback(v8::Persistent<v8::Value> wrapper, void* parameter) 61 { 62 V8TestCallback* object = static_cast<V8TestCallback*>(parameter); 63 object->m_callback.Dispose(); 64 object->m_callback.Clear(); 65 } 66 67 // FIXME: m_callback should be a ScopedPersistent. 60 68 v8::Persistent<v8::Object> m_callback; 61 69 WorldContextHandle m_worldContext; -
trunk/Source/WebCore/bindings/v8/V8HiddenPropertyName.h
r134351 r135305 38 38 #define V8_HIDDEN_PROPERTIES(V) \ 39 39 V(attributeListener) \ 40 V(callback) \ 40 41 V(detail) \ 41 42 V(document) \ -
trunk/Source/WebCore/bindings/v8/custom/V8MutationObserverCustom.cpp
r135185 r135305 62 62 63 63 ScriptExecutionContext* context = getScriptExecutionContext(); 64 v8::Handle<v8::Object> wrapper = args.Holder(); 64 65 65 RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context );66 RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context, wrapper); 66 67 RefPtr<MutationObserver> observer = MutationObserver::create(callback.release()); 67 68 68 v8::Handle<v8::Object> wrapper = args.Holder();69 69 V8DOMWrapper::createDOMWrapper(observer.release(), &info, wrapper); 70 70 return wrapper;
Note:
See TracChangeset
for help on using the changeset viewer.