[jsinterp] Added debugger and throw parser (test needed)

This commit is contained in:
sulyi 2016-12-11 19:04:17 +01:00
parent dedb6eea79
commit bae3166eb7
2 changed files with 41 additions and 5 deletions

View File

@ -631,7 +631,6 @@ class TestJSInterpreterParser(unittest.TestCase):
self.assertEqual(list(jsi.statements()), ast)
def test_if(self):
# TODO if test
jsi = JSInterpreter(
'''
function a(x) {
@ -763,6 +762,29 @@ class TestJSInterpreterParser(unittest.TestCase):
ast = []
self.assertEqual(list(jsi.statements()), ast)
@unittest.skip('Test not yet implemented: missing code and ast')
def test_try(self):
# TODO try test
jsi = JSInterpreter('')
ast = []
self.assertEqual(list(jsi.statements()), ast)
@unittest.skip('Test not yet implemented: missing code and ast')
def test_throw(self):
# TODO throw test
# might be combined with another
jsi = JSInterpreter('')
ast = []
self.assertEqual(list(jsi.statements()), ast)
@unittest.skip('Test not yet implemented: missing code and ast')
def test_debug(self):
# TODO debug test
# might be combined with another
jsi = JSInterpreter('')
ast = []
self.assertEqual(list(jsi.statements()), ast)
def test_unshift(self):
# https://hg.mozilla.org/mozilla-central/file/tip/js/src/tests/ecma_5/Array/unshift-01.js
jsi = JSInterpreter(

View File

@ -268,8 +268,16 @@ class JSInterpreter(object):
statement = (Token.BLOCK, discriminant, block)
elif token_value == 'throw':
# TODO parse throwstatement
raise ExtractorError('Throw statement is not yet supported at %d' % token_pos)
token_stream.pop()
# XXX no line break here
expr = self._expression(token_stream, stack_top - 1)
statement = (Token.RETURN, expr)
peek_id, peek_value, peek_pos = token_stream.peek()
if peek_id is not Token.END:
# FIXME automatic end insertion
raise ExtractorError('Unexpected sequence %s at %d' % (peek_value, peek_pos))
else:
token_stream.pop()
elif token_value == 'try':
token_stream.pop()
@ -307,8 +315,14 @@ class JSInterpreter(object):
statement = (Token.TRY, try_block, catch_block, finally_block)
elif token_value == 'debugger':
# TODO parse debuggerstatement
raise ExtractorError('Debugger statement is not yet supported at %d' % token_pos)
token_stream.pop()
statement = (Token.DEBUG)
peek_id, peek_value, peek_pos = token_stream.peek()
if peek_id is not Token.END:
# FIXME automatic end insertion
raise ExtractorError('Unexpected sequence %s at %d' % (peek_value, peek_pos))
else:
token_stream.pop()
# expr
if statement is None: