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

RESOLVED FIXED in Firefox 67

Status

()

enhancement
P3
normal
RESOLVED FIXED
2 months ago
a month ago

People

(Reporter: arai, Assigned: arai)

Tracking

(Blocks 1 bug)

Trunk
mozilla67
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox67 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

2 months ago

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')
(Assignee)

Updated

2 months ago
Blocks: 1524931

Comment 2

2 months ago
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

Comment 3

a month ago
bugherder
Status: ASSIGNED → RESOLVED
Last Resolved: a month ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67
You need to log in before you can comment on or make changes to this bug.