feat: Map/Set 支持 for-of 迭代与 entries/values/keys(内部槽方式)

This commit is contained in:
爱特每羊队
2026-06-27 17:49:19 +08:00
parent 19bc8e64a4
commit a78056f2ff
6 changed files with 337 additions and 3 deletions
+31 -1
View File
@@ -15,7 +15,7 @@ macro_rules! native_try {
};
}
type MapInner = indexmap::IndexMap<SetKey, JsValue>;
pub(crate) type MapInner = indexmap::IndexMap<SetKey, JsValue>;
/// Retrieve the `IndexMap` pointer stored in a Map object's native-data slot.
///
@@ -201,3 +201,33 @@ pub fn map_size<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
let inner = native_try!(get_map_inner(vm, this_val));
NativeResult::Ok(JsValue::float(unsafe { (*inner).len() } as f64))
}
pub fn map_entries<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
let this_val = vm.reg(if args.is_empty() { 0 } else { args[0] });
let _inner = native_try!(get_map_inner(vm, this_val));
NativeResult::Ok(crate::iterator::make_mode_iterator(
vm,
this_val,
crate::iterator::map_entries_iter_next::<H> as *const (),
))
}
pub fn map_values<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
let this_val = vm.reg(if args.is_empty() { 0 } else { args[0] });
let _inner = native_try!(get_map_inner(vm, this_val));
NativeResult::Ok(crate::iterator::make_mode_iterator(
vm,
this_val,
crate::iterator::map_values_iter_next::<H> as *const (),
))
}
pub fn map_keys<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
let this_val = vm.reg(if args.is_empty() { 0 } else { args[0] });
let _inner = native_try!(get_map_inner(vm, this_val));
NativeResult::Ok(crate::iterator::make_mode_iterator(
vm,
this_val,
crate::iterator::map_keys_iter_next::<H> as *const (),
))
}