mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 02:31:13 +08:00
fix: Object.prototype.toString 补 Math/JSON/Arguments 标签
This commit is contained in:
@@ -1011,6 +1011,12 @@ pub fn object_proto_to_string<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResul
|
||||
"TypedArray"
|
||||
} else if obj.is_array_buffer_obj() {
|
||||
"ArrayBuffer"
|
||||
} else if obj.is_arguments_obj() {
|
||||
"Arguments"
|
||||
} else if std::ptr::eq(ptr, vm.session().builtin_world().math_object.as_ptr()) {
|
||||
"Math"
|
||||
} else if std::ptr::eq(ptr, vm.session().builtin_world().json_object.as_ptr()) {
|
||||
"JSON"
|
||||
} else {
|
||||
"Object"
|
||||
};
|
||||
|
||||
@@ -449,6 +449,8 @@ impl JsObject {
|
||||
pub const OBJ_TYPE_ZONED_DATE_TIME: u8 = 18;
|
||||
/// Temporal.PlainDateTime 对象:ISO 年/月/日与午夜后纳秒存于 prop 0-3。
|
||||
pub const OBJ_TYPE_PLAIN_DATE_TIME: u8 = 19;
|
||||
/// Arguments 对象:`Object.prototype.toString` 返回 `[object Arguments]`。
|
||||
pub const OBJ_TYPE_ARGUMENTS: u8 = 20;
|
||||
/// `is_session_epoch` 字段中的 session 标记位。
|
||||
pub const SESSION_EPOCH_BIT: u8 = 0x01;
|
||||
/// `is_session_epoch` 字段中的 GC 标记位。
|
||||
@@ -545,6 +547,11 @@ impl JsObject {
|
||||
self.type_tag == Self::OBJ_TYPE_PLAIN_DATE_TIME
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_arguments_obj(&self) -> bool {
|
||||
self.type_tag == Self::OBJ_TYPE_ARGUMENTS
|
||||
}
|
||||
|
||||
/// 构造无属性、可扩展的空对象(`new Object()` 的基础对象)。
|
||||
pub fn new_empty(shape_id: ShapeId, proto: JsValue) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -168,6 +168,7 @@ impl Vm {
|
||||
let proto_ptr = &*self.object_prototype as *const JsObject as *mut JsObject;
|
||||
let obj_ptr = self.alloc_object(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::from_js_object(proto_ptr)));
|
||||
let obj = unsafe { &mut *obj_ptr };
|
||||
obj.type_tag = JsObject::OBJ_TYPE_ARGUMENTS;
|
||||
|
||||
// 索引属性:按实参下标写入 shape 槽,属性描述符为默认(可写/可枚举/可配置)。
|
||||
for i in 0..count as usize {
|
||||
@@ -216,12 +217,8 @@ impl Vm {
|
||||
let rest_len = n.saturating_sub(fixed_count);
|
||||
let proto_ptr = self.session.builtin_world().array_proto.as_ptr() as *mut JsObject;
|
||||
let bump = self.epoch.bump();
|
||||
let obj_ptr = self.alloc_object(JsObject::new_array(
|
||||
EMPTY_SHAPE_ID,
|
||||
JsValue::from_js_object(proto_ptr),
|
||||
rest_len,
|
||||
bump,
|
||||
));
|
||||
let obj_ptr =
|
||||
self.alloc_object(JsObject::new_array(EMPTY_SHAPE_ID, JsValue::from_js_object(proto_ptr), rest_len, bump));
|
||||
let obj = unsafe { &mut *obj_ptr };
|
||||
for i in 0..rest_len {
|
||||
let val = self
|
||||
|
||||
Reference in New Issue
Block a user