use std::sync::Arc; use crate::bindings::{ apply_binding_table, bind_accessor_getter, bind_accessor_getter_key, bind_well_known_method, configure_native_constructor, }; use oxide_kernel::kernel::{KernelCore, KernelSession}; use oxide_types::object::JsObject; use crate::bind_constructor; /// 把 RegExp 构造器与原型方法绑定到 global。 pub fn bind_regexp(core: &Arc, session: &KernelSession, global: &mut JsObject) { let ctor_ptr = session.builtin_world().regexp_constructor.as_ptr() as *mut JsObject; let ctor = unsafe { &mut *ctor_ptr }; let proto_ptr = session.builtin_world().regexp_proto.as_ptr() as *mut JsObject; let proto = unsafe { &mut *proto_ptr }; configure_native_constructor(ctor, oxide_builtins::regexp::regexp_constructor:: as *const (), 2); // 静态方法 escape 装到构造器对象(wrapper 的 length/name 与槽属性由 bind_method 统一保证)。 apply_binding_table( session.builtin_world(), ctor, core, &[("escape", oxide_builtins::regexp::regexp_escape:: as *const (), 1)], ); apply_binding_table( session.builtin_world(), proto, core, &[ ("exec", oxide_builtins::regexp::regexp_exec:: as *const (), 1), ("test", oxide_builtins::regexp::regexp_test:: as *const (), 1), ("toString", oxide_builtins::regexp::regexp_to_string:: as *const (), 0), ], ); // source/flags 只读访问器(set 恒 undefined,getter 读实例字段)。 bind_accessor_getter( core, session, proto, "source", oxide_builtins::regexp::regexp_get_source:: as *const (), ); bind_accessor_getter( core, session, proto, "flags", oxide_builtins::regexp::regexp_get_flags:: as *const (), ); // 8 个单 flag 只读访问器(set 恒 undefined,getter 读实例 flags 串判码元)。 bind_accessor_getter( core, session, proto, "global", oxide_builtins::regexp::regexp_get_global:: as *const (), ); bind_accessor_getter( core, session, proto, "ignoreCase", oxide_builtins::regexp::regexp_get_ignore_case:: as *const (), ); bind_accessor_getter( core, session, proto, "multiline", oxide_builtins::regexp::regexp_get_multiline:: as *const (), ); bind_accessor_getter( core, session, proto, "dotAll", oxide_builtins::regexp::regexp_get_dot_all:: as *const (), ); bind_accessor_getter( core, session, proto, "sticky", oxide_builtins::regexp::regexp_get_sticky:: as *const (), ); bind_accessor_getter( core, session, proto, "unicode", oxide_builtins::regexp::regexp_get_unicode:: as *const (), ); bind_accessor_getter( core, session, proto, "hasIndices", oxide_builtins::regexp::regexp_get_has_indices:: as *const (), ); bind_accessor_getter( core, session, proto, "unicodeSets", oxide_builtins::regexp::regexp_get_unicode_sets:: as *const (), ); // well-known symbol 方法按 Symbol 键安装,name 属性取 `[Symbol.match]` 式标签,供 `re[Symbol.match]` 等读取。 let world = session.builtin_world(); bind_well_known_method( world, core, proto, 1, "[Symbol.match]", oxide_builtins::regexp::regexp_symbol_match:: as *const (), 1, ); bind_well_known_method( world, core, proto, 2, "[Symbol.replace]", oxide_builtins::regexp::regexp_symbol_replace:: as *const (), 2, ); bind_well_known_method( world, core, proto, 3, "[Symbol.search]", oxide_builtins::regexp::regexp_symbol_search:: as *const (), 1, ); bind_well_known_method( world, core, proto, 4, "[Symbol.split]", oxide_builtins::regexp::regexp_symbol_split:: as *const (), 2, ); bind_well_known_method( world, core, proto, 7, "[Symbol.matchAll]", oxide_builtins::regexp::regexp_symbol_match_all:: as *const (), 1, ); // RegExp[Symbol.species] 访问器:getter 返回 receiver,派生类沿静态原型链解析 // @@species 得自身构造器(规范不给 class 默认 static @@species,类上无 own)。 bind_accessor_getter_key( core, session, ctor, oxide_types::private_key::make_well_known_symbol_key(oxide_types::private_key::WELL_KNOWN_SYMBOL_SPECIES), "get [Symbol.species]", oxide_builtins::array::array_species_get:: as *const (), ); bind_constructor!(core, global, "RegExp", ctor_ptr, oxide_builtins::regexp::regexp_constructor::, 2, hash: true); }