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 #include #include +#include #include #include #include @@ -1233,6 +1234,17 @@ JS::NonnullGCPtr Document::create_comment(DeprecatedString const& data) return *heap().allocate(realm(), *this, data); } +// https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction +WebIDL::ExceptionOr> 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(realm(), *this, data, target) }; +} + JS::NonnullGCPtr 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 create_document_fragment(); JS::NonnullGCPtr create_text_node(DeprecatedString const& data); JS::NonnullGCPtr create_comment(DeprecatedString const& data); + WebIDL::ExceptionOr> create_processing_instruction(DeprecatedString const& target, DeprecatedString const& data); + WebIDL::ExceptionOr> create_event(DeprecatedString const& interface); JS::NonnullGCPtr 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 #import #import +#import #import #import #import @@ -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);