Version: (using KDE KDE 3.3.2) Installed from: Gentoo Packages OS: Linux When loading an image from pure JS the onload event (meaning a successful load) is triggered with no error checking, so the onerror event is never triggered no matter how mangled the src attribute is. The following example displays "Image loaded" even though the supplied src attribute is not valid: <script type="text/javascript"> var img = new Image; img.onload = function() { alert('Image loaded'); } img.onerror = function() { alert('Error'); } img.src = 'http://fake/url/fake_image.jpg'; </script> Changing the attribute to something uglier, even with no protocol at all, produces the same results. This only applies to pure JavaScript image loading. When specifying the src attribute directly in an HTML img tag events are correctly handled.
Created attachment 11505 [details] naive patch naive patch. Some code consolidation might be in order, and I don't understand why the cast from ATTR_ONLOAD is there, seems like it's an internal detail?
Yeah, the event types are bogus, as can be seen by testing event.type in the handlers. Revised patch for that next comment..
Created attachment 11506 [details] fixes event type, too revised
To update you: I've fixed up a lot of stuff with Image, and it now does distinguish onload vs. onerror, but there is a confusion inside KHTML about what onerror means (there are basically 2 types!), and so the handler doesn't get invoked, but that should be easy to fix once I can talk to person who put that stuff in and ask for some rationale.
SVN commit 502559 by orlovich: Make onerror work for images by actually using the same type of events for events and listeners. BUG:98461 M +2 -2 ecma/kjs_dom.cpp M +2 -2 ecma/kjs_window.cpp M +0 -2 xml/dom2_eventsimpl.cpp M +0 -1 xml/dom2_eventsimpl.h --- branches/KDE/3.5/kdelibs/khtml/ecma/kjs_dom.cpp #502558:502559 @@ -210,7 +210,7 @@ case OnDragDrop: return getListener(DOM::EventImpl::KHTML_DRAGDROP_EVENT); case OnError: - return getListener(DOM::EventImpl::KHTML_ERROR_EVENT); + return getListener(DOM::EventImpl::ERROR_EVENT); case OnFocus: return getListener(DOM::EventImpl::FOCUS_EVENT); case OnKeyDown: @@ -351,7 +351,7 @@ setListener(exec,DOM::EventImpl::KHTML_DRAGDROP_EVENT,value); break; case OnError: - setListener(exec,DOM::EventImpl::KHTML_ERROR_EVENT,value); + setListener(exec,DOM::EventImpl::ERROR_EVENT,value); break; case OnFocus: setListener(exec,DOM::EventImpl::FOCUS_EVENT,value); --- branches/KDE/3.5/kdelibs/khtml/ecma/kjs_window.cpp #502558:502559 @@ -752,7 +752,7 @@ case Ondragdrop: return getListener(exec,DOM::EventImpl::KHTML_DRAGDROP_EVENT); case Onerror: - return getListener(exec,DOM::EventImpl::KHTML_ERROR_EVENT); + return getListener(exec,DOM::EventImpl::ERROR_EVENT); case Onfocus: return getListener(exec,DOM::EventImpl::FOCUS_EVENT); case Onkeydown: @@ -928,7 +928,7 @@ return; case Onerror: if (isSafeScript(exec)) - setListener(exec,DOM::EventImpl::KHTML_ERROR_EVENT,value); + setListener(exec,DOM::EventImpl::ERROR_EVENT,value); return; case Onfocus: if (isSafeScript(exec)) --- branches/KDE/3.5/kdelibs/khtml/xml/dom2_eventsimpl.cpp #502558:502559 @@ -260,8 +260,6 @@ return "click"; case KHTML_DRAGDROP_EVENT: return "khtml_dragdrop"; - case KHTML_ERROR_EVENT: - return "khtml_error"; case KHTML_MOVE_EVENT: return "khtml_move"; case KHTML_READYSTATECHANGE_EVENT: --- branches/KDE/3.5/kdelibs/khtml/xml/dom2_eventsimpl.h #502558:502559 @@ -84,7 +84,6 @@ KHTML_ECMA_DBLCLICK_EVENT, // for html ondblclick KHTML_ECMA_CLICK_EVENT, // for html onclick KHTML_DRAGDROP_EVENT, - KHTML_ERROR_EVENT, KHTML_MOVE_EVENT, // XMLHttpRequest events KHTML_READYSTATECHANGE_EVENT
SVN commit 502570 by orlovich: Regression test for #98461 CCBUG:98461 A baseline/events/img_on_error.html-dom A baseline/events/img_on_error.html-render M +1 -0 baseline/events/svnignore A tests/events/img_on_error.html --- trunk/tests/khtmltests/regression/baseline/events/svnignore #502569:502570 @@ -12,3 +12,4 @@ iframe_display.html-dom window_addevent.html-render wrong-type-1.html-dump.png +img_on_error.html-dump.png