docs: 添加 Rustdoc 注释

This commit is contained in:
2026-08-05 21:46:47 +08:00
parent 7c8f19f61a
commit 263fd255b6
158 changed files with 1440 additions and 15 deletions
@@ -7,6 +7,7 @@ use oxide_types::object::{JsObject, PropAttributes};
use crate::bind_constructor;
use crate::bindings::apply_binding_table;
/// 把 Array 构造器与原型方法绑定到 global。
pub fn bind_array(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let _array_methods = ArrayMethods {
is_array: oxide_builtins::array::array_is_array::<crate::vm::Vm> as *const (),
@@ -5,6 +5,7 @@ use crate::bindings::{apply_binding_table, configure_native_constructor};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
/// 把 ArrayBuffer 构造器与原型方法绑定到 global。
pub fn bind_array_buffer(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let ctor_ptr = session.builtin_world().array_buffer_constructor.as_ptr() as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
@@ -5,6 +5,7 @@ use crate::bindings::{apply_binding_table, configure_native_constructor};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
/// 把 Boolean 构造器与原型方法绑定到 global。
pub fn bind_boolean(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let ctor_ptr = session.builtin_world().boolean_constructor.as_ptr() as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
@@ -5,6 +5,7 @@ use crate::bindings::{apply_binding_table, configure_native_constructor};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
/// 把 DataView 构造器与原型方法绑定到 global。
pub fn bind_data_view(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let ctor_ptr = session.builtin_world().data_view_constructor.as_ptr() as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
@@ -5,6 +5,7 @@ use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
use oxide_types::value::JsValue;
/// 把 Date 构造器与原型方法绑定到 global。
pub fn bind_date(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let ctor_ptr = session.builtin_world().date_constructor.as_ptr() as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
@@ -43,6 +43,7 @@ fn bind_error_subtype_constructor(
global.bump_generation();
}
/// 把 Error 及各子类型(TypeError/ReferenceError/...)构造器与原型方法绑定到 global。
pub fn bind_error(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let error_methods = ErrorMethods {
error: oxide_builtins::error::error_constructor::<crate::vm::Vm> as *const (),
@@ -7,6 +7,7 @@ use oxide_types::value::JsValue;
use super::bind_global_value;
/// 把 Function 构造器与原型方法绑定到 global。
pub fn bind_function(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let function_methods = FunctionMethods {
call: oxide_builtins::function::function_call::<crate::vm::Vm> as *const (),
@@ -5,6 +5,7 @@ use oxide_types::object::JsObject;
use crate::bindings::apply_binding_table;
/// 把普通全局函数(`isNaN`、`parseInt`、`decodeURIComponent` 等)绑定到 global。
pub fn bind_global(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
apply_binding_table(
session.builtin_world(),
@@ -7,6 +7,7 @@ use oxide_types::value::JsValue;
use crate::bindings::{apply_binding_table, bind_global_value, configure_native_constructor};
/// 绑定迭代器基础设施:`%IteratorPrototype%` 与 `%ArrayIteratorPrototype%` 等。
pub fn bind_iterator(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let function_proto = session.builtin_world().function_proto.as_ptr() as *mut JsObject;
let mut iterator = Box::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::from_js_object(function_proto)));
@@ -5,6 +5,7 @@ use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
use oxide_types::value::JsValue;
/// 把 JSON 单例对象及其方法(parse/stringify 等)绑定到 global。
pub fn bind_json(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let json_ptr = session.builtin_world().json_object.as_ptr() as *mut JsObject;
let json = unsafe { &mut *json_ptr };
+1
View File
@@ -5,6 +5,7 @@ use crate::bindings::{apply_binding_table, configure_native_constructor};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
/// 把 Map 构造器与原型方法绑定到 global。
pub fn bind_map(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let ctor_ptr = session.builtin_world().map_constructor.as_ptr() as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
@@ -5,6 +5,7 @@ use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
use oxide_types::value::JsValue;
/// 把 Math 单例对象及其方法(abs/floor/max/random 等)绑定到 global。
pub fn bind_math(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let math_ptr = session.builtin_world().math_object.as_ptr() as *mut JsObject;
let math = unsafe { &mut *math_ptr };
@@ -6,6 +6,7 @@ use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::{JsObject, PropAttributes};
use oxide_types::value::JsValue;
/// 把 Number 构造器与原型方法绑定到 global(含 NaN/POSITIVE_INFINITY 等常量)。
pub fn bind_number(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let ctor_ptr = session.builtin_world().number_constructor.as_ptr() as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
@@ -7,6 +7,7 @@ use oxide_types::object::{JsObject, PropAttributes};
use crate::bind_constructor;
use crate::bindings::apply_binding_table;
/// 把 Object 构造器与原型方法绑定到 global。
pub fn bind_object(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let methods = ObjectMethods {
keys: oxide_builtins::object::object_keys::<crate::vm::Vm> as *const (),
@@ -6,6 +6,7 @@ use oxide_kernel::shape_forge::EMPTY_SHAPE_ID;
use oxide_types::object::JsObject;
use oxide_types::value::JsValue;
/// 把 Reflect 单例对象及其方法(get/set/construct/defineProperty 等)绑定到 global。
pub fn bind_reflect(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let mut reflect = Box::new(JsObject::new_empty(
EMPTY_SHAPE_ID,
@@ -6,6 +6,7 @@ use oxide_types::object::JsObject;
use crate::bind_constructor;
/// 把 RegExp 构造器与原型方法绑定到 global。
pub fn bind_regexp(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let ctor_ptr = session.builtin_world().regexp_constructor.as_ptr() as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
+1
View File
@@ -5,6 +5,7 @@ use crate::bindings::{apply_binding_table, configure_native_constructor};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
/// 把 Set 构造器与原型方法绑定到 global。
pub fn bind_set(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let ctor_ptr = session.builtin_world().set_constructor.as_ptr() as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
@@ -6,6 +6,7 @@ use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
use oxide_types::value::JsValue;
/// 把 String 构造器与原型方法绑定到 global。
pub fn bind_string(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let string_methods = StringMethods {
from_char_code: oxide_builtins::string::string_from_char_code::<crate::vm::Vm> as *const (),
@@ -27,6 +27,8 @@ const STUBS: [(&str, *const (), u8); 8] = [
("Atomics", oxide_builtins::stubs::atomics_stub::<crate::vm::Vm> as *const (), 0),
];
/// 把未实现内置(Proxy/BigInt/WeakMap/WeakSet/WeakRef/FinalizationRegistry/SharedArrayBuffer/Atomics)
/// 的 stub 构造器绑定到 global,并登记到 `stub_objects` 供快照跟踪。
pub fn bind_stubs(core: &Arc<KernelCore>, session: &mut KernelSession, global: &mut JsObject) {
let builtin_world = Arc::get_mut(&mut session.builtin_world)
.expect("BuiltinWorld must be uniquely owned during init_kernel_builtins");
@@ -7,6 +7,7 @@ use oxide_types::value::JsValue;
use crate::bind_constructor;
/// 把 Symbol 构造器与原型方法绑定到 global(含 `Symbol.iterator` 等 well-known symbols)。
pub fn bind_symbol(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let ctor_ptr = session.builtin_world().symbol_constructor.as_ptr() as *mut JsObject;
let ctor = unsafe { &mut *ctor_ptr };
@@ -13,6 +13,7 @@ macro_rules! bind_typed_array_constructor {
}};
}
/// 把所有 TypedArray 家族构造器(Int8Array/Uint8Array/.../BigUint64Array)与其共享原型绑定到 global。
pub fn bind_typed_array(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let shared_proto_ptr = session.builtin_world().typed_array_proto.as_ptr() as *mut JsObject;
let shared_proto = unsafe { &mut *shared_proto_ptr };
+31
View File
@@ -1,23 +1,48 @@
//! 内置对象绑定:把 `oxide_builtins` 中的 native 实现安装到每个 session 的
//! builtin 构造器/原型及 global object 上。绑定在 session 创建(`init_kernel_builtins`)
//! 与 dirty reset(`rebind_dirty_builtins`)两个时机执行。
/// Array 构造器与原型的 native 方法绑定。
pub mod bind_array;
/// ArrayBuffer 构造器与原型的 native 方法绑定。
pub mod bind_array_buffer;
/// Boolean 构造器与原型的 native 方法绑定。
pub mod bind_boolean;
/// DataView 构造器与原型的 native 方法绑定。
pub mod bind_data_view;
/// Date 构造器与原型的 native 方法绑定。
pub mod bind_date;
/// Error 家族构造器与原型的 native 方法绑定(含各子类型构造器创建)。
pub mod bind_error;
/// Function 构造器与原型的 native 方法绑定。
pub mod bind_function;
/// global 对象上的普通全局函数(parseInt、isNaN 等)绑定。
pub mod bind_global;
/// Iterator 相关全局辅助对象(%IteratorPrototype% 等)绑定。
pub mod bind_iterator;
/// JSON 单例对象及其 native 方法绑定。
pub mod bind_json;
/// Map 构造器与原型的 native 方法绑定。
pub mod bind_map;
/// Math 单例对象及其 native 方法绑定。
pub mod bind_math;
/// Number 构造器与原型的 native 方法绑定(含常量属性)。
pub mod bind_number;
/// Object 构造器与原型的 native 方法绑定。
pub mod bind_object;
/// Reflect 单例对象及其 native 方法绑定。
pub mod bind_reflect;
/// RegExp 构造器与原型的 native 方法绑定。
pub mod bind_regexp;
/// Set 构造器与原型的 native 方法绑定。
pub mod bind_set;
/// String 构造器与原型的 native 方法绑定。
pub mod bind_string;
/// 未实现内置(Proxy/BigInt/WeakMap 等)的 stub 构造器绑定。
pub mod bind_stubs;
/// Symbol 构造器与原型的 native 方法绑定。
pub mod bind_symbol;
/// 各 TypedArray 构造器与共享原型的 native 方法绑定。
pub mod bind_typed_array;
use std::sync::Arc;
@@ -256,6 +281,10 @@ fn bind_stub_globals(core: &Arc<KernelCore>, session: &KernelSession, global: &m
}
}
/// 把已有 builtin 构造器的 native 实现与 global 槽位一次性装配完整。
///
/// 在 global 对象重建(dirty reset)后调用:重新配置构造器 native 函数并重绑
/// `Object`/`Array`/`Math` 等全局名、TypedArray 家族、stub 与 `globalThis`。
pub fn bind_global_builtin_slots(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
let world = session.builtin_world();
@@ -464,6 +493,7 @@ pub fn bind_global_builtin_slots(core: &Arc<KernelCore>, session: &KernelSession
/// Maintenance: when adding a `BuiltinDirtySet` group, update this rebind map,
/// `BuiltinSnapshot`, and `BuiltinWorld::rebuild_with_dirty()` together.
/// 按脏标记重绑被污染的内置对象;`dirty` 为 `None` 时绑定全部(初始化路径)。
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 };
@@ -524,6 +554,7 @@ pub fn rebind_dirty_builtins(core: &Arc<KernelCore>, session: &mut KernelSession
}
}
/// 完整初始化一个 session 的内置对象(全量绑定 + `globalThis` + 快照记录)。
pub fn init_kernel_builtins(core: &Arc<KernelCore>, session: &mut KernelSession) {
rebind_dirty_builtins(core, session, None);
let global_ptr = session.global_object().as_ptr() as *mut oxide_types::object::JsObject;