Truly independent web browser
LibWeb: Read a new DOMTokenList's attribute without a namespace
Shannon Booth22bb8fea75b9
diff --git a/Libraries/LibWeb/Bindings/Rust/src/dom/dom_token_list.rs b/Libraries/LibWeb/Bindings/Rust/src/dom/dom_token_list.rsindex a308a79c70f..4dc0f8fc29c 100644--- a/Libraries/LibWeb/Bindings/Rust/src/dom/dom_token_list.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/dom/dom_token_list.rs@@ -45,7 +45,7 @@ impl Wrappable for DOMTokenList {impl DOMTokenList {// https://dom.spec.whatwg.org/#ref-for-domtokenlist%E2%91%A0%E2%91%A2- fn new(associated_element: CppElement, associated_attribute: Utf16FlyString, value: Option<Utf16String>) -> Self {+ fn new(associated_element: CppElement, associated_attribute: Utf16FlyString) -> Self {let list = Self {associated_element,associated_attribute,@@ -57,7 +57,10 @@ impl DOMTokenList {// 1. Let element be set’s element.// 2. Let attributeName be set’s attribute name.// 3. Let value be the result of getting an attribute value given element and attributeName.- // NB: The caller gets the attribute value.+ let value = list+ .associated_element+ .get_attribute_ns(None, &list.associated_attribute);+// 4. Run the attribute change steps for element, attributeName, value, value, and null.list.associated_attribute_changed(value);list@@ -444,15 +447,9 @@ fn serialize_ordered_set(token_set: &[Utf16String]) -> Utf16String {/// # Safety///-/// The caller passes a live VM and Element, lends the interned attribute name, and transfers ownership-/// of the initial attribute value if it is nonzero.+/// The caller passes a live VM and Element, and lends the interned attribute name.#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_dom_token_list_create(- vm: &Vm,- element: *mut c_void,- attribute: usize,- value: usize,-) -> *mut c_void {+pub unsafe extern "C" fn web_dom_token_list_create(vm: &Vm, element: *mut c_void, attribute: usize) -> *mut c_void {// SAFETY: The caller passes a live Element and a live, borrowed attribute name.let (element, attribute) = unsafe {(@@ -460,9 +457,7 @@ pub unsafe extern "C" fn web_dom_token_list_create(Utf16FlyString::from_raw_borrowed(attribute),)};- // SAFETY: A nonzero value transfers an ownership reference.- let value = (value != 0).then(|| unsafe { Utf16String::from_raw_owned(value) });- cell_into_abi(allocate(vm, |_| DOMTokenList::new(element, attribute, value)))+ cell_into_abi(allocate(vm, |_| DOMTokenList::new(element, attribute)))}/// # Safetydiff --git a/Libraries/LibWeb/DOM/DOMTokenList.cpp b/Libraries/LibWeb/DOM/DOMTokenList.cppindex fdad19157c2..7e7f37f0e8b 100644--- a/Libraries/LibWeb/DOM/DOMTokenList.cpp+++ b/Libraries/LibWeb/DOM/DOMTokenList.cpp@@ -15,7 +15,7 @@ namespace Web::DOM {extern "C" {// Defined in Bindings/Rust/src/dom/dom_token_list.rs.-void* web_dom_token_list_create(JSVM*, Element*, FlatPtr attribute_name, FlatPtr initial_value);+void* web_dom_token_list_create(JSVM*, Element*, FlatPtr attribute_name);void web_dom_token_list_attribute_changed(DOMTokenList*, FlatPtr value);void web_dom_token_list_add(DOMTokenList*, FlatPtr token);void web_dom_token_list_remove(DOMTokenList*, FlatPtr token);@@ -24,10 +24,8 @@ void web_dom_token_list_toggle(DOMTokenList*, FlatPtr token, bool force);GC::Ref<DOMTokenList> DOMTokenList::create(Element& element, Utf16FlyString const& associated_attribute){- auto value = element.attribute(associated_attribute);return GC::Ref { *static_cast<DOMTokenList*>(web_dom_token_list_create(- JS::HostABI::vm_to_abi(JS::VM::the()), &element, associated_attribute.raw_identity(),- value.has_value() ? value.release_value().into_raw() : 0)) };+ JS::HostABI::vm_to_abi(JS::VM::the()), &element, associated_attribute.raw_identity())) };}void DOMTokenList::associated_attribute_changed(Optional<Utf16String> const& value)diff --git a/Tests/LibWeb/Text/expected/DOM/DOMTokenList-ignores-namespaced-attribute.txt b/Tests/LibWeb/Text/expected/DOM/DOMTokenList-ignores-namespaced-attribute.txtnew file mode 100644index 00000000000..dd01cdaf982--- /dev/null+++ b/Tests/LibWeb/Text/expected/DOM/DOMTokenList-ignores-namespaced-attribute.txt@@ -0,0 +1,3 @@+length: 0+null namespace: bar+urn:x: foodiff --git a/Tests/LibWeb/Text/input/DOM/DOMTokenList-ignores-namespaced-attribute.html b/Tests/LibWeb/Text/input/DOM/DOMTokenList-ignores-namespaced-attribute.htmlnew file mode 100644index 00000000000..2aa69556e73--- /dev/null+++ b/Tests/LibWeb/Text/input/DOM/DOMTokenList-ignores-namespaced-attribute.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ test(() => {+ const element = document.createElement("div");+ element.setAttributeNS("urn:x", "class", "foo");+ const list = element.classList;+ println(`length: ${list.length}`);+ list.add("bar");+ println(`null namespace: ${element.getAttributeNS(null, "class")}`);+ println(`urn:x: ${element.getAttributeNS("urn:x", "class")}`);+ });+</script>