#include <AK/TypeCasts.h>
#include <AK/Variant.h>
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Promise.h>
#include <LibJS/Runtime/VM.h>
#include <LibJS/Runtime/Value.h>
#include <LibJS/Runtime/ValueInlines.h>
#include <LibWeb/Bindings/EventTarget.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/MediaStreamConstraints.h>
#include <LibWeb/Bindings/MediaStreamTrack.h>
#include <LibWeb/MediaCapture/MediaStreamTrack.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/Promise.h>
#include <LibWeb/WebIDL/Tracing.h>
#include <LibWeb/WebIDL/Types.h>

namespace Web::Bindings {

void MediaStreamTrackConstructor::initialize(JS::Realm& realm, JS::NativeFunction& object)
{
    auto& vm = realm.vm();
    [[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable;

    object.set_prototype(&ensure_web_constructor<EventTargetPrototype>(realm, "EventTarget"_fly_string));
    object.define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
    object.define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "MediaStreamTrack"_utf16), JS::Attribute::Configurable);
    object.define_direct_property(vm.names.prototype, &ensure_web_prototype<MediaStreamTrackPrototype>(realm, "MediaStreamTrack"_fly_string), 0);
}

JS::ThrowCompletionOr<GC::Ref<JS::Object>> MediaStreamTrackConstructor::construct([[maybe_unused]] InterfaceConstructor& constructor, [[maybe_unused]] JS::FunctionObject& new_target)
{
    WebIDL::log_trace(constructor.vm(), "MediaStreamTrackConstructor::construct");
    return constructor.vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "MediaStreamTrack");
}

