mirror of
				https://github.com/ytdl-org/youtube-dl
				synced 2025-10-31 09:43:32 +00:00 
			
		
		
		
	[JSInterp] Reorganise some declarations to align better with yt-dlp
This commit is contained in:
		
							parent
							
								
									67dbfa65f2
								
							
						
					
					
						commit
						7513413794
					
				| @ -7,6 +7,7 @@ from __future__ import unicode_literals | |||||||
| import os | import os | ||||||
| import sys | import sys | ||||||
| import unittest | import unittest | ||||||
|  | 
 | ||||||
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||||||
| 
 | 
 | ||||||
| import math | import math | ||||||
| @ -146,6 +147,25 @@ class TestJSInterpreter(unittest.TestCase): | |||||||
|         # https://github.com/ytdl-org/youtube-dl/issues/32815 |         # https://github.com/ytdl-org/youtube-dl/issues/32815 | ||||||
|         self._test('function f(){return 0  - 7 * - 6;}', 42) |         self._test('function f(){return 0  - 7 * - 6;}', 42) | ||||||
| 
 | 
 | ||||||
|  |     def test_bitwise_operators_typecast(self): | ||||||
|  |         # madness | ||||||
|  |         self._test('function f(){return null << 5}', 0) | ||||||
|  |         self._test('function f(){return undefined >> 5}', 0) | ||||||
|  |         self._test('function f(){return 42 << NaN}', 42) | ||||||
|  |         self._test('function f(){return 42 << Infinity}', 42) | ||||||
|  |         self._test('function f(){return 0.0 << null}', 0) | ||||||
|  |         self._test('function f(){return NaN << 42}', 0) | ||||||
|  |         self._test('function f(){return "21.9" << 1}', 42) | ||||||
|  |         self._test('function f(){return true << "5";}', 32) | ||||||
|  |         self._test('function f(){return true << true;}', 2) | ||||||
|  |         self._test('function f(){return "19" & "21.9";}', 17) | ||||||
|  |         self._test('function f(){return "19" & false;}', 0) | ||||||
|  |         self._test('function f(){return "11.0" >> "2.1";}', 2) | ||||||
|  |         self._test('function f(){return 5 ^ 9;}', 12) | ||||||
|  |         self._test('function f(){return 0.0 << NaN}', 0) | ||||||
|  |         self._test('function f(){return null << undefined}', 0) | ||||||
|  |         self._test('function f(){return 21 << 4294967297}', 42) | ||||||
|  | 
 | ||||||
|     def test_array_access(self): |     def test_array_access(self): | ||||||
|         self._test('function f(){var x = [1,2,3]; x[0] = 4; x[0] = 5; x[2.0] = 7; return x;}', [5, 2, 7]) |         self._test('function f(){var x = [1,2,3]; x[0] = 4; x[0] = 5; x[2.0] = 7; return x;}', [5, 2, 7]) | ||||||
| 
 | 
 | ||||||
| @ -482,25 +502,6 @@ class TestJSInterpreter(unittest.TestCase): | |||||||
|         self._test('function f(){return -524999584 << 5}', 379882496) |         self._test('function f(){return -524999584 << 5}', 379882496) | ||||||
|         self._test('function f(){return 1236566549 << 5}', 915423904) |         self._test('function f(){return 1236566549 << 5}', 915423904) | ||||||
| 
 | 
 | ||||||
