예제 #1
0
def parse_float(this, args):
    from js.runistr import encode_unicode_utf8
    from js.constants import num_lit_rexp

    string = get_arg(args, 0)
    input_string = string.to_string()
    trimmed_string = _strip(input_string)
    str_trimmed_string = encode_unicode_utf8(trimmed_string)

    match_data = num_lit_rexp.match(str_trimmed_string)
    if match_data is not None:
        number_string = match_data.group()
    else:
        number_string = ''

    if number_string == 'Infinity' or number_string == '+Infinity':
        return INFINITY
    elif number_string == '-Infinity':
        return -INFINITY

    try:
        number = float(number_string)
        return number
    except ValueError:
        pass

    return NAN
예제 #2
0
def parse_float(this, args):
    from js.runistr import encode_unicode_utf8
    from js.constants import num_lit_rexp

    string = get_arg(args, 0)
    input_string = string.to_string()
    trimmed_string = _strip(input_string)
    str_trimmed_string = encode_unicode_utf8(trimmed_string)

    match_data = num_lit_rexp.match(str_trimmed_string)
    if match_data is not None:
        number_string = match_data.group()
    else:
        number_string = ''

    if number_string == 'Infinity' or number_string == '+Infinity':
        return INFINITY
    elif number_string == '-Infinity':
        return -INFINITY

    try:
        number = float(number_string)
        return number
    except ValueError:
        pass

    return NAN
예제 #3
0
def parse_to_ast(code):
    #assert isinstance(code, unicode)
    from js.jsparser import parse
    from js.runistr import encode_unicode_utf8
    src = encode_unicode_utf8(code)
    parse_tree = parse(src)
    ast = parse_tree_to_ast(parse_tree)
    return ast
예제 #4
0
def printjs(this, args):
    if len(args) == 0:
        return

    from rpython.rlib.rstring import UnicodeBuilder
    from js.runistr import encode_unicode_utf8

    builder = UnicodeBuilder()
    for arg in args[:-1]:
        builder.append(arg.to_string())
        builder.append(u',')

    builder.append(args[-1].to_string())

    u_print_str = builder.build()
    print_str = encode_unicode_utf8(u_print_str)
    print(print_str)
예제 #5
0
def printjs(this, args):
    if len(args) == 0:
        return

    from rpython.rlib.rstring import UnicodeBuilder
    from js.runistr import encode_unicode_utf8

    builder = UnicodeBuilder()
    for arg in args[:-1]:
        builder.append(arg.to_string())
        builder.append(u',')

    builder.append(args[-1].to_string())

    u_print_str = builder.build()
    print_str = encode_unicode_utf8(u_print_str)
    print(print_str)
예제 #6
0
    def ToNumber(self):
        from js.builtins.js_global import _strip
        from js.runistr import encode_unicode_utf8
        from js.constants import hex_rexp, oct_rexp, num_rexp

        u_strval = self._strval_

        u_strval = _strip(u_strval)
        s = encode_unicode_utf8(u_strval)

        if s == '':
            return 0.0

        match_data = num_rexp.match(s)
        if match_data is not None:
            num_lit = match_data.group()
            assert num_lit is not None
            assert isinstance(num_lit, str)

            if num_lit == 'Infinity' or num_lit == '+Infinity':
                return INFINITY
            elif num_lit == '-Infinity':
                return -INFINITY

            return float(num_lit)

        from js.builtins.js_global import _parse_int

        match_data = hex_rexp.match(s)
        if match_data is not None:
            hex_lit = match_data.group(1)
            assert hex_lit is not None
            assert hex_lit.startswith('0x') is False
            assert hex_lit.startswith('0X') is False
            return float(_parse_int(unicode(hex_lit), 16))

        match_data = oct_rexp.match(s)
        if match_data is not None:
            oct_lit = match_data.group(1)
            assert oct_lit is not None
            return float(_parse_int(unicode(oct_lit), 8))

        return NAN
예제 #7
0
def printmessage(msg):
    from js.runistr import encode_unicode_utf8
    os.write(1, encode_unicode_utf8(msg))
예제 #8
0
def printmessage(msg):
    from js.runistr import encode_unicode_utf8
    os.write(1, encode_unicode_utf8(msg))