Diff
Modified: trunk/LayoutTests/ChangeLog (206468 => 206469)
--- trunk/LayoutTests/ChangeLog 2016-09-27 23:20:56 UTC (rev 206468)
+++ trunk/LayoutTests/ChangeLog 2016-09-27 23:33:08 UTC (rev 206469)
@@ -1,3 +1,15 @@
+2016-09-27 Chris Dumez <[email protected]>
+
+ It should be possible to dispatch events on documents created using DOMParser
+ https://bugs.webkit.org/show_bug.cgi?id=26147
+
+ Reviewed by Ryosuke Niwa.
+
+ Add layout test coverage.
+
+ * fast/dom/parsed-document-dispatchEvent-expected.txt: Added.
+ * fast/dom/parsed-document-dispatchEvent.html: Added.
+
2016-09-27 Ryan Haddad <[email protected]>
Marking fast/scrolling/rtl-scrollbars-alternate-iframe-body-dir-attr-does-not-update-scrollbar-placement.html as flaky on Sierra.
Added: trunk/LayoutTests/fast/dom/parsed-document-dispatchEvent-expected.txt (0 => 206469)
--- trunk/LayoutTests/fast/dom/parsed-document-dispatchEvent-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/parsed-document-dispatchEvent-expected.txt 2016-09-27 23:33:08 UTC (rev 206469)
@@ -0,0 +1,11 @@
+Test that it is possible to dispatchEvent() works on documents created using DOMParser.parseFromString().
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS wasEventDispatched is false
+PASS wasEventDispatched is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/parsed-document-dispatchEvent.html (0 => 206469)
--- trunk/LayoutTests/fast/dom/parsed-document-dispatchEvent.html (rev 0)
+++ trunk/LayoutTests/fast/dom/parsed-document-dispatchEvent.html 2016-09-27 23:33:08 UTC (rev 206469)
@@ -0,0 +1,26 @@
+<DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Test that it is possible to dispatchEvent() works on documents created using DOMParser.parseFromString().");
+
+var wasEventDispatched = false;
+var documentString = '<?xml version="1.0" encoding="UTF-8"?>\
+<root>\
+ <foo>bar</foo>\
+</root>';
+var parser = new DOMParser();
+var parsedDocument = parser.parseFromString(documentString, 'text/xml');
+parsedDocument.addEventListener("click", function(evt) {
+ shouldBeFalse("wasEventDispatched");
+ wasEventDispatched = true;
+}, true);
+var clickEvent = parsedDocument.createEvent("Event");
+clickEvent.initEvent("click", true, true);
+parsedDocument.getElementsByTagName("foo")[0].dispatchEvent(clickEvent);
+shouldBeTrue("wasEventDispatched");
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (206468 => 206469)
--- trunk/Source/WebCore/ChangeLog 2016-09-27 23:20:56 UTC (rev 206468)
+++ trunk/Source/WebCore/ChangeLog 2016-09-27 23:33:08 UTC (rev 206469)
@@ -1,3 +1,25 @@
+2016-09-27 Chris Dumez <[email protected]>
+
+ It should be possible to dispatch events on documents created using DOMParser
+ https://bugs.webkit.org/show_bug.cgi?id=26147
+
+ Reviewed by Ryosuke Niwa.
+
+ It should be possible to dispatch events on documents created using
+ DOMParser. It did not work because we were not setting the context
+ document on the newly created document in DOMParser::parseFromString().
+
+ Firefox and Chrome both already support this.
+
+ Test: fast/dom/parsed-document-dispatchEvent.html
+
+ * xml/DOMParser.cpp:
+ (WebCore::DOMParser::DOMParser):
+ (WebCore::DOMParser::parseFromString):
+ * xml/DOMParser.h:
+ (WebCore::DOMParser::create):
+ * xml/DOMParser.idl:
+
2016-09-26 Myles C. Maxfield <[email protected]>
[Cocoa] Improve performance of complex text codepath
Modified: trunk/Source/WebCore/xml/DOMParser.cpp (206468 => 206469)
--- trunk/Source/WebCore/xml/DOMParser.cpp 2016-09-27 23:20:56 UTC (rev 206468)
+++ trunk/Source/WebCore/xml/DOMParser.cpp 2016-09-27 23:33:08 UTC (rev 206469)
@@ -25,8 +25,13 @@
namespace WebCore {
-RefPtr<Document> DOMParser::parseFromString(const String& str, const String& contentType, ExceptionCode& ec)
+DOMParser::DOMParser(Document& contextDocument)
+ : m_contextDocument(contextDocument.createWeakPtr())
{
+}
+
+RefPtr<Document> DOMParser::parseFromString(const String& string, const String& contentType, ExceptionCode& ec)
+{
if (contentType != "text/html"
&& contentType != "text/xml"
&& contentType != "application/xml"
@@ -36,9 +41,11 @@
return nullptr;
}
- Ref<Document> doc = DOMImplementation::createDocument(contentType, nullptr, URL());
- doc->setContent(str);
- return WTFMove(doc);
+ Ref<Document> document = DOMImplementation::createDocument(contentType, nullptr, URL());
+ if (m_contextDocument)
+ document->setContextDocument(*m_contextDocument.get());
+ document->setContent(string);
+ return WTFMove(document);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/xml/DOMParser.h (206468 => 206469)
--- trunk/Source/WebCore/xml/DOMParser.h 2016-09-27 23:20:56 UTC (rev 206468)
+++ trunk/Source/WebCore/xml/DOMParser.h 2016-09-27 23:33:08 UTC (rev 206469)
@@ -22,6 +22,7 @@
#include <wtf/Forward.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
+#include <wtf/WeakPtr.h>
namespace WebCore {
typedef int ExceptionCode;
@@ -30,12 +31,17 @@
class DOMParser : public RefCounted<DOMParser> {
public:
- static Ref<DOMParser> create() { return adoptRef(*new DOMParser); }
+ static Ref<DOMParser> create(Document& contextDocument)
+ {
+ return adoptRef(*new DOMParser(contextDocument));
+ }
RefPtr<Document> parseFromString(const String&, const String& contentType, ExceptionCode&);
private:
- DOMParser() { }
+ explicit DOMParser(Document& contextDocument);
+
+ WeakPtr<Document> m_contextDocument;
};
}
Modified: trunk/Source/WebCore/xml/DOMParser.idl (206468 => 206469)
--- trunk/Source/WebCore/xml/DOMParser.idl 2016-09-27 23:20:56 UTC (rev 206468)
+++ trunk/Source/WebCore/xml/DOMParser.idl 2016-09-27 23:33:08 UTC (rev 206469)
@@ -19,6 +19,7 @@
[
Constructor,
+ ConstructorCallWith=Document,
ImplementationLacksVTable,
] interface DOMParser {
[RaisesException, NewObject] Document parseFromString(DOMString str, DOMString contentType);