|     def test_bitwise_operators_typecast(self): |  | ||||||
|         # madness |  | ||||||
|         self._test('function f(){return null << 5}', 0) |  | ||||||
|         self._test('function f(){return undefined >> 5}', 0) |  | ||||||
|         self._test('function f(){return 42 << NaN}', 42) |  | ||||||
|         self._test('function f(){return 42 << Infinity}', 42) |  | ||||||
|         self._test('function f(){return 0.0 << null}', 0) |  | ||||||
|         self._test('function f(){return NaN << 42}', 0) |  | ||||||
|         self._test('function f(){return "21.9" << 1}', 42) |  | ||||||
|         self._test('function f(){return 21 << 4294967297}', 42) |  | ||||||
|         self._test('function f(){return true << "5";}', 32) |  | ||||||
|         self._test('function f(){return true << true;}', 2) |  | ||||||
|         self._test('function f(){return "19" & "21.9";}', 17) |  | ||||||
|         self._test('function f(){return "19" & false;}', 0) |  | ||||||
|         self._test('function f(){return "11.0" >> "2.1";}', 2) |  | ||||||
|         self._test('function f(){return 5 ^ 9;}', 12) |  | ||||||
|         self._test('function f(){return 0.0 << NaN}', 0) |  | ||||||
|         self._test('function f(){return null << undefined}', 0) |  | ||||||
| 
 |  | ||||||
|     def test_negative(self): |     def test_negative(self): | ||||||
|         self._test('function f(){return 2    *    -2.0    ;}', -4) |         self._test('function f(){return 2    *    -2.0    ;}', -4) | ||||||
|         self._test('function f(){return 2    -    - -2    ;}', 0) |         self._test('function f(){return 2    -    - -2    ;}', 0) | ||||||
|  | |||||||
| @ -283,17 +283,6 @@ _OPERATORS = ( | |||||||
|     ('**', _js_exp), |     ('**', _js_exp), | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| _COMP_OPERATORS = ( |  | ||||||
|     ('===', _js_id_op(operator.is_)), |  | ||||||
|     ('!==', _js_id_op(operator.is_not)), |  | ||||||
|     ('==', _js_eq), |  | ||||||
|     ('!=', _js_neq), |  | ||||||
|     ('<=', _js_comp_op(operator.le)), |  | ||||||
|     ('>=', _js_comp_op(operator.ge)), |  | ||||||
|     ('<', _js_comp_op(operator.lt)), |  | ||||||
|     ('>', _js_comp_op(operator.gt)), |  | ||||||
| ) |  | ||||||
| 
 |  | ||||||
| _LOG_OPERATORS = ( | _LOG_OPERATORS = ( | ||||||
|     ('|', _js_bit_op(operator.or_)), |     ('|', _js_bit_op(operator.or_)), | ||||||
|     ('^', _js_bit_op(operator.xor)), |     ('^', _js_bit_op(operator.xor)), | ||||||
| @ -314,6 +303,17 @@ _UNARY_OPERATORS_X = ( | |||||||
| 
 | 
 | ||||||
| _OPERATOR_RE = '|'.join(map(lambda x: re.escape(x[0]), _OPERATORS + _LOG_OPERATORS)) | _OPERATOR_RE = '|'.join(map(lambda x: re.escape(x[0]), _OPERATORS + _LOG_OPERATORS)) | ||||||
| 
 | 
 | ||||||
|  | _COMP_OPERATORS = ( | ||||||
|  |     ('===', _js_id_op(operator.is_)), | ||||||
|  |     ('!==', _js_id_op(operator.is_not)), | ||||||
|  |     ('==', _js_eq), | ||||||
|  |     ('!=', _js_neq), | ||||||
|  |     ('<=', _js_comp_op(operator.le)), | ||||||
|  |     ('>=', _js_comp_op(operator.ge)), | ||||||
|  |     ('<', _js_comp_op(operator.lt)), | ||||||
|  |     ('>', _js_comp_op(operator.gt)), | ||||||
|  | ) | ||||||
|  | 
 | ||||||
| _NAME_RE = r'[a-zA-Z_$][\w$]*' | _NAME_RE = r'[a-zA-Z_$][\w$]*' | ||||||
| _MATCHING_PARENS = dict(zip(*zip('()', '{}', '[]'))) | _MATCHING_PARENS = dict(zip(*zip('()', '{}', '[]'))) | ||||||
| _QUOTES = '\'"/' | _QUOTES = '\'"/' | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 dirkf
						dirkf