示例#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)