In a document loaded with DOMParser, events are not propagated. This example doesn't work (no alert) in Safari (3.2 and 4beta) and in Chrome 2: var thatDoc = '<?xml version="1.0" encoding="UTF-8"?>\ <root>\ <foo>bar</foo>\ </root>'; var parser = new DOMParser(); var doc = parser.parseFromString(thatDoc, 'text/xml'); doc.addEventListener("click", function(evt){ alert('ok');}, true); var evt = doc.createEvent("Event"); evt.initEvent( "click", true, true ); doc.getElementsByTagName("foo")[0].dispatchEvent(evt); It works in Gecko and Opera.
Confirmed. This works fine for XML documents in frames, but not for frameless ones (as created by DOMParser or XMLHttpRequest).
*** Bug 63905 has been marked as a duplicate of this bug. ***
Created attachment 109264 [details] testcase The attached test case is to be placed in LayoutTests/fast/events/DOMParse-addEventListener.html and will fail as expected with the following output: This tests is for https://bugs.webkit.org/show_bug.cgi?id=26147 and shows that in a document loaded with DOMParser, events are propagated. On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". FAIL fired should be true. Was false. PASS successfullyParsed is true TEST COMPLETE
In order to figure out where the problem happens, the execution of the proposed test case is run step by step under gdb, comparing what happens with : document.dispatchEvent(evt); where document is the document being displayed and doc.dispatchEvent(evt); where doc is the result of var doc = parser.parseFromString(thatDoc, 'text/xml'); It differs in void JSEventListener::handleEvent(ScriptExecutionContext* scriptExecutionContext, Event* event) { ... JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(scriptExecutionContext, m_isolatedWorld.get()); if (!globalObject) return; ... } where globalObject is null for the parsed XML document and the handler is therefore not fired. The reason why it is null is because the scriptExecutionContext->frame() function returns null. It matches the diagnostic of the bug report claiming that the problem does not exist when the XML document is loaded using an iframe.
Created attachment 109614 [details] DOMParse-addEventListener testcase The new testcase checks that the document returned by parseFromString supports http://www.w3.org/TR/DOM-Level-2-Events/events.html with shouldBeTrue('doc.implementation.hasFeature("Events","2.0")'); It may be worth returning false so that the caller can rely on this assertion to know the events will be ignored.
In Source/WebCore/dom/DOMImplementation.h static bool hasFeature(const String& feature, const String& version); being static does not allow for a per-document return value. Making sure hasFeature returns false as suggested above is not a trivial change.
This is related to bug 27662
Fixing via Bug 162620. *** This bug has been marked as a duplicate of bug 162620 ***
I'll try the test case on this bug before duping this in case this is not covered.
Yes, I don't think the DOMParser.parseFromString() case is covered by my patch yet and will require some more work. I'll use this bug to support documents created this way.
Created attachment 290015 [details] Patch
Comment on attachment 290015 [details] Patch Clearing flags on attachment: 290015 Committed r206469: <http://trac.webkit.org/changeset/206469>
All reviewed patches have been landed. Closing bug.
Mass moving XML DOM bugs to the "DOM" Component.