Bug 26147

Summary: No support of DOM events on a frameless document
Product: WebKit Reporter: Laurentj <laurent>
Component: XML DOMAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Major CC: ap, cmarcelo, david.rivron, dominicc, loic, olivierg, tonikitoo
Priority: P2    
Version: 525.x (Safari 3.2)   
Hardware: Macintosh   
OS: OS X 10.5   
Bug Depends on: 27662    
Bug Blocks:    
Description Flags
DOMParse-addEventListener testcase none

Description Laurentj 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"?>\
      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 );

It works in Gecko and Opera.
Comment 1 Alexey Proskuryakov 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).
Comment 2 Alexey Proskuryakov 2011-07-05 00:12:31 PDT
*** Bug 63905 has been marked as a duplicate of this bug. ***
Comment 3 Loic Dachary 2011-09-30 01:22:46 PDT
Created attachment 109264 [details]

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

Comment 4 Loic Dachary 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 :


where document is the document being displayed and


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)

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.
Comment 5 Loic Dachary 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


It may be worth returning false so that the caller can rely on this assertion to know the events will be ignored.
Comment 6 Loic Dachary 2011-10-04 08:46:34 PDT


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.
Comment 7 Loic Dachary 2011-10-05 07:01:13 PDT
This is related to bug 27662