IDLGenerators: Make USVString attribute reflection spec compliant

USVString attributes Now replace any surrogates with the replacement
character U+FFFD and resolve any relative URLs to an absolute URL. This
brings our implementation in line with the specification.
This commit is contained in:
Tim Ledbetter 2024-08-13 11:22:08 +01:00 committed by Andreas Kling
parent d56da8cf9a
commit 335d51d678
Notes: github-actions[bot] 2024-08-17 05:59:17 +00:00

View file

@ -3635,6 +3635,41 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.getter_callback@)
}
}
}
)~~~");
}
// If a reflected IDL attribute has the type USVString:
else if (attribute.type->name() == "USVString") {
// The getter steps are:
// 1. Let element be the result of running this's get the element.
// NOTE: this is "impl" above
// 2. Let contentAttributeValue be the result of running this's get the content attribute.
attribute_generator.append(R"~~~(
auto content_attribute_value = impl->attribute(HTML::AttributeNames::@attribute.reflect_name@);
)~~~");
// 3. Let attributeDefinition be the attribute definition of element's content attribute whose namespace is null and local name is the reflected content attribute name.
// NOTE: this is "attribute" above
// 4. If attributeDefinition indicates it contains a URL:
if (attribute.extended_attributes.contains("URL")) {
// 1. If contentAttributeValue is null, then return the empty string.
// 2. Let urlString be the result of encoding-parsing-and-serializing a URL given contentAttributeValue, relative to element's node document.
// 3. If urlString is not failure, then return urlString.
attribute_generator.append(R"~~~(
if (!content_attribute_value.has_value())
return JS::PrimitiveString::create(vm, String {});
auto url_string = impl->document().parse_url(*content_attribute_value);
if (url_string.is_valid())
return JS::PrimitiveString::create(vm, MUST(url_string.to_string()));
)~~~");
}
// 5. Return contentAttributeValue, converted to a scalar value string.
attribute_generator.append(R"~~~(
String retval;
if (content_attribute_value.has_value())
retval = MUST(Infra::convert_to_scalar_value_string(*content_attribute_value));
)~~~");
} else {
attribute_generator.append(R"~~~(
@ -4615,6 +4650,7 @@ void generate_prototype_implementation(IDL::Interface const& interface, StringBu
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/Infra/Strings.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/Buffers.h>
#include <LibWeb/WebIDL/Tracing.h>