diff --git a/test/test_jsinterp_parser.py b/test/test_jsinterp_parser.py index ca7154932..b0fab9f6c 100644 --- a/test/test_jsinterp_parser.py +++ b/test/test_jsinterp_parser.py @@ -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( diff --git a/youtube_dl/jsinterp/jsinterp.py b/youtube_dl/jsinterp/jsinterp.py index 7ee8e963a..1b82a6bad 100644 --- a/youtube_dl/jsinterp/jsinterp.py +++ b/youtube_dl/jsinterp/jsinterp.py @@ -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: