mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-27 20:21:12 +08:00
feat: Function.prototype 调用返回 undefined 且动态函数 prototype 不可配置
This commit is contained in:
@@ -26,9 +26,10 @@ fn gc_pressure_mode_from_env() -> bool {
|
||||
std::env::var_os("OXIDE_GC_PRESSURE").is_some()
|
||||
}
|
||||
|
||||
/// 函数种类标志位集合:箭头、类构造器、派生构造器,压缩在单个 `u8` 中。
|
||||
/// 函数种类标志位集合:箭头、类构造器、派生构造器、动态函数,压缩在单个 `u8` 中。
|
||||
///
|
||||
/// 位定义:bit0 = arrow,bit1 = class_constructor,bit2 = derived_constructor。
|
||||
/// 位定义:bit0 = arrow,bit1 = class_constructor,bit2 = derived_constructor,
|
||||
/// bit3 = dynamic。
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct FunctionFlags(pub u8);
|
||||
|
||||
@@ -39,6 +40,9 @@ impl FunctionFlags {
|
||||
pub(crate) const CLASS_CONSTRUCTOR: u8 = 0b010;
|
||||
/// 派生构造器标志位(bit2)。
|
||||
pub(crate) const DERIVED_CONSTRUCTOR: u8 = 0b100;
|
||||
/// 动态函数标志位(bit3):经 Function 构造器创建的函数对象,其
|
||||
/// `prototype` 属性不可配置。
|
||||
pub(crate) const DYNAMIC: u8 = 0b1000;
|
||||
|
||||
/// 无标志(普通函数)。
|
||||
pub(crate) const fn none() -> Self {
|
||||
@@ -74,6 +78,11 @@ impl FunctionFlags {
|
||||
pub(crate) const fn is_derived_constructor(self) -> bool {
|
||||
self.0 & Self::DERIVED_CONSTRUCTOR != 0
|
||||
}
|
||||
|
||||
/// 是否动态函数(经 Function 构造器创建)。
|
||||
pub(crate) const fn is_dynamic(self) -> bool {
|
||||
self.0 & Self::DYNAMIC != 0
|
||||
}
|
||||
}
|
||||
|
||||
/// 模块级装载缓存条目三件套:已转换常量池、BigInt 自持存储、si 侧表。
|
||||
@@ -891,16 +900,17 @@ impl Vm {
|
||||
prototype.bump_generation();
|
||||
}
|
||||
|
||||
// 函数自身 `prototype` 属性:生成器 writable:true / enumerable:false /
|
||||
// configurable:false;普通函数与构造器 writable:true / enumerable:false /
|
||||
// configurable:true。显式落元数据——缺元数据按默认描述符(可枚举)
|
||||
// 判定,`prototype` 会泄漏进 keys / for-in / 聚合枚举。
|
||||
// 函数自身 `prototype` 属性:生成器与动态函数(Function 构造器产物)
|
||||
// writable:true / enumerable:false / configurable:false;普通函数与
|
||||
// 构造器 writable:true / enumerable:false / configurable:true。显式
|
||||
// 落元数据——缺元数据按默认描述符(可枚举)判定,`prototype` 会泄漏
|
||||
// 进 keys / for-in / 聚合枚举。
|
||||
let prototype_si = self.kernel_core.perm_interner().intern("prototype").0;
|
||||
let func = unsafe { &mut *obj_ptr };
|
||||
let prototype_shape = self.kernel_core.shape_forge().make_shape(func.shape_id(), prototype_si);
|
||||
func.set_shape_id(prototype_shape);
|
||||
let prototype_pos = func.push_prop(prototype_val);
|
||||
if is_generator || is_async_generator {
|
||||
if is_generator || is_async_generator || flags.is_dynamic() {
|
||||
func.set_data_meta(prototype_pos, PropAttributes::new(true, false, false));
|
||||
} else {
|
||||
func.set_data_meta(prototype_pos, PropAttributes::new(true, false, true));
|
||||
|
||||
Reference in New Issue
Block a user