js/src/jsapi-tests/binast/invalid/tests/param-too-many.py
author Tooru Fujisawa <arai_a@mac.com>
Mon, 11 Mar 2019 16:04:04 +0000
changeset 463501 6b9b50bc446d892779619254ce852f8b2f0c9bcf
parent 459467 0934e6142eb942c5f3ba28bb426c85eb47dbd897
permissions -rw-r--r--
Bug 1533711 - Provide class with method chain in filter_utils.py for BinAST invalid file test. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D22888

def filter_ast(ast):
    # Duplicate parameter up to 65536 entries.
    import filter_utils as utils

    param_names = utils.wrap(ast) \
        .assert_interface('Script') \
        .field('statements') \
        .elem(0) \
        .assert_interface('EagerFunctionDeclaration') \
        .field('contents') \
        .assert_interface('FunctionOrMethodContents') \
        .field('parameterScope') \
        .assert_interface('AssertedParameterScope') \
        .field('paramNames')

    param_name = param_names.elem(0) \
        .assert_interface('AssertedPositionalParameterName')

    for i in range(1, 65536 + 1):
        copied_param_name = param_name.copy()

        copied_param_name.field('index') \
            .set_unsigned_long(i)

        copied_param_name.field('name') \
            .set_identifier_name('a{}'.format(i))

        param_names.append_elem(copied_param_name)

    return ast