完成 Ruff 全量清理

This commit is contained in:
yml2213
2026-08-31 10:55:44 +08:00
parent 840af3108e
commit 09ab80e062
68 changed files with 323 additions and 291 deletions
+36 -40
View File
@@ -13,6 +13,8 @@ JS 语义辅助复用 algorithm.py(_ic/i32/js_add/js_index/JSObject/JSFunction
from __future__ import annotations
import json
import math
from pathlib import Path
from .algorithm import (
UNDEF,
@@ -20,6 +22,7 @@ from .algorithm import (
JSDate,
JSFunction,
JSObject,
Window,
_ic,
h_decodeuri,
h_decodeuricomponent,
@@ -57,6 +60,8 @@ from .algorithm import (
ushr,
)
REPLAY = Path(__file__).resolve().parent.parent / "replay"
__all__ = ["REPLAY", "PagedooVM", "run_frame"]
@@ -66,28 +71,28 @@ __all__ = ["REPLAY", "PagedooVM", "run_frame"]
def _cmp_lt(a, b):
try:
return a < b
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return False
def _cmp_le(a, b):
try:
return a <= b
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return False
def _cmp_gt(a, b):
try:
return a > b
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return False
def _cmp_ge(a, b):
try:
return a >= b
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
return False
@@ -122,8 +127,8 @@ def h_arr_slice(this, a=None, b=None):
a = 0
if b is None or b is UNDEF:
b = n
a = int(a) if a == a else 0
b = int(b) if b == b else n
a = int(a) if not isinstance(a, float) or not math.isnan(a) else 0
b = int(b) if not isinstance(b, float) or not math.isnan(b) else n
if a < 0:
a = max(0, n + a)
if b < 0:
@@ -303,30 +308,29 @@ def _pg_index(obj, key):
return HostFunction(
lambda this: this.t if isinstance(this, JSDate) else obj.t, "valueOf"
)
if isinstance(obj, str):
if isinstance(key, str):
if key == "length":
return len(obj)
if key == "charCodeAt":
return HostFunction(h_char_code_at, "charCodeAt")
if key == "charAt":
return HostFunction(h_char_at, "charAt")
if key == "indexOf":
return HostFunction(h_str_indexof, "indexOf")
if key == "slice":
return HostFunction(h_str_slice, "slice")
if key == "split":
return HostFunction(h_str_split, "split")
if key == "toLowerCase":
return HostFunction(h_str_tolower, "toLowerCase")
if key == "toUpperCase":
return HostFunction(h_str_toupper, "toUpperCase")
if key == "toString":
return HostFunction(h_str_tostring, "toString")
if key == "substr":
return HostFunction(h_str_substr, "substr")
if key == "substring":
return HostFunction(h_str_substring, "substring")
if isinstance(obj, str) and isinstance(key, str):
if key == "length":
return len(obj)
if key == "charCodeAt":
return HostFunction(h_char_code_at, "charCodeAt")
if key == "charAt":
return HostFunction(h_char_at, "charAt")
if key == "indexOf":
return HostFunction(h_str_indexof, "indexOf")
if key == "slice":
return HostFunction(h_str_slice, "slice")
if key == "split":
return HostFunction(h_str_split, "split")
if key == "toLowerCase":
return HostFunction(h_str_tolower, "toLowerCase")
if key == "toUpperCase":
return HostFunction(h_str_toupper, "toUpperCase")
if key == "toString":
return HostFunction(h_str_tostring, "toString")
if key == "substr":
return HostFunction(h_str_substr, "substr")
if key == "substring":
return HostFunction(h_str_substring, "substring")
return js_index(obj, key)
@@ -486,15 +490,7 @@ class PagedooVM:
and len(self._host_log) < 2000
):
# 记录调用目标(简化)
_tgt = (
o[u + 2]
if op in (4, 11, 44, 50)
else (
o[u + 2]
if op in (0, 18, 23, 26, 43, 48, 84, 107)
else o[u + 2]
)
)
_tgt = o[u + 2]
try:
_tv = C[_tgt] if 0 <= _tgt < len(C) else UNDEF
_tr = (
@@ -505,7 +501,7 @@ class PagedooVM:
else repr(_tv)[:30]
)
self._host_log.append((op, u, _tr))
except Exception:
except Exception: # noqa: BLE001 外部接口与任务边界需要保留宽泛异常兜底
self._host_log.append((op, u, "?"))
if (
getattr(self, "_trace", None) is not None