mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-08-10 18:59:39 +00:00
[jsinterp] Add charcodeAt
and bitwise overflow (#4706)
Authored by: elyse0
This commit is contained in:
@@ -18,10 +18,11 @@ from .utils import (
|
||||
|
||||
|
||||
def _js_bit_op(op):
|
||||
def zeroise(x):
|
||||
return 0 if x in (None, JS_Undefined) else x
|
||||
|
||||
def wrapped(a, b):
|
||||
def zeroise(x):
|
||||
return 0 if x in (None, JS_Undefined) else x
|
||||
return op(zeroise(a), zeroise(b))
|
||||
return op(zeroise(a), zeroise(b)) & 0xffffffff
|
||||
|
||||
return wrapped
|
||||
|
||||
@@ -692,6 +693,13 @@ class JSInterpreter:
|
||||
return obj.index(idx, start)
|
||||
except ValueError:
|
||||
return -1
|
||||
elif member == 'charCodeAt':
|
||||
assertion(isinstance(obj, str), 'must be applied on a string')
|
||||
assertion(len(argvals) == 1, 'takes exactly one argument')
|
||||
idx = argvals[0] if isinstance(argvals[0], int) else 0
|
||||
if idx >= len(obj):
|
||||
return None
|
||||
return ord(obj[idx])
|
||||
|
||||
idx = int(member) if isinstance(obj, list) else member
|
||||
return obj[idx](argvals, allow_recursion=allow_recursion)
|
||||
|
Reference in New Issue
Block a user