Serenity Operating System
1/*
2 * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
3 * Copyright (c) 2020, Luke Wilde <lukew@serenityos.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#include <LibWeb/DOM/Document.h>
9#include <LibWeb/DOM/ElementFactory.h>
10#include <LibWeb/HTML/HTMLAnchorElement.h>
11#include <LibWeb/HTML/HTMLAreaElement.h>
12#include <LibWeb/HTML/HTMLAudioElement.h>
13#include <LibWeb/HTML/HTMLBRElement.h>
14#include <LibWeb/HTML/HTMLBaseElement.h>
15#include <LibWeb/HTML/HTMLBlinkElement.h>
16#include <LibWeb/HTML/HTMLBodyElement.h>
17#include <LibWeb/HTML/HTMLButtonElement.h>
18#include <LibWeb/HTML/HTMLCanvasElement.h>
19#include <LibWeb/HTML/HTMLDListElement.h>
20#include <LibWeb/HTML/HTMLDataElement.h>
21#include <LibWeb/HTML/HTMLDataListElement.h>
22#include <LibWeb/HTML/HTMLDetailsElement.h>
23#include <LibWeb/HTML/HTMLDialogElement.h>
24#include <LibWeb/HTML/HTMLDirectoryElement.h>
25#include <LibWeb/HTML/HTMLDivElement.h>
26#include <LibWeb/HTML/HTMLEmbedElement.h>
27#include <LibWeb/HTML/HTMLFieldSetElement.h>
28#include <LibWeb/HTML/HTMLFontElement.h>
29#include <LibWeb/HTML/HTMLFormElement.h>
30#include <LibWeb/HTML/HTMLFrameElement.h>
31#include <LibWeb/HTML/HTMLFrameSetElement.h>
32#include <LibWeb/HTML/HTMLHRElement.h>
33#include <LibWeb/HTML/HTMLHeadElement.h>
34#include <LibWeb/HTML/HTMLHeadingElement.h>
35#include <LibWeb/HTML/HTMLHtmlElement.h>
36#include <LibWeb/HTML/HTMLIFrameElement.h>
37#include <LibWeb/HTML/HTMLImageElement.h>
38#include <LibWeb/HTML/HTMLInputElement.h>
39#include <LibWeb/HTML/HTMLLIElement.h>
40#include <LibWeb/HTML/HTMLLabelElement.h>
41#include <LibWeb/HTML/HTMLLegendElement.h>
42#include <LibWeb/HTML/HTMLLinkElement.h>
43#include <LibWeb/HTML/HTMLMapElement.h>
44#include <LibWeb/HTML/HTMLMarqueeElement.h>
45#include <LibWeb/HTML/HTMLMenuElement.h>
46#include <LibWeb/HTML/HTMLMetaElement.h>
47#include <LibWeb/HTML/HTMLMeterElement.h>
48#include <LibWeb/HTML/HTMLModElement.h>
49#include <LibWeb/HTML/HTMLOListElement.h>
50#include <LibWeb/HTML/HTMLObjectElement.h>
51#include <LibWeb/HTML/HTMLOptGroupElement.h>
52#include <LibWeb/HTML/HTMLOptionElement.h>
53#include <LibWeb/HTML/HTMLOutputElement.h>
54#include <LibWeb/HTML/HTMLParagraphElement.h>
55#include <LibWeb/HTML/HTMLParamElement.h>
56#include <LibWeb/HTML/HTMLPictureElement.h>
57#include <LibWeb/HTML/HTMLPreElement.h>
58#include <LibWeb/HTML/HTMLProgressElement.h>
59#include <LibWeb/HTML/HTMLQuoteElement.h>
60#include <LibWeb/HTML/HTMLScriptElement.h>
61#include <LibWeb/HTML/HTMLSelectElement.h>
62#include <LibWeb/HTML/HTMLSlotElement.h>
63#include <LibWeb/HTML/HTMLSourceElement.h>
64#include <LibWeb/HTML/HTMLSpanElement.h>
65#include <LibWeb/HTML/HTMLStyleElement.h>
66#include <LibWeb/HTML/HTMLTableCaptionElement.h>
67#include <LibWeb/HTML/HTMLTableCellElement.h>
68#include <LibWeb/HTML/HTMLTableColElement.h>
69#include <LibWeb/HTML/HTMLTableElement.h>
70#include <LibWeb/HTML/HTMLTableRowElement.h>
71#include <LibWeb/HTML/HTMLTableSectionElement.h>
72#include <LibWeb/HTML/HTMLTemplateElement.h>
73#include <LibWeb/HTML/HTMLTextAreaElement.h>
74#include <LibWeb/HTML/HTMLTimeElement.h>
75#include <LibWeb/HTML/HTMLTitleElement.h>
76#include <LibWeb/HTML/HTMLTrackElement.h>
77#include <LibWeb/HTML/HTMLUListElement.h>
78#include <LibWeb/HTML/HTMLUnknownElement.h>
79#include <LibWeb/HTML/HTMLVideoElement.h>
80#include <LibWeb/SVG/SVGCircleElement.h>
81#include <LibWeb/SVG/SVGClipPathElement.h>
82#include <LibWeb/SVG/SVGDefsElement.h>
83#include <LibWeb/SVG/SVGEllipseElement.h>
84#include <LibWeb/SVG/SVGForeignObjectElement.h>
85#include <LibWeb/SVG/SVGGElement.h>
86#include <LibWeb/SVG/SVGLineElement.h>
87#include <LibWeb/SVG/SVGPathElement.h>
88#include <LibWeb/SVG/SVGPolygonElement.h>
89#include <LibWeb/SVG/SVGPolylineElement.h>
90#include <LibWeb/SVG/SVGRectElement.h>
91#include <LibWeb/SVG/SVGSVGElement.h>
92#include <LibWeb/SVG/SVGTextContentElement.h>
93#include <LibWeb/SVG/TagNames.h>
94
95namespace Web::DOM {
96
97// https://dom.spec.whatwg.org/#concept-create-element
98WebIDL::ExceptionOr<JS::NonnullGCPtr<Element>> create_element(Document& document, DeprecatedFlyString local_name, DeprecatedFlyString namespace_, DeprecatedFlyString prefix)
99{
100 // 1. If prefix was not given, let prefix be null.
101 // NOTE: This is already taken care of by `prefix` having a default value.
102
103 // FIXME: 2. If is was not given, let is be null.
104 // FIXME: 3. Let result be null.
105 // FIXME: 4. Let definition be the result of looking up a custom element definition given document, namespace, localName, and is.
106 // FIXME: 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: ...
107 // FIXME: 6. Otherwise, if definition is non-null, then: ...
108
109 // 7. Otherwise:
110 // 1. Let interface be the element interface for localName and namespace.
111 // 2. Set result to a new element that implements interface, with no attributes, namespace set to namespace, namespace prefix set to prefix,
112 // local name set to localName, custom element state set to "uncustomized", custom element definition set to null, is value set to is,
113 // and node document set to document.
114 // FIXME: 3. If namespace is the HTML namespace, and either localName is a valid custom element name or is is non-null,
115 // then set result’s custom element state to "undefined".
116 // 8. Return result.
117
118 auto& realm = document.realm();
119 auto lowercase_tag_name = local_name.to_lowercase();
120
121 auto qualified_name = QualifiedName { local_name, prefix, namespace_ };
122 if (lowercase_tag_name == HTML::TagNames::a)
123 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLAnchorElement>(realm, document, move(qualified_name)));
124 if (lowercase_tag_name == HTML::TagNames::area)
125 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLAreaElement>(realm, document, move(qualified_name)));
126 if (lowercase_tag_name == HTML::TagNames::audio)
127 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLAudioElement>(realm, document, move(qualified_name)));
128 if (lowercase_tag_name == HTML::TagNames::base)
129 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLBaseElement>(realm, document, move(qualified_name)));
130 if (lowercase_tag_name == HTML::TagNames::blink)
131 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLBlinkElement>(realm, document, move(qualified_name)));
132 if (lowercase_tag_name == HTML::TagNames::body)
133 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLBodyElement>(realm, document, move(qualified_name)));
134 if (lowercase_tag_name == HTML::TagNames::br)
135 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLBRElement>(realm, document, move(qualified_name)));
136 if (lowercase_tag_name == HTML::TagNames::button)
137 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLButtonElement>(realm, document, move(qualified_name)));
138 if (lowercase_tag_name == HTML::TagNames::canvas)
139 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLCanvasElement>(realm, document, move(qualified_name)));
140 if (lowercase_tag_name == HTML::TagNames::data)
141 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLDataElement>(realm, document, move(qualified_name)));
142 if (lowercase_tag_name == HTML::TagNames::datalist)
143 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLDataListElement>(realm, document, move(qualified_name)));
144 if (lowercase_tag_name == HTML::TagNames::details)
145 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLDetailsElement>(realm, document, move(qualified_name)));
146 if (lowercase_tag_name == HTML::TagNames::dialog)
147 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLDialogElement>(realm, document, move(qualified_name)));
148 if (lowercase_tag_name == HTML::TagNames::dir)
149 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLDirectoryElement>(realm, document, move(qualified_name)));
150 if (lowercase_tag_name == HTML::TagNames::div)
151 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLDivElement>(realm, document, move(qualified_name)));
152 if (lowercase_tag_name == HTML::TagNames::dl)
153 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLDListElement>(realm, document, move(qualified_name)));
154 if (lowercase_tag_name == HTML::TagNames::embed)
155 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLEmbedElement>(realm, document, move(qualified_name)));
156 if (lowercase_tag_name == HTML::TagNames::fieldset)
157 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLFieldSetElement>(realm, document, move(qualified_name)));
158 if (lowercase_tag_name == HTML::TagNames::font)
159 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLFontElement>(realm, document, move(qualified_name)));
160 if (lowercase_tag_name == HTML::TagNames::form)
161 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLFormElement>(realm, document, move(qualified_name)));
162 if (lowercase_tag_name == HTML::TagNames::frame)
163 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLFrameElement>(realm, document, move(qualified_name)));
164 if (lowercase_tag_name == HTML::TagNames::frameset)
165 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLFrameSetElement>(realm, document, move(qualified_name)));
166 if (lowercase_tag_name == HTML::TagNames::head)
167 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLHeadElement>(realm, document, move(qualified_name)));
168 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))
169 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLHeadingElement>(realm, document, move(qualified_name)));
170 if (lowercase_tag_name == HTML::TagNames::hr)
171 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLHRElement>(realm, document, move(qualified_name)));
172 if (lowercase_tag_name == HTML::TagNames::html)
173 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLHtmlElement>(realm, document, move(qualified_name)));
174 if (lowercase_tag_name == HTML::TagNames::iframe)
175 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLIFrameElement>(realm, document, move(qualified_name)));
176 if (lowercase_tag_name == HTML::TagNames::img)
177 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLImageElement>(realm, document, move(qualified_name)));
178 if (lowercase_tag_name == HTML::TagNames::input)
179 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLInputElement>(realm, document, move(qualified_name)));
180 if (lowercase_tag_name == HTML::TagNames::label)
181 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLLabelElement>(realm, document, move(qualified_name)));
182 if (lowercase_tag_name == HTML::TagNames::legend)
183 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLLegendElement>(realm, document, move(qualified_name)));
184 if (lowercase_tag_name == HTML::TagNames::li)
185 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLLIElement>(realm, document, move(qualified_name)));
186 if (lowercase_tag_name == HTML::TagNames::link)
187 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLLinkElement>(realm, document, move(qualified_name)));
188 if (lowercase_tag_name == HTML::TagNames::map)
189 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLMapElement>(realm, document, move(qualified_name)));
190 if (lowercase_tag_name == HTML::TagNames::marquee)
191 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLMarqueeElement>(realm, document, move(qualified_name)));
192 if (lowercase_tag_name == HTML::TagNames::menu)
193 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLMenuElement>(realm, document, move(qualified_name)));
194 if (lowercase_tag_name == HTML::TagNames::meta)
195 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLMetaElement>(realm, document, move(qualified_name)));
196 if (lowercase_tag_name == HTML::TagNames::meter)
197 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLMeterElement>(realm, document, move(qualified_name)));
198 if (lowercase_tag_name.is_one_of(HTML::TagNames::ins, HTML::TagNames::del))
199 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLModElement>(realm, document, move(qualified_name)));
200 if (lowercase_tag_name == HTML::TagNames::object)
201 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLObjectElement>(realm, document, move(qualified_name)));
202 if (lowercase_tag_name == HTML::TagNames::ol)
203 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLOListElement>(realm, document, move(qualified_name)));
204 if (lowercase_tag_name == HTML::TagNames::optgroup)
205 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLOptGroupElement>(realm, document, move(qualified_name)));
206 if (lowercase_tag_name == HTML::TagNames::option)
207 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLOptionElement>(realm, document, move(qualified_name)));
208 if (lowercase_tag_name == HTML::TagNames::output)
209 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLOutputElement>(realm, document, move(qualified_name)));
210 if (lowercase_tag_name == HTML::TagNames::p)
211 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLParagraphElement>(realm, document, move(qualified_name)));
212 if (lowercase_tag_name == HTML::TagNames::param)
213 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLParamElement>(realm, document, move(qualified_name)));
214 if (lowercase_tag_name == HTML::TagNames::picture)
215 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLPictureElement>(realm, document, move(qualified_name)));
216 // NOTE: The obsolete elements "listing" and "xmp" are explicitly mapped to HTMLPreElement in the specification.
217 if (lowercase_tag_name.is_one_of(HTML::TagNames::pre, HTML::TagNames::listing, HTML::TagNames::xmp))
218 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLPreElement>(realm, document, move(qualified_name)));
219 if (lowercase_tag_name == HTML::TagNames::progress)
220 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLProgressElement>(realm, document, move(qualified_name)));
221 if (lowercase_tag_name.is_one_of(HTML::TagNames::blockquote, HTML::TagNames::q))
222 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLQuoteElement>(realm, document, move(qualified_name)));
223 if (lowercase_tag_name == HTML::TagNames::script)
224 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLScriptElement>(realm, document, move(qualified_name)));
225 if (lowercase_tag_name == HTML::TagNames::select)
226 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLSelectElement>(realm, document, move(qualified_name)));
227 if (lowercase_tag_name == HTML::TagNames::slot)
228 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLSlotElement>(realm, document, move(qualified_name)));
229 if (lowercase_tag_name == HTML::TagNames::source)
230 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLSourceElement>(realm, document, move(qualified_name)));
231 if (lowercase_tag_name == HTML::TagNames::span)
232 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLSpanElement>(realm, document, move(qualified_name)));
233 if (lowercase_tag_name == HTML::TagNames::style)
234 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLStyleElement>(realm, document, move(qualified_name)));
235 if (lowercase_tag_name == HTML::TagNames::caption)
236 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTableCaptionElement>(realm, document, move(qualified_name)));
237 if (lowercase_tag_name.is_one_of(Web::HTML::TagNames::td, Web::HTML::TagNames::th))
238 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTableCellElement>(realm, document, move(qualified_name)));
239 if (lowercase_tag_name.is_one_of(HTML::TagNames::colgroup, HTML::TagNames::col))
240 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTableColElement>(realm, document, move(qualified_name)));
241 if (lowercase_tag_name == HTML::TagNames::table)
242 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTableElement>(realm, document, move(qualified_name)));
243 if (lowercase_tag_name == HTML::TagNames::tr)
244 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTableRowElement>(realm, document, move(qualified_name)));
245 if (lowercase_tag_name.is_one_of(HTML::TagNames::tbody, HTML::TagNames::thead, HTML::TagNames::tfoot))
246 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTableSectionElement>(realm, document, move(qualified_name)));
247 if (lowercase_tag_name == HTML::TagNames::template_)
248 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTemplateElement>(realm, document, move(qualified_name)));
249 if (lowercase_tag_name == HTML::TagNames::textarea)
250 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTextAreaElement>(realm, document, move(qualified_name)));
251 if (lowercase_tag_name == HTML::TagNames::time)
252 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTimeElement>(realm, document, move(qualified_name)));
253 if (lowercase_tag_name == HTML::TagNames::title)
254 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTitleElement>(realm, document, move(qualified_name)));
255 if (lowercase_tag_name == HTML::TagNames::track)
256 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLTrackElement>(realm, document, move(qualified_name)));
257 if (lowercase_tag_name == HTML::TagNames::ul)
258 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLUListElement>(realm, document, move(qualified_name)));
259 if (lowercase_tag_name == HTML::TagNames::video)
260 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLVideoElement>(realm, document, move(qualified_name)));
261 if (lowercase_tag_name.is_one_of(
262 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,
263 // Obsolete
264 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))
265 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLElement>(realm, document, move(qualified_name)));
266 if (lowercase_tag_name == SVG::TagNames::svg)
267 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGSVGElement>(realm, document, move(qualified_name)));
268 // FIXME: Support SVG's mixedCase tag names properly.
269 if (lowercase_tag_name.equals_ignoring_ascii_case(SVG::TagNames::clipPath))
270 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGClipPathElement>(realm, document, move(qualified_name)));
271 if (lowercase_tag_name == SVG::TagNames::circle)
272 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGCircleElement>(realm, document, move(qualified_name)));
273 if (lowercase_tag_name.equals_ignoring_ascii_case(SVG::TagNames::defs))
274 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGDefsElement>(realm, document, move(qualified_name)));
275 if (lowercase_tag_name == SVG::TagNames::ellipse)
276 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGEllipseElement>(realm, document, move(qualified_name)));
277 if (lowercase_tag_name.equals_ignoring_ascii_case(SVG::TagNames::foreignObject))
278 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGForeignObjectElement>(realm, document, move(qualified_name)));
279 if (lowercase_tag_name == SVG::TagNames::line)
280 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGLineElement>(realm, document, move(qualified_name)));
281 if (lowercase_tag_name == SVG::TagNames::path)
282 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGPathElement>(realm, document, move(qualified_name)));
283 if (lowercase_tag_name == SVG::TagNames::polygon)
284 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGPolygonElement>(realm, document, move(qualified_name)));
285 if (lowercase_tag_name == SVG::TagNames::polyline)
286 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGPolylineElement>(realm, document, move(qualified_name)));
287 if (lowercase_tag_name == SVG::TagNames::rect)
288 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGRectElement>(realm, document, move(qualified_name)));
289 if (lowercase_tag_name == SVG::TagNames::g)
290 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGGElement>(realm, document, move(qualified_name)));
291 if (lowercase_tag_name == SVG::TagNames::text)
292 return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGTextContentElement>(realm, document, move(qualified_name)));
293
294 // FIXME: If name is a valid custom element name, then return HTMLElement.
295
296 return MUST_OR_THROW_OOM(realm.heap().allocate<HTML::HTMLUnknownElement>(realm, document, move(qualified_name)));
297}
298
299}