fix: 顶层声明撞不可定义全局按规范抛 TypeError

This commit is contained in:
2026-09-14 14:32:39 +00:00
parent 91946f3fe3
commit d161b7cfe3
11 changed files with 332 additions and 57 deletions
+8 -1
View File
@@ -740,11 +740,18 @@ mod tests {
assert_group(&[OpCode::NEW_OBJECT, OpCode::NEW_SESSION_OBJECT, OpCode::NEW_ARRAY], Some(1), &[], true);
// define 语义属性写入 / arguments / rest
assert_group(
&[OpCode::DEFINE_PROP, OpCode::DEFINE_GLOBAL_PROP, OpCode::DEFINE_GLOBAL_PROP_IF_ABSENT],
&[
OpCode::DEFINE_PROP,
OpCode::DEFINE_GLOBAL_PROP,
OpCode::DEFINE_GLOBAL_PROP_IF_ABSENT,
OpCode::DEFINE_GLOBAL_FUNC_BIND,
],
None,
&[1, 2, 3],
false,
);
// 全局函数绑定声明检查:a 槽无操作数,use 集只含 rd/b。
assert_contract(OpCode::CAN_DECLARE_GLOBAL_FUNC, None, &[1, 3], false);
assert_group(&[OpCode::DEFINE_GLOBAL_PROP_C, OpCode::DEFINE_GLOBAL_PROP_C_IF_ABSENT], None, &[2], false);
// delete 全局内置:结果写 rd、镜像槽寄存器是 a 槽 use
assert_contract(OpCode::DELETE_GLOBAL_PROP_C, Some(1), &[2], false);
+14
View File
@@ -255,6 +255,20 @@ impl Inst {
)
}
/// 顶层函数声明的全局绑定声明检查(GDI step 9):target 为全局对象,key 为
/// 声明名寄存器。运行期按 CanDeclareGlobalFunction 判定——撞既有不可配置
/// 非可写数据属性(或不可扩展上的缺失名)抛 TypeError。
pub fn can_declare_global_func(target: Operand, key: Operand) -> Self {
Self::new(OpCode::CAN_DECLARE_GLOBAL_FUNC, target, Operand::None, key)
}
/// 创建全局函数绑定(CreateGlobalFunctionBinding,脚本面 deletable=false):
/// target 为全局对象,value/key 为寄存器。缺失或既有可配置属性定义可写/可枚举/
/// 不可配置数据属性;既有不可配置可写数据属性仅更新值保描述符。
pub fn define_global_func_bind(target: Operand, value: Operand, key: Operand) -> Self {
Self::new(OpCode::DEFINE_GLOBAL_FUNC_BIND, target, value, key)
}
/// 静态删除属性:obj 同时放 rd/a 槽,const_idx 为属性名常量下标。
pub fn delete_prop_static(obj: Operand, const_idx: u32) -> Self {
Self::with_ext(OpCode::DELETE_PROP_STATIC, obj, obj, Operand::None, &[const_idx])