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 {