[JSInterp] Improve tests

* from yt-dlp/yt-dlp#12313
* also fix d7c2708
This commit is contained in:
dirkf 2025-03-10 11:44:06 +00:00
parent 32f89de92b
commit 420d53387c
2 changed files with 20 additions and 4 deletions

View file

@ -154,6 +154,7 @@ def _js_to_primitive(v):
)
# more exact: yt-dlp/yt-dlp#12110
def _js_toString(v):
return (
'undefined' if v is JS_Undefined
@ -162,7 +163,7 @@ def _js_toString(v):
else 'null' if v is None
# bool <= int: do this first
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))