void MediaStreamTrackPrototype::initialize(JS::Realm& realm, JS::Object& object)
{
    [[maybe_unused]] auto& vm = realm.vm();
    [[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable | JS::Attribute::Configurable | JS::Attribute::Writable;

    object.set_prototype(GC::Ref { ensure_web_prototype<EventTargetPrototype>(realm, "EventTarget"_fly_string) });

    auto kind_id = "kind"_utf16_fly_string;
    auto native_kind_getter = JS::NativeFunction::create(realm, kind_getter, 0, kind_id, &realm, "get"sv);
    GC::Ptr<JS::NativeFunction> native_kind_setter;

    // 4. Let configurable be false if attr is unforgeable and true otherwise.
    auto kind_attributes = default_attributes;

    // 5. Let desc be the PropertyDescriptor{[[Get]]: getter, [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: configurable}.

    // 7. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_accessor(kind_id, native_kind_getter, native_kind_setter, kind_attributes);

    // 8. FIXME: If attr’s type is an observable array type with type argument T, then set target’s backing observable array exotic object for attr to the result of creating an observable array exotic object in realm, given T, attr’s set an indexed value algorithm, and attr’s delete an indexed value algorithm.
    auto id_id = "id"_utf16_fly_string;
    auto native_id_getter = JS::NativeFunction::create(realm, id_getter, 0, id_id, &realm, "get"sv);
    GC::Ptr<JS::NativeFunction> native_id_setter;

    // 4. Let configurable be false if attr is unforgeable and true otherwise.
    auto id_attributes = default_attributes;

    // 5. Let desc be the PropertyDescriptor{[[Get]]: getter, [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: configurable}.

    // 7. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_accessor(id_id, native_id_getter, native_id_setter, id_attributes);

    // 8. FIXME: If attr’s type is an observable array type with type argument T, then set target’s backing observable array exotic object for attr to the result of creating an observable array exotic object in realm, given T, attr’s set an indexed value algorithm, and attr’s delete an indexed value algorithm.
    auto label_id = "label"_utf16_fly_string;
    auto native_label_getter = JS::NativeFunction::create(realm, label_getter, 0, label_id, &realm, "get"sv);
    GC::Ptr<JS::NativeFunction> native_label_setter;

    // 4. Let configurable be false if attr is unforgeable and true otherwise.
    auto label_attributes = default_attributes;

    // 5. Let desc be the PropertyDescriptor{[[Get]]: getter, [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: configurable}.

    // 7. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_accessor(label_id, native_label_getter, native_label_setter, label_attributes);

    // 8. FIXME: If attr’s type is an observable array type with type argument T, then set target’s backing observable array exotic object for attr to the result of creating an observable array exotic object in realm, given T, attr’s set an indexed value algorithm, and attr’s delete an indexed value algorithm.
    auto enabled_id = "enabled"_utf16_fly_string;
    auto native_enabled_getter = JS::NativeFunction::create(realm, enabled_getter, 0, enabled_id, &realm, "get"sv);
    auto native_enabled_setter = JS::NativeFunction::create(realm, enabled_setter, 1, enabled_id, &realm, "set"sv);

    // 4. Let configurable be false if attr is unforgeable and true otherwise.
    auto enabled_attributes = default_attributes;

    // 5. Let desc be the PropertyDescriptor{[[Get]]: getter, [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: configurable}.

    // 7. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_accessor(enabled_id, native_enabled_getter, native_enabled_setter, enabled_attributes);

    // 8. FIXME: If attr’s type is an observable array type with type argument T, then set target’s backing observable array exotic object for attr to the result of creating an observable array exotic object in realm, given T, attr’s set an indexed value algorithm, and attr’s delete an indexed value algorithm.
    auto muted_id = "muted"_utf16_fly_string;
    auto native_muted_getter = JS::NativeFunction::create(realm, muted_getter, 0, muted_id, &realm, "get"sv);
    GC::Ptr<JS::NativeFunction> native_muted_setter;

    // 4. Let configurable be false if attr is unforgeable and true otherwise.
    auto muted_attributes = default_attributes;

    // 5. Let desc be the PropertyDescriptor{[[Get]]: getter, [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: configurable}.

    // 7. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_accessor(muted_id, native_muted_getter, native_muted_setter, muted_attributes);

    // 8. FIXME: If attr’s type is an observable array type with type argument T, then set target’s backing observable array exotic object for attr to the result of creating an observable array exotic object in realm, given T, attr’s set an indexed value algorithm, and attr’s delete an indexed value algorithm.
    auto ready_state_id = "readyState"_utf16_fly_string;
    auto native_ready_state_getter = JS::NativeFunction::create(realm, ready_state_getter, 0, ready_state_id, &realm, "get"sv);
    GC::Ptr<JS::NativeFunction> native_ready_state_setter;

    // 4. Let configurable be false if attr is unforgeable and true otherwise.
    auto ready_state_attributes = default_attributes;

    // 5. Let desc be the PropertyDescriptor{[[Get]]: getter, [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: configurable}.

    // 7. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_accessor(ready_state_id, native_ready_state_getter, native_ready_state_setter, ready_state_attributes);

    // 8. FIXME: If attr’s type is an observable array type with type argument T, then set target’s backing observable array exotic object for attr to the result of creating an observable array exotic object in realm, given T, attr’s set an indexed value algorithm, and attr’s delete an indexed value algorithm.
    object.define_native_function(realm, "stop"_utf16_fly_string, stop, 0, default_attributes);

    object.define_native_function(realm, "getCapabilities"_utf16_fly_string, get_capabilities, 0, default_attributes);

    object.define_native_function(realm, "getConstraints"_utf16_fly_string, get_constraints, 0, default_attributes);

    object.define_native_function(realm, "getSettings"_utf16_fly_string, get_settings, 0, default_attributes);

    object.define_native_function(realm, "applyConstraints"_utf16_fly_string, apply_constraints, 0, default_attributes);

    object.define_direct_property(vm.well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm, "MediaStreamTrack"_utf16), JS::Attribute::Configurable);
}

void MediaStreamTrackPrototype::define_unforgeable_attributes(JS::Realm& realm, [[maybe_unused]] JS::Object& object)
{
    [[maybe_unused]] auto& vm = realm.vm();
    [[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable;
}

[[maybe_unused]] static JS::ThrowCompletionOr<MediaCapture::MediaStreamTrack*> impl_from(JS::VM& vm, JS::Value js_value)
{

    if (auto impl = js_value.as_if<MediaCapture::MediaStreamTrack>())
        return impl.ptr();
    return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "MediaStreamTrack");
}

[[maybe_unused]] static JS::ThrowCompletionOr<MediaCapture::MediaStreamTrack*> impl_from(JS::VM& vm)
{
    auto this_value = vm.this_value();
    if (this_value.is_nullish())
        this_value = &vm.current_realm()->global_object();
    return impl_from(vm, this_value);
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::kind_getter)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::kind_getter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    auto* idl_object = TRY(impl_from(vm));


    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->kind(); }));

    return JS::PrimitiveString::create(vm, idl_enum_to_string(R));
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::id_getter)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::id_getter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    auto* idl_object = TRY(impl_from(vm));


    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->id(); }));

    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::label_getter)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::label_getter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    auto* idl_object = TRY(impl_from(vm));


    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->label(); }));

    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::enabled_getter)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::enabled_getter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    auto* idl_object = TRY(impl_from(vm));


    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->enabled(); }));

    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::muted_getter)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::muted_getter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    auto* idl_object = TRY(impl_from(vm));


    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->muted(); }));

    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::ready_state_getter)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::ready_state_getter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    auto* idl_object = TRY(impl_from(vm));


    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->ready_state(); }));

    return JS::PrimitiveString::create(vm, idl_enum_to_string(R));
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::enabled_setter)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::enabled_setter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    // 1. Let V be undefined.
    auto V = JS::js_undefined();

    // 2. If any arguments were passed, then set V to the value of the first argument passed.
    if (vm.argument_count() > 0)
        V = vm.argument(0);

    // 3. Let id be attribute’s identifier.

    // 4. Let idlObject be null.
    [[maybe_unused]] MediaCapture::MediaStreamTrack* idl_object = nullptr;

    // 5. If attribute is a regular attribute:

    // 1. Let jsValue be the this value, if it is not null or undefined, or realm’s global object otherwise. (This will subsequently cause a TypeError in a few steps, if the global object does not implement target and [LegacyLenientThis] is not specified.)
    auto js_value = vm.this_value();
    if (js_value.is_nullish())
        js_value = &realm.global_object();

    // 2. FIXME: If jsValue is a platform object, then perform a security check, passing jsValue, attribute’s identifier, and "setter".

    // 3. Let validThis be true if jsValue implements target, or false otherwise.
    auto maybe_idl_object = impl_from(vm, js_value);

    // 4. If validThis is false and attribute was not specified with the [LegacyLenientThis] extended attribute, then throw a TypeError.
    idl_object = TRY(maybe_idl_object);

    auto original_steps = [&]() -> JS::ThrowCompletionOr<JS::Value> {
        // 6. Let idlValue be determined as follows:
        // -> Otherwise, idlValue is the result of converting V to an IDL value of attribute’s type.
        auto idl_value = TRY(throw_dom_exception_if_needed(vm, [&] { return V.to_boolean(); }));

        // 7. Run the setter steps of attribute with idlObject as this and idlValue as the value.
        auto setter_result = [&]() -> JS::ThrowCompletionOr<void> {
            TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_enabled(idl_value); }));
    return {};
        }();

        if (setter_result.is_error())
            return setter_result.release_error();

        return JS::js_undefined();
    };

    // 8. Return undefined.
    return TRY(original_steps());
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::stop)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::stop");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] MediaCapture::MediaStreamTrack* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->stop(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::get_capabilities)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::get_capabilities");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] MediaCapture::MediaStreamTrack* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->get_capabilities(); }));
    return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.aspect_ratio.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("aspectRatio"_utf16_fly_string, [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.aspect_ratio.value().max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(R.aspect_ratio.value().max.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.aspect_ratio.value().min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(R.aspect_ratio.value().min.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.auto_gain_control.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("autoGainControl"_utf16_fly_string, [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = R.auto_gain_control.value().size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = R.auto_gain_control.value().at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = JS::Value(sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.background_blur.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("backgroundBlur"_utf16_fly_string, [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = R.background_blur.value().size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = R.background_blur.value().at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = JS::Value(sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.channel_count.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("channelCount"_utf16_fly_string, [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.channel_count.value().max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.channel_count.value().max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.channel_count.value().min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.channel_count.value().min.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.device_id.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("deviceId"_utf16_fly_string, WebIDL::primitive_string_from_string(vm, R.device_id.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.echo_cancellation.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("echoCancellation"_utf16_fly_string, [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = R.echo_cancellation.value().size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = R.echo_cancellation.value().at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = sequence_element.visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](String const& visited_union_value1) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value1);
        }
    );

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.facing_mode.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("facingMode"_utf16_fly_string, [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = R.facing_mode.value().size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = R.facing_mode.value().at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.frame_rate.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("frameRate"_utf16_fly_string, [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.frame_rate.value().max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(R.frame_rate.value().max.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.frame_rate.value().min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(R.frame_rate.value().min.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.group_id.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("groupId"_utf16_fly_string, WebIDL::primitive_string_from_string(vm, R.group_id.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.height.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("height"_utf16_fly_string, [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.height.value().max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.height.value().max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.height.value().min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.height.value().min.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.latency.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("latency"_utf16_fly_string, [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.latency.value().max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(R.latency.value().max.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.latency.value().min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(R.latency.value().min.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.noise_suppression.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("noiseSuppression"_utf16_fly_string, [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = R.noise_suppression.value().size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = R.noise_suppression.value().at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = JS::Value(sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.resize_mode.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("resizeMode"_utf16_fly_string, [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = R.resize_mode.value().size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = R.resize_mode.value().at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_rate.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("sampleRate"_utf16_fly_string, [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_rate.value().max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.sample_rate.value().max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_rate.value().min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.sample_rate.value().min.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_size.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("sampleSize"_utf16_fly_string, [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_size.value().max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.sample_size.value().max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_size.value().min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.sample_size.value().min.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }()));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.width.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("width"_utf16_fly_string, [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.width.value().max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.width.value().max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.width.value().min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.width.value().min.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }()));
        }

        // 4. Return O.
        return dictionary_object;
    }();
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::get_constraints)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::get_constraints");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] MediaCapture::MediaStreamTrack* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->get_constraints(); }));
    return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.aspect_ratio.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("aspectRatio"_utf16_fly_string, R.aspect_ratio.value().visit(
        [&](double const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainDoubleRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(visited_union_value1.max.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(visited_union_value1.min.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.auto_gain_control.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("autoGainControl"_utf16_fly_string, R.auto_gain_control.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainBooleanParameters const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.background_blur.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("backgroundBlur"_utf16_fly_string, R.background_blur.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainBooleanParameters const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.channel_count.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("channelCount"_utf16_fly_string, R.channel_count.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.device_id.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("deviceId"_utf16_fly_string, R.device_id.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        },
        [&](ConstrainDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.echo_cancellation.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("echoCancellation"_utf16_fly_string, R.echo_cancellation.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](String const& visited_union_value1) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value1);
        },
        [&](ConstrainBooleanOrDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](String const& visited_union_value1) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value1);
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](String const& visited_union_value1) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value1);
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.facing_mode.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("facingMode"_utf16_fly_string, R.facing_mode.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        },
        [&](ConstrainDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.frame_rate.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("frameRate"_utf16_fly_string, R.frame_rate.value().visit(
        [&](double const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainDoubleRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(visited_union_value1.max.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(visited_union_value1.min.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.group_id.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("groupId"_utf16_fly_string, R.group_id.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        },
        [&](ConstrainDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.height.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("height"_utf16_fly_string, R.height.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.latency.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("latency"_utf16_fly_string, R.latency.value().visit(
        [&](double const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainDoubleRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(visited_union_value1.max.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(visited_union_value1.min.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.noise_suppression.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("noiseSuppression"_utf16_fly_string, R.noise_suppression.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainBooleanParameters const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.resize_mode.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("resizeMode"_utf16_fly_string, R.resize_mode.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        },
        [&](ConstrainDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_rate.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("sampleRate"_utf16_fly_string, R.sample_rate.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_size.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("sampleSize"_utf16_fly_string, R.sample_size.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.width.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("width"_utf16_fly_string, R.width.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.advanced.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("advanced"_utf16_fly_string, [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = R.advanced.value().size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = R.advanced.value().at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.aspect_ratio.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("aspectRatio"_utf16_fly_string, sequence_element.aspect_ratio.value().visit(
        [&](double const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainDoubleRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(visited_union_value1.max.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(visited_union_value1.min.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.auto_gain_control.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("autoGainControl"_utf16_fly_string, sequence_element.auto_gain_control.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainBooleanParameters const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.background_blur.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("backgroundBlur"_utf16_fly_string, sequence_element.background_blur.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainBooleanParameters const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.channel_count.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("channelCount"_utf16_fly_string, sequence_element.channel_count.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.device_id.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("deviceId"_utf16_fly_string, sequence_element.device_id.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        },
        [&](ConstrainDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.echo_cancellation.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("echoCancellation"_utf16_fly_string, sequence_element.echo_cancellation.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](String const& visited_union_value1) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value1);
        },
        [&](ConstrainBooleanOrDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](String const& visited_union_value1) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value1);
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](String const& visited_union_value1) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value1);
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.facing_mode.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("facingMode"_utf16_fly_string, sequence_element.facing_mode.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        },
        [&](ConstrainDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.frame_rate.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("frameRate"_utf16_fly_string, sequence_element.frame_rate.value().visit(
        [&](double const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainDoubleRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(visited_union_value1.max.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(visited_union_value1.min.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.group_id.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("groupId"_utf16_fly_string, sequence_element.group_id.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        },
        [&](ConstrainDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.height.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("height"_utf16_fly_string, sequence_element.height.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.latency.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("latency"_utf16_fly_string, sequence_element.latency.value().visit(
        [&](double const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainDoubleRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(visited_union_value1.max.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(visited_union_value1.min.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.noise_suppression.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("noiseSuppression"_utf16_fly_string, sequence_element.noise_suppression.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](ConstrainBooleanParameters const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(visited_union_value1.exact.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(visited_union_value1.ideal.value())));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.resize_mode.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("resizeMode"_utf16_fly_string, sequence_element.resize_mode.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        },
        [&](ConstrainDOMStringParameters const& visited_union_value2) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, visited_union_value2.exact.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value2.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, visited_union_value2.ideal.value().visit(
        [&](String const& visited_union_value0) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value0);
        },
        [&](Vector<String> const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // An IDL sequence<T> value S is converted to a JavaScript value as follows:
        // 1. Let n be the length of S.
        auto sequence_length = visited_union_value1.size();

        // 2. Let A be a new Array object created as if by the expression [].
        auto sequence_array = MUST(JS::Array::create(realm, sequence_length));

        // 3. Initialize i to be 0.
        // 4. While i < n:
        for (size_t sequence_index = 0; sequence_index < sequence_length; ++sequence_index) {
            // 1. Let V be the value in S at index i.
            auto& sequence_element = visited_union_value1.at(sequence_index);

            // 2. Let E be the result of converting V to a JavaScript value.
            JS::Value js_sequence_element = WebIDL::primitive_string_from_string(vm, sequence_element);

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }();
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.sample_rate.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("sampleRate"_utf16_fly_string, sequence_element.sample_rate.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.sample_size.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("sampleSize"_utf16_fly_string, sequence_element.sample_size.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (sequence_element.width.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("width"_utf16_fly_string, sequence_element.width.value().visit(
        [&](WebIDL::UnsignedLong const& visited_union_value0) -> JS::Value
        {
            return JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value0));
        },
        [&](ConstrainULongRange const& visited_union_value1) -> JS::Value
        {
            return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.max.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("max"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.max.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.min.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("min"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.min.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.exact.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("exact"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.exact.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (visited_union_value1.ideal.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("ideal"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(visited_union_value1.ideal.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
        }
    )));
        }

        // 4. Return O.
        return dictionary_object;
    }();

            // 3. Let P be the result of calling ! ToString(i).
            // 4. Perform ! CreateDataPropertyOrThrow(A, P, E).
            MUST(sequence_array->create_data_property(JS::PropertyKey { sequence_index }, js_sequence_element));

            // 5. Set i to i + 1.
        }

        // 5. Return A.
        return sequence_array;
    }()));
        }

        // 4. Return O.
        return dictionary_object;
    }();
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::get_settings)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::get_settings");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] MediaCapture::MediaStreamTrack* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->get_settings(); }));
    return [&]() -> JS::Value {
        // 1. Let O be OrdinaryObjectCreate(%Object.prototype%).
        auto dictionary_object = JS::Object::create(realm, realm.intrinsics().object_prototype());

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.aspect_ratio.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("aspectRatio"_utf16_fly_string, JS::Value(R.aspect_ratio.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.auto_gain_control.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("autoGainControl"_utf16_fly_string, JS::Value(R.auto_gain_control.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.background_blur.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("backgroundBlur"_utf16_fly_string, JS::Value(R.background_blur.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.channel_count.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("channelCount"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.channel_count.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.device_id.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("deviceId"_utf16_fly_string, WebIDL::primitive_string_from_string(vm, R.device_id.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.echo_cancellation.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("echoCancellation"_utf16_fly_string, R.echo_cancellation.value().visit(
        [&](bool const& visited_union_value0) -> JS::Value
        {
            return JS::Value(visited_union_value0);
        },
        [&](String const& visited_union_value1) -> JS::Value
        {
            return WebIDL::primitive_string_from_string(vm, visited_union_value1);
        }
    )));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.facing_mode.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("facingMode"_utf16_fly_string, WebIDL::primitive_string_from_string(vm, R.facing_mode.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.frame_rate.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("frameRate"_utf16_fly_string, JS::Value(R.frame_rate.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.group_id.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("groupId"_utf16_fly_string, WebIDL::primitive_string_from_string(vm, R.group_id.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.height.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("height"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.height.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.latency.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("latency"_utf16_fly_string, JS::Value(R.latency.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.noise_suppression.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("noiseSuppression"_utf16_fly_string, JS::Value(R.noise_suppression.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.resize_mode.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("resizeMode"_utf16_fly_string, WebIDL::primitive_string_from_string(vm, R.resize_mode.value())));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_rate.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("sampleRate"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.sample_rate.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.sample_size.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("sampleSize"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.sample_size.value()))));
        }

        // 1. Let key be the identifier of member.
        // 2. If V[key] exists, then:
        if (R.width.has_value()) {

        // 1. Let idlValue be V[key].
        // 2. Let value be the result of converting idlValue to a JavaScript value.
        // 3. Perform ! CreateDataPropertyOrThrow(O, key, value).
        MUST(dictionary_object->create_data_property("width"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedLong>(R.width.value()))));
        }

        // 4. Return O.
        return dictionary_object;
    }();
}

JS_DEFINE_NATIVE_FUNCTION(MediaStreamTrackPrototype::apply_constraints)
{
    WebIDL::log_trace(vm, "MediaStreamTrackPrototype::apply_constraints");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    auto steps = [&realm, &vm]() -> JS::ThrowCompletionOr<GC::Ref<WebIDL::Promise>> {
        (void)realm;
    [[maybe_unused]] MediaCapture::MediaStreamTrack* idl_object = TRY(impl_from(vm));

    auto arg0 = vm.argument(0);
    MediaTrackConstraints constraints = MediaTrackConstraints {};
    if (!arg0.is_undefined())
        constraints = TRY(throw_dom_exception_if_needed(vm, [&] { return convert_to_idl_value_for_media_track_constraints(vm, arg0); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->apply_constraints(constraints); }));
        return R;
    };

    auto maybe_R = steps();

    // And then, if an exception E was thrown:
    // 1. If op has a return type that is a promise type, then return ! Call(%Promise.reject%, %Promise%, «E»).
    // 2. Otherwise, end these steps and allow the exception to propagate.
    if (maybe_R.is_throw_completion())
        return WebIDL::create_rejected_promise(realm, maybe_R.error_value())->promise();

    return GC::Ref { as<JS::Promise>(*maybe_R.release_value()->promise()) };
}

// https://webidl.spec.whatwg.org/#idl-enumeration
JS::ThrowCompletionOr<MediaStreamTrackState> convert_to_idl_value_for_media_stream_track_state(JS::VM& vm, JS::Value value)
{
    // 1. Let S be the result of calling ? ToString(V).
    auto value_as_string = TRY(value.to_utf16_string(vm));

    // 2. If S is not one of E’s enumeration values, then throw a TypeError.
    // 3. Return the enumeration value of type E that is equal to S.
    if (value_as_string == "live"sv)
        return MediaStreamTrackState::Live;
    if (value_as_string == "ended"sv)
        return MediaStreamTrackState::Ended;
    return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidEnumerationValue, value_as_string, "MediaStreamTrackState");
}

// https://webidl.spec.whatwg.org/#idl-enumeration
Utf16String idl_enum_to_string(MediaStreamTrackState value)
{
    // The result of converting an IDL enumeration type value to a JavaScript value is the String value that represents the same sequence of code units as the enumeration value.
    switch (value) {
    case MediaStreamTrackState::Live:
        return "live"_utf16;
    case MediaStreamTrackState::Ended:
        return "ended"_utf16;
    }
    VERIFY_NOT_REACHED();
}

// https://webidl.spec.whatwg.org/#idl-enumeration
JS::ThrowCompletionOr<MediaStreamTrackKind> convert_to_idl_value_for_media_stream_track_kind(JS::VM& vm, JS::Value value)
{
    // 1. Let S be the result of calling ? ToString(V).
    auto value_as_string = TRY(value.to_utf16_string(vm));

    // 2. If S is not one of E’s enumeration values, then throw a TypeError.
    // 3. Return the enumeration value of type E that is equal to S.
    if (value_as_string == "audio"sv)
        return MediaStreamTrackKind::Audio;
    if (value_as_string == "video"sv)
        return MediaStreamTrackKind::Video;
    return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidEnumerationValue, value_as_string, "MediaStreamTrackKind");
}

// https://webidl.spec.whatwg.org/#idl-enumeration
Utf16String idl_enum_to_string(MediaStreamTrackKind value)
{
    // The result of converting an IDL enumeration type value to a JavaScript value is the String value that represents the same sequence of code units as the enumeration value.
    switch (value) {
    case MediaStreamTrackKind::Audio:
        return "audio"_utf16;
    case MediaStreamTrackKind::Video:
        return "video"_utf16;
    }
    VERIFY_NOT_REACHED();
}

} // namespace Web::Bindings
