feat: class 私有成员语义(字段/方法/访问器 + brand 检查 + 契约修复)
This commit is contained in:
@@ -362,10 +362,7 @@ pub fn object_is<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
/// # 副作用
|
||||
/// - 修改 obj 的 shape 链、属性表与 generation
|
||||
fn define_from_descriptor<H: VmHost>(
|
||||
vm: &mut H,
|
||||
obj_ptr: *mut JsObject,
|
||||
key_si: u32,
|
||||
desc_val: JsValue,
|
||||
vm: &mut H, obj_ptr: *mut JsObject, key_si: u32, desc_val: JsValue,
|
||||
) -> Result<(), String> {
|
||||
if !desc_val.is_object() {
|
||||
return Err("Property description must be an object".to_string());
|
||||
@@ -477,9 +474,7 @@ fn define_from_descriptor<H: VmHost>(
|
||||
/// # 副作用
|
||||
/// - 修改 target 的 shape 链、属性表与 generation
|
||||
fn define_all_from_properties<H: VmHost>(
|
||||
vm: &mut H,
|
||||
target_ptr: *mut JsObject,
|
||||
props_val: JsValue,
|
||||
vm: &mut H, target_ptr: *mut JsObject, props_val: JsValue,
|
||||
) -> Result<(), String> {
|
||||
if !props_val.is_object() {
|
||||
return Err("Property description must be an object".to_string());
|
||||
@@ -495,11 +490,7 @@ fn define_all_from_properties<H: VmHost>(
|
||||
for (key_si, offset) in prop_keys {
|
||||
let props = unsafe { &*props_ptr };
|
||||
// 非可枚举自身属性跳过;无显式 meta 视为可枚举(普通字面量默认)。
|
||||
if props
|
||||
.prop_meta_at(offset)
|
||||
.map(|m| !m.attributes.enumerable())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
if props.prop_meta_at(offset).map(|m| !m.attributes.enumerable()).unwrap_or(false) {
|
||||
continue;
|
||||
}
|
||||
let desc_val = vm.ordinary_get(props, key_si, props_val)?;
|
||||
|
||||
@@ -224,12 +224,9 @@ pub fn regexp_exec<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let group_count = m.captures.len();
|
||||
let n = 1 + group_count;
|
||||
let proto = vm.session().builtin_world().array_proto.as_ptr() as *mut JsObject;
|
||||
let arr = vm.epoch().alloc(JsObject::new_array(
|
||||
EMPTY_SHAPE_ID,
|
||||
JsValue::from_js_object(proto),
|
||||
n,
|
||||
vm.epoch().bump(),
|
||||
));
|
||||
let arr =
|
||||
vm.epoch()
|
||||
.alloc(JsObject::new_array(EMPTY_SHAPE_ID, JsValue::from_js_object(proto), n, vm.epoch().bump()));
|
||||
unsafe {
|
||||
(*arr).set_prop_at(0, vm.new_string(&haystack[range.start..range.end]));
|
||||
// 捕获组:未参与匹配的组为 undefined。
|
||||
@@ -545,4 +542,3 @@ pub fn regexp_symbol_match_all<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResu
|
||||
vm.set_or_create_prop_value(wrapper_obj, next_si, next_fn);
|
||||
NativeResult::Ok(JsValue::from_js_object(wrapper))
|
||||
}
|
||||
|
||||
|
||||
@@ -973,10 +973,7 @@ pub fn string_code_point_at<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult
|
||||
let pos = if args.len() > 1 {
|
||||
let pos_val = vm.reg(args[1]);
|
||||
if pos_val.is_symbol() {
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
"Cannot convert a Symbol value to a number",
|
||||
));
|
||||
return NativeResult::Err(crate::error::create_type_error(vm, "Cannot convert a Symbol value to a number"));
|
||||
}
|
||||
match vm.coerce_number_bounded(pos_val) {
|
||||
Ok(n) => n,
|
||||
@@ -985,10 +982,7 @@ pub fn string_code_point_at<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult
|
||||
if let Some(exc) = vm.take_uncaught_value() {
|
||||
return NativeResult::Err(exc);
|
||||
}
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
"Cannot convert argument to a number",
|
||||
));
|
||||
return NativeResult::Err(crate::error::create_type_error(vm, "Cannot convert argument to a number"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1264,6 +1258,3 @@ pub fn string_replace_all<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let result = s.replace(&pattern, &replacement);
|
||||
NativeResult::Ok(vm.new_string(&result))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user