// basic-array.test-mojom.MojoProfile.swift is auto generated by mojom_bindings_generator.py, do not edit

// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file is autogenerated by:
//     mojo/public/tools/bindings/generators/mojom_fuzzilli_generator.py
// For:
//     basic-array.test-mojom
//

private let mojoPrefix = "golden."

///
/// Interfaces
///
extension ILType {
    // Primary
    fileprivate static let jsGoldenPrimaryRemote: ILType = .object(
        ofGroup: "golden.PrimaryRemote",
        withProperties: ["$"],
        withMethods: [
            "get",
            "syncGetBools",
            "syncGetStrings",
            "getBools",
            "getStrings",
            "passFloats",
            "passInts",
        ])
    fileprivate static let jsGoldenPrimaryRemoteWrapper: ILType = .object(
        ofGroup: "golden.PrimaryRemoteWrapper",
        withMethods: ["close", "isBound", "associateAndPassReceiver"])
    fileprivate static let jsGoldenPrimaryPendingReceiver: ILType = .object(
        ofGroup: "golden.PrimaryPendingReceiver")
}

extension ObjectGroup {
    // Primary
    fileprivate static let goldenPrimaryRemote = ObjectGroup(
        name: "golden.PrimaryRemote",
        instanceType: .jsGoldenPrimaryRemote,
        properties: ["$": .jsGoldenPrimaryRemoteWrapper],
        methods: [
            "get": [
                .plain(.jsGoldenEntryArray),
                .plain(.integer),
            ] => .jsPromise(resolvingTo: .jsGoldenPrimary_Get_ResponseParams),
            "syncGetBools": [
            ] => .jsGoldenPrimary_SyncGetBools_ResponseParams,
            "syncGetStrings": [
            ] => .jsGoldenPrimary_SyncGetStrings_ResponseParams,
            "getBools": [
            ] => .jsPromise(resolvingTo: .jsGoldenPrimary_GetBools_ResponseParams),
            "getStrings": [
            ] => .jsPromise(resolvingTo: .jsGoldenPrimary_GetStrings_ResponseParams),
            "passFloats": [
                .plain(.jsFloatArray),
            ] => .undefined,
            "passInts": [
                .plain(.jsIntegerArray),
            ] => .undefined,
        ]
    )

    fileprivate static let goldenPrimaryRemoteWrapper = ObjectGroup(
        name: "golden.PrimaryRemoteWrapper",
        instanceType: .jsGoldenPrimaryRemoteWrapper,
        properties: [:],
        methods: [
            "close": [] => .undefined,
            "isBound": [] => .boolean,
            "associateAndPassReceiver": [] => .jsGoldenPrimaryPendingReceiver,
        ]
    )

    fileprivate static let goldenPrimaryPendingReceiver = ObjectGroup(
        name: "golden.PrimaryPendingReceiver",
        instanceType: .jsGoldenPrimaryPendingReceiver,
        properties: [:],
        methods: [:]
    )
}

///
/// Structs
///
extension ILType {
    fileprivate static let jsGoldenEntry: ILType = .object(
        ofGroup: "golden.Entry",
        withProperties: [
        ])
    fileprivate static let jsGoldenEntryConstructor: ILType = .constructor([
    ] => .jsGoldenEntry)
    fileprivate static let jsGoldenPrimary_Get_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_Get_ResponseParams",
        withProperties: [
            "result",
        ])
    fileprivate static let jsGoldenPrimary_SyncGetBools_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_SyncGetBools_ResponseParams",
        withProperties: [
            "bools",
        ])
    fileprivate static let jsGoldenPrimary_SyncGetStrings_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_SyncGetStrings_ResponseParams",
        withProperties: [
            "strings",
        ])
    fileprivate static let jsGoldenPrimary_GetBools_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_GetBools_ResponseParams",
        withProperties: [
            "bools",
        ])
    fileprivate static let jsGoldenPrimary_GetStrings_ResponseParams: ILType = .object(
        ofGroup: "golden.Primary_GetStrings_ResponseParams",
        withProperties: [
            "strings",
        ])
}

