docs: 补充注释与格式化

This commit is contained in:
爱特每羊队
2026-08-06 23:10:27 +08:00
parent 4e0fd762c2
commit 328b8a3ddc
156 changed files with 2393 additions and 1687 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ pub fn bind_array(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
core,
&[("toString", oxide_builtins::array::array_to_string::<crate::vm::Vm> as *const (), 0)],
);
// Built-in prototype methods are non-enumerable (otherwise they leak into for-in).
// 内置原型方法不可枚举(否则会泄漏进 for-in)。
let si = core.perm_interner().intern("toString").0;
if let Some(pos) = core.shape_forge().lookup_position(array_proto.shape_id(), si) {
array_proto.set_data_meta(pos, PropAttributes::new(true, false, true));
+2 -2
View File
@@ -16,7 +16,7 @@ fn bind_error_subtype_constructor(
let mut ctor = Box::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::from_js_object(function_proto_ptr)));
ctor.set_function(true);
// SAFETY: ctor_fn is a NativeFn fn-item pointer cast to *const () by callers.
// SAFETY: ctor_fn 是调用方转成 *const () 的 NativeFn 函数项指针。
ctor.set_native_fn(Some(unsafe { NativeFnPtr::from_raw(ctor_fn) }));
ctor.set_native_arg_count(1);
@@ -121,7 +121,7 @@ pub fn bind_error(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
{
let err_ctor_ptr = session.builtin_world().error_constructor.as_ptr() as *mut JsObject;
let err_ctor = unsafe { &mut *err_ctor_ptr };
// SAFETY: error_constructor is a NativeFn fn-item.
// SAFETY: error_constructor 是 NativeFn 函数项。
err_ctor.set_native_fn(Some(unsafe {
NativeFnPtr::from_raw(oxide_builtins::error::error_constructor::<crate::vm::Vm> as *const ())
}));
+1 -1
View File
@@ -53,7 +53,7 @@ pub fn bind_object(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
("valueOf", oxide_builtins::object::object_proto_value_of::<crate::vm::Vm> as *const (), 0),
],
);
// Built-in prototype methods are non-enumerable (otherwise they leak into for-in).
// 内置原型方法不可枚举(否则会泄漏进 for-in)。
for name in ["toString", "valueOf"] {
let si = core.perm_interner().intern(name).0;
if let Some(pos) = core.shape_forge().lookup_position(object_proto.shape_id(), si) {
+6 -4
View File
@@ -83,7 +83,7 @@ macro_rules! bind_constructor {
}
pub(crate) fn configure_native_constructor(ctor: &mut JsObject, native_fn: *const (), arg_count: u8) {
// SAFETY: native_fn is always a valid NativeFn fn-item pointer cast to *const () by callers.
// SAFETY: native_fn 始终是调用方转成 *const () 的合法 NativeFn 函数项指针。
ctor.set_native_fn(Some(unsafe { NativeFnPtr::from_raw(native_fn) }));
ctor.set_native_arg_count(arg_count);
}
@@ -100,7 +100,7 @@ pub(crate) fn apply_binding_table(
let shape_forge = core.shape_forge().as_ref();
let string_forge = core.perm_interner().as_ref();
for (name, func, nargs) in bindings {
// SAFETY: all entries in the binding table are NativeFn fn-item pointers cast to *const ().
// SAFETY: 绑定表中所有条目都是转成 *const () 的 NativeFn 函数项指针。
let fn_ptr = unsafe { oxide_types::object::NativeFnPtr::from_raw(*func) };
let _ = world.bind_method(target, shape_forge, string_forge, name, fn_ptr, *nargs);
}
@@ -491,9 +491,11 @@ pub fn bind_global_builtin_slots(core: &Arc<KernelCore>, session: &KernelSession
bind_existing_global(core, global, "globalThis", global_this);
}
/// Maintenance: when adding a `BuiltinDirtySet` group, update this rebind map,
/// `BuiltinSnapshot`, and `BuiltinWorld::rebuild_with_dirty()` together.
/// 按脏标记重绑被污染的内置对象;`dirty` 为 `None` 时绑定全部(初始化路径)。
///
/// # 注意事项
/// 维护:新增 `BuiltinDirtySet` 分组时,须同步更新本重绑映射、`BuiltinSnapshot` 与
/// `BuiltinWorld::rebuild_with_dirty()`。
pub fn rebind_dirty_builtins(core: &Arc<KernelCore>, session: &mut KernelSession, dirty: Option<&BuiltinDirtySet>) {
let global_ptr = session.global_object().as_ptr() as *mut JsObject;
let global = unsafe { &mut *global_ptr };