예제 #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)