2020-01-18 09:38:21 +01:00
/*
2022-08-28 13:42:07 +02:00
* Copyright ( c ) 2018 - 2022 , Andreas Kling < kling @ serenityos . org >
2023-03-29 23:46:18 +01:00
* Copyright ( c ) 2020 - 2023 , Luke Wilde < lukew @ serenityos . org >
2020-01-18 09:38:21 +01:00
*
2021-04-22 01:24:48 -07:00
* SPDX - License - Identifier : BSD - 2 - Clause
2020-01-18 09:38:21 +01:00
*/
2022-08-28 13:42:07 +02:00
# include <LibWeb/DOM/Document.h>
2020-03-07 10:32:51 +01:00
# include <LibWeb/DOM/ElementFactory.h>
2023-03-29 23:46:18 +01:00
# include <LibWeb/HTML/CustomElements/CustomElementDefinition.h>
2023-03-23 04:28:25 -04:00
# include <LibWeb/HTML/CustomElements/CustomElementName.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLAnchorElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLAreaElement.h>
# include <LibWeb/HTML/HTMLAudioElement.h>
2020-09-18 09:49:51 +02:00
# include <LibWeb/HTML/HTMLBRElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLBaseElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLBlinkElement.h>
# include <LibWeb/HTML/HTMLBodyElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLButtonElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLCanvasElement.h>
2020-09-18 09:49:51 +02:00
# include <LibWeb/HTML/HTMLDListElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLDataElement.h>
# include <LibWeb/HTML/HTMLDataListElement.h>
# include <LibWeb/HTML/HTMLDetailsElement.h>
# include <LibWeb/HTML/HTMLDialogElement.h>
2020-11-12 04:16:41 +00:00
# include <LibWeb/HTML/HTMLDirectoryElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLDivElement.h>
# include <LibWeb/HTML/HTMLEmbedElement.h>
# include <LibWeb/HTML/HTMLFieldSetElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLFontElement.h>
# include <LibWeb/HTML/HTMLFormElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLFrameElement.h>
# include <LibWeb/HTML/HTMLFrameSetElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLHRElement.h>
# include <LibWeb/HTML/HTMLHeadElement.h>
# include <LibWeb/HTML/HTMLHeadingElement.h>
# include <LibWeb/HTML/HTMLHtmlElement.h>
# include <LibWeb/HTML/HTMLIFrameElement.h>
# include <LibWeb/HTML/HTMLImageElement.h>
# include <LibWeb/HTML/HTMLInputElement.h>
2020-09-18 09:49:51 +02:00
# include <LibWeb/HTML/HTMLLIElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLLabelElement.h>
# include <LibWeb/HTML/HTMLLegendElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLLinkElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLMapElement.h>
# include <LibWeb/HTML/HTMLMarqueeElement.h>
# include <LibWeb/HTML/HTMLMenuElement.h>
# include <LibWeb/HTML/HTMLMetaElement.h>
# include <LibWeb/HTML/HTMLMeterElement.h>
# include <LibWeb/HTML/HTMLModElement.h>
# include <LibWeb/HTML/HTMLOListElement.h>
2020-09-18 09:49:51 +02:00
# include <LibWeb/HTML/HTMLObjectElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLOptGroupElement.h>
# include <LibWeb/HTML/HTMLOptionElement.h>
# include <LibWeb/HTML/HTMLOutputElement.h>
# include <LibWeb/HTML/HTMLParagraphElement.h>
# include <LibWeb/HTML/HTMLParamElement.h>
# include <LibWeb/HTML/HTMLPictureElement.h>
# include <LibWeb/HTML/HTMLPreElement.h>
# include <LibWeb/HTML/HTMLProgressElement.h>
# include <LibWeb/HTML/HTMLQuoteElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLScriptElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLSelectElement.h>
# include <LibWeb/HTML/HTMLSlotElement.h>
# include <LibWeb/HTML/HTMLSourceElement.h>
# include <LibWeb/HTML/HTMLSpanElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLStyleElement.h>
2023-06-02 21:08:14 +02:00
# include <LibWeb/HTML/HTMLSummaryElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLTableCaptionElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLTableCellElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLTableColElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLTableElement.h>
# include <LibWeb/HTML/HTMLTableRowElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLTableSectionElement.h>
# include <LibWeb/HTML/HTMLTemplateElement.h>
2020-09-18 09:49:51 +02:00
# include <LibWeb/HTML/HTMLTextAreaElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLTimeElement.h>
2020-07-26 15:08:16 +02:00
# include <LibWeb/HTML/HTMLTitleElement.h>
2020-09-18 09:49:51 +02:00
# include <LibWeb/HTML/HTMLTrackElement.h>
2020-08-09 17:10:41 +01:00
# include <LibWeb/HTML/HTMLUListElement.h>
# include <LibWeb/HTML/HTMLUnknownElement.h>
# include <LibWeb/HTML/HTMLVideoElement.h>
2023-03-29 23:46:18 +01:00
# include <LibWeb/HTML/Scripting/ExceptionReporter.h>
# include <LibWeb/Namespace.h>
2022-02-11 16:14:58 +00:00
# include <LibWeb/SVG/SVGCircleElement.h>
2022-04-10 19:05:12 +02:00
# include <LibWeb/SVG/SVGClipPathElement.h>
2022-04-11 16:59:03 +02:00
# include <LibWeb/SVG/SVGDefsElement.h>
2022-02-11 16:45:59 +00:00
# include <LibWeb/SVG/SVGEllipseElement.h>
2022-11-10 13:49:26 +01:00
# include <LibWeb/SVG/SVGForeignObjectElement.h>
2021-09-18 00:04:19 +02:00
# include <LibWeb/SVG/SVGGElement.h>
2022-02-11 16:56:36 +00:00
# include <LibWeb/SVG/SVGLineElement.h>
2023-04-22 18:51:00 +01:00
# include <LibWeb/SVG/SVGLinearGradientElement.h>
2023-08-10 09:55:15 +02:00
# include <LibWeb/SVG/SVGMaskElement.h>
2020-07-23 09:44:42 -07:00
# include <LibWeb/SVG/SVGPathElement.h>
2022-02-11 17:36:05 +00:00
# include <LibWeb/SVG/SVGPolygonElement.h>
2022-02-11 17:28:24 +00:00
# include <LibWeb/SVG/SVGPolylineElement.h>
2023-05-02 23:11:58 +01:00
# include <LibWeb/SVG/SVGRadialGradientElement.h>
2022-02-11 15:52:42 +00:00
# include <LibWeb/SVG/SVGRectElement.h>
2020-07-23 09:44:42 -07:00
# include <LibWeb/SVG/SVGSVGElement.h>
2023-04-20 18:51:00 +01:00
# include <LibWeb/SVG/SVGStopElement.h>
2023-06-08 17:48:33 +01:00
# include <LibWeb/SVG/SVGStyleElement.h>
2023-05-31 00:50:12 +01:00
# include <LibWeb/SVG/SVGSymbolElement.h>
2023-07-22 19:34:51 +01:00
# include <LibWeb/SVG/SVGTSpanElement.h>
2023-07-22 19:24:55 +01:00
# include <LibWeb/SVG/SVGTextElement.h>
2023-06-08 11:46:44 -04:00
# include <LibWeb/SVG/SVGTitleElement.h>
2023-05-30 21:23:52 +01:00
# include <LibWeb/SVG/SVGUseElement.h>
2020-07-23 09:44:42 -07:00
# include <LibWeb/SVG/TagNames.h>
2023-03-29 23:46:18 +01:00
# include <LibWeb/WebIDL/AbstractOperations.h>
2019-10-12 13:02:38 +02:00
2020-07-26 19:37:56 +02:00
namespace Web : : DOM {
2020-03-07 10:27:02 +01:00
2023-03-29 23:46:18 +01:00
ErrorOr < FixedArray < DeprecatedFlyString > > valid_local_names_for_given_html_element_interface ( StringView html_element_interface_name )
2019-10-12 13:02:38 +02:00
{
2023-03-29 23:46:18 +01:00
if ( html_element_interface_name = = " HTMLAnchorElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : a } ) ;
if ( html_element_interface_name = = " HTMLAreaElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : area } ) ;
if ( html_element_interface_name = = " HTMLAudioElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : audio } ) ;
if ( html_element_interface_name = = " HTMLBaseElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : base } ) ;
if ( html_element_interface_name = = " HTMLBodyElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : body } ) ;
if ( html_element_interface_name = = " HTMLBRElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : br } ) ;
if ( html_element_interface_name = = " HTMLButtonElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : button } ) ;
if ( html_element_interface_name = = " HTMLCanvasElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : canvas } ) ;
if ( html_element_interface_name = = " HTMLDataElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : data } ) ;
if ( html_element_interface_name = = " HTMLDataListElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : datalist } ) ;
if ( html_element_interface_name = = " HTMLDetailsElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : details } ) ;
if ( html_element_interface_name = = " HTMLDialogElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : dialog } ) ;
if ( html_element_interface_name = = " HTMLDirectoryElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : dir } ) ;
if ( html_element_interface_name = = " HTMLDivElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : div } ) ;
if ( html_element_interface_name = = " HTMLDListElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : dl } ) ;
if ( html_element_interface_name = = " HTMLEmbedElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : embed } ) ;
if ( html_element_interface_name = = " HTMLFieldsetElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : fieldset } ) ;
if ( html_element_interface_name = = " HTMLFontElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : font } ) ;
if ( html_element_interface_name = = " HTMLFormElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : form } ) ;
if ( html_element_interface_name = = " HTMLFrameElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : frame } ) ;
if ( html_element_interface_name = = " HTMLFrameSetElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : frameset } ) ;
if ( html_element_interface_name = = " HTMLHeadElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : head } ) ;
if ( html_element_interface_name = = " HTMLHeadingElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : h1 , HTML : : TagNames : : h2 , HTML : : TagNames : : h3 , HTML : : TagNames : : h4 , HTML : : TagNames : : h5 , HTML : : TagNames : : h6 } ) ;
if ( html_element_interface_name = = " HTMLHRElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : hr } ) ;
if ( html_element_interface_name = = " HTMLHtmlElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : html } ) ;
if ( html_element_interface_name = = " HTMLIFrameElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : iframe } ) ;
if ( html_element_interface_name = = " HTMLImageElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : img } ) ;
if ( html_element_interface_name = = " HTMLInputElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : input } ) ;
if ( html_element_interface_name = = " HTMLLabelElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : label } ) ;
if ( html_element_interface_name = = " HTMLLIElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : li } ) ;
if ( html_element_interface_name = = " HTMLLinkElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : link } ) ;
if ( html_element_interface_name = = " HTMLMapElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : map } ) ;
if ( html_element_interface_name = = " HTMLMarqueeElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : marquee } ) ;
if ( html_element_interface_name = = " HTMLMenuElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : menu } ) ;
if ( html_element_interface_name = = " HTMLMeterElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : meter } ) ;
if ( html_element_interface_name = = " HTMLModElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : ins , HTML : : TagNames : : del } ) ;
if ( html_element_interface_name = = " HTMLObjectElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : object } ) ;
if ( html_element_interface_name = = " HTMLOutputElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : output } ) ;
if ( html_element_interface_name = = " HTMLParagraphElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : p } ) ;
if ( html_element_interface_name = = " HTMLParamElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : param } ) ;
if ( html_element_interface_name = = " HTMLPictureElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : picture } ) ;
if ( html_element_interface_name = = " HTMLPreElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : pre , HTML : : TagNames : : listing , HTML : : TagNames : : xmp } ) ;
if ( html_element_interface_name = = " HTMLProgressElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : progress } ) ;
if ( html_element_interface_name = = " HTMLQuoteElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : blockquote , HTML : : TagNames : : q } ) ;
if ( html_element_interface_name = = " HTMLScriptElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : script } ) ;
if ( html_element_interface_name = = " HTMLSelectElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : select } ) ;
if ( html_element_interface_name = = " HTMLSlotElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : slot } ) ;
if ( html_element_interface_name = = " HTMLSourceElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : source } ) ;
if ( html_element_interface_name = = " HTMLSpanElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : span } ) ;
if ( html_element_interface_name = = " HTMLStyleElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : style } ) ;
if ( html_element_interface_name = = " HTMLTableCaptionElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : caption } ) ;
if ( html_element_interface_name = = " HTMLTableCellElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : td , HTML : : TagNames : : th } ) ;
if ( html_element_interface_name = = " HTMLTableColElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : colgroup , HTML : : TagNames : : col } ) ;
if ( html_element_interface_name = = " HTMLTableElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : table } ) ;
if ( html_element_interface_name = = " HTMLTableSectionElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : tbody , HTML : : TagNames : : thead , HTML : : TagNames : : tfoot } ) ;
if ( html_element_interface_name = = " HTMLTemplateElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : template_ } ) ;
if ( html_element_interface_name = = " HTMLTextAreaElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : textarea } ) ;
if ( html_element_interface_name = = " HTMLTimeElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : time } ) ;
if ( html_element_interface_name = = " HTMLTitleElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : title } ) ;
if ( html_element_interface_name = = " HTMLTrackElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : track } ) ;
if ( html_element_interface_name = = " HTMLUListElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : ul } ) ;
if ( html_element_interface_name = = " HTMLVideoElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : video } ) ;
if ( html_element_interface_name = = " HTMLElement " sv )
return FixedArray < DeprecatedFlyString > : : create ( { HTML : : TagNames : : article , HTML : : TagNames : : section , HTML : : TagNames : : nav , HTML : : TagNames : : aside , HTML : : TagNames : : hgroup , HTML : : TagNames : : header , HTML : : TagNames : : footer , HTML : : TagNames : : address , HTML : : TagNames : : dt , HTML : : TagNames : : dd , HTML : : TagNames : : figure , HTML : : TagNames : : figcaption , HTML : : TagNames : : main , HTML : : TagNames : : em , HTML : : TagNames : : strong , HTML : : TagNames : : small , HTML : : TagNames : : s , HTML : : TagNames : : cite , HTML : : TagNames : : dfn , HTML : : TagNames : : abbr , HTML : : TagNames : : ruby , HTML : : TagNames : : rt , HTML : : TagNames : : rp , HTML : : TagNames : : code , HTML : : TagNames : : var , HTML : : TagNames : : samp , HTML : : TagNames : : kbd , HTML : : TagNames : : sub , HTML : : TagNames : : sup , HTML : : TagNames : : i , HTML : : TagNames : : b , HTML : : TagNames : : u , HTML : : TagNames : : mark , HTML : : TagNames : : bdi , HTML : : TagNames : : bdo , HTML : : TagNames : : wbr , HTML : : TagNames : : summary , HTML : : TagNames : : noscript , HTML : : TagNames : : acronym , HTML : : TagNames : : basefont , HTML : : TagNames : : big , HTML : : TagNames : : center , HTML : : TagNames : : nobr , HTML : : TagNames : : noembed , HTML : : TagNames : : noframes , HTML : : TagNames : : plaintext , HTML : : TagNames : : rb , HTML : : TagNames : : rtc , HTML : : TagNames : : strike , HTML : : TagNames : : tt } ) ;
return FixedArray < DeprecatedFlyString > : : create ( { } ) ;
}
2022-02-25 21:29:12 +01:00
2023-03-29 23:46:18 +01:00
// https://html.spec.whatwg.org/multipage/dom.html#elements-in-the-dom%3Aelement-interface
bool is_unknown_html_element ( DeprecatedFlyString const & tag_name )
{
// NOTE: This is intentionally case-sensitive.
2022-02-25 21:29:12 +01:00
2023-03-29 23:46:18 +01:00
// 1. If name is applet, bgsound, blink, isindex, keygen, multicol, nextid, or spacer, then return HTMLUnknownElement.
if ( tag_name . is_one_of ( HTML : : TagNames : : applet , HTML : : TagNames : : bgsound , HTML : : TagNames : : blink , HTML : : TagNames : : isindex , HTML : : TagNames : : keygen , HTML : : TagNames : : multicol , HTML : : TagNames : : nextid , HTML : : TagNames : : spacer ) )
return true ;
2022-03-02 10:55:16 +01:00
2023-03-29 23:46:18 +01:00
// 2. If name is acronym, basefont, big, center, nobr, noembed, noframes, plaintext, rb, rtc, strike, or tt, then return HTMLElement.
// 3. If name is listing or xmp, then return HTMLPreElement.
// 4. Otherwise, if this specification defines an interface appropriate for the element type corresponding to the local name name, then return that interface.
// 5. If other applicable specifications define an appropriate interface for name, then return the interface they define.
# define __ENUMERATE_HTML_TAG(name) \
if ( tag_name = = HTML : : TagNames : : name ) \
return false ;
ENUMERATE_HTML_TAGS
# undef __ENUMERATE_HTML_TAG
// 6. If name is a valid custom element name, then return HTMLElement.
if ( HTML : : is_valid_custom_element_name ( tag_name ) )
return false ;
// 7. Return HTMLUnknownElement.
return true ;
}
// https://html.spec.whatwg.org/#elements-in-the-dom:element-interface
static WebIDL : : ExceptionOr < JS : : NonnullGCPtr < Element > > create_html_element ( JS : : Realm & realm , Document & document , QualifiedName qualified_name )
{
auto lowercase_tag_name = qualified_name . local_name ( ) . to_lowercase ( ) ;
2022-03-02 10:55:16 +01:00
2020-06-07 23:27:03 +02:00
if ( lowercase_tag_name = = HTML : : TagNames : : a )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLAnchorElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : area )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLAreaElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : audio )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLAudioElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : base )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLBaseElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : blink )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLBlinkElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-06-07 23:27:03 +02:00
if ( lowercase_tag_name = = HTML : : TagNames : : body )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLBodyElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : br )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLBRElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : button )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLButtonElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : canvas )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLCanvasElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : data )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLDataElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : datalist )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLDataListElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : details )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLDetailsElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : dialog )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLDialogElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-11-12 04:16:41 +00:00
if ( lowercase_tag_name = = HTML : : TagNames : : dir )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLDirectoryElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : div )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLDivElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : dl )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLDListElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : embed )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLEmbedElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : fieldset )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLFieldSetElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-06-07 23:27:03 +02:00
if ( lowercase_tag_name = = HTML : : TagNames : : font )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLFontElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : form )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLFormElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : frame )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLFrameElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : frameset )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLFrameSetElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : head )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLHeadElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name . is_one_of ( HTML : : TagNames : : h1 , HTML : : TagNames : : h2 , HTML : : TagNames : : h3 , HTML : : TagNames : : h4 , HTML : : TagNames : : h5 , HTML : : TagNames : : h6 ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLHeadingElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-06-07 23:27:03 +02:00
if ( lowercase_tag_name = = HTML : : TagNames : : hr )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLHRElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : html )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLHtmlElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : iframe )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLIFrameElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-06-07 23:27:03 +02:00
if ( lowercase_tag_name = = HTML : : TagNames : : img )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLImageElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-06-07 23:27:03 +02:00
if ( lowercase_tag_name = = HTML : : TagNames : : input )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLInputElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : label )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLLabelElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : legend )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLLegendElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : li )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLLIElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : link )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLLinkElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : map )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLMapElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : marquee )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLMarqueeElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : menu )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLMenuElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : meta )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLMetaElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : meter )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLMeterElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name . is_one_of ( HTML : : TagNames : : ins , HTML : : TagNames : : del ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLModElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : object )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLObjectElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : ol )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLOListElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : optgroup )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLOptGroupElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : option )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLOptionElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : output )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLOutputElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : p )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLParagraphElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : param )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLParamElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : picture )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLPictureElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
// NOTE: The obsolete elements "listing" and "xmp" are explicitly mapped to HTMLPreElement in the specification.
if ( lowercase_tag_name . is_one_of ( HTML : : TagNames : : pre , HTML : : TagNames : : listing , HTML : : TagNames : : xmp ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLPreElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : progress )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLProgressElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name . is_one_of ( HTML : : TagNames : : blockquote , HTML : : TagNames : : q ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLQuoteElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : script )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLScriptElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : select )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLSelectElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : slot )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLSlotElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : source )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLSourceElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : span )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLSpanElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : style )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLStyleElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-06-02 21:08:14 +02:00
if ( lowercase_tag_name = = HTML : : TagNames : : summary )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLSummaryElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : caption )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTableCaptionElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name . is_one_of ( Web : : HTML : : TagNames : : td , Web : : HTML : : TagNames : : th ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTableCellElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name . is_one_of ( HTML : : TagNames : : colgroup , HTML : : TagNames : : col ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTableColElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-06-07 23:27:03 +02:00
if ( lowercase_tag_name = = HTML : : TagNames : : table )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTableElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-06-07 23:27:03 +02:00
if ( lowercase_tag_name = = HTML : : TagNames : : tr )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTableRowElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name . is_one_of ( HTML : : TagNames : : tbody , HTML : : TagNames : : thead , HTML : : TagNames : : tfoot ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTableSectionElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : template_ )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTemplateElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : textarea )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTextAreaElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : time )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTimeElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : title )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTitleElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : track )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLTrackElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : ul )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLUListElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name = = HTML : : TagNames : : video )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLVideoElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
if ( lowercase_tag_name . is_one_of (
2023-06-02 21:08:14 +02:00
HTML : : TagNames : : article , HTML : : TagNames : : section , HTML : : TagNames : : nav , HTML : : TagNames : : aside , HTML : : TagNames : : hgroup , HTML : : TagNames : : header , HTML : : TagNames : : footer , HTML : : TagNames : : address , HTML : : TagNames : : dt , HTML : : TagNames : : dd , HTML : : TagNames : : figure , HTML : : TagNames : : figcaption , HTML : : TagNames : : main , HTML : : TagNames : : em , HTML : : TagNames : : strong , HTML : : TagNames : : small , HTML : : TagNames : : s , HTML : : TagNames : : cite , HTML : : TagNames : : dfn , HTML : : TagNames : : abbr , HTML : : TagNames : : ruby , HTML : : TagNames : : rt , HTML : : TagNames : : rp , HTML : : TagNames : : code , HTML : : TagNames : : var , HTML : : TagNames : : samp , HTML : : TagNames : : kbd , HTML : : TagNames : : sub , HTML : : TagNames : : sup , HTML : : TagNames : : i , HTML : : TagNames : : b , HTML : : TagNames : : u , HTML : : TagNames : : mark , HTML : : TagNames : : bdi , HTML : : TagNames : : bdo , HTML : : TagNames : : wbr , HTML : : TagNames : : noscript ,
2020-09-18 09:49:51 +02:00
// Obsolete
HTML : : TagNames : : acronym , HTML : : TagNames : : basefont , HTML : : TagNames : : big , HTML : : TagNames : : center , HTML : : TagNames : : nobr , HTML : : TagNames : : noembed , HTML : : TagNames : : noframes , HTML : : TagNames : : plaintext , HTML : : TagNames : : rb , HTML : : TagNames : : rtc , HTML : : TagNames : : strike , HTML : : TagNames : : tt ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( HTML : : is_valid_custom_element_name ( qualified_name . local_name ( ) ) )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLElement > ( realm , document , move ( qualified_name ) ) ) ;
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < HTML : : HTMLUnknownElement > ( realm , document , move ( qualified_name ) ) ) ;
}
static WebIDL : : ExceptionOr < JS : : GCPtr < SVG : : SVGElement > > create_svg_element ( JS : : Realm & realm , Document & document , QualifiedName qualified_name )
{
auto const & local_name = qualified_name . local_name ( ) ;
if ( local_name = = SVG : : TagNames : : svg )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGSVGElement > ( realm , document , move ( qualified_name ) ) ) ;
2022-04-10 19:05:12 +02:00
// FIXME: Support SVG's mixedCase tag names properly.
2023-03-29 23:46:18 +01:00
if ( local_name . equals_ignoring_ascii_case ( SVG : : TagNames : : clipPath ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGClipPathElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name = = SVG : : TagNames : : circle )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGCircleElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name . equals_ignoring_ascii_case ( SVG : : TagNames : : defs ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGDefsElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name = = SVG : : TagNames : : ellipse )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGEllipseElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name . equals_ignoring_ascii_case ( SVG : : TagNames : : foreignObject ) )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGForeignObjectElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name = = SVG : : TagNames : : line )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGLineElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-04-22 18:51:00 +01:00
if ( local_name = = SVG : : TagNames : : linearGradient )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGLinearGradientElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-08-10 09:55:15 +02:00
if ( local_name = = SVG : : TagNames : : mask )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGMaskElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name = = SVG : : TagNames : : path )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGPathElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name = = SVG : : TagNames : : polygon )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGPolygonElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name = = SVG : : TagNames : : polyline )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGPolylineElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-05-02 23:11:58 +01:00
if ( local_name = = SVG : : TagNames : : radialGradient )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGRadialGradientElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name = = SVG : : TagNames : : rect )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGRectElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name = = SVG : : TagNames : : g )
2023-02-19 16:22:24 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGGElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-04-20 18:51:00 +01:00
if ( local_name = = SVG : : TagNames : : stop )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGStopElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-06-08 17:48:33 +01:00
if ( local_name = = SVG : : TagNames : : style )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGStyleElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-05-31 00:50:12 +01:00
if ( local_name = = SVG : : TagNames : : symbol )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGSymbolElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-03-29 23:46:18 +01:00
if ( local_name = = SVG : : TagNames : : text )
2023-07-22 19:24:55 +01:00
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGTextElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-06-08 11:46:44 -04:00
if ( local_name = = SVG : : TagNames : : title )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGTitleElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-07-22 19:34:51 +01:00
if ( local_name = = SVG : : TagNames : : tspan )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGTSpanElement > ( realm , document , move ( qualified_name ) ) ) ;
2023-05-30 21:23:52 +01:00
if ( local_name = = SVG : : TagNames : : use )
return MUST_OR_THROW_OOM ( realm . heap ( ) . allocate < SVG : : SVGUseElement > ( realm , document , move ( qualified_name ) ) ) ;
2020-08-09 17:10:41 +01:00
2023-03-29 23:46:18 +01:00
return nullptr ;
}
// https://dom.spec.whatwg.org/#concept-create-element
WebIDL : : ExceptionOr < JS : : NonnullGCPtr < Element > > create_element ( Document & document , DeprecatedFlyString local_name , DeprecatedFlyString namespace_ , DeprecatedFlyString prefix , Optional < String > is_value , bool synchronous_custom_elements_flag )
{
auto & realm = document . realm ( ) ;
// 1. If prefix was not given, let prefix be null.
// NOTE: This is already taken care of by `prefix` having a default value.
// 2. If is was not given, let is be null.
// NOTE: This is already taken care of by `is` having a default value.
// 3. Let result be null.
// NOTE: We collapse this into just returning an element where necessary.
// 4. Let definition be the result of looking up a custom element definition given document, namespace, localName, and is.
auto definition = document . lookup_custom_element_definition ( namespace_ , local_name , is_value ) ;
// 5. If definition is non-null, and definition’ s name is not equal to its local name (i.e., definition represents a customized built-in element), then:
if ( definition & & definition - > name ( ) ! = definition - > local_name ( ) ) {
// 1. Let interface be the element interface for localName and the HTML namespace.
// 2. Set result to a new element that implements interface, with no attributes, namespace set to the HTML namespace,
// namespace prefix set to prefix, local name set to localName, custom element state set to "undefined", custom element definition set to null,
// is value set to is, and node document set to document.
auto element = TRY ( create_html_element ( realm , document , QualifiedName { local_name , prefix , Namespace : : HTML } ) ) ;
// 3. If the synchronous custom elements flag is set, then run this step while catching any exceptions:
if ( synchronous_custom_elements_flag ) {
// 1. Upgrade element using definition.
auto upgrade_result = element - > upgrade_element ( * definition ) ;
// If this step threw an exception, then:
if ( upgrade_result . is_throw_completion ( ) ) {
// 1. Report the exception.
HTML : : report_exception ( upgrade_result , realm ) ;
// 2. Set result’ s custom element state to "failed".
element - > set_custom_element_state ( CustomElementState : : Failed ) ;
}
}
// 4. Otherwise, enqueue a custom element upgrade reaction given result and definition.
else {
element - > enqueue_a_custom_element_upgrade_reaction ( * definition ) ;
}
return element ;
2023-03-23 04:28:25 -04:00
}
2023-03-29 23:46:18 +01:00
// 6. Otherwise, if definition is non-null, then:
if ( definition ) {
// 1. If the synchronous custom elements flag is set, then run these steps while catching any exceptions:
if ( synchronous_custom_elements_flag ) {
auto synchronously_upgrade_custom_element = [ & ] ( ) - > JS : : ThrowCompletionOr < JS : : NonnullGCPtr < HTML : : HTMLElement > > {
auto & vm = document . vm ( ) ;
// 1. Let C be definition’ s constructor.
auto & constructor = definition - > constructor ( ) ;
// 2. Set result to the result of constructing C, with no arguments.
auto result = TRY ( WebIDL : : construct ( constructor ) ) ;
// FIXME: 3. Assert: result’ s custom element state and custom element definition are initialized.
// FIXME: 4. Assert: result’ s namespace is the HTML namespace.
// Spec Note: IDL enforces that result is an HTMLElement object, which all use the HTML namespace.
// IDL does not currently convert the object for us, so we will have to do it here.
if ( ! result . has_value ( ) | | ! result - > is_object ( ) | | ! is < HTML : : HTMLElement > ( result - > as_object ( ) ) )
return vm . throw_completion < JS : : TypeError > ( JS : : ErrorType : : NotAnObjectOfType , " HTMLElement " sv ) ;
JS : : NonnullGCPtr < HTML : : HTMLElement > element = verify_cast < HTML : : HTMLElement > ( result - > as_object ( ) ) ;
// 5. If result’ s attribute list is not empty, then throw a "NotSupportedError" DOMException.
if ( element - > has_attributes ( ) )
return JS : : throw_completion ( WebIDL : : NotSupportedError : : create ( realm , " Synchronously created custom element cannot have attributes " sv ) ) ;
// 6. If result has children, then throw a "NotSupportedError" DOMException.
if ( element - > has_children ( ) )
return JS : : throw_completion ( WebIDL : : NotSupportedError : : create ( realm , " Synchronously created custom element cannot have children " sv ) ) ;
// 7. If result’ s parent is not null, then throw a "NotSupportedError" DOMException.
if ( element - > parent ( ) )
return JS : : throw_completion ( WebIDL : : NotSupportedError : : create ( realm , " Synchronously created custom element cannot have a parent " sv ) ) ;
// 8. If result’ s node document is not document, then throw a "NotSupportedError" DOMException.
if ( & element - > document ( ) ! = & document )
return JS : : throw_completion ( WebIDL : : NotSupportedError : : create ( realm , " Synchronously created custom element must be in the same document that element creation was invoked in " sv ) ) ;
// 9. If result’ s local name is not equal to localName, then throw a "NotSupportedError" DOMException.
if ( element - > local_name ( ) ! = local_name )
return JS : : throw_completion ( WebIDL : : NotSupportedError : : create ( realm , " Synchronously created custom element must have the same local name that element creation was invoked with " sv ) ) ;
// 10. Set result’ s namespace prefix to prefix.
element - > set_prefix ( prefix ) ;
// 11. Set result’ s is value to null.
element - > set_is_value ( Optional < String > { } ) ;
return element ;
} ;
auto result = synchronously_upgrade_custom_element ( ) ;
// If any of these steps threw an exception, then:
if ( result . is_throw_completion ( ) ) {
// 1. Report the exception.
HTML : : report_exception ( result , realm ) ;
// 2. Set result to a new element that implements the HTMLUnknownElement interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix,
// local name set to localName, custom element state set to "failed", custom element definition set to null, is value set to null, and node document set to document.
JS : : NonnullGCPtr < Element > element = realm . heap ( ) . allocate < HTML : : HTMLUnknownElement > ( realm , document , QualifiedName { local_name , prefix , Namespace : : HTML } ) . release_allocated_value_but_fixme_should_propagate_errors ( ) ;
element - > set_custom_element_state ( CustomElementState : : Failed ) ;
return element ;
}
return result . release_value ( ) ;
}
// 2. Otherwise:
// 1. Set result to a new element that implements the HTMLElement interface, with no attributes, namespace set to the HTML namespace, namespace prefix set to prefix,
// local name set to localName, custom element state set to "undefined", custom element definition set to null, is value set to null, and node document set to document.
JS : : NonnullGCPtr < Element > element = realm . heap ( ) . allocate < HTML : : HTMLElement > ( realm , document , QualifiedName { local_name , prefix , Namespace : : HTML } ) . release_allocated_value_but_fixme_should_propagate_errors ( ) ;
element - > set_custom_element_state ( CustomElementState : : Undefined ) ;
// 2. Enqueue a custom element upgrade reaction given result and definition.
element - > enqueue_a_custom_element_upgrade_reaction ( * definition ) ;
return element ;
}
// 7. Otherwise:
// 1. Let interface be the element interface for localName and namespace.
// 2. Set result to a new element that implements interface, with no attributes, namespace set to namespace, namespace prefix set to prefix,
// local name set to localName, custom element state set to "uncustomized", custom element definition set to null, is value set to is,
// and node document set to document.
auto qualified_name = QualifiedName { local_name , prefix , namespace_ } ;
if ( namespace_ = = Namespace : : HTML ) {
auto element = TRY ( create_html_element ( realm , document , move ( qualified_name ) ) ) ;
element - > set_is_value ( move ( is_value ) ) ;
element - > set_custom_element_state ( CustomElementState : : Uncustomized ) ;
// 3. If namespace is the HTML namespace, and either localName is a valid custom element name or is is non-null,
// then set result’ s custom element state to "undefined".
if ( HTML : : is_valid_custom_element_name ( local_name ) | | is_value . has_value ( ) )
element - > set_custom_element_state ( CustomElementState : : Undefined ) ;
return element ;
}
if ( namespace_ = = Namespace : : SVG ) {
auto element = TRY ( create_svg_element ( realm , document , qualified_name ) ) ;
if ( element ) {
element - > set_is_value ( move ( is_value ) ) ;
element - > set_custom_element_state ( CustomElementState : : Uncustomized ) ;
return JS : : NonnullGCPtr < Element > { * element } ;
}
}
// 8. Return result.
// NOTE: See step 3.
// https://dom.spec.whatwg.org/#concept-element-interface
// The element interface for any name and namespace is Element, unless stated otherwise.
dbgln ( " Potential FIXME: Creating unknown generic element '{}' in namespace '{}' " , local_name , namespace_ ) ;
JS : : NonnullGCPtr < Element > element = realm . heap ( ) . allocate < DOM : : Element > ( realm , document , move ( qualified_name ) ) . release_allocated_value_but_fixme_should_propagate_errors ( ) ;
element - > set_is_value ( move ( is_value ) ) ;
element - > set_custom_element_state ( CustomElementState : : Uncustomized ) ;
return element ;
2019-10-12 13:02:38 +02:00
}
2020-03-07 10:27:02 +01:00
}