Closed Bug 1533711 Opened 5 years ago Closed 5 years ago

[BinAST] Change filter_utils.py to provide class with method chain to reduce repeated variable names

Categories

(Core :: JavaScript Engine, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla67
Tracking Status
firefox67 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 file)

Current filter_utils.py provides function-based utility.

with it, there are so many repeated variable names in the testcase, for assignment, assertion, and to get field/element.

like:

    utils.assert_interface(ast, 'Script')
    global_stmts = utils.get_field(ast, 'statements')

    try_stmt = utils.get_element(global_stmts, 0)
    utils.assert_interface(try_stmt, 'TryCatchStatement')

    catch = utils.get_field(try_stmt, 'catchClause')
    utils.assert_interface(catch, 'CatchClause')

    scope = utils.get_field(catch, 'bindingScope')
    utils.assert_interface(scope, 'AssertedBoundNamesScope')

    names = utils.get_field(scope, 'boundNames')
    bound_name = utils.get_element(names, 0)
    utils.assert_interface(bound_name, 'AssertedBoundName')

    name = utils.get_field(bound_name, 'name')

    utils.set_identifier_name(name, 'b')

that's tedious when writing new testcase.
it's better providing better way to reduce the repeated variable names.

I'm going to add class with method chain, like:

    utils.wrap(ast) \
        .assert_interface('Script') \
        .field('statements') \
        .elem(0) \
        .assert_interface('TryCatchStatement') \
        .field('catchClause') \
        .assert_interface('CatchClause') \
        .field('bindingScope') \
        .assert_interface('AssertedBoundNamesScope') \
        .field('boundNames') \
        .elem(0) \
        .assert_interface('AssertedBoundName') \
        .field('name') \
        .set_identifier_name('b')
Blocks: 1524931
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/6b9b50bc446d
Provide class with method chain in filter_utils.py for BinAST invalid file test. r=Yoric
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: