1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:27:35 +00:00

LibWeb: Implement document.createCDATASection()

This commit is contained in:
Tim Ledbetter 2024-02-18 14:27:25 +00:00 committed by Andreas Kling
parent ee6b0e144a
commit 02c2b1e67e
6 changed files with 45 additions and 1 deletions

View file

@ -25,6 +25,7 @@
#include <LibWeb/CSS/VisualViewport.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/CDATASection.h>
#include <LibWeb/DOM/Comment.h>
#include <LibWeb/DOM/CustomEvent.h>
#include <LibWeb/DOM/DOMImplementation.h>
@ -1473,6 +1474,21 @@ JS::NonnullGCPtr<Text> Document::create_text_node(String const& data)
return heap().allocate<Text>(realm(), *this, data);
}
// https://dom.spec.whatwg.org/#dom-document-createcdatasection
WebIDL::ExceptionOr<JS::NonnullGCPtr<CDATASection>> Document::create_cdata_section(String const& data)
{
// 1. If this is an HTML document, then throw a "NotSupportedError" DOMException.
if (is_html_document())
return WebIDL::NotSupportedError::create(realm(), "This operation is not supported for HTML documents"_fly_string);
// 2. If data contains the string "]]>", then throw an "InvalidCharacterError" DOMException.
if (data.contains("]]>"sv))
return WebIDL::InvalidCharacterError::create(realm(), "String may not contain ']]>'"_fly_string);
// 3. Return a new CDATASection node with its data set to data and node document set to this.
return heap().allocate<CDATASection>(realm(), *this, data);
}
JS::NonnullGCPtr<Comment> Document::create_comment(String const& data)
{
return heap().allocate<Comment>(realm(), *this, data);