mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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:
parent
d56da8cf9a
commit
335d51d678
Notes:
github-actions[bot]
2024-08-17 05:59:17 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/335d51d6782 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1059 Reviewed-by: https://github.com/shannonbooth
1 changed files with 36 additions and 0 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue