Changeset 19820 in webkit
- Timestamp:
- Feb 22, 2007, 7:48:56 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r19811 r19820 1 2007-02-22 Ian Eng <ian.eng.webkit@gmail.com> 2 3 Reviewed by Maciej. 4 5 - Test for http://bugs.webkit.org/show_bug.cgi?id=12850 6 Leaks >10k objects 7 8 * fast/events/remove-event-listener-expected.txt: Added. 9 * fast/events/remove-event-listener.html: Added. 10 1 11 2007-02-22 Justin Garcia <justin.garcia@apple.com> 2 12 -
trunk/WebCore/ChangeLog
r19819 r19820 1 2007-02-22 Ian Eng <ian.eng.webkit@gmail.com> 2 3 Reviewed by Maciej. 4 5 - Patch for http://bugs.webkit.org/show_bug.cgi?id=12850 6 Leaks >10k objects 7 8 and 9 10 - http://bugs.webkit.org/show_bug.cgi?id=12853 11 add a EventListener leak counter 12 13 Problem: RemoveEventListener leaks memory if the listener is not 14 registered. 15 Fix: Added Window::findJSEventListener function w/o creating a 16 JSEventListener; Renamed getJSEventListener to findOrCreateJSEventListener; 17 18 As an enhancement, added a leak counter for EventListeners. 19 20 Added a test case, LayoutTests/fast/events/remove-event-listener.html. 21 22 * WebCore/bindings/js/kjs_dom.cpp: 23 * WebCore/bindings/js/kjs_window.h: 24 * WebCore/bindings/js/kjs_window.cpp: 25 * WebCore/bindings/js/kjs_event.cpp: Add a leak counter. 26 * WebCore/bindings/js/JSXMLHttpRequest.cpp: 27 * LayoutTests/fast/events/remove-event-listener.html: 28 1 29 2007-02-22 Anders Carlsson <acarlsson@apple.com> 2 30 -
trunk/WebCore/bindings/js/JSXMLHttpRequest.cpp
r18912 r19820 140 140 switch (token) { 141 141 case Onreadystatechange: 142 m_impl->setOnReadyStateChangeListener(Window::retrieveActive(exec)-> getJSUnprotectedEventListener(value, true));142 m_impl->setOnReadyStateChangeListener(Window::retrieveActive(exec)->findOrCreateJSUnprotectedEventListener(value, true)); 143 143 break; 144 144 case Onload: 145 m_impl->setOnLoadListener(Window::retrieveActive(exec)-> getJSUnprotectedEventListener(value, true));145 m_impl->setOnLoadListener(Window::retrieveActive(exec)->findOrCreateJSUnprotectedEventListener(value, true)); 146 146 break; 147 147 } … … 273 273 274 274 case JSXMLHttpRequest::AddEventListener: { 275 JSUnprotectedEventListener* listener = Window::retrieveActive(exec)-> getJSUnprotectedEventListener(args[1], true);275 JSUnprotectedEventListener* listener = Window::retrieveActive(exec)->findOrCreateJSUnprotectedEventListener(args[1], true); 276 276 if (listener) 277 277 request->m_impl->addEventListener(args[0]->toString(exec), listener, args[2]->toBoolean(exec)); … … 279 279 } 280 280 case JSXMLHttpRequest::RemoveEventListener: { 281 JSUnprotectedEventListener* listener = Window::retrieveActive(exec)-> getJSUnprotectedEventListener(args[1], true);281 JSUnprotectedEventListener* listener = Window::retrieveActive(exec)->findJSUnprotectedEventListener(args[1], true); 282 282 if (listener) 283 283 request->m_impl->removeEventListener(args[0]->toString(exec), listener, args[2]->toBoolean(exec)); -
trunk/WebCore/bindings/js/kjs_dom.cpp
r19617 r19820 624 624 void DOMEventTargetNode::setListener(ExecState* exec, const AtomicString &eventType, JSValue* func) const 625 625 { 626 EventTargetNodeCast(impl())->setHTMLEventListener(eventType, Window::retrieveActive(exec)-> getJSEventListener(func, true));626 EventTargetNodeCast(impl())->setHTMLEventListener(eventType, Window::retrieveActive(exec)->findOrCreateJSEventListener(func, true)); 627 627 } 628 628 … … 662 662 switch (id) { 663 663 case DOMEventTargetNode::AddEventListener: { 664 JSEventListener *listener = Window::retrieveActive(exec)-> getJSEventListener(args[1]);664 JSEventListener *listener = Window::retrieveActive(exec)->findOrCreateJSEventListener(args[1]); 665 665 if (listener) 666 666 node->addEventListener(args[0]->toString(exec), listener,args[2]->toBoolean(exec)); … … 668 668 } 669 669 case DOMEventTargetNode::RemoveEventListener: { 670 JSEventListener *listener = Window::retrieveActive(exec)-> getJSEventListener(args[1]);671 if (listener) 670 JSEventListener *listener = Window::retrieveActive(exec)->findJSEventListener(args[1]); 671 if (listener) 672 672 node->removeEventListener(args[0]->toString(exec), listener,args[2]->toBoolean(exec)); 673 673 return jsUndefined(); -
trunk/WebCore/bindings/js/kjs_events.cpp
r19538 r19820 202 202 } 203 203 204 #ifndef NDEBUG 205 #ifndef LOG_CHANNEL_PREFIX 206 #define LOG_CHANNEL_PREFIX Log 207 #endif 208 WTFLogChannel LogWebCoreEventListenerLeaks = { 0x00000000, "", WTFLogChannelOn }; 209 210 struct EventListenerCounter { 211 static unsigned count; 212 ~EventListenerCounter() 213 { 214 if (count) 215 LOG(WebCoreEventListenerLeaks, "LEAK: %u EventListeners\n", count); 216 } 217 }; 218 unsigned EventListenerCounter::count = 0; 219 static EventListenerCounter eventListenerCounter; 220 #endif 221 204 222 // ------------------------------------------------------------------------- 205 223 … … 214 232 listeners.set(_listener, this); 215 233 } 234 #ifndef NDEBUG 235 ++eventListenerCounter.count; 236 #endif 216 237 } 217 238 … … 223 244 listeners.remove(listener); 224 245 } 246 #ifndef NDEBUG 247 --eventListenerCounter.count; 248 #endif 225 249 } 226 250 -
trunk/WebCore/bindings/js/kjs_window.cpp
r19617 r19820 1281 1281 return; 1282 1282 1283 doc->setHTMLWindowEventListener(eventType, getJSEventListener(func,true));1283 doc->setHTMLWindowEventListener(eventType, findOrCreateJSEventListener(func,true)); 1284 1284 } 1285 1285 … … 1299 1299 } 1300 1300 1301 JSEventListener *Window::getJSEventListener(JSValue *val, bool html) 1302 { 1301 JSEventListener* Window::findJSEventListener(JSValue* val, bool html) 1302 { 1303 if (!val->isObject()) 1304 return 0; 1305 JSObject* object = static_cast<JSObject*>(val); 1306 ListenersMap& listeners = html ? jsHTMLEventListeners : jsEventListeners; 1307 return listeners.get(object); 1308 } 1309 1310 JSEventListener *Window::findOrCreateJSEventListener(JSValue *val, bool html) 1311 { 1312 JSEventListener *listener = findJSEventListener(val, html); 1313 if (listener) 1314 return listener; 1315 1303 1316 if (!val->isObject()) 1304 1317 return 0; 1305 1318 JSObject *object = static_cast<JSObject *>(val); 1306 1319 1307 ListenersMap& listeners = html ? jsHTMLEventListeners : jsEventListeners;1308 if (JSEventListener* listener = listeners.get(object))1309 return listener;1310 1311 1320 // Note that the JSEventListener constructor adds it to our jsEventListeners list 1312 1321 return new JSEventListener(object, this, html); 1313 1322 } 1314 1323 1315 JSUnprotectedEventListener *Window::getJSUnprotectedEventListener(JSValue *val, bool html) 1316 { 1324 JSUnprotectedEventListener* Window::findJSUnprotectedEventListener(JSValue* val, bool html) 1325 { 1326 if (!val->isObject()) 1327 return 0; 1328 JSObject* object = static_cast<JSObject*>(val); 1329 UnprotectedListenersMap& listeners = html ? jsUnprotectedHTMLEventListeners : jsUnprotectedEventListeners; 1330 return listeners.get(object); 1331 } 1332 1333 JSUnprotectedEventListener *Window::findOrCreateJSUnprotectedEventListener(JSValue *val, bool html) 1334 { 1335 JSUnprotectedEventListener *listener = findJSUnprotectedEventListener(val, html); 1336 if (listener) 1337 return listener; 1338 1317 1339 if (!val->isObject()) 1318 1340 return 0; 1319 JSObject* object = static_cast<JSObject *>(val); 1320 1321 UnprotectedListenersMap& listeners = html ? jsUnprotectedHTMLEventListeners : jsUnprotectedEventListeners; 1322 if (JSUnprotectedEventListener* listener = listeners.get(object)) 1323 return listener; 1341 JSObject *object = static_cast<JSObject *>(val); 1324 1342 1325 1343 // The JSUnprotectedEventListener constructor adds it to our jsUnprotectedEventListeners map. … … 1788 1806 if (!window->isSafeScript(exec)) 1789 1807 return jsUndefined(); 1790 if (JSEventListener *listener = Window::retrieveActive(exec)-> getJSEventListener(args[1]))1808 if (JSEventListener *listener = Window::retrieveActive(exec)->findOrCreateJSEventListener(args[1])) 1791 1809 if (Document *doc = frame->document()) 1792 1810 doc->addWindowEventListener(AtomicString(args[0]->toString(exec)), listener, args[2]->toBoolean(exec)); … … 1795 1813 if (!window->isSafeScript(exec)) 1796 1814 return jsUndefined(); 1797 if (JSEventListener *listener = Window::retrieveActive(exec)-> getJSEventListener(args[1]))1815 if (JSEventListener *listener = Window::retrieveActive(exec)->findJSEventListener(args[1])) 1798 1816 if (Document *doc = frame->document()) 1799 1817 doc->removeWindowEventListener(AtomicString(args[0]->toString(exec)), listener, args[2]->toBoolean(exec)); -
trunk/WebCore/bindings/js/kjs_window.h
r19617 r19820 136 136 BarInfo *statusbar(ExecState*) const; 137 137 BarInfo *toolbar(ExecState*) const; 138 JSEventListener *getJSEventListener(JSValue*, bool html = false); 139 JSUnprotectedEventListener *getJSUnprotectedEventListener(JSValue*, bool html = false); 138 139 // Finds a wrapper of a JS EventListener, returns 0 if no existing one. 140 JSEventListener* findJSEventListener(JSValue*, bool html = false); 141 142 // Finds or creates a wrapper of a JS EventListener. JS EventListener object is GC-protected. 143 JSEventListener *findOrCreateJSEventListener(JSValue*, bool html = false); 144 145 // Finds a wrapper of a GC-unprotected JS EventListener, returns 0 if no existing one. 146 JSUnprotectedEventListener* findJSUnprotectedEventListener(JSValue*, bool html = false); 147 148 // Finds or creates a wrapper of a JS EventListener. JS EventListener object is *NOT* GC-protected. 149 JSUnprotectedEventListener *findOrCreateJSUnprotectedEventListener(JSValue*, bool html = false); 150 140 151 void clear(); 141 152 virtual UString toString(ExecState *) const;
Note:
See TracChangeset
for help on using the changeset viewer.