]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[jsinterp] Support alternative function definition form
authorYen Chi Hsuan <yan12125@gmail.com>
Tue, 10 Nov 2015 04:54:02 +0000 (12:54 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Tue, 10 Nov 2015 04:54:02 +0000 (12:54 +0800)
test/test_jsinterp.py
youtube_dl/jsinterp.py

index fc73e5dc29a5c8faab88f4604f99df4ee9de6b2e..63c350b8fa986fc63d70af43a6a0fdcaf5958eed 100644 (file)
@@ -19,6 +19,9 @@ class TestJSInterpreter(unittest.TestCase):
         jsi = JSInterpreter('function x3(){return 42;}')
         self.assertEqual(jsi.call_function('x3'), 42)
 
+        jsi = JSInterpreter('var x5 = function(){return 42;}')
+        self.assertEqual(jsi.call_function('x5'), 42)
+
     def test_calc(self):
         jsi = JSInterpreter('function x4(a){return 2*a+1;}')
         self.assertEqual(jsi.call_function('x4', 3), 7)
index 0e0c7d90d5aa2fbb8039dddf642ac4692f2974a7..9bc8551441cb7faf0cfb58fddc25f2183dc6da00 100644 (file)
@@ -232,10 +232,10 @@ class JSInterpreter(object):
     def extract_function(self, funcname):
         func_m = re.search(
             r'''(?x)
-                (?:function\s+%s|[{;]%s\s*=\s*function)\s*
+                (?:function\s+%s|[{;]%s\s*=\s*function|var\s+%s\s*=\s*function)\s*
                 \((?P<args>[^)]*)\)\s*
                 \{(?P<code>[^}]+)\}''' % (
-                re.escape(funcname), re.escape(funcname)),
+                re.escape(funcname), re.escape(funcname), re.escape(funcname)),
             self.code)
         if func_m is None:
             raise ExtractorError('Could not find JS function %r' % funcname)