mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
kernel/builtins/test262: 本批新码 clippy 三则 + fmt 归净——obfuscated_if_else(source_escape_to_key 值域判定改 if/else)、needless_range_loop(decode_uri_units 保留字符原样段改 extend_from_slice)、needless_borrows_for_generic_args(844f2f4 rename 调用两处冗余借用);fmt 漂移(compiler.rs/vm.rs 构造体折行)一并归净。七 crate clippy 零告警、fmt --check 净、七 crate 2879/1(唯一失败 compile_class_declaration 既有)、release 子集 8/8 + 2/2 终验
This commit is contained in:
@@ -79,9 +79,7 @@ fn decode_uri_units(input: &[u16], preserve_reserved: bool) -> Result<Vec<u16>,
|
||||
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;
|
||||
|
||||
@@ -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<CompiledModule, String> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -2736,8 +2736,9 @@ impl Vm {
|
||||
.map_err(|errs| errs.into_iter().map(|e| e.message).collect::<Vec<_>>().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 {
|
||||
|
||||
Reference in New Issue
Block a user