// FIXME: De-duplicate this from the IDL generator.
// 1. If the result of calling IsCallable(V) is false and the conversion to an IDL value is not being performed due to V being assigned to an attribute whose type is a nullable callback function that is annotated with [LegacyTreatNonObjectAsNull], then throw a TypeError.
// 2. Return the IDL callback function type value that represents a reference to the same object that V represents, with the incumbent settings object as the callback context.
// 2. If next is false, then return an IDL sequence value of type sequence<T> of length i, where the value of the element at index j is Sj.
if(!next)
returnsequence_of_strings;
// 3. Let nextItem be ? IteratorValue(next).
autonext_item=TRY(JS::iterator_value(vm,*next));
// 4. Initialize Si to the result of converting nextItem to an IDL value of type T.
// https://webidl.spec.whatwg.org/#es-DOMString
// An ECMAScript value V is converted to an IDL DOMString value by running the following algorithm:
// 1. If V is null and the conversion is to an IDL type associated with the [LegacyNullToEmptyString] extended attribute, then return the DOMString value that represents the empty string.
// NOTE: This doesn't apply.
// 2. Let x be ? ToString(V).
// 3. Return the IDL DOMString value that represents the same sequence of code units as the one the ECMAScript String value x represents.
returnJS::throw_completion(WebIDL::NotSupportedError::create(realm,DeprecatedString::formatted("A custom element with name '{}' is already defined"sv,name)));
// 4. If this CustomElementRegistry contains an entry with constructor constructor, then throw a "NotSupportedError" DOMException.
returnJS::throw_completion(WebIDL::NotSupportedError::create(realm,"The given constructor is already in use by another custom element"sv));
// 5. Let localName be name.
Stringlocal_name=name;
// 6. Let extends be the value of the extends member of options, or null if no such member exists.
auto&extends=options.extends;
// 7. If extends is not null, then:
if(extends.has_value()){
// 1. If extends is a valid custom element name, then throw a "NotSupportedError" DOMException.
if(is_valid_custom_element_name(extends.value()))
returnJS::throw_completion(WebIDL::NotSupportedError::create(realm,DeprecatedString::formatted("'{}' is a custom element name, only non-custom elements can be extended"sv,extends.value())));
// 2. If the element interface for extends and the HTML namespace is HTMLUnknownElement (e.g., if extends does not indicate an element definition in this specification), then throw a "NotSupportedError" DOMException.
// 9. Set this CustomElementRegistry's element definition is running flag.
m_element_definition_is_running=true;
// 10. Let formAssociated be false.
boolform_associated=false;
// 11. Let disableInternals be false.
booldisable_internals=false;
// 12. Let disableShadow be false.
booldisable_shadow=false;
// 13. Let observedAttributes be an empty sequence<DOMString>.
Vector<String>observed_attributes;
// NOTE: This is not in the spec, but is required because of how we catch the exception by using a lambda, meaning we need to define this variable outside of it to use it later.
// 3. Let lifecycleCallbacks be a map with the keys "connectedCallback", "disconnectedCallback", "adoptedCallback", and "attributeChangedCallback", each of which belongs to an entry whose value is null.
// 2. If callbackValue is not undefined, then set the value of the entry in lifecycleCallbacks with key callbackName to the result of converting callbackValue to the Web IDL Function callback type. Rethrow any exceptions from the conversion.
// 2. If observedAttributesIterable is not undefined, then set observedAttributes to the result of converting observedAttributesIterable to a sequence<DOMString>. Rethrow any exceptions from the conversion.
// 8. If disabledFeaturesIterable is not undefined, then set disabledFeatures to the result of converting disabledFeaturesIterable to a sequence<DOMString>. Rethrow any exceptions from the conversion.
// 13. If formAssociated is true, for each of "formAssociatedCallback", "formResetCallback", "formDisabledCallback", and "formStateRestoreCallback" callbackName:
// 2. If callbackValue is not undefined, then set the value of the entry in lifecycleCallbacks with key callbackName to the result of converting callbackValue to the Web IDL Function callback type. Rethrow any exceptions from the conversion.
// Then, perform the following substep, regardless of whether the above steps threw an exception or not:
// 1. Unset this CustomElementRegistry's element definition is running flag.
m_element_definition_is_running=false;
// Finally, if the first set of substeps threw an exception, then rethrow that exception (thus terminating this algorithm). Otherwise, continue onward.
if(maybe_exception.is_throw_completion())
returnmaybe_exception.release_error();
// 15. Let definition be a new custom element definition with name name, local name localName, constructor constructor, observed attributes observedAttributes, lifecycle callbacks lifecycleCallbacks, form-associated formAssociated, disable internals disableInternals, and disable shadow disableShadow.
// 18. Let upgrade candidates be all elements that are shadow-including descendants of document, whose namespace is the HTML namespace and whose local name is localName, in shadow-including tree order.
// Additionally, if extends is non-null, only include elements whose is value is equal to name.