From 68d2974eb5c4f766ab07cbb9cf8d042271b497c0 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Mon, 14 Sep 2026 08:18:38 +0000 Subject: [PATCH] =?UTF-8?q?kernel/builtins/test262:=20=E6=9C=AC=E6=89=B9?= =?UTF-8?q?=E6=96=B0=E7=A0=81=20clippy=20=E4=B8=89=E5=88=99=20+=20fmt=20?= =?UTF-8?q?=E5=BD=92=E5=87=80=E2=80=94=E2=80=94obfuscated=5Fif=5Felse?= =?UTF-8?q?=EF=BC=88source=5Fescape=5Fto=5Fkey=20=E5=80=BC=E5=9F=9F?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=E6=94=B9=20if/else=EF=BC=89=E3=80=81needless?= =?UTF-8?q?=5Frange=5Floop=EF=BC=88decode=5Furi=5Funits=20=E4=BF=9D?= =?UTF-8?q?=E7=95=99=E5=AD=97=E7=AC=A6=E5=8E=9F=E6=A0=B7=E6=AE=B5=E6=94=B9?= =?UTF-8?q?=20extend=5Ffrom=5Fslice=EF=BC=89=E3=80=81needless=5Fborrows=5F?= =?UTF-8?q?for=5Fgeneric=5Fargs=EF=BC=88844f2f4=20rename=20=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E4=B8=A4=E5=A4=84=E5=86=97=E4=BD=99=E5=80=9F=E7=94=A8?= =?UTF-8?q?=EF=BC=89=EF=BC=9Bfmt=20=E6=BC=82=E7=A7=BB=EF=BC=88compiler.rs/?= =?UTF-8?q?vm.rs=20=E6=9E=84=E9=80=A0=E4=BD=93=E6=8A=98=E8=A1=8C=EF=BC=89?= =?UTF-8?q?=E4=B8=80=E5=B9=B6=E5=BD=92=E5=87=80=E3=80=82=E4=B8=83=20crate?= =?UTF-8?q?=20clippy=20=E9=9B=B6=E5=91=8A=E8=AD=A6=E3=80=81fmt=20--check?= =?UTF-8?q?=20=E5=87=80=E3=80=81=E4=B8=83=20crate=202879/1=EF=BC=88?= =?UTF-8?q?=E5=94=AF=E4=B8=80=E5=A4=B1=E8=B4=A5=20compile=5Fclass=5Fdeclar?= =?UTF-8?q?ation=20=E6=97=A2=E6=9C=89=EF=BC=89=E3=80=81release=20=E5=AD=90?= =?UTF-8?q?=E9=9B=86=208/8=20+=202/2=20=E7=BB=88=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_builtins/src/global/uri.rs | 4 +--- crates/oxide_compiler/src/compiler.rs | 13 +++++++++---- crates/oxide_kernel/src/string_forge.rs | 16 +++++++--------- crates/oxide_test262/src/main.rs | 2 +- crates/oxide_vm/src/vm.rs | 9 +++++---- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/crates/oxide_builtins/src/global/uri.rs b/crates/oxide_builtins/src/global/uri.rs index 448b0e80..7154d615 100644 --- a/crates/oxide_builtins/src/global/uri.rs +++ b/crates/oxide_builtins/src/global/uri.rs @@ -79,9 +79,7 @@ fn decode_uri_units(input: &[u16], preserve_reserved: bool) -> Result, let decoded = std::str::from_utf8(&encoded).map_err(|_| ())?; let ch = decoded.chars().next().expect("单字节序解出恰一个码点"); if preserve_reserved && ch.is_ascii() && URI_RESERVED.contains(ch) { - for k in raw_start..i { - out.push(input[k]); - } + out.extend_from_slice(&input[raw_start..i]); continue; } let cp = ch as u32; diff --git a/crates/oxide_compiler/src/compiler.rs b/crates/oxide_compiler/src/compiler.rs index 379a5c04..ebb55497 100644 --- a/crates/oxide_compiler/src/compiler.rs +++ b/crates/oxide_compiler/src/compiler.rs @@ -59,15 +59,20 @@ impl Compiler { /// 标记源码为 `source_escape` 产物(动态编译入口:eval / Function 构造器)。 pub fn with_source_encoded(self, enable: bool) -> Self { - Self { is_source_encoded: enable, ..self } + Self { + is_source_encoded: enable, + ..self + } } /// 编译整个 script program:AST → IR(`Emitter::emit_program`)→ 统一 IR 管线。 pub fn compile(&self, program: &oxide_parser::Program) -> Result { crate::compiler_debug!("compile: starting..."); - let ir = Emitter::new() - .with_source_encoded(self.is_source_encoded) - .emit_program(program, self.repl_persist, self.is_eval_script)?; + let ir = Emitter::new().with_source_encoded(self.is_source_encoded).emit_program( + program, + self.repl_persist, + self.is_eval_script, + )?; self.compile_ir(ir) } diff --git a/crates/oxide_kernel/src/string_forge.rs b/crates/oxide_kernel/src/string_forge.rs index 7c62afac..e5df2a1a 100644 --- a/crates/oxide_kernel/src/string_forge.rs +++ b/crates/oxide_kernel/src/string_forge.rs @@ -191,9 +191,7 @@ pub fn source_escape_to_key(text: &str) -> String { if i + 1 < chars.len() && chars[i + 1] == '\\' { let is_marker = i + 7 <= chars.len() && chars[i + 2] == 'u' - && chars[i + 3..i + 7] - .iter() - .all(|c| matches!(c, '0'..='9' | 'a'..='f')); + && chars[i + 3..i + 7].iter().all(|c| matches!(c, '0'..='9' | 'a'..='f')); if is_marker { out.push('\\'); i += 1; @@ -209,12 +207,12 @@ pub fn source_escape_to_key(text: &str) -> String { if i + 1 < chars.len() && chars[i + 1] == 'u' { let tail_len = 4.min(chars.len() - i - 2); let tail = &chars[i + 2..i + 2 + tail_len]; - let ok = tail - .iter() - .all(|c| matches!(c, '0'..='9' | 'a'..='f')); - let v: u32 = ok - .then(|| tail.iter().fold(0u32, |v, c| v * 16 + c.to_digit(16).unwrap())) - .unwrap_or(0); + let ok = tail.iter().all(|c| matches!(c, '0'..='9' | 'a'..='f')); + let v: u32 = if ok { + tail.iter().fold(0u32, |v, c| v * 16 + c.to_digit(16).unwrap()) + } else { + 0 + }; if tail_len == 4 && ok && (v == 0xFFFD || (0xD800..=0xDFFF).contains(&v)) { out.push('\u{FFFD}'); out.extend(tail); diff --git a/crates/oxide_test262/src/main.rs b/crates/oxide_test262/src/main.rs index 9349c2f2..cfa41c03 100644 --- a/crates/oxide_test262/src/main.rs +++ b/crates/oxide_test262/src/main.rs @@ -1257,7 +1257,7 @@ fn supervise_window( let _ = std::fs::remove_file(format!("{}.tmp", hb_path.display())); // 旁路失败行归档而非删除:统计已由心跳合并入父进程,此文件是收尾逐文件 // 差分的终态依据(删除即永久丢记录)。 - let _ = std::fs::rename(&hb_path.with_extension("fails"), &hb_path.with_extension("fails.done")); + let _ = std::fs::rename(hb_path.with_extension("fails"), hb_path.with_extension("fails.done")); stats } diff --git a/crates/oxide_vm/src/vm.rs b/crates/oxide_vm/src/vm.rs index f69288df..93e70d3a 100644 --- a/crates/oxide_vm/src/vm.rs +++ b/crates/oxide_vm/src/vm.rs @@ -2736,8 +2736,9 @@ impl Vm { .map_err(|errs| errs.into_iter().map(|e| e.message).collect::>().join("\n"))?; // 动态路径源契约:调用方以源码域转义(`string_forge::source_escape`) // 形态传源;正则字面量源文本常量与静态同路径(`pool_key_plain`)。 - let mut module = - oxide_compiler::compiler::Compiler::new().with_source_encoded(true).compile(&program)?; + let mut module = oxide_compiler::compiler::Compiler::new() + .with_source_encoded(true) + .compile(&program)?; let anonymous = module.sub_modules.remove(0); // 形参数以编译结果为准:单个实参 "a,b,c" 拼接后解析为 3 个形参 // (ES 动态函数把非末位实参以逗号连接成参数串再解析)。 @@ -2851,13 +2852,13 @@ impl Vm { #[cfg(test)] mod tests { - use super::{opcode, ForOfEntry, JsValue, TryHandler, Vm}; use super::{canonical_index_of, canonical_index_units}; - use oxide_types::private_key::INT_KEY_COUNT; + use super::{opcode, ForOfEntry, JsValue, TryHandler, Vm}; use oxide_bytecode::module::CompiledModule; use oxide_runtime_api::{NativeResult, VmHost}; use oxide_types::object::NativeFnPtr; use oxide_types::object::{JsObject, PropAttributes}; + use oxide_types::private_key::INT_KEY_COUNT; use std::sync::Arc; fn native_return_7(_vm: &mut Vm, _args: &[u8]) -> NativeResult {