mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-22 16:44:32 +01:00
[jsinterp] Support alternative function definition form
This commit is contained in:
parent
b25f753397
commit
ff29bf81f8
@ -19,6 +19,9 @@ class TestJSInterpreter(unittest.TestCase):
|
|||||||
jsi = JSInterpreter('function x3(){return 42;}')
|
jsi = JSInterpreter('function x3(){return 42;}')
|
||||||
self.assertEqual(jsi.call_function('x3'), 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):
|
def test_calc(self):
|
||||||
jsi = JSInterpreter('function x4(a){return 2*a+1;}')
|
jsi = JSInterpreter('function x4(a){return 2*a+1;}')
|
||||||
self.assertEqual(jsi.call_function('x4', 3), 7)
|
self.assertEqual(jsi.call_function('x4', 3), 7)
|
||||||
|
@ -232,10 +232,10 @@ class JSInterpreter(object):
|
|||||||
def extract_function(self, funcname):
|
def extract_function(self, funcname):
|
||||||
func_m = re.search(
|
func_m = re.search(
|
||||||
r'''(?x)
|
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<args>[^)]*)\)\s*
|
||||||
\{(?P<code>[^}]+)\}''' % (
|
\{(?P<code>[^}]+)\}''' % (
|
||||||
re.escape(funcname), re.escape(funcname)),
|
re.escape(funcname), re.escape(funcname), re.escape(funcname)),
|
||||||
self.code)
|
self.code)
|
||||||
if func_m is None:
|
if func_m is None:
|
||||||
raise ExtractorError('Could not find JS function %r' % funcname)
|
raise ExtractorError('Could not find JS function %r' % funcname)
|
||||||
|
Loading…
Reference in New Issue
Block a user