Ejemplo n.º 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)
Ejemplo n.º 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()))
Ejemplo n.º 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']
Ejemplo n.º 4
0
def test_boolean_literal(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 5
0
def test_get_property(source: str, expected: Any):
    assert execute(source, environment={'foo': {'baz': 2}}) == expected
Ejemplo n.º 6
0
def test_new_string():
    assert execute('new String(2)') == '2'
Ejemplo n.º 7
0
def test_execute_deprecated(source: str, expected: Any) -> None:
    class FakeException(Exception):
        pass
    assert execute(source, '<ast>', {'FakeException': FakeException}) == expected
Ejemplo n.º 8
0
def test_initialized_class_field():
    assert execute('class X { var a = 42 }; new X().a') == 42
Ejemplo n.º 9
0
def test_augmented_assignment(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 10
0
def test_variable_definition(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 11
0
def test_label():
    # For the sake of simplicity a label is evaluated to `None`.
    assert execute('addr58:') is None
Ejemplo n.º 12
0
def test_null():
    assert execute('null') is None
Ejemplo n.º 13
0
def test_conditional(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 14
0
def test_float_literal(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 15
0
def test_undefined():
    assert execute('undefined') == undefined
Ejemplo n.º 16
0
def test_class_constructor():
    assert execute('var expected; class X { function X() { expected = 42 } }; new X(); expected') == 42
Ejemplo n.º 17
0
def test_get_missing_class_field():
    assert execute('class X { }; new X().a') is undefined
Ejemplo n.º 18
0
def test_addition():
    assert execute('2 + 2') == 4
Ejemplo n.º 19
0
def test_priority(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 20
0
def test_for(source: str, expected: Any):
    environment = {'foo': 0}
    assert execute(source, environment=environment) == expected
Ejemplo n.º 21
0
def test_new_string_generic():
    assert execute('new String.<Whatever>(2)') == '2'
Ejemplo n.º 22
0
def test_function_parameter(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 23
0
def test_math(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 24
0
def test_function_return(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 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
Ejemplo n.º 26
0
def test_assign_property(source: str, expected: Any):
    assert execute(source, environment={'dict_': {}}) == expected
Ejemplo n.º 27
0
def test_unary(source: str, expected: Any):
    assert execute(source) == expected
Ejemplo n.º 28
0
def test_reference_error(source: str):
    with raises(ASReferenceError):
        execute(source)