1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-01 11:39:22 +00:00

LibWeb: Added HTMLLinkElement.as

(cherry picked from commit 2f4668edce2effb38563b9da229d00d3ba5dc508,
manually amended to move `||` at the start of the line to appease
clang-format)
This commit is contained in:
Hexeption 2024-06-04 08:04:44 +01:00 committed by Nico Weber
parent 5e4e39d84a
commit 928576e0ac
5 changed files with 48 additions and 1 deletions

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Link AS test</title>
</head>
<body>
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'https://fonts.googleapis.com/css?family=Roboto:400,700';
link.as = 'style';
console.log("Link.as: " + link.as); // should be 'style'
link.as = 'uwu';
console.log("Link.as: " + link.as); // should be ''
</script>
</body>
</html>

View File

@ -25,6 +25,7 @@ namespace AttributeNames {
__ENUMERATE_HTML_ATTRIBUTE(alt) \
__ENUMERATE_HTML_ATTRIBUTE(archive) \
__ENUMERATE_HTML_ATTRIBUTE(async) \
__ENUMERATE_HTML_ATTRIBUTE(as) \
__ENUMERATE_HTML_ATTRIBUTE(autocomplete) \
__ENUMERATE_HTML_ATTRIBUTE(autofocus) \
__ENUMERATE_HTML_ATTRIBUTE(autoplay) \

View File

@ -90,6 +90,29 @@ void HTMLLinkElement::inserted()
}
}
// https://html.spec.whatwg.org/multipage/semantics.html#dom-link-as
String HTMLLinkElement::as() const
{
String attribute_value = get_attribute_value(HTML::AttributeNames::as);
if (attribute_value.equals_ignoring_ascii_case("fetch"sv)
|| attribute_value.equals_ignoring_ascii_case("image"sv)
|| attribute_value.equals_ignoring_ascii_case("script"sv)
|| attribute_value.equals_ignoring_ascii_case("style"sv)
|| attribute_value.equals_ignoring_ascii_case("video"sv)
|| attribute_value.equals_ignoring_ascii_case("audio"sv)
|| attribute_value.equals_ignoring_ascii_case("track"sv)
|| attribute_value.equals_ignoring_ascii_case("font"sv))
return attribute_value.to_lowercase().release_value();
return String {};
}
WebIDL::ExceptionOr<void> HTMLLinkElement::set_as(String const& value)
{
return set_attribute(HTML::AttributeNames::as, move(value));
}
// https://html.spec.whatwg.org/multipage/semantics.html#dom-link-rellist
JS::NonnullGCPtr<DOM::DOMTokenList> HTMLLinkElement::rel_list()
{

View File

@ -33,6 +33,8 @@ public:
String rel() const { return get_attribute_value(HTML::AttributeNames::rel); }
String type() const { return get_attribute_value(HTML::AttributeNames::type); }
String href() const { return get_attribute_value(HTML::AttributeNames::href); }
String as() const;
WebIDL::ExceptionOr<void> set_as(String const&);
JS::NonnullGCPtr<DOM::DOMTokenList> rel_list();

View File

@ -12,7 +12,7 @@ interface HTMLLinkElement : HTMLElement {
[CEReactions, Reflect] attribute DOMString href;
[CEReactions, Reflect=crossorigin, Enumerated=CORSSettingsAttribute] attribute DOMString? crossOrigin;
[CEReactions, Reflect] attribute DOMString rel;
[FIXME, CEReactions] attribute DOMString as;
[CEReactions] attribute DOMString as;
[SameObject, PutForwards=value] readonly attribute DOMTokenList relList;
[CEReactions, Reflect] attribute DOMString media;
[CEReactions, Reflect] attribute DOMString integrity;