mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-03 19:29:51 +01:00
[jsinterp] Fix function calls without arguments.
This commit is contained in:
parent
bc40b3a5ba
commit
189935f159
@ -104,6 +104,13 @@ def test_precedence(self):
|
|||||||
}''')
|
}''')
|
||||||
self.assertEqual(jsi.call_function('x'), [20, 20, 30, 40, 50])
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -198,12 +198,12 @@ def interpret_expression(self, expr, local_vars, allow_recursion):
|
|||||||
return opfunc(x, y)
|
return opfunc(x, y)
|
||||||
|
|
||||||
m = re.match(
|
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:
|
if m:
|
||||||
fname = m.group('func')
|
fname = m.group('func')
|
||||||
argvals = tuple([
|
argvals = tuple([
|
||||||
int(v) if v.isdigit() else local_vars[v]
|
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:
|
if fname not in self._functions:
|
||||||
self._functions[fname] = self.extract_function(fname)
|
self._functions[fname] = self.extract_function(fname)
|
||||||
return self._functions[fname](argvals)
|
return self._functions[fname](argvals)
|
||||||
|
Loading…
Reference in New Issue
Block a user