Skip to content

Commit

Permalink
Make Attr.nodeValue/textContent not nullable
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=249323
rdar://problem/103602803

Reviewed by Chris Dumez.

This patch aligns WebKit with Gecko / Firefox and Blink / Chromium.

Inspired: https://chromium.googlesource.com/chromium/blink/+/a7c3bb9f22401c30e906a3ec53595247e707de83

This patch updates Attr value for 'nodeVAlue' and 'textContent' to
return empty string if null.

Web-Spec: https://dom.spec.whatwg.org/#interface-attr

* Source/WebCore/dom/Attr.cpp:
(Attr::setNodeValue): As per commit message
* LayoutTests/fast/dom/coreDOM-element-attribute-js-null.xhtml: Rebaselined
* LayoutTests/fast/dom/coreDOM-element-attribute-js-null-expected.txt: Rebaselined

Canonical link: https://commits.webkit.org/265769@main
  • Loading branch information
Ahmad-S792 authored and cdumez committed Jul 5, 2023
1 parent 8e5e36c commit 2da4c96
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
This test setting various attributes of a elements to JavaScript null.

TEST SUCCEEDED: The value was the string 'null'. [tested Attr.value]
TEST SUCCEEDED: The value was the empty string. [tested Attr.nodeValue]
TEST SUCCEEDED: The value was the empty string. [tested Attr.textContent]

TEST SUCCEEDED: The value was the empty string. [tested ProcessingInstruction.data]

Expand Down
4 changes: 3 additions & 1 deletion LayoutTests/fast/dom/coreDOM-element-attribute-js-null.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@
type: 'Attr',
elementToUse: document.createAttributeNS('http://www.w3.org/1999/xhtml','anAttribute'),
attributes: [
{name: 'value', expectedNull: 'null'}
{name: 'value', expectedNull: 'null'},
{name: 'nodeValue', expectedNull: ''},
{name: 'textContent', expectedNull: ''}
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void Attr::setValue(const AtomString& value)

void Attr::setNodeValue(const String& value)
{
setValue(AtomString { value });
setValue(value.isNull() ? emptyAtom() : AtomString(value));
}

Ref<Node> Attr::cloneNodeInternal(Document& targetDocument, CloningOperation)
Expand Down

0 comments on commit 2da4c96

Please sign in to comment.