From 4b080b6f630ec7a81551f604e58857e59c8ee097 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Thu, 17 Sep 2026 12:50:15 +0000 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=94=B9=E5=86=99=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E5=9F=9F=E6=B3=A8=E9=87=8A=E5=B9=B6=E8=A1=A5=E6=AD=A3?= =?UTF-8?q?=E5=88=99=E5=B7=A5=E5=85=B7=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit string/common.rs:文本通道节头改写为三载荷形态与两条匹配入口的范围单位约定,删依赖 crate 名与历史表述;to_value 文档由「物化/臂」改为「构造/变体」。 string/regex.rs:为 is_regexp_obj、builder_wrapper、make_match_done_result 补函数文档;string_raw 体内注释删除规范章节号,仅保留语义。 --- crates/oxide_builtins/src/string/common.rs | 12 +++++++----- crates/oxide_builtins/src/string/regex.rs | 7 ++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/oxide_builtins/src/string/common.rs b/crates/oxide_builtins/src/string/common.rs index f4f3a0db..b167cd88 100644 --- a/crates/oxide_builtins/src/string/common.rs +++ b/crates/oxide_builtins/src/string/common.rs @@ -18,10 +18,12 @@ pub(crate) use try_string; // ── 文本通道 ───────────────────────────────────────────────────────────── // -// 字符串值的载荷分形态:Flat(良形 UTF-8)、FlatU16(单元载荷,可含孤立 -// surrogate)、Cons(rope)。正则家族按文本通道分臂——Str 臂走良形文本 -// (字节口径,与旧代码路径一致),Units 臂走单元序列(regress utf16 接口, -// 匹配范围即码元);其余方法统一按单元序列处理(规格口径)。 +// 字符串值有三种载荷形态:Flat(良形 UTF-8 字节串)、FlatU16(UTF-16 单元 +// 数组,可含孤立 surrogate)、Cons(分段拼接的 rope)。正则匹配按载荷形态 +// 分两条入口:Str 入口以字节串调用匹配器,返回的匹配范围以字节为单位; +// Units 入口以单元数组调用匹配器,匹配范围以 UTF-16 码元为单位。两条入口 +// 的范围单位不可互换,匹配片段端点必须换算到与所在入口相同的单位; +// 正则之外的 String 方法统一取单元序列处理。 /// 正则家族的匹配文本通道。 pub(crate) enum MatchText<'a> { @@ -142,7 +144,7 @@ impl OwnedText { } } - /// 物化为字符串值(Str 臂文本 / Units 臂单元,载荷形态各自最小)。 + /// 构造字符串值:Str 变体按字节串、Units 变体按单元数组,载荷形态各自最小。 pub(crate) fn to_value(&self, vm: &mut H) -> JsValue { match self { OwnedText::Str(s) => vm.new_string(s), diff --git a/crates/oxide_builtins/src/string/regex.rs b/crates/oxide_builtins/src/string/regex.rs index ac8a6182..d6b36954 100644 --- a/crates/oxide_builtins/src/string/regex.rs +++ b/crates/oxide_builtins/src/string/regex.rs @@ -238,6 +238,8 @@ fn string_replace_fn( NativeResult::Ok(vm.new_string_units_owned(out)) } +/// 判断值是否为 RegExp 对象:非对象、空指针、原型非对象均返回 false, +/// 原型指针与 `%RegExpPrototype%` 恒等比较。 fn is_regexp_obj(val: JsValue, vm: &H) -> bool { if !val.is_object() { return false; @@ -799,6 +801,8 @@ pub fn string_match_all(vm: &mut H, args: &[u8]) -> NativeResult { builder_wrapper(vm, input_val, re_obj) } +/// 构造 matchAll 包装对象:原型挂 `%RegExpStringIteratorPrototype%`, +/// own 属性为 input/index(0)/re 三槽,next 由原型提供。 fn builder_wrapper(vm: &mut H, input_val: JsValue, re_obj: JsValue) -> NativeResult { // matchAll 迭代器挂 %RegExpStringIteratorPrototype%(链到 %IteratorPrototype%), // next 由原型提供(不挂实例 own)。 @@ -945,6 +949,7 @@ pub fn string_match_all_next(vm: &mut H, args: &[u8]) -> NativeResult make_match_done_result(vm, value) } +/// 构造迭代器结果对象 `{value, done}`(done 仅在 value 为 undefined 时为 true)。 fn make_match_done_result(vm: &mut H, value: JsValue) -> NativeResult { let done = value.is_undefined(); let object_proto = vm.session().builtin_world().object_proto.as_ptr() as *mut JsObject; @@ -1061,7 +1066,7 @@ pub fn string_raw(vm: &mut H, args: &[u8]) -> NativeResult { result.extend(raw_units); // 段间(i + 1 < length)才追加 substitutions[i];substitutions 缺失时 - // 追加空串(spec 24.b.i),末段后不再追加任何内容。 + // 追加空串,末段后不再追加任何内容。 if i + 1 < raw_len { let sub_idx = i + 2; if sub_idx < args.len() {