diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 2f4f2572aa..3f880e343a 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -143,14 +143,18 @@ String Node::descendant_text_content() const String Node::text_content() const { // The textContent getter steps are to return the following, switching on the interface this implements: + // If DocumentFragment or Element, return the descendant text content of this. if (is(this) || is(this)) return descendant_text_content(); - else if (is(this)) - // If CharacterData, return this’s data. - return verify_cast(this)->data(); - // FIXME: If this is an Attr node, return this's value. + // If CharacterData, return this’s data. + if (is(this)) + return static_cast(*this).data(); + + // If Attr node, return this's value. + if (is(*this)) + return static_cast(*this).value(); // Otherwise, return null return {}; @@ -165,16 +169,21 @@ void Node::set_text_content(String const& content) // If DocumentFragment or Element, string replace all with the given value within this. if (is(this) || is(this)) { string_replace_all(content); - } else if (is(this)) { - // If CharacterData, replace data with node this, offset 0, count this’s length, and data the given value. + } + + // If CharacterData, replace data with node this, offset 0, count this’s length, and data the given value. + else if (is(this)) { + auto* character_data_node = verify_cast(this); character_data_node->set_data(content); // FIXME: CharacterData::set_data is not spec compliant. Make this match the spec when set_data becomes spec compliant. // Do note that this will make this function able to throw an exception. - } else { - // FIXME: If this is an Attr node, set an existing attribute value with this and the given value. - return; + } + + // If Attr, set an existing attribute value with this and the given value. + if (is(*this)) { + static_cast(*this).set_value(content); } // Otherwise, do nothing.