mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 19:21:11 +08:00
style: 全 workspace 格式订正,消除 fmt 漂移
This commit is contained in:
@@ -191,8 +191,7 @@ pub(crate) fn unit_string_value<H: VmHost>(vm: &mut H, unit: u16) -> JsValue {
|
||||
pub(crate) fn arraylike_index_present<H: VmHost>(vm: &mut H, ptr: *mut JsObject, i: usize) -> bool {
|
||||
// SAFETY: ptr 来自 this/参数对象,指向存活对象。
|
||||
let key_si = vm.string_key_si(&i.to_string());
|
||||
vm.has_property(unsafe { &*ptr }, key_si)
|
||||
.unwrap_or(false)
|
||||
vm.has_property(unsafe { &*ptr }, key_si).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// 元素读取失败时直接把异常作为 NativeResult::Err 返回。
|
||||
|
||||
@@ -1042,15 +1042,7 @@ pub fn date_set_year<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let full_year = if (0..=99).contains(&y_int) { y_int + 1900 } else { y_int };
|
||||
finish_local_setter(
|
||||
obj,
|
||||
make_local_timestamp(
|
||||
full_year as f64,
|
||||
dm as f64,
|
||||
dd as f64,
|
||||
dh as f64,
|
||||
dmin as f64,
|
||||
dsec as f64,
|
||||
dms as f64,
|
||||
),
|
||||
make_local_timestamp(full_year as f64, dm as f64, dd as f64, dh as f64, dmin as f64, dsec as f64, dms as f64),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,7 @@ fn escape_units(input: &[u16]) -> Vec<u16> {
|
||||
continue;
|
||||
}
|
||||
// 转义序列恒为全 ASCII,按码元推入。
|
||||
let text = if u <= 0xFF {
|
||||
format!("%{u:02X}")
|
||||
} else {
|
||||
format!("%u{u:04X}")
|
||||
};
|
||||
let text = if u <= 0xFF { format!("%{u:02X}") } else { format!("%u{u:04X}") };
|
||||
out.extend(text.encode_utf16());
|
||||
}
|
||||
out
|
||||
@@ -42,10 +38,7 @@ fn unescape_units(input: &[u16]) -> Vec<u16> {
|
||||
while i < input.len() {
|
||||
if input[i] == b'%' as u16 {
|
||||
// %uXXXX:后跟 4 位十六进制。
|
||||
if i + 6 <= input.len()
|
||||
&& input[i + 1] == b'u' as u16
|
||||
&& (2..6).all(|k| hex_val(input[i + k]).is_some())
|
||||
{
|
||||
if i + 6 <= input.len() && input[i + 1] == b'u' as u16 && (2..6).all(|k| hex_val(input[i + k]).is_some()) {
|
||||
let v = (0..4).fold(0u16, |acc, k| acc * 16 + hex_val(input[i + 2 + k]).unwrap());
|
||||
out.push(v);
|
||||
i += 6;
|
||||
|
||||
@@ -946,11 +946,10 @@ pub fn module_defer_object<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let fn_val = vm.reg(args[1]);
|
||||
let ns_val = vm.reg(args[2]);
|
||||
// fn 为函数或 undefined(哨兵);其余抛 TypeError。
|
||||
let fn_is_function = fn_val.is_object()
|
||||
&& {
|
||||
let ptr = fn_val.as_js_object_ptr();
|
||||
!ptr.is_null() && unsafe { (*ptr).is_function() }
|
||||
};
|
||||
let fn_is_function = fn_val.is_object() && {
|
||||
let ptr = fn_val.as_js_object_ptr();
|
||||
!ptr.is_null() && unsafe { (*ptr).is_function() }
|
||||
};
|
||||
if !fn_is_function && !fn_val.is_undefined() {
|
||||
return type_error(vm, "__moduleDeferObject: first argument must be a function or undefined");
|
||||
}
|
||||
@@ -1165,11 +1164,7 @@ mod tests {
|
||||
|
||||
// 再收集一次:若 error 边漏登,err 被回收、计数回落。
|
||||
vm.collect_session_gc();
|
||||
assert_eq!(
|
||||
vm.session_object_count(),
|
||||
steady_count,
|
||||
"失败缓存错误应跨收集存活(GC 边已登记)"
|
||||
);
|
||||
assert_eq!(vm.session_object_count(), steady_count, "失败缓存错误应跨收集存活(GC 边已登记)");
|
||||
// 原地 sweep 不搬移:ns 与状态盒原地保留,error 指针稳定。
|
||||
let ns_obj = unsafe { &*ns_val.as_js_object_ptr() };
|
||||
let state = deferred_state(ns_obj).expect("deferred state 应存活");
|
||||
|
||||
@@ -842,12 +842,18 @@ pub fn regexp_compile<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
return NativeResult::Err(crate::error::create_type_error(vm, "null object"));
|
||||
}
|
||||
if !unsafe { &*this_ptr }.is_regexp_obj() {
|
||||
return NativeResult::Err(crate::error::create_type_error(vm, "RegExp.prototype.compile called on non-RegExp object"));
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
"RegExp.prototype.compile called on non-RegExp object",
|
||||
));
|
||||
}
|
||||
// proto 精确恒等:子类实例(proto = 子类 prototype)抛 TypeError。
|
||||
let proto_ptr = vm.builtin_proto(ProtoKind::RegExpProto);
|
||||
if unsafe { &*this_ptr }.proto() != JsValue::from_js_object(proto_ptr) {
|
||||
return NativeResult::Err(crate::error::create_type_error(vm, "RegExp.prototype.compile called on subclass instance"));
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
"RegExp.prototype.compile called on subclass instance",
|
||||
));
|
||||
}
|
||||
|
||||
// 第 2 / 3 步:pattern / flags 取参。
|
||||
|
||||
Reference in New Issue
Block a user