summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2022-07-11 16:23:50 +0100
committerAndreas Kling <kling@serenityos.org>2022-07-11 22:35:08 +0200
commitee719870c84c90769c831ef3a8678aa72a219947 (patch)
treecddec2bf3137201ca4af1978c11dd4a0283a94c5 /Userland/Libraries/LibWeb
parentaf5b4ae1c49e106b26324e85e76c25c118765dc9 (diff)
downloadserenity-ee719870c84c90769c831ef3a8678aa72a219947.zip
LibWeb: Implement CharacterData.{append,insert,delete}Data
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/DOM/CharacterData.cpp21
-rw-r--r--Userland/Libraries/LibWeb/DOM/CharacterData.h3
-rw-r--r--Userland/Libraries/LibWeb/DOM/CharacterData.idl3
3 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/CharacterData.cpp b/Userland/Libraries/LibWeb/DOM/CharacterData.cpp
index 13ba46eacb..aaf5e79e6f 100644
--- a/Userland/Libraries/LibWeb/DOM/CharacterData.cpp
+++ b/Userland/Libraries/LibWeb/DOM/CharacterData.cpp
@@ -103,4 +103,25 @@ ExceptionOr<void> CharacterData::replace_data(size_t offset, size_t count, Strin
return {};
}
+// https://dom.spec.whatwg.org/#dom-characterdata-appenddata
+ExceptionOr<void> CharacterData::append_data(String const& data)
+{
+ // The appendData(data) method steps are to replace data with node this, offset thisโ€™s length, count 0, and data data.
+ return replace_data(m_data.length(), 0, data);
+}
+
+// https://dom.spec.whatwg.org/#dom-characterdata-insertdata
+ExceptionOr<void> CharacterData::insert_data(size_t offset, String const& data)
+{
+ // The insertData(offset, data) method steps are to replace data with node this, offset offset, count 0, and data data.
+ return replace_data(offset, 0, data);
+}
+
+// https://dom.spec.whatwg.org/#dom-characterdata-deletedata
+ExceptionOr<void> CharacterData::delete_data(size_t offset, size_t count)
+{
+ // The deleteData(offset, count) method steps are to replace data with node this, offset offset, count count, and data the empty string.
+ return replace_data(offset, count, String::empty());
+}
+
}
diff --git a/Userland/Libraries/LibWeb/DOM/CharacterData.h b/Userland/Libraries/LibWeb/DOM/CharacterData.h
index d72d5bdfc4..5765ee3f3d 100644
--- a/Userland/Libraries/LibWeb/DOM/CharacterData.h
+++ b/Userland/Libraries/LibWeb/DOM/CharacterData.h
@@ -28,6 +28,9 @@ public:
unsigned length() const { return m_data.length(); }
ExceptionOr<String> substring_data(size_t offset, size_t count) const;
+ ExceptionOr<void> append_data(String const&);
+ ExceptionOr<void> insert_data(size_t offset, String const&);
+ ExceptionOr<void> delete_data(size_t offset, size_t count);
ExceptionOr<void> replace_data(size_t offset, size_t count, String const&);
protected:
diff --git a/Userland/Libraries/LibWeb/DOM/CharacterData.idl b/Userland/Libraries/LibWeb/DOM/CharacterData.idl
index 15b7af0825..856f9c16a3 100644
--- a/Userland/Libraries/LibWeb/DOM/CharacterData.idl
+++ b/Userland/Libraries/LibWeb/DOM/CharacterData.idl
@@ -7,6 +7,9 @@ interface CharacterData : Node {
readonly attribute unsigned long length;
DOMString substringData(unsigned long offset, unsigned long count);
+ undefined appendData(DOMString data);
+ undefined insertData(unsigned long offset, DOMString data);
+ undefined deleteData(unsigned long offset, unsigned long count);
undefined replaceData(unsigned long offset, unsigned long count, DOMString data);
readonly attribute Element? nextElementSibling;