Skip to main content

script/dom/element/
create.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use html5ever::{LocalName, Prefix, QualName, local_name, ns};
6use js::context::JSContext;
7use js::rust::HandleObject;
8
9use crate::dom::bindings::error::{report_pending_exception, throw_dom_exception};
10use crate::dom::bindings::inheritance::Castable;
11use crate::dom::bindings::reflector::DomGlobal;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::customelementregistry::{
14    CustomElementRegistry, CustomElementState, is_valid_custom_element_name, upgrade_element,
15};
16use crate::dom::document::Document;
17use crate::dom::element::{CustomElementCreationMode, Element, ElementCreator};
18use crate::dom::globalscope::GlobalScope;
19use crate::dom::html::form_controls::htmlinputelement::HTMLInputElement;
20use crate::dom::html::htmlanchorelement::HTMLAnchorElement;
21use crate::dom::html::htmlareaelement::HTMLAreaElement;
22use crate::dom::html::htmlaudioelement::HTMLAudioElement;
23use crate::dom::html::htmlbaseelement::HTMLBaseElement;
24use crate::dom::html::htmlbodyelement::HTMLBodyElement;
25use crate::dom::html::htmlbrelement::HTMLBRElement;
26use crate::dom::html::htmlbuttonelement::HTMLButtonElement;
27use crate::dom::html::htmlcanvaselement::HTMLCanvasElement;
28use crate::dom::html::htmldataelement::HTMLDataElement;
29use crate::dom::html::htmldatalistelement::HTMLDataListElement;
30use crate::dom::html::htmldetailselement::HTMLDetailsElement;
31use crate::dom::html::htmldialogelement::HTMLDialogElement;
32use crate::dom::html::htmldirectoryelement::HTMLDirectoryElement;
33use crate::dom::html::htmldivelement::HTMLDivElement;
34use crate::dom::html::htmldlistelement::HTMLDListElement;
35use crate::dom::html::htmlelement::HTMLElement;
36use crate::dom::html::htmlembedelement::HTMLEmbedElement;
37use crate::dom::html::htmlfieldsetelement::HTMLFieldSetElement;
38use crate::dom::html::htmlfontelement::HTMLFontElement;
39use crate::dom::html::htmlformelement::HTMLFormElement;
40use crate::dom::html::htmlframeelement::HTMLFrameElement;
41use crate::dom::html::htmlframesetelement::HTMLFrameSetElement;
42use crate::dom::html::htmlheadelement::HTMLHeadElement;
43use crate::dom::html::htmlheadingelement::{HTMLHeadingElement, HeadingLevel};
44use crate::dom::html::htmlhrelement::HTMLHRElement;
45use crate::dom::html::htmlhtmlelement::HTMLHtmlElement;
46use crate::dom::html::htmliframeelement::HTMLIFrameElement;
47use crate::dom::html::htmlimageelement::HTMLImageElement;
48use crate::dom::html::htmllabelelement::HTMLLabelElement;
49use crate::dom::html::htmllegendelement::HTMLLegendElement;
50use crate::dom::html::htmllielement::HTMLLIElement;
51use crate::dom::html::htmllinkelement::HTMLLinkElement;
52use crate::dom::html::htmlmapelement::HTMLMapElement;
53use crate::dom::html::htmlmenuelement::HTMLMenuElement;
54use crate::dom::html::htmlmetaelement::HTMLMetaElement;
55use crate::dom::html::htmlmeterelement::HTMLMeterElement;
56use crate::dom::html::htmlmodelement::HTMLModElement;
57use crate::dom::html::htmlobjectelement::HTMLObjectElement;
58use crate::dom::html::htmlolistelement::HTMLOListElement;
59use crate::dom::html::htmloptgroupelement::HTMLOptGroupElement;
60use crate::dom::html::htmloptionelement::HTMLOptionElement;
61use crate::dom::html::htmloutputelement::HTMLOutputElement;
62use crate::dom::html::htmlparagraphelement::HTMLParagraphElement;
63use crate::dom::html::htmlparamelement::HTMLParamElement;
64use crate::dom::html::htmlpictureelement::HTMLPictureElement;
65use crate::dom::html::htmlpreelement::HTMLPreElement;
66use crate::dom::html::htmlprogresselement::HTMLProgressElement;
67use crate::dom::html::htmlquoteelement::HTMLQuoteElement;
68use crate::dom::html::htmlscriptelement::HTMLScriptElement;
69use crate::dom::html::htmlselectelement::HTMLSelectElement;
70use crate::dom::html::htmlslotelement::HTMLSlotElement;
71use crate::dom::html::htmlsourceelement::HTMLSourceElement;
72use crate::dom::html::htmlspanelement::HTMLSpanElement;
73use crate::dom::html::htmlstyleelement::HTMLStyleElement;
74use crate::dom::html::htmltablecaptionelement::HTMLTableCaptionElement;
75use crate::dom::html::htmltablecellelement::HTMLTableCellElement;
76use crate::dom::html::htmltablecolelement::HTMLTableColElement;
77use crate::dom::html::htmltableelement::HTMLTableElement;
78use crate::dom::html::htmltablerowelement::HTMLTableRowElement;
79use crate::dom::html::htmltablesectionelement::HTMLTableSectionElement;
80use crate::dom::html::htmltemplateelement::HTMLTemplateElement;
81use crate::dom::html::htmltextareaelement::HTMLTextAreaElement;
82use crate::dom::html::htmltimeelement::HTMLTimeElement;
83use crate::dom::html::htmltitleelement::HTMLTitleElement;
84use crate::dom::html::htmltrackelement::HTMLTrackElement;
85use crate::dom::html::htmlulistelement::HTMLUListElement;
86use crate::dom::html::htmlunknownelement::HTMLUnknownElement;
87use crate::dom::html::htmlvideoelement::HTMLVideoElement;
88use crate::dom::htmlmarqueeelement::HTMLMarqueeElement;
89use crate::dom::svg::svgcircleelement::SVGCircleElement;
90use crate::dom::svg::svgdefselement::SVGDefsElement;
91use crate::dom::svg::svgelement::SVGElement;
92use crate::dom::svg::svgellipseelement::SVGEllipseElement;
93use crate::dom::svg::svggelement::SVGGElement;
94use crate::dom::svg::svgimageelement::SVGImageElement;
95use crate::dom::svg::svglineargradientelement::SVGLinearGradientElement;
96use crate::dom::svg::svglineelement::SVGLineElement;
97use crate::dom::svg::svgpathelement::SVGPathElement;
98use crate::dom::svg::svgpolygonelement::SVGPolygonElement;
99use crate::dom::svg::svgpolylineelement::SVGPolylineElement;
100use crate::dom::svg::svgradialgradientelement::SVGRadialGradientElement;
101use crate::dom::svg::svgrectelement::SVGRectElement;
102use crate::dom::svg::svgstopelement::SVGStopElement;
103use crate::dom::svg::svgsvgelement::SVGSVGElement;
104use crate::dom::svg::svgsymbolelement::SVGSymbolElement;
105use crate::dom::svg::svguseelement::SVGUseElement;
106use crate::event_loop::script_thread::ScriptThread;
107use crate::realms::enter_auto_realm;
108
109fn create_svg_element(
110    cx: &mut JSContext,
111    name: QualName,
112    prefix: Option<Prefix>,
113    document: &Document,
114    proto: Option<HandleObject>,
115) -> DomRoot<Element> {
116    assert_eq!(name.ns, ns!(svg));
117
118    macro_rules! make(
119        ($ctor:ident) => ({
120            let obj = $ctor::new(cx, name.local, prefix, document, proto);
121            DomRoot::upcast(obj)
122        });
123    );
124
125    match name.local {
126        local_name!("circle") => make!(SVGCircleElement),
127        local_name!("defs") => make!(SVGDefsElement),
128        local_name!("ellipse") => make!(SVGEllipseElement),
129        local_name!("g") => make!(SVGGElement),
130        local_name!("image") => make!(SVGImageElement),
131        local_name!("line") => make!(SVGLineElement),
132        local_name!("linearGradient") => make!(SVGLinearGradientElement),
133        local_name!("path") => make!(SVGPathElement),
134        local_name!("polygon") => make!(SVGPolygonElement),
135        local_name!("polyline") => make!(SVGPolylineElement),
136        local_name!("radialGradient") => make!(SVGRadialGradientElement),
137        local_name!("stop") => make!(SVGStopElement),
138        local_name!("rect") => make!(SVGRectElement),
139        local_name!("svg") => make!(SVGSVGElement),
140        local_name!("symbol") => make!(SVGSymbolElement),
141        local_name!("use") => make!(SVGUseElement),
142        _ => make!(SVGElement),
143    }
144}
145
146/// <https://dom.spec.whatwg.org/#concept-create-element>
147#[expect(clippy::too_many_arguments)]
148fn create_html_element(
149    cx: &mut JSContext,
150    name: QualName,
151    prefix: Option<Prefix>,
152    is: Option<LocalName>,
153    document: &Document,
154    creator: ElementCreator,
155    mode: CustomElementCreationMode,
156    proto: Option<HandleObject>,
157) -> DomRoot<Element> {
158    assert_eq!(name.ns, ns!(html));
159
160    // Step 2. If registry is "default", then set registry
161    // to the result of looking up a custom element registry given document.
162    // TODO: We don't pass in any other value than "default" atm
163    let registry = CustomElementRegistry::lookup_a_custom_element_registry(document.upcast());
164
165    // Step 3. Let definition be the result of looking up a custom element
166    // definition given registry, namespace, localName, and is.
167    let definition = CustomElementRegistry::lookup_custom_element_definition(
168        registry.as_deref(),
169        &name.ns,
170        &name.local,
171        is.as_ref(),
172    );
173
174    // Step 4. If definition is non-null...
175    if let Some(definition) = definition {
176        // ...and definition’s name is not equal to its local name
177        // (i.e., definition represents a customized built-in element):
178        if !definition.is_autonomous() {
179            // Step 4.1. Let interface be the element interface for localName and the HTML namespace.
180            // Step 4.2. Set result to the result of creating an element internal given document,
181            // interface, localName, the HTML namespace, prefix, "undefined", is, and registry.
182            let element = create_native_html_element(cx, name, prefix, document, creator, proto);
183            element.set_is(definition.name.clone());
184            element.set_custom_element_state(CustomElementState::Undefined, cx.no_gc());
185            element.set_custom_element_registry(registry.as_deref(), cx.no_gc());
186
187            match mode {
188                // Step 4.3. If synchronousCustomElements is true, then run this step while catching any exceptions:
189                CustomElementCreationMode::Synchronous => {
190                    // Step 4.3.1. Upgrade result using definition.
191                    upgrade_element(cx, definition, &element);
192                    // TODO: "If this step threw an exception exception:" steps.
193                },
194                // Step 4.4. Otherwise, enqueue a custom element upgrade reaction given result and definition.
195                CustomElementCreationMode::Asynchronous => {
196                    ScriptThread::enqueue_upgrade_reaction(cx, &element, definition)
197                },
198            }
199            return element;
200        } else {
201            // Step 5. Otherwise, if definition is non-null:
202            match mode {
203                // Step 5.1. If synchronousCustomElements is true, then run these
204                // steps while catching any exceptions:
205                CustomElementCreationMode::Synchronous => {
206                    let local_name = name.local;
207                    // TODO(jdm) Pass proto to create_element?
208                    // Steps 4.1.1-4.1.11
209                    return match definition.create_element(
210                        cx,
211                        document,
212                        prefix.clone(),
213                        registry.as_deref(),
214                    ) {
215                        Ok(element) => {
216                            element.set_custom_element_definition(definition.clone(), cx.no_gc());
217                            element
218                        },
219                        Err(error) => {
220                            // If any of these steps threw an exception exception:
221                            let global =
222                                GlobalScope::current().unwrap_or_else(|| document.global());
223
224                            let mut realm = enter_auto_realm(cx, &*global);
225                            let cx = &mut realm.current_realm();
226
227                            // Substep 1. Report exception for definition’s constructor’s corresponding
228                            // JavaScript object’s associated realm’s global object.
229                            throw_dom_exception(cx, &global, error);
230                            report_pending_exception(cx);
231
232                            // Substep 2. Set result to the result of creating an element internal given document,
233                            // HTMLUnknownElement, localName, the HTML namespace, prefix, "failed", null, and registry.
234                            let element = DomRoot::upcast::<Element>(HTMLUnknownElement::new(
235                                cx, local_name, prefix, document, proto,
236                            ));
237                            element
238                                .set_custom_element_state(CustomElementState::Failed, cx.no_gc());
239                            element.set_custom_element_registry(registry.as_deref(), cx.no_gc());
240                            element
241                        },
242                    };
243                },
244                // Step 4.2. Otherwise:
245                CustomElementCreationMode::Asynchronous => {
246                    // Step 4.2.1. Set result to a new element that implements the HTMLElement interface,
247                    // with no attributes, namespace set to the HTML namespace, namespace prefix set to
248                    // prefix, local name set to localName, custom element state set to "undefined",
249                    // custom element definition set to null, is value set to null, and node document
250                    // set to document.
251                    let result = DomRoot::upcast::<Element>(HTMLElement::new(
252                        cx, name.local, prefix, document, proto,
253                    ));
254                    result.set_custom_element_state(CustomElementState::Undefined, cx.no_gc());
255                    result.set_custom_element_registry(registry.as_deref(), cx.no_gc());
256                    // Step 4.2.2. Enqueue a custom element upgrade reaction given result and definition.
257                    ScriptThread::enqueue_upgrade_reaction(cx, &result, definition);
258                    return result;
259                },
260            }
261        }
262    }
263
264    // Step 5. Otherwise:
265    // Step 5.1. Let interface be the element interface for localName and namespace.
266    // Step 5.2. Set result to a new element that implements interface, with no attributes,
267    // namespace set to namespace, namespace prefix set to prefix, local name set to localName,
268    // custom element state set to "uncustomized", custom element definition set to null,
269    // is value set to is, and node document set to document.
270    let result = create_native_html_element(cx, name.clone(), prefix, document, creator, proto);
271    // Step 5.3. If namespace is the HTML namespace, and either localName is a valid custom element name or
272    // is is non-null, then set result’s custom element state to "undefined".
273    match is {
274        Some(is) => {
275            result.set_is(is);
276            result.set_custom_element_state(CustomElementState::Undefined, cx.no_gc());
277            result.set_custom_element_registry(registry.as_deref(), cx.no_gc());
278        },
279        None => {
280            if is_valid_custom_element_name(&name.local) {
281                result.set_custom_element_state(CustomElementState::Undefined, cx.no_gc());
282                result.set_custom_element_registry(registry.as_deref(), cx.no_gc());
283            } else {
284                // Note: This is a performance optimization. See the doc comment of the method for
285                // more information.
286                result.set_initial_custom_element_state_to_uncustomized();
287            }
288        },
289    };
290
291    // Step 6. Return result.
292    result
293}
294
295pub(crate) fn create_native_html_element(
296    cx: &mut JSContext,
297    name: QualName,
298    prefix: Option<Prefix>,
299    document: &Document,
300    creator: ElementCreator,
301    proto: Option<HandleObject>,
302) -> DomRoot<Element> {
303    assert_eq!(name.ns, ns!(html));
304
305    macro_rules! make(
306        ($ctor:ident) => ({
307            let obj = $ctor::new(cx, name.local, prefix, document, proto);
308            DomRoot::upcast(obj)
309        });
310        ($ctor:ident, $($arg:expr),+) => ({
311            let obj = $ctor::new(cx, name.local, prefix, document, proto, $($arg),+);
312            DomRoot::upcast(obj)
313        })
314    );
315
316    // This is a big match, and the IDs for inline-interned atoms are not very structured.
317    // Perhaps we should build a perfect hash from those IDs instead.
318    // https://html.spec.whatwg.org/multipage/#elements-in-the-dom
319    match name.local {
320        local_name!("a") => make!(HTMLAnchorElement),
321        local_name!("abbr") => make!(HTMLElement),
322        local_name!("acronym") => make!(HTMLElement),
323        local_name!("address") => make!(HTMLElement),
324        local_name!("area") => make!(HTMLAreaElement),
325        local_name!("article") => make!(HTMLElement),
326        local_name!("aside") => make!(HTMLElement),
327        local_name!("audio") => make!(HTMLAudioElement),
328        local_name!("b") => make!(HTMLElement),
329        local_name!("base") => make!(HTMLBaseElement),
330        local_name!("bdi") => make!(HTMLElement),
331        local_name!("bdo") => make!(HTMLElement),
332        // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:bgsound
333        local_name!("bgsound") => make!(HTMLUnknownElement),
334        local_name!("big") => make!(HTMLElement),
335        // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:blink
336        local_name!("blink") => make!(HTMLUnknownElement),
337        // https://html.spec.whatwg.org/multipage/#the-blockquote-element
338        local_name!("blockquote") => make!(HTMLQuoteElement),
339        local_name!("body") => make!(HTMLBodyElement),
340        local_name!("br") => make!(HTMLBRElement),
341        local_name!("button") => make!(HTMLButtonElement),
342        local_name!("canvas") => make!(HTMLCanvasElement),
343        local_name!("caption") => make!(HTMLTableCaptionElement),
344        local_name!("center") => make!(HTMLElement),
345        local_name!("cite") => make!(HTMLElement),
346        local_name!("code") => make!(HTMLElement),
347        local_name!("col") => make!(HTMLTableColElement),
348        local_name!("colgroup") => make!(HTMLTableColElement),
349        local_name!("data") => make!(HTMLDataElement),
350        local_name!("datalist") => make!(HTMLDataListElement),
351        local_name!("dd") => make!(HTMLElement),
352        local_name!("del") => make!(HTMLModElement),
353        local_name!("details") => make!(HTMLDetailsElement),
354        local_name!("dfn") => make!(HTMLElement),
355        local_name!("dialog") => make!(HTMLDialogElement),
356        local_name!("dir") => make!(HTMLDirectoryElement),
357        local_name!("div") => make!(HTMLDivElement),
358        local_name!("dl") => make!(HTMLDListElement),
359        local_name!("dt") => make!(HTMLElement),
360        local_name!("em") => make!(HTMLElement),
361        local_name!("embed") => make!(HTMLEmbedElement),
362        local_name!("fieldset") => make!(HTMLFieldSetElement),
363        local_name!("figcaption") => make!(HTMLElement),
364        local_name!("figure") => make!(HTMLElement),
365        local_name!("font") => make!(HTMLFontElement),
366        local_name!("footer") => make!(HTMLElement),
367        local_name!("form") => make!(HTMLFormElement),
368        local_name!("frame") => make!(HTMLFrameElement),
369        local_name!("frameset") => make!(HTMLFrameSetElement),
370        local_name!("h1") => make!(HTMLHeadingElement, HeadingLevel::Heading1),
371        local_name!("h2") => make!(HTMLHeadingElement, HeadingLevel::Heading2),
372        local_name!("h3") => make!(HTMLHeadingElement, HeadingLevel::Heading3),
373        local_name!("h4") => make!(HTMLHeadingElement, HeadingLevel::Heading4),
374        local_name!("h5") => make!(HTMLHeadingElement, HeadingLevel::Heading5),
375        local_name!("h6") => make!(HTMLHeadingElement, HeadingLevel::Heading6),
376        local_name!("head") => make!(HTMLHeadElement),
377        local_name!("header") => make!(HTMLElement),
378        local_name!("hgroup") => make!(HTMLElement),
379        local_name!("hr") => make!(HTMLHRElement),
380        local_name!("html") => make!(HTMLHtmlElement),
381        local_name!("i") => make!(HTMLElement),
382        local_name!("iframe") => make!(HTMLIFrameElement),
383        local_name!("img") => make!(HTMLImageElement, creator),
384        local_name!("input") => make!(HTMLInputElement),
385        local_name!("ins") => make!(HTMLModElement),
386        // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:isindex-2
387        local_name!("isindex") => make!(HTMLUnknownElement),
388        local_name!("kbd") => make!(HTMLElement),
389        // https://html.spec.whatwg.org/multipage/#keygen
390        local_name!("keygen") => make!(HTMLUnknownElement),
391        local_name!("label") => make!(HTMLLabelElement),
392        local_name!("legend") => make!(HTMLLegendElement),
393        local_name!("li") => make!(HTMLLIElement),
394        local_name!("link") => make!(HTMLLinkElement, creator),
395        // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:listing
396        local_name!("listing") => make!(HTMLPreElement),
397        local_name!("main") => make!(HTMLElement),
398        local_name!("map") => make!(HTMLMapElement),
399        local_name!("mark") => make!(HTMLElement),
400        local_name!("marquee") => make!(HTMLMarqueeElement),
401        local_name!("menu") => make!(HTMLMenuElement),
402        local_name!("meta") => make!(HTMLMetaElement),
403        local_name!("meter") => make!(HTMLMeterElement),
404        // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:multicol
405        local_name!("multicol") => make!(HTMLUnknownElement),
406        local_name!("nav") => make!(HTMLElement),
407        // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:nextid
408        local_name!("nextid") => make!(HTMLUnknownElement),
409        local_name!("nobr") => make!(HTMLElement),
410        local_name!("noframes") => make!(HTMLElement),
411        local_name!("noscript") => make!(HTMLElement),
412        local_name!("object") => make!(HTMLObjectElement),
413        local_name!("ol") => make!(HTMLOListElement),
414        local_name!("optgroup") => make!(HTMLOptGroupElement),
415        local_name!("option") => make!(HTMLOptionElement),
416        local_name!("output") => make!(HTMLOutputElement),
417        local_name!("p") => make!(HTMLParagraphElement),
418        local_name!("param") => make!(HTMLParamElement),
419        local_name!("picture") => make!(HTMLPictureElement),
420        local_name!("plaintext") => make!(HTMLPreElement),
421        local_name!("pre") => make!(HTMLPreElement),
422        local_name!("progress") => make!(HTMLProgressElement),
423        local_name!("q") => make!(HTMLQuoteElement),
424        local_name!("rp") => make!(HTMLElement),
425        local_name!("rt") => make!(HTMLElement),
426        local_name!("ruby") => make!(HTMLElement),
427        local_name!("s") => make!(HTMLElement),
428        local_name!("samp") => make!(HTMLElement),
429        local_name!("script") => make!(HTMLScriptElement, creator),
430        local_name!("section") => make!(HTMLElement),
431        local_name!("select") => make!(HTMLSelectElement),
432        local_name!("slot") => make!(HTMLSlotElement),
433        local_name!("small") => make!(HTMLElement),
434        local_name!("source") => make!(HTMLSourceElement),
435        // https://html.spec.whatwg.org/multipage/#other-elements,-attributes-and-apis:spacer
436        local_name!("spacer") => make!(HTMLUnknownElement),
437        local_name!("span") => make!(HTMLSpanElement),
438        local_name!("strike") => make!(HTMLElement),
439        local_name!("strong") => make!(HTMLElement),
440        local_name!("style") => make!(HTMLStyleElement, creator),
441        local_name!("sub") => make!(HTMLElement),
442        local_name!("summary") => make!(HTMLElement),
443        local_name!("sup") => make!(HTMLElement),
444        local_name!("table") => make!(HTMLTableElement),
445        local_name!("tbody") => make!(HTMLTableSectionElement),
446        local_name!("td") => make!(HTMLTableCellElement),
447        local_name!("template") => make!(HTMLTemplateElement),
448        local_name!("textarea") => make!(HTMLTextAreaElement),
449        // https://html.spec.whatwg.org/multipage/#the-tfoot-element:concept-element-dom
450        local_name!("tfoot") => make!(HTMLTableSectionElement),
451        local_name!("th") => make!(HTMLTableCellElement),
452        // https://html.spec.whatwg.org/multipage/#the-thead-element:concept-element-dom
453        local_name!("thead") => make!(HTMLTableSectionElement),
454        local_name!("time") => make!(HTMLTimeElement),
455        local_name!("title") => make!(HTMLTitleElement),
456        local_name!("tr") => make!(HTMLTableRowElement),
457        local_name!("tt") => make!(HTMLElement),
458        local_name!("track") => make!(HTMLTrackElement),
459        local_name!("u") => make!(HTMLElement),
460        local_name!("ul") => make!(HTMLUListElement),
461        local_name!("var") => make!(HTMLElement),
462        local_name!("video") => make!(HTMLVideoElement),
463        local_name!("wbr") => make!(HTMLElement),
464        local_name!("xmp") => make!(HTMLPreElement),
465        _ if is_valid_custom_element_name(&name.local) => make!(HTMLElement),
466        _ => make!(HTMLUnknownElement),
467    }
468}
469
470pub(crate) fn create_element(
471    cx: &mut JSContext,
472    name: QualName,
473    is: Option<LocalName>,
474    document: &Document,
475    creator: ElementCreator,
476    mode: CustomElementCreationMode,
477    proto: Option<HandleObject>,
478) -> DomRoot<Element> {
479    let prefix = name.prefix.clone();
480    match name.ns {
481        ns!(html) => create_html_element(cx, name, prefix, is, document, creator, mode, proto),
482        ns!(svg) => create_svg_element(cx, name, prefix, document, proto),
483        _ => Element::new(cx, name.local, name.ns, prefix, document, proto),
484    }
485}