extension ObjectGroup {
    fileprivate static let goldenEntry = ObjectGroup(
        name: "golden.Entry",
        instanceType: .jsGoldenEntry,
        properties: [:],
        methods: [:]
    )
    fileprivate static let goldenPrimaryGetResponseParams = ObjectGroup(
        name: "golden.Primary_Get_ResponseParams",
        instanceType: .jsGoldenPrimary_Get_ResponseParams,
        properties: [
            "result": .jsGoldenEntry,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimarySyncGetBoolsResponseParams = ObjectGroup(
        name: "golden.Primary_SyncGetBools_ResponseParams",
        instanceType: .jsGoldenPrimary_SyncGetBools_ResponseParams,
        properties: [
            "bools": .jsBooleanArray,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimarySyncGetStringsResponseParams = ObjectGroup(
        name: "golden.Primary_SyncGetStrings_ResponseParams",
        instanceType: .jsGoldenPrimary_SyncGetStrings_ResponseParams,
        properties: [
            "strings": .jsStringArray,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimaryGetBoolsResponseParams = ObjectGroup(
        name: "golden.Primary_GetBools_ResponseParams",
        instanceType: .jsGoldenPrimary_GetBools_ResponseParams,
        properties: [
            "bools": .jsBooleanArray,
        ],
        methods: [:]
    )
    fileprivate static let goldenPrimaryGetStringsResponseParams = ObjectGroup(
        name: "golden.Primary_GetStrings_ResponseParams",
        instanceType: .jsGoldenPrimary_GetStrings_ResponseParams,
        properties: [
            "strings": .jsStringArray,
        ],
        methods: [:]
    )
}

///
/// Arrays
///
extension ILType {
    fileprivate static let jsGoldenEntryArray: ILType =
        .createJsArrayType(ofElementType: .jsGoldenEntry)
    fileprivate static let jsBooleanArray: ILType =
        .createJsArrayType(ofElementType: .jsBooleanElement)
    fileprivate static let jsStringArray: ILType =
        .createJsArrayType(ofElementType: .jsStringElement)
    fileprivate static let jsFloatArray: ILType =
        .createJsArrayType(ofElementType: .jsFloatElement)
    fileprivate static let jsIntegerArray: ILType =
        .createJsArrayType(ofElementType: .jsIntegerElement)
}

/// As Fuzzilli runs, the OperationMutator and VariadicInputReducer will modify
/// the `CreateArray` operation to increase or decrease the element count. This
/// allows arrays to be arbitrarily long.
///
/// `findOrGenerateType` is preferred over specifying `inputs` because
/// Fuzzilli only uses CodeGenerators to produce types in `inputs`, while
/// `findOrGenerateType` uses a variety of sources (e.g. `builtins`, other
/// method properties and methods). An input is specified (i.e. `.one`)
/// to prevent the CodeGenerator from being scheduled first when there are
/// no visible variables, as `findOrGenerateType` causes a crash if there
/// are no visibile variables.
private let MojoGoldenEntryArrayGenerator = CodeGenerator(
    "MojoGoldenEntryArrayGenerator",
    inputs: .one,
    produces: [.jsGoldenEntryArray]
) { b, _ in
    let elem = b.findOrGenerateType(.jsGoldenEntry)
    var elements: [Variable] = [elem]
    b.createArray(
        with: elements,
        elementGroupName:
            ObjectGroup.goldenEntry.name)
}
private let MojoBooleanArrayGenerator = CodeGenerator(
    "MojoBooleanArrayGenerator",
    inputs: .one,
    produces: [.jsBooleanArray]
) { b, _ in
    let elem = b.findOrGenerateType(.boolean)
    var elements: [Variable] = [elem]
    b.createArray(
        with: elements,
        elementGroupName:
            ObjectGroup.booleanElement.name)
}
private let MojoStringArrayGenerator = CodeGenerator(
    "MojoStringArrayGenerator",
    inputs: .one,
    produces: [.jsStringArray]
) { b, _ in
    let elem = b.findOrGenerateType(.string)
    var elements: [Variable] = [elem]
    b.createArray(
        with: elements,
        elementGroupName:
            ObjectGroup.stringElement.name)
}
private let MojoFloatArrayGenerator = CodeGenerator(
    "MojoFloatArrayGenerator",
    inputs: .one,
    produces: [.jsFloatArray]
) { b, _ in
    let elem = b.findOrGenerateType(.float)
    var elements: [Variable] = [elem]
    b.createArray(
        with: elements,
        elementGroupName:
            ObjectGroup.floatElement.name)
}
private let MojoIntegerArrayGenerator = CodeGenerator(
    "MojoIntegerArrayGenerator",
    inputs: .one,
    produces: [.jsIntegerArray]
) { b, _ in
    let elem = b.findOrGenerateType(.integer)
    var elements: [Variable] = [elem]
    b.createArray(
        with: elements,
        elementGroupName:
            ObjectGroup.integerElement.name)
}

///
/// Generators
///
// TODO(crbug.com/500386713) Consider using mojoBuiltins or another list instead of regex
private func isTargetObject(type: ILType) -> Bool {
    guard type.Is(.object()), let group = type.group else { return false }
    return group.starts(with: mojoPrefix)
}

/// Mojo variant of the builtin `MethodCallGenerator` that operates only on
/// "Mojo" objects instead of all the objects in the JavaScript environment,
/// most of which are unrelated to the interface. This generator emits random
/// method calls, generating any arguments that are not available.
private let MojoMethodCallGenerator = CodeGenerator("MojoMethodCallGenerator") {
    b in
    // Pick a variable among all Mojo variables with methods
    var targetVar = b.findVariable {
        let type = b.type(of: $0)
        return isTargetObject(type: type) && !type.methods.isEmpty
    }

    // If we can't find a Mojo object in scope, create the Primary remote
    guard let obj = targetVar else {
        let getRemoteFunc = b.createNamedVariable(forBuiltin: "getOrCreatePrimaryRemote")
        b.callFunction(getRemoteFunc, withArgs: [])
        return
    }

    let methodName = b.type(of: obj).randomMethod()!
    let signatures = b.methodSignatures(of: methodName, on: obj)
    let signature = chooseUniform(from: signatures)
    let arguments = b.findOrGenerateArguments(forSignature: signature)
    b.callMethod(methodName, on: obj, withArgs: arguments, guard: false)
}

/// Mojo variant of the builtin `PropertyRetrievalGenerator` that operates only
/// on "Mojo" objects instead of all the objects in the JavaScript environment,
/// most of which are unrelated to the interface. This generator emits random
/// property retrievals.
private let MojoPropertyRetrievalGenerator = CodeGenerator(
    "MojoPropertyRetrievalGenerator"
) { b in
    let targetVar = b.findVariable { isTargetObject(type: b.type(of: $0)) }
    guard let obj = targetVar else { return }

    let propertyName =
        b.type(of: obj).randomProperty() ?? b.randomCustomPropertyName()
    b.getProperty(propertyName, of: obj)
}

private let mojoBuiltins: [String: ILType] = [
    /// Profiles declare this method, a wrapper method around `getRemote` that follows
    /// the Singleton pattern, in `codePrefix`. This method ensures: (1) `getRemote`
    /// is only called once, and (2) the remote is saved to a global variable so it
    /// can be closed at the end of the program.
    "getOrCreatePrimaryRemote": .function([] => .jsGoldenPrimaryRemote),
    "golden.Entry": .jsGoldenEntryConstructor,
]

private let keepGenerators = [
    "IntegerGenerator", "StringGenerator", "TernaryOperationGenerator",
    "PlainFunctionGenerator", "AsyncFunctionGenerator", "AwaitGenerator",
    "SubroutineReturnGenerator", "TryCatchGenerator",
]

private let mojoDisabledGenerators: [String] = CodeGenerators.map { $0.name }
    .filter {
        !keepGenerators.contains($0)
    }

let mojoPrimaryProfile = Profile(
    processArgs: { _ in return [] },
    processArgsReference: nil,
    processEnv: [
        "ASAN_OPTIONS": "detect_odr_violation=0:abort_on_error=1", "DISPLAY": ":20",
    ],
    maxExecsBeforeRespawn: 1000,
    timeout: Timeout.interval(11000, 11000),
    codePrefix: """
        let globalRemote = null;
        function getOrCreatePrimaryRemote() {
            if (!globalRemote) {
                globalRemote = golden.Primary.getRemote();
            }
            return globalRemote;
        }
        """,
    codeSuffix: "if (globalRemote) {globalRemote.$.close()}",
    ecmaVersion: v8Profile.ecmaVersion,
    startupTests: [
        ("fuzzilli('FUZZILLI_PRINT', 'test')", .shouldSucceed),
        (
            """
            if (typeof golden == 'undefined' \
            || golden?.Primary === undefined) \
            throw 'Primary not found'
            """,
            .shouldSucceed
        ),
    ] + v8Profile.startupTests,
    additionalCodeGenerators: [
        (MojoMethodCallGenerator, 10000),
        (MojoPropertyRetrievalGenerator, 10000),
        (MojoGoldenEntryArrayGenerator, 1),
        (MojoBooleanArrayGenerator, 1),
        (MojoStringArrayGenerator, 1),
        (MojoFloatArrayGenerator, 1),
        (MojoIntegerArrayGenerator, 1),
    ] + commonMojoCodeGenerators,
    additionalProgramTemplates: WeightedList([]),
    disabledCodeGenerators: mojoDisabledGenerators,
    disabledMutators: [
        "ExplorationMutator", "ProbingMutator", "PropertyAccessorMutator"
    ],
    additionalBuiltins: mojoBuiltins.merging(commonMojoBuiltins) { (existing, _) in existing },
    additionalObjectGroups: [
        .goldenPrimaryRemote,
        .goldenPrimaryRemoteWrapper,
        .goldenPrimaryPendingReceiver,
        .goldenEntry,
        .goldenPrimaryGetResponseParams,
        .goldenPrimarySyncGetBoolsResponseParams,
        .goldenPrimarySyncGetStringsResponseParams,
        .goldenPrimaryGetBoolsResponseParams,
        .goldenPrimaryGetStringsResponseParams,
    ] + commonMojoObjectGroups,
    additionalEnumerations: [
    ] + commonMojoEnumerations,
    additionalOptionsBags: [
    ] + commonMojoOptionsBags,
    optionalPostProcessor: nil
)