RESOLVED FIXED 26147
It should be possible to dispatch events on documents created using DOMParser
https://bugs.webkit.org/show_bug.cgi?id=26147
Summary It should be possible to dispatch events on documents created using DOMParser
Laurentj
Reported 2009-06-02 13:36:31 PDT
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.
Attachments
testcase (926 bytes, text/plain)
2011-09-30 01:22 PDT, Loic Dachary
no flags
DOMParse-addEventListener testcase (1.07 KB, text/plain)
2011-10-04 06:37 PDT, Loic Dachary
no flags
Patch (6.39 KB, patch)
2016-09-27 15:22 PDT, Chris Dumez
no flags
Alexey Proskuryakov
Comment 1 2009-06-04 04:02:18 PDT
Confirmed. This works fine for XML documents in frames, but not for frameless ones (as created by DOMParser or XMLHttpRequest).
Alexey Proskuryakov
Comment 2 2011-07-05 00:12:31 PDT
*** Bug 63905 has been marked as a duplicate of this bug. ***
Loic Dachary
Comment 3 2011-09-30 01:22:46 PDT
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
Loic Dachary
Comment 4 2011-10-04 02:50:04 PDT
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.
Loic Dachary
Comment 5 2011-10-04 06:37:30 PDT
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.
Loic Dachary
Comment 6 2011-10-04 08:46:34 PDT
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.
Loic Dachary
Comment 7 2011-10-05 07:01:13 PDT
This is related to bug 27662
Chris Dumez
Comment 8 2016-09-27 12:51:18 PDT
Fixing via Bug 162620. *** This bug has been marked as a duplicate of bug 162620 ***
Chris Dumez
Comment 9 2016-09-27 12:52:47 PDT
I'll try the test case on this bug before duping this in case this is not covered.
Chris Dumez
Comment 10 2016-09-27 12:55:49 PDT
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.
Chris Dumez
Comment 11 2016-09-27 15:22:25 PDT
WebKit Commit Bot
Comment 12 2016-09-27 16:35:29 PDT
Comment on attachment 290015 [details] Patch Clearing flags on attachment: 290015 Committed r206469: <http://trac.webkit.org/changeset/206469>
WebKit Commit Bot
Comment 13 2016-09-27 16:35:34 PDT
All reviewed patches have been landed. Closing bug.
Lucas Forschler
Comment 14 2019-02-06 09:04:18 PST
Mass moving XML DOM bugs to the "DOM" Component.
Note You need to log in before you can comment on or make changes to this bug.