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

LibWeb: Add Document.createProcessingInstruction()

These nodes don't really do anything interesting yet, but let's allow
creating them. :^)
This commit is contained in:
Andreas Kling 2022-12-13 13:24:56 +01:00
parent bf759ce5e3
commit 8b0ace6289
3 changed files with 17 additions and 0 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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);