]> gitweb @ CieloNegro.org - youtube-dl.git/commitdiff
[jsinterp] Fix function calls without arguments.
authorKacper Michajłow <kasper93@gmail.com>
Sat, 5 Nov 2016 05:11:51 +0000 (06:11 +0100)
committerKacper Michajłow <kasper93@gmail.com>
Fri, 11 Nov 2016 14:36:57 +0000 (15:36 +0100)
test/test_jsinterp.py
youtube_dl/jsinterp.py

index 63c350b8fa986fc63d70af43a6a0fdcaf5958eed..a9abae5f54406a9e06d67e828bb89efc207a0cf8 100644 (file)
@@ -104,6 +104,13 @@ class TestJSInterpreter(unittest.TestCase):
         }''')
         self.assertEqual(jsi.call_function('x'), [20, 20, 30, 40, 50])
 
+    def test_call(self):
+        jsi = JSInterpreter('''
+        function x() { return 2; }
+        function y(a) { return x() + a; }
+        function z() { return y(3); }
+        ''')
+        self.assertEqual(jsi.call_function('z'), 5)
 
 if __name__ == '__main__':
     unittest.main()
index 9737f70021d3285a4e8df616467b764de1a91fa2..a8df4aef0a2553222d45b9f38131a2945470d412 100644 (file)
@@ -198,12 +198,12 @@ class JSInterpreter(object):
             return opfunc(x, y)
 
         m = re.match(
-            r'^(?P<func>%s)\((?P<args>[a-zA-Z0-9_$,]+)\)$' % _NAME_RE, expr)
+            r'^(?P<func>%s)\((?P<args>[a-zA-Z0-9_$,]*)\)$' % _NAME_RE, expr)
         if m:
             fname = m.group('func')
             argvals = tuple([
                 int(v) if v.isdigit() else local_vars[v]
-                for v in m.group('args').split(',')])
+                for v in m.group('args').split(',')]) if len(m.group('args')) > 0 else tuple()
             if fname not in self._functions:
                 self._functions[fname] = self.extract_function(fname)
             return self._functions[fname](argvals)