mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:57:45 +00:00
LibWeb: Make XHR.response an actual XMLDocument for XML documents
Before this change, we were producing a generic DOM::Document, which was not distinguishable from an XMLDocument by IDL interface type.
This commit is contained in:
parent
2b343c9508
commit
0762388709
5 changed files with 29 additions and 2 deletions
|
@ -0,0 +1 @@
|
||||||
|
PASS
|
|
@ -0,0 +1,19 @@
|
||||||
|
<script src="include.js"></script>
|
||||||
|
<script>
|
||||||
|
asyncTest((done) => {
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
xhr.responseType = "document";
|
||||||
|
xhr.open("GET", "data:text/xml,<?xml version='1.0'?><lol/>", true);
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
|
let xml = xhr.responseXML;
|
||||||
|
if (xml instanceof XMLDocument)
|
||||||
|
println("PASS");
|
||||||
|
else
|
||||||
|
println("FAIL");
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.send();
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -9,6 +9,11 @@
|
||||||
|
|
||||||
namespace Web::DOM {
|
namespace Web::DOM {
|
||||||
|
|
||||||
|
JS::NonnullGCPtr<XMLDocument> XMLDocument::create(JS::Realm& realm, AK::URL const& url)
|
||||||
|
{
|
||||||
|
return realm.heap().allocate<XMLDocument>(realm, realm, url);
|
||||||
|
}
|
||||||
|
|
||||||
XMLDocument::XMLDocument(JS::Realm& realm, AK::URL const& url)
|
XMLDocument::XMLDocument(JS::Realm& realm, AK::URL const& url)
|
||||||
: Document(realm, url)
|
: Document(realm, url)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,7 @@ class XMLDocument final : public Document {
|
||||||
WEB_PLATFORM_OBJECT(XMLDocument, Document);
|
WEB_PLATFORM_OBJECT(XMLDocument, Document);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static JS::NonnullGCPtr<XMLDocument> create(JS::Realm&, AK::URL const&);
|
||||||
virtual ~XMLDocument() override = default;
|
virtual ~XMLDocument() override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org>
|
||||||
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
|
||||||
* Copyright (c) 2022-2023, Luke Wilde <lukew@serenityos.org>
|
* Copyright (c) 2022-2023, Luke Wilde <lukew@serenityos.org>
|
||||||
* Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
|
* Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
|
||||||
|
@ -22,6 +22,7 @@
|
||||||
#include <LibWeb/DOM/Event.h>
|
#include <LibWeb/DOM/Event.h>
|
||||||
#include <LibWeb/DOM/EventDispatcher.h>
|
#include <LibWeb/DOM/EventDispatcher.h>
|
||||||
#include <LibWeb/DOM/IDLEventListener.h>
|
#include <LibWeb/DOM/IDLEventListener.h>
|
||||||
|
#include <LibWeb/DOM/XMLDocument.h>
|
||||||
#include <LibWeb/Fetch/BodyInit.h>
|
#include <LibWeb/Fetch/BodyInit.h>
|
||||||
#include <LibWeb/Fetch/Fetching/Fetching.h>
|
#include <LibWeb/Fetch/Fetching/Fetching.h>
|
||||||
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
|
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
|
||||||
|
@ -317,7 +318,7 @@ void XMLHttpRequest::set_document_response()
|
||||||
|
|
||||||
// 6. Otherwise, let document be a document that represents the result of running the XML parser with XML scripting support disabled on xhr’s received bytes. If that fails (unsupported character encoding, namespace well-formedness error, etc.), then return null.
|
// 6. Otherwise, let document be a document that represents the result of running the XML parser with XML scripting support disabled on xhr’s received bytes. If that fails (unsupported character encoding, namespace well-formedness error, etc.), then return null.
|
||||||
else {
|
else {
|
||||||
document = DOM::Document::create(realm());
|
document = DOM::XMLDocument::create(realm(), m_response->url().value_or({}));
|
||||||
if (!Web::build_xml_document(*document, m_received_bytes)) {
|
if (!Web::build_xml_document(*document, m_received_bytes)) {
|
||||||
m_response_object = Empty {};
|
m_response_object = Empty {};
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue