chore: 全仓 rustfmt 格式化归拢
This commit is contained in:
@@ -30,7 +30,11 @@ pub fn bind_global(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
|
||||
("__moduleObject", oxide_builtins::module::module_object::<crate::vm::Vm> as *const (), 0),
|
||||
("__moduleSet", oxide_builtins::module::module_set::<crate::vm::Vm> as *const (), 3),
|
||||
("__moduleGet", oxide_builtins::module::module_get::<crate::vm::Vm> as *const (), 2),
|
||||
("__moduleLinkGet", oxide_builtins::module::module_link_get::<crate::vm::Vm> as *const (), 2),
|
||||
(
|
||||
"__moduleLinkGet",
|
||||
oxide_builtins::module::module_link_get::<crate::vm::Vm> as *const (),
|
||||
2,
|
||||
),
|
||||
("__moduleStar", oxide_builtins::module::module_star::<crate::vm::Vm> as *const (), 2),
|
||||
("__moduleSeal", oxide_builtins::module::module_seal::<crate::vm::Vm> as *const (), 1),
|
||||
("__moduleEval", oxide_builtins::module::module_eval::<crate::vm::Vm> as *const (), 1),
|
||||
|
||||
@@ -550,26 +550,14 @@ pub fn bind_temporal(core: &Arc<KernelCore>, session: &KernelSession, global: &m
|
||||
oxide_builtins::temporal::plain_date_time_to_json::<crate::vm::Vm> as *const (),
|
||||
0,
|
||||
),
|
||||
(
|
||||
"add",
|
||||
oxide_builtins::temporal::plain_date_time_add::<crate::vm::Vm> as *const (),
|
||||
1,
|
||||
),
|
||||
("add", oxide_builtins::temporal::plain_date_time_add::<crate::vm::Vm> as *const (), 1),
|
||||
(
|
||||
"subtract",
|
||||
oxide_builtins::temporal::plain_date_time_subtract::<crate::vm::Vm> as *const (),
|
||||
1,
|
||||
),
|
||||
(
|
||||
"until",
|
||||
oxide_builtins::temporal::plain_date_time_until::<crate::vm::Vm> as *const (),
|
||||
1,
|
||||
),
|
||||
(
|
||||
"since",
|
||||
oxide_builtins::temporal::plain_date_time_since::<crate::vm::Vm> as *const (),
|
||||
1,
|
||||
),
|
||||
("until", oxide_builtins::temporal::plain_date_time_until::<crate::vm::Vm> as *const (), 1),
|
||||
("since", oxide_builtins::temporal::plain_date_time_since::<crate::vm::Vm> as *const (), 1),
|
||||
(
|
||||
"equals",
|
||||
oxide_builtins::temporal::plain_date_time_equals::<crate::vm::Vm> as *const (),
|
||||
|
||||
@@ -104,16 +104,8 @@ impl Vm {
|
||||
return self.new_string_owned(buf);
|
||||
}
|
||||
// 大链走 Cons rope:非字符串操作数先转叶子,再 O(1) 链接(文本惰性扁平化)。
|
||||
let lv = if lhs.is_string() {
|
||||
lhs
|
||||
} else {
|
||||
self.string_leaf(lhs)
|
||||
};
|
||||
let rv = if rhs.is_string() {
|
||||
rhs
|
||||
} else {
|
||||
self.string_leaf(rhs)
|
||||
};
|
||||
let lv = if lhs.is_string() { lhs } else { self.string_leaf(lhs) };
|
||||
let rv = if rhs.is_string() { rhs } else { self.string_leaf(rhs) };
|
||||
self.new_cons_string(lv, rv)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
//! 核心入口为 [`vm::Vm`];`VmPool` 负责 VM 实例的复用;`session_gc` 提供
|
||||
//! session 内存回收;`bindings` 把内置对象绑定到每个 session 的 global 上。
|
||||
|
||||
mod async_func;
|
||||
mod async_from_sync;
|
||||
mod async_func;
|
||||
mod async_generator;
|
||||
/// 内置对象绑定模块:向 session 的 global 对象安装 Object/Array/... 及各原型。
|
||||
pub mod bindings;
|
||||
|
||||
@@ -193,8 +193,16 @@ fn function_symbol_has_instance_bound() {
|
||||
fn function_symbol_has_instance_poisoned_prototype_throws() {
|
||||
let mut vm = Vm::new();
|
||||
// 可调用但 prototype 非对象 → TypeError(OrdinaryHasInstance 唯一抛错点)。
|
||||
let err = eval(&mut vm, "var f = function(){}; f.prototype = 1; try { f[Symbol.hasInstance]({}) } catch (e) { e }").unwrap();
|
||||
let name = eval(&mut vm, "var f = function(){}; f.prototype = null; try { f[Symbol.hasInstance]({}) } catch (e) { e.name }").unwrap();
|
||||
let err = eval(
|
||||
&mut vm,
|
||||
"var f = function(){}; f.prototype = 1; try { f[Symbol.hasInstance]({}) } catch (e) { e }",
|
||||
)
|
||||
.unwrap();
|
||||
let name = eval(
|
||||
&mut vm,
|
||||
"var f = function(){}; f.prototype = null; try { f[Symbol.hasInstance]({}) } catch (e) { e.name }",
|
||||
)
|
||||
.unwrap();
|
||||
let _ = err;
|
||||
assert_eq!(vm.lookup_str(name).unwrap_or_default(), "TypeError");
|
||||
}
|
||||
@@ -208,7 +216,10 @@ fn bound_function_construct_semantics() {
|
||||
("function C(v){ this.v = v; } var B = C.bind({}, 1); new B(2).v", 1.0),
|
||||
("function C(a, b){ this.s = a + b; } var B = C.bind(null, 2); new B(3).s", 5.0),
|
||||
// 多层 bound 链:绑定实参按 内层先、外层后 拼接。
|
||||
("function C(v){ this.v = v; } var B = C.bind({}, 1); var D = B.bind({}, 2); new D().v", 1.0),
|
||||
(
|
||||
"function C(v){ this.v = v; } var B = C.bind({}, 1); var D = B.bind({}, 2); new D().v",
|
||||
1.0,
|
||||
),
|
||||
// native 构造器 target。
|
||||
("var arr = Array.bind(null); new arr(3).length", 3.0),
|
||||
];
|
||||
|
||||
@@ -211,7 +211,8 @@ fn has_instance_preserves_ordinary_has_instance() {
|
||||
#[test]
|
||||
fn symbol_keys_stay_distinct() {
|
||||
let mut vm = Vm::new();
|
||||
let result = eval(&mut vm, "var s1=Symbol('a'), s2=Symbol('b'); var o={}; o[s1]=1; o[s2]=2; [o[s1],o[s2]]").unwrap();
|
||||
let result =
|
||||
eval(&mut vm, "var s1=Symbol('a'), s2=Symbol('b'); var o={}; o[s1]=1; o[s2]=2; [o[s1],o[s2]]").unwrap();
|
||||
let arr = unsafe { &*result.as_js_object_ptr() };
|
||||
assert_eq!(arr.get_prop_at(0).as_int(), 1);
|
||||
assert_eq!(arr.get_prop_at(1).as_int(), 2);
|
||||
@@ -248,7 +249,11 @@ fn symbol_keys_excluded_from_for_in() {
|
||||
#[test]
|
||||
fn get_own_property_symbols_roundtrip() {
|
||||
let mut vm = Vm::new();
|
||||
let result = eval(&mut vm, "var s=Symbol('x'); var o={}; o[s]=7; var k=Object.getOwnPropertySymbols(o)[0]; o[k]").unwrap();
|
||||
let result = eval(
|
||||
&mut vm,
|
||||
"var s=Symbol('x'); var o={}; o[s]=7; var k=Object.getOwnPropertySymbols(o)[0]; o[k]",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(result.as_int(), 7);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,9 +67,8 @@ fn reset_preserves_session_strings_after_runtime_gc() {
|
||||
#[test]
|
||||
fn strings_only_then_reset_keeps_global_subtree_strings() {
|
||||
let mut vm = vm_with_threshold(4096);
|
||||
let first = compile(
|
||||
"globalThis.kept = { s: 'he' + 'llo' }; var t; for (var i = 0; i < 500000; i++) { t = 'x' + i; } 0",
|
||||
);
|
||||
let first =
|
||||
compile("globalThis.kept = { s: 'he' + 'llo' }; var t; for (var i = 0; i < 500000; i++) { t = 'x' + i; } 0");
|
||||
vm.run(&first).expect("run1");
|
||||
assert!(vm.session_gc_stats().total_collections > 0, "run1 应触发执行期字符串 GC");
|
||||
vm.reset();
|
||||
@@ -92,12 +91,7 @@ fn regexp_exec_strings_survive_runtime_gc() {
|
||||
);
|
||||
let result = vm.run(&module).expect("run");
|
||||
let text = vm.lookup_str(result).expect("exec 结果应为字符串").to_string();
|
||||
let expected = format!(
|
||||
"{}|{}|{}",
|
||||
"a".repeat(500) + &"b".repeat(500),
|
||||
"a".repeat(500),
|
||||
"b".repeat(500)
|
||||
);
|
||||
let expected = format!("{}|{}|{}", "a".repeat(500) + &"b".repeat(500), "a".repeat(500), "b".repeat(500));
|
||||
assert_eq!(text, expected);
|
||||
assert!(vm.session_gc_stats().total_collections > 0, "执行期应触发字符串 GC");
|
||||
}
|
||||
|
||||
@@ -108,4 +108,3 @@ fn yield_star_inner_without_return() {
|
||||
"1,9,true"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -125,10 +125,7 @@ fn eval_computed_compound_assign_getter_order() {
|
||||
fn eval_computed_compound_assign_read_error_skips_rhs() {
|
||||
// 读取抛错时 RHS 不求值,其副作用不泄漏。
|
||||
assert_eq!(eval("var h={get a(){throw 1}}; try{h[\"a\"]+=1}catch(e){e}"), "1");
|
||||
assert_eq!(
|
||||
eval("var side=0; var h={get a(){throw 1}}; try{h[\"a\"]+=(side=99)}catch(e){} side"),
|
||||
"0"
|
||||
);
|
||||
assert_eq!(eval("var side=0; var h={get a(){throw 1}}; try{h[\"a\"]+=(side=99)}catch(e){} side"), "0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user