mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-30 22:25:19 +00:00 
			
		
		
		
	[jsinterp] Implement Function.prototype resolving for call and apply (#10392)
				
					
				
			Authored by: Grub4K
This commit is contained in:
		| @@ -636,6 +636,8 @@ class JSInterpreter: | ||||
|                     raise self.Exception(f'{member} {msg}', expr) | ||||
| 
 | ||||
|             def eval_method(): | ||||
|                 nonlocal member | ||||
| 
 | ||||
|                 if (variable, member) == ('console', 'debug'): | ||||
|                     if Debugger.ENABLED: | ||||
|                         Debugger.write(self.interpret_expression(f'[{arg_str}]', local_vars, allow_recursion)) | ||||
| @@ -644,6 +646,7 @@ class JSInterpreter: | ||||
|                 types = { | ||||
|                     'String': str, | ||||
|                     'Math': float, | ||||
|                     'Array': list, | ||||
|                 } | ||||
|                 obj = local_vars.get(variable, types.get(variable, NO_DEFAULT)) | ||||
|                 if obj is NO_DEFAULT: | ||||
| @@ -667,6 +670,21 @@ class JSInterpreter: | ||||
|                     self.interpret_expression(v, local_vars, allow_recursion) | ||||
|                     for v in self._separate(arg_str)] | ||||
| 
 | ||||
|                 # Fixup prototype call | ||||
|                 if isinstance(obj, type) and member.startswith('prototype.'): | ||||
|                     new_member, _, func_prototype = member.partition('.')[2].partition('.') | ||||
|                     assertion(argvals, 'takes one or more arguments') | ||||
|                     assertion(isinstance(argvals[0], obj), f'needs binding to type {obj}') | ||||
|                     if func_prototype == 'call': | ||||
|                         obj, *argvals = argvals | ||||
|                     elif func_prototype == 'apply': | ||||
|                         assertion(len(argvals) == 2, 'takes two arguments') | ||||
|                         obj, argvals = argvals | ||||
|                         assertion(isinstance(argvals, list), 'second argument needs to be a list') | ||||
|                     else: | ||||
|                         raise self.Exception(f'Unsupported Function method {func_prototype}', expr) | ||||
|                     member = new_member | ||||
| 
 | ||||
|                 if obj is str: | ||||
|                     if member == 'fromCharCode': | ||||
|                         assertion(argvals, 'takes one or more arguments') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Simon Sawicki
					Simon Sawicki