Skip to content

Commit

Permalink
LibWeb: Implement HTMLScriptElement.async
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Apr 14, 2024
1 parent d47a36a commit d5d66c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,34 @@ void HTMLScriptElement::unmark_as_parser_inserted(Badge<DOM::Range>)
m_parser_document = nullptr;
}

// https://html.spec.whatwg.org/multipage/scripting.html#dom-script-async
bool HTMLScriptElement::async() const
{
// 1. If this's force async is true, then return true.
if (m_force_async)
return true;

// 2. If this's async content attribute is present, then return true.
if (has_attribute(HTML::AttributeNames::async))
return true;

// 3. Return false.
return false;
}

void HTMLScriptElement::set_async(bool async)
{
// 1. Set this's force async to false.
m_force_async = false;

// 2. If the given value is true, then set this's async content attribute to the empty string.
if (async) {
MUST(set_attribute(HTML::AttributeNames::async, ""_string));
}
// 3. Otherwise, remove this's async content attribute.
else {
remove_attribute(HTML::AttributeNames::async);
}
}

}
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class HTMLScriptElement final : public HTMLElement {
String text() { return child_text_content(); }
void set_text(String const& text) { string_replace_all(text); }

[[nodiscard]] bool async() const;
void set_async(bool);

private:
HTMLScriptElement(DOM::Document&, DOM::QualifiedName);

Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/HTML/HTMLScriptElement.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface HTMLScriptElement : HTMLElement {
[CEReactions, Reflect] attribute DOMString src;
[CEReactions, Reflect] attribute DOMString type;
[CEReactions, Reflect=nomodule] attribute boolean noModule;
// FIXME: [CEReactions] attribute boolean async;
[CEReactions] attribute boolean async;
[CEReactions, Reflect] attribute boolean defer;
[CEReactions, Reflect=crossorigin, Enumerated=CORSSettingsAttribute] attribute DOMString? crossOrigin;
[CEReactions] attribute DOMString text;
Expand Down

0 comments on commit d5d66c5

Please sign in to comment.