summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-12-13 13:24:56 +0100
committerAndreas Kling <kling@serenityos.org>2022-12-14 15:21:48 +0100
commit8b0ace62898475ed864317ed684497c2c932a54b (patch)
treea934653e70a9253e408b483fde47699c2738c1eb
parentbf759ce5e3501b8911b3a1fd8ba05037504b489f (diff)
downloadserenity-8b0ace62898475ed864317ed684497c2c932a54b.zip
LibWeb: Add Document.createProcessingInstruction()
These nodes don't really do anything interesting yet, but let's allow creating them. :^)
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.cpp12
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.h2
-rw-r--r--Userland/Libraries/LibWeb/DOM/Document.idl3
3 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 17d2c32d85..bc08f546bd 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -29,6 +29,7 @@
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/HTMLCollection.h>
#include <LibWeb/DOM/NodeIterator.h>
+#include <LibWeb/DOM/ProcessingInstruction.h>
#include <LibWeb/DOM/Range.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/DOM/Text.h>
@@ -1233,6 +1234,17 @@ JS::NonnullGCPtr<Comment> Document::create_comment(DeprecatedString const& data)
return *heap().allocate<Comment>(realm(), *this, data);
}
+// https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction
+WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> Document::create_processing_instruction(DeprecatedString const& target, DeprecatedString const& data)
+{
+ // FIXME: 1. If target does not match the Name production, then throw an "InvalidCharacterError" DOMException.
+
+ // FIXME: 2. If data contains the string "?>", then throw an "InvalidCharacterError" DOMException.
+
+ // 3. Return a new ProcessingInstruction node, with target set to target, data set to data, and node document set to this.
+ return JS::NonnullGCPtr { *heap().allocate<ProcessingInstruction>(realm(), *this, data, target) };
+}
+
JS::NonnullGCPtr<Range> Document::create_range()
{
return Range::create(*this);
diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h
index 50a9461f72..6f2946a8e6 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.h
+++ b/Userland/Libraries/LibWeb/DOM/Document.h
@@ -227,6 +227,8 @@ public:
JS::NonnullGCPtr<DocumentFragment> create_document_fragment();
JS::NonnullGCPtr<Text> create_text_node(DeprecatedString const& data);
JS::NonnullGCPtr<Comment> create_comment(DeprecatedString const& data);
+ WebIDL::ExceptionOr<JS::NonnullGCPtr<ProcessingInstruction>> create_processing_instruction(DeprecatedString const& target, DeprecatedString const& data);
+
WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create_event(DeprecatedString const& interface);
JS::NonnullGCPtr<Range> create_range();
diff --git a/Userland/Libraries/LibWeb/DOM/Document.idl b/Userland/Libraries/LibWeb/DOM/Document.idl
index f4342674f6..9685246f74 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.idl
+++ b/Userland/Libraries/LibWeb/DOM/Document.idl
@@ -12,6 +12,7 @@
#import <DOM/NodeIterator.idl>
#import <DOM/NodeList.idl>
#import <DOM/ParentNode.idl>
+#import <DOM/ProcessingInstruction.idl>
#import <DOM/Range.idl>
#import <DOM/Text.idl>
#import <DOM/TreeWalker.idl>
@@ -78,6 +79,8 @@ interface Document : Node {
DocumentFragment createDocumentFragment();
Text createTextNode(DOMString data);
Comment createComment(DOMString data);
+ [NewObject] ProcessingInstruction createProcessingInstruction(DOMString target, DOMString data);
+
Range createRange();
Event createEvent(DOMString interface);