feat: BigInt constructor ToPrimitive semantics, toString(radix), asIntN/asUintN; ctor [[Prototype]]=Function.prototype

This commit is contained in:
爱特每羊队
2026-08-12 02:23:27 +08:00
parent ff9958d78b
commit 28477a3e47
3 changed files with 371 additions and 65 deletions
+25 -1
View File
@@ -2,7 +2,7 @@ use std::sync::Arc;
use crate::bindings::{apply_binding_table, bind_global_value, configure_native_constructor};
use oxide_kernel::kernel::{KernelCore, KernelSession};
use oxide_types::object::JsObject;
use oxide_types::object::{JsObject, PropAttributes};
use oxide_types::value::JsValue;
/// 把 BigInt 构造器与原型方法绑定到 global。
@@ -18,6 +18,24 @@ pub fn bind_bigint(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
let proto = unsafe { &mut *proto_ptr };
configure_native_constructor(ctor, oxide_builtins::bigint::bigint_constructor::<crate::vm::Vm> as *const (), 1);
// BigInt.length = 1,属性 { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }。
let length_si = core.perm_interner().intern("length").0;
let length_shape = core.shape_forge().make_shape(ctor.shape_id(), length_si);
ctor.set_shape_id(length_shape);
ctor.ensure_hash_props().push(JsValue::int(1));
let length_pos = ctor.hash_props_vec().map_or(0, |v| v.len() as u32).saturating_sub(1);
ctor.set_data_meta(length_pos, PropAttributes::new(false, false, true));
// 静态方法:asIntN / asUintN(length 均为 2)。
apply_binding_table(
world,
ctor,
core,
&[
("asIntN", oxide_builtins::bigint::bigint_as_int_n::<crate::vm::Vm> as *const (), 2),
("asUintN", oxide_builtins::bigint::bigint_as_uint_n::<crate::vm::Vm> as *const (), 2),
],
);
apply_binding_table(
world,
@@ -25,9 +43,15 @@ pub fn bind_bigint(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
core,
&[
("toString", oxide_builtins::bigint::bigint_to_string::<crate::vm::Vm> as *const (), 0),
("toLocaleString", oxide_builtins::bigint::bigint_to_locale_string::<crate::vm::Vm> as *const (), 0),
("valueOf", oxide_builtins::bigint::bigint_value_of::<crate::vm::Vm> as *const (), 0),
],
);
bind_global_value(core, global, "BigInt", JsValue::from_js_object(ctor_ptr));
// 全局 BigInt 属性描述符:{ writable: true, enumerable: false, configurable: true }。
let bigint_si = core.perm_interner().intern("BigInt").0;
if let Some(pos) = core.shape_forge().lookup_position(global.shape_id(), bigint_si) {
global.set_data_meta(pos, PropAttributes::new(true, false, true));
}
}