mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-04-05 06:30:14 -05:00
parent
32f89de92b
commit
420d53387c
@ -212,9 +212,16 @@ class TestJSInterpreter(unittest.TestCase):
|
|||||||
# undefined
|
# undefined
|
||||||
self._test(jsi, NaN, args=[JS_Undefined])
|
self._test(jsi, NaN, args=[JS_Undefined])
|
||||||
# y,m,d, ... - may fail with older dates lacking DST data
|
# y,m,d, ... - may fail with older dates lacking DST data
|
||||||
jsi = JSInterpreter('function f() { return new Date(%s); }'
|
jsi = JSInterpreter(
|
||||||
% ('2024, 5, 29, 2, 52, 12, 42',))
|
'function f() { return new Date(%s); }'
|
||||||
self._test(jsi, 1719625932042)
|
% ('2024, 5, 29, 2, 52, 12, 42',))
|
||||||
|
self._test(jsi, (
|
||||||
|
1719625932042 # UK value
|
||||||
|
+ (
|
||||||
|
+ 3600 # back to GMT
|
||||||
|
+ (time.altzone if time.daylight # host's DST
|
||||||
|
else time.timezone)
|
||||||
|
) * 1000))
|
||||||
# no arg
|
# no arg
|
||||||
self.assertAlmostEqual(JSInterpreter(
|
self.assertAlmostEqual(JSInterpreter(
|
||||||
'function f() { return new Date() - 0; }').call_function('f'),
|
'function f() { return new Date() - 0; }').call_function('f'),
|
||||||
@ -485,6 +492,14 @@ class TestJSInterpreter(unittest.TestCase):
|
|||||||
self._test('function f(){return NaN << 42}', 0)
|
self._test('function f(){return NaN << 42}', 0)
|
||||||
self._test('function f(){return "21.9" << 1}', 42)
|
self._test('function f(){return "21.9" << 1}', 42)
|
||||||
self._test('function f(){return 21 << 4294967297}', 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)
|
||||||
|
@ -154,6 +154,7 @@ def _js_to_primitive(v):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# more exact: yt-dlp/yt-dlp#12110
|
||||||
def _js_toString(v):
|
def _js_toString(v):
|
||||||
return (
|
return (
|
||||||
'undefined' if v is JS_Undefined
|
'undefined' if v is JS_Undefined
|
||||||
@ -162,7 +163,7 @@ def _js_toString(v):
|
|||||||
else 'null' if v is None
|
else 'null' if v is None
|
||||||
# bool <= int: do this first
|
# bool <= int: do this first
|
||||||
else ('false', 'true')[v] if isinstance(v, bool)
|
else ('false', 'true')[v] if isinstance(v, bool)
|
||||||
else '{0:.7f}'.format(v).rstrip('.0') if isinstance(v, compat_numeric_types)
|
else re.sub(r'(?<=\d)\.?0*$', '', '{0:.7f}'.format(v)) if isinstance(v, compat_numeric_types)
|
||||||
else _js_to_primitive(v))
|
else _js_to_primitive(v))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user