Пример #1
0
def main(shell: bool, packages_path: str, scripts: Tuple[str]):
    """
    Execute ActionScript files.
    """
    environment = {}
    for script in scripts:
        path = Path(script)
        try:
            execute(
                path.open('rt', encoding='utf-8').read(), str(path),
                environment)
        except Exception as e:
            print_exception(e)
            sys.exit(1)
    if shell:
        run_shell(environment)
Пример #2
0
def run_shell(environment: dict):
    session = PromptSession()
    style = style_from_pygments_cls(NativeStyle)

    click.echo(f'{click.style("Welcome to as3 shell!", fg="yellow")}')

    while True:
        line = session.prompt(
            '>>> ',
            lexer=PygmentsLexer(ActionScript3Lexer),
            style=style,
            auto_suggest=AutoSuggestFromHistory(),
        )
        try:
            value = execute(line, '<shell>', environment)
        except Exception as e:
            print_exception(e)
        else:
            print(
                highlight(repr(value), ActionScript3Lexer(),
                          TerminalFormatter()))
Пример #3
0
def test_simple_class():
    object_ = execute('class X { }; new X()')
    assert isinstance(object_, dict)
    assert object_['__proto__'] == {}
    assert object_['__proto__'] is object_['constructor']['prototype']
Пример #4
0
def test_boolean_literal(source: str, expected: Any):
    assert execute(source) == expected
Пример #5
0
def test_get_property(source: str, expected: Any):
    assert execute(source, environment={'foo': {'baz': 2}}) == expected
Пример #6
0
def test_new_string():
    assert execute('new String(2)') == '2'
Пример #7
0
def test_execute_deprecated(source: str, expected: Any) -> None:
    class FakeException(Exception):
        pass
    assert execute(source, '<ast>', {'FakeException': FakeException}) == expected
Пример #8
0
def test_initialized_class_field():
    assert execute('class X { var a = 42 }; new X().a') == 42
Пример #9
0
def test_augmented_assignment(source: str, expected: Any):
    assert execute(source) == expected
Пример #10
0
def test_variable_definition(source: str, expected: Any):
    assert execute(source) == expected
Пример #11
0
def test_label():
    # For the sake of simplicity a label is evaluated to `None`.
    assert execute('addr58:') is None
Пример #12
0
def test_null():
    assert execute('null') is None
Пример #13
0
def test_conditional(source: str, expected: Any):
    assert execute(source) == expected
Пример #14
0
def test_float_literal(source: str, expected: Any):
    assert execute(source) == expected
Пример #15
0
def test_undefined():
    assert execute('undefined') == undefined
Пример #16
0
def test_class_constructor():
    assert execute('var expected; class X { function X() { expected = 42 } }; new X(); expected') == 42
Пример #17
0
def test_get_missing_class_field():
    assert execute('class X { }; new X().a') is undefined
Пример #18
0
def test_addition():
    assert execute('2 + 2') == 4
Пример #19
0
def test_priority(source: str, expected: Any):
    assert execute(source) == expected
Пример #20
0
def test_for(source: str, expected: Any):
    environment = {'foo': 0}
    assert execute(source, environment=environment) == expected
Пример #21
0
def test_new_string_generic():
    assert execute('new String.<Whatever>(2)') == '2'
Пример #22
0
def test_function_parameter(source: str, expected: Any):
    assert execute(source) == expected
Пример #23
0
def test_math(source: str, expected: Any):
    assert execute(source) == expected
Пример #24
0
def test_function_return(source: str, expected: Any):
    assert execute(source) == expected
Пример #25
0
def test_call_function(source: str, expected: Any):
    assert execute(source, environment={
        'bar': make_function_object(lambda a, b: a + b),
        'baz': make_function_object(lambda: 42),
    }) == expected
Пример #26
0
def test_assign_property(source: str, expected: Any):
    assert execute(source, environment={'dict_': {}}) == expected
Пример #27
0
def test_unary(source: str, expected: Any):
    assert execute(source) == expected
Пример #28
0
def test_reference_error(source: str):
    with raises(ASReferenceError):
        execute(source)