[jsinterp] Fixing TODOs and comments

This commit is contained in:
sulyi 2018-06-04 03:09:14 +02:00
parent 38b260228a
commit b9061d69e2
4 changed files with 9 additions and 5 deletions

View File

@ -1,3 +1,5 @@
# TODO use json instead of py
# TODO create devscript to generate ASTs (using e.g. acorn)
# """ # """
# This package contains templates for `test_jsinterp` and `test_interp_parse` to create test methods. # This package contains templates for `test_jsinterp` and `test_interp_parse` to create test methods.
# These modules will create a test method for each module in this package. A test method consist of one or more subtest. # These modules will create a test method for each module in this package. A test method consist of one or more subtest.

View File

@ -39,7 +39,7 @@ tests = [
]) ])
] ]
}, { }, {
# FIXME built-in functions not yet implemented # FIXME built-in functions are not yet implemented
'exclude': ('jsinterp2',), 'exclude': ('jsinterp2',),
'code': 'function x(a) { return a.split(""); }', 'code': 'function x(a) { return a.split(""); }',
'asserts': [{'value': ["a", "b", "c"], 'call': ('x', "abc")}], 'asserts': [{'value': ["a", "b", "c"], 'call': ('x', "abc")}],

View File

@ -83,6 +83,7 @@ def to_number(o):
if v: if v:
s = 1 if v.startswith('+') or v.startswith('-') else 0 s = 1 if v.startswith('+') or v.startswith('-') else 0
if v[s:] == 'Infinity': if v[s:] == 'Infinity':
# FIXME: declare in jsbuilt_ins (propery of global_obj)
return float(v[:s] + 'inf') # 10 ** 10000 according to spec return float(v[:s] + 'inf') # 10 ** 10000 according to spec
elif v[s:].isdigit(): elif v[s:].isdigit():
return int(v) return int(v)
@ -93,6 +94,7 @@ def to_number(o):
else: else:
return 0 return 0
else: else:
# FIXME: declare in jsbuilt_ins (propery of global_obj)
return float('nan') return float('nan')
elif isinstance(o, JSObjectPrototype): elif isinstance(o, JSObjectPrototype):

View File

@ -30,7 +30,7 @@ __ESC_HEX_RE = r'x[0-9a-fA-F]{2}'
# NOTE order is fixed due to regex matching, does not represent any precedence # NOTE order is fixed due to regex matching, does not represent any precedence
# NOTE unary operator 'delete', 'void', 'instanceof' and relation 'in' and 'instanceof' do not handled this way # NOTE unary operator 'delete', 'void', 'instanceof' and relation 'in' and 'instanceof' are not handled this way
_logical_operator = ['||', '&&'] _logical_operator = ['||', '&&']
_relation = ['===', '!==', '==', '!=', '<=', '>=', '<', '>'] _relation = ['===', '!==', '==', '!=', '<=', '>=', '<', '>']
_unary_operator = ['++', '--', '!', '~'] _unary_operator = ['++', '--', '!', '~']
@ -44,8 +44,8 @@ _NAME_RE = r'[a-zA-Z_$][a-zA-Z_$0-9]*'
# non-escape char also can be escaped, but line continuation and quotes has to be # non-escape char also can be escaped, but line continuation and quotes has to be
# XXX unicode and hexadecimal escape sequences should be validated # XXX unicode and hexadecimal escape sequences should be validated
_SINGLE_QUOTED_RE = r"""'(?:(?:\\'|\n)|[^'\n])*'""" _SINGLE_QUOTED_RE = r"'(?:(?:\\'|\n)|[^'\n])*'"
_DOUBLE_QUOTED_RE = r'''"(?:(?:\\"|\n)|[^"\n])*"''' _DOUBLE_QUOTED_RE = r'"(?:(?:\\"|\n)|[^"\n])*"'
_STRING_RE = r'(?:%s)|(?:%s)' % (_SINGLE_QUOTED_RE, _DOUBLE_QUOTED_RE) _STRING_RE = r'(?:%s)|(?:%s)' % (_SINGLE_QUOTED_RE, _DOUBLE_QUOTED_RE)
_INTEGER_RE = r'(?:%(hex)s)|(?:%(dec)s)|(?:%(oct)s)' % {'hex': __HEXADECIMAL_RE, 'dec': __DECIMAL_RE, 'oct': __OCTAL_RE} _INTEGER_RE = r'(?:%(hex)s)|(?:%(dec)s)|(?:%(oct)s)' % {'hex': __HEXADECIMAL_RE, 'dec': __DECIMAL_RE, 'oct': __OCTAL_RE}
@ -54,7 +54,7 @@ _FLOAT_RE = r'(?:(?:%(dec)s\.[0-9]*)|(?:\.[0-9]+))(?:[eE][+-]?[0-9]+)?' % {'dec'
_BOOL_RE = r'true|false' _BOOL_RE = r'true|false'
_NULL_RE = r'null' _NULL_RE = r'null'
# XXX early validation might needed # XXX early validation might be needed
# r'''/(?!\*) # r'''/(?!\*)
# (?:(?:\\(?:[tnvfr0.\\+*?^$\[\]{}()|/]|[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Z]|))|[^/\n])* # (?:(?:\\(?:[tnvfr0.\\+*?^$\[\]{}()|/]|[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Z]|))|[^/\n])*
# /(?:(?![gimy]*(?P<flag>[gimy])[gimy]*(?P=flag))[gimy]{0,4}\b|\s|$)''' # /(?:(?![gimy]*(?P<flag>[gimy])[gimy]*(?P=flag))[gimy]{0,4}\b|\s|$)'''