Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (206461 => 206462)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2016-09-27 20:55:20 UTC (rev 206462)
@@ -1,5 +1,21 @@
2016-09-27 Chris Dumez <cdu...@apple.com>
+ It should be possible to dispatch events on documents that do not have a browsing context
+ https://bugs.webkit.org/show_bug.cgi?id=162620
+
+ Reviewed by Ryosuke Niwa.
+
+ * web-platform-tests/dom/events/Event-dispatch-bubbles-false-expected.txt:
+ * web-platform-tests/dom/events/Event-dispatch-bubbles-true-expected.txt:
+ Rebaseline several W3C tests now that more checks are passing.
+
+ * web-platform-tests/dom/events/Event-dispatch-other-document-expected.txt: Added.
+ * web-platform-tests/dom/events/Event-dispatch-other-document.html: Added.
+ * web-platform-tests/dom/events/w3c-import.log:
+ Import more test coverage from W3C.
+
+2016-09-27 Chris Dumez <cdu...@apple.com>
+
Second parameter to MutationObserver.observe() should be optional
https://bugs.webkit.org/show_bug.cgi?id=162627
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-false-expected.txt (206461 => 206462)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-false-expected.txt 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-false-expected.txt 2016-09-27 20:55:20 UTC (rev 206462)
@@ -1,7 +1,7 @@
PASS In window.document with click event
PASS In window.document with load event
-FAIL In window.document.cloneNode(true) assert_array_equals: targets lengths differ, expected 8 got 0
-FAIL In new Document() assert_array_equals: targets lengths differ, expected 8 got 0
-FAIL In DOMImplementation.createHTMLDocument() assert_array_equals: targets lengths differ, expected 8 got 0
+PASS In window.document.cloneNode(true)
+PASS In new Document()
+PASS In DOMImplementation.createHTMLDocument()
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-true-expected.txt (206461 => 206462)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-true-expected.txt 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-true-expected.txt 2016-09-27 20:55:20 UTC (rev 206462)
@@ -1,7 +1,7 @@
PASS In window.document with click event
PASS In window.document with load event
-FAIL In window.document.cloneNode(true) assert_array_equals: targets lengths differ, expected 14 got 0
-FAIL In new Document() assert_array_equals: targets lengths differ, expected 14 got 0
-FAIL In DOMImplementation.createHTMLDocument() assert_array_equals: targets lengths differ, expected 14 got 0
+PASS In window.document.cloneNode(true)
+PASS In new Document()
+PASS In DOMImplementation.createHTMLDocument()
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document-expected.txt (0 => 206462)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document-expected.txt 2016-09-27 20:55:20 UTC (rev 206462)
@@ -0,0 +1,3 @@
+
+PASS Custom event on an element in another document
+
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html (0 => 206462)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html 2016-09-27 20:55:20 UTC (rev 206462)
@@ -0,0 +1,22 @@
+<!doctype html>
+<title>Custom event on an element in another document</title>
+<script src=""
+<script src=""
+<div id=log></div>
+<script>
+test(function() {
+ var doc = document.implementation.createHTMLDocument("Demo");
+ var element = doc.createElement("div");
+ var called = false;
+ element.addEventListener("foo", this.step_func(function(ev) {
+ assert_false(called);
+ called = true;
+ assert_equals(ev.target, element);
+ }));
+ doc.body.appendChild(element);
+
+ var event = new Event("foo");
+ element.dispatchEvent(event);
+ assert_true(called);
+});
+</script>
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/w3c-import.log (206461 => 206462)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/w3c-import.log 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/w3c-import.log 2016-09-27 20:55:20 UTC (rev 206462)
@@ -29,6 +29,7 @@
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-multiple-stopPropagation.html
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-omitted-capture.html
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-order.html
+/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-propagation-stopped.html
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-redispatch.html
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-reenter.html
Modified: trunk/Source/WebCore/ChangeLog (206461 => 206462)
--- trunk/Source/WebCore/ChangeLog 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/Source/WebCore/ChangeLog 2016-09-27 20:55:20 UTC (rev 206462)
@@ -1,3 +1,39 @@
+2016-09-27 Chris Dumez <cdu...@apple.com>
+
+ It should be possible to dispatch events on documents that do not have a browsing context
+ https://bugs.webkit.org/show_bug.cgi?id=162620
+
+ Reviewed by Ryosuke Niwa.
+
+ It should be possible to dispatch events on documents that do not have a browsing
+ context (e.g. Documents created using DOMImplementation.createHTMLDocument()).
+ Gecko and Blink both allow this but WebKit did not.
+
+ The approach chosen to support this is similar to the one in Blink. When constructing
+ a new document (e.g. using DOMImplementation.createHTMLDocument()) we now keep track
+ of the context document. When requesting the scriptExecutionContext(), we now return
+ the context document if the document has one instead of the document itself.
+
+ Test: imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html
+
+ * bindings/js/JSDocumentCustom.cpp:
+ (WebCore::JSDocument::visitAdditionalChildren):
+ * dom/DOMImplementation.cpp:
+ (WebCore::DOMImplementation::createDocument):
+ (WebCore::DOMImplementation::createHTMLDocument):
+ * dom/Document.cpp:
+ (WebCore::Document::create):
+ (WebCore::Document::cloneDataFromDocument):
+ (WebCore::Document::contextDocument):
+ (WebCore::Document::takeDOMWindowFrom): Deleted.
+ * dom/Document.h:
+ (WebCore::Document::setContextDocument):
+ (WebCore::Node::scriptExecutionContext):
+ (WebCore::Node::isDocumentNode): Deleted.
+ * dom/Document.idl:
+ * xml/XMLHttpRequest.cpp:
+ (WebCore::XMLHttpRequest::responseXML):
+
2016-09-27 Alex Christensen <achristen...@webkit.org>
Implement URLParser::syntaxViolation
Modified: trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp (206461 => 206462)
--- trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp 2016-09-27 20:55:20 UTC (rev 206462)
@@ -175,7 +175,7 @@
void JSDocument::visitAdditionalChildren(SlotVisitor& visitor)
{
- visitor.addOpaqueRoot(wrapped().scriptExecutionContext());
+ visitor.addOpaqueRoot(static_cast<ScriptExecutionContext*>(&wrapped()));
}
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/DOMImplementation.cpp (206461 => 206462)
--- trunk/Source/WebCore/dom/DOMImplementation.cpp 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/Source/WebCore/dom/DOMImplementation.cpp 2016-09-27 20:55:20 UTC (rev 206462)
@@ -114,7 +114,7 @@
ExceptionOr<Ref<XMLDocument>> DOMImplementation::createDocument(const String& namespaceURI, const String& qualifiedName, DocumentType* documentType)
{
auto document = createXMLDocument(namespaceURI);
-
+ document->setContextDocument(m_document.contextDocument());
document->setSecurityOriginPolicy(m_document.securityOriginPolicy());
RefPtr<Element> documentElement;
@@ -153,6 +153,7 @@
ASSERT(document->head());
document->head()->appendChild(titleElement);
}
+ document->setContextDocument(m_document.contextDocument());
document->setSecurityOriginPolicy(m_document.securityOriginPolicy());
return document;
}
Modified: trunk/Source/WebCore/dom/Document.cpp (206461 => 206462)
--- trunk/Source/WebCore/dom/Document.cpp 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/Source/WebCore/dom/Document.cpp 2016-09-27 20:55:20 UTC (rev 206462)
@@ -576,10 +576,11 @@
}
#endif
-Ref<Document> Document::create(ScriptExecutionContext& context)
+Ref<Document> Document::create(Document& contextDocument)
{
Ref<Document> document = adoptRef(*new Document(nullptr, URL()));
- document->setSecurityOriginPolicy(context.securityOriginPolicy());
+ document->setContextDocument(contextDocument);
+ document->setSecurityOriginPolicy(contextDocument.securityOriginPolicy());
return document;
}
@@ -3505,6 +3506,7 @@
m_documentURI = other.documentURI();
setCompatibilityMode(other.m_compatibilityMode);
+ setContextDocument(other.contextDocument());
setSecurityOriginPolicy(other.securityOriginPolicy());
overrideMIMEType(other.contentType());
setDecoder(other.decoder());
@@ -4113,6 +4115,13 @@
ASSERT(m_domWindow->frame() == m_frame);
}
+Document& Document::contextDocument() const
+{
+ if (m_contextDocument)
+ return *m_contextDocument.get();
+ return const_cast<Document&>(*this);
+}
+
void Document::setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& attributeValue)
{
setAttributeEventListener(eventType, JSLazyEventListener::create(*this, attributeName, attributeValue));
Modified: trunk/Source/WebCore/dom/Document.h (206461 => 206462)
--- trunk/Source/WebCore/dom/Document.h 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/Source/WebCore/dom/Document.h 2016-09-27 20:55:20 UTC (rev 206462)
@@ -297,7 +297,7 @@
{
return adoptRef(*new Document(frame, url, DefaultDocumentClass, NonRenderedPlaceholder));
}
- static Ref<Document> create(ScriptExecutionContext&);
+ static Ref<Document> create(Document&);
virtual ~Document();
@@ -771,6 +771,9 @@
// In DOM Level 2, the Document's DOMWindow is called the defaultView.
DOMWindow* defaultView() const { return domWindow(); }
+ Document& contextDocument() const;
+ void setContextDocument(Document& document) { m_contextDocument = document.createWeakPtr(); }
+
// Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
void setWindowAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value);
void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
@@ -1411,6 +1414,7 @@
Frame* m_frame;
RefPtr<DOMWindow> m_domWindow;
+ WeakPtr<Document> m_contextDocument;
Ref<CachedResourceLoader> m_cachedResourceLoader;
RefPtr<DocumentParser> m_parser;
@@ -1791,7 +1795,7 @@
inline ScriptExecutionContext* Node::scriptExecutionContext() const
{
- return &document();
+ return &document().contextDocument();
}
Element* eventTargetElementForDocument(Document*);
Modified: trunk/Source/WebCore/dom/Document.idl (206461 => 206462)
--- trunk/Source/WebCore/dom/Document.idl 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/Source/WebCore/dom/Document.idl 2016-09-27 20:55:20 UTC (rev 206462)
@@ -20,7 +20,7 @@
[
Constructor,
- ConstructorCallWith=ScriptExecutionContext,
+ ConstructorCallWith=Document,
CustomToJSObject,
ExportMacro=WEBCORE_EXPORT,
JSCustomHeader,
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (206461 => 206462)
--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2016-09-27 20:47:27 UTC (rev 206461)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2016-09-27 20:55:20 UTC (rev 206462)
@@ -199,6 +199,7 @@
m_responseDocument = XMLDocument::create(0, m_url);
// FIXME: Set Last-Modified.
m_responseDocument->setContent(m_responseBuilder.toStringPreserveCapacity());
+ m_responseDocument->setContextDocument(downcast<Document>(*scriptExecutionContext()));
m_responseDocument->setSecurityOriginPolicy(scriptExecutionContext()->securityOriginPolicy());
m_responseDocument->overrideMIMEType(mimeType);