mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
refactor: 内置十四文件迁移内核访问器调用至能力方法
This commit is contained in:
@@ -13,7 +13,7 @@ use crate::typed_array::{
|
||||
get_typed_array_data, read_element, ta_element_value, ta_to_integer_or_infinity, ta_validate, write_element,
|
||||
TypedArrayData,
|
||||
};
|
||||
use oxide_runtime_api::{NativeResult, VmHost};
|
||||
use oxide_runtime_api::{NativeResult, ProtoKind, VmHost};
|
||||
|
||||
macro_rules! native_try {
|
||||
($expr:expr) => {
|
||||
@@ -369,7 +369,7 @@ pub fn atomics_is_lock_free<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult
|
||||
/// waitAsync 结果对象:普通对象(proto = Object.prototype),own 属性
|
||||
/// async/value 双 data 属性(普通创建路径默认形)。
|
||||
fn wait_async_result_object<H: VmHost>(vm: &mut H, async_arm: bool, value: JsValue) -> JsValue {
|
||||
let object_proto = vm.session().builtin_world().object_proto.as_ptr() as *mut JsObject;
|
||||
let object_proto = vm.builtin_proto(ProtoKind::ObjectProto);
|
||||
let obj_ptr = vm.alloc_object(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::from_js_object(object_proto)));
|
||||
// SAFETY: alloc_object 返回存活 arena 指针,借出期间无别名。
|
||||
let obj = unsafe { &mut *obj_ptr };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use num_bigint::BigInt;
|
||||
use oxide_runtime_api::{to_primitive, NativeResult, ToPrimitiveHint, VmHost};
|
||||
use oxide_runtime_api::{to_primitive, NativeResult, ProtoKind, ToPrimitiveHint, VmHost};
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
/// JS `BigInt(value)` 构造逻辑(§21.2.1.1):
|
||||
@@ -184,8 +184,7 @@ fn this_bigint_value<H: VmHost>(vm: &mut H, this_val: JsValue) -> Result<JsValue
|
||||
let obj = unsafe { &*ptr };
|
||||
if obj.proto().is_object() {
|
||||
let proto_ptr = obj.proto().as_js_object_ptr();
|
||||
let bigint_proto =
|
||||
vm.session().builtin_world().bigint_proto.as_ptr() as *mut oxide_types::object::JsObject;
|
||||
let bigint_proto = vm.builtin_proto(ProtoKind::BigIntProto);
|
||||
if !proto_ptr.is_null() && std::ptr::eq(proto_ptr, bigint_proto) {
|
||||
let v = obj.boxed_value();
|
||||
if v.is_bigint() {
|
||||
|
||||
@@ -2,7 +2,7 @@ use num_traits::Zero;
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
use oxide_runtime_api::{NativeResult, VmHost};
|
||||
use oxide_runtime_api::{NativeResult, ProtoKind, VmHost};
|
||||
|
||||
/// JS `Boolean()` 构造逻辑:把参数按 ToBoolean 语义转换。
|
||||
/// 以普通函数调用时返回原始 bool;以 new 语义调用时返回 `[[BooleanData]]` 为结果的包装对象。
|
||||
@@ -38,7 +38,7 @@ pub fn boolean_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
false
|
||||
};
|
||||
|
||||
let boolean_proto = vm.session().builtin_world().boolean_proto.as_ptr() as *mut JsObject;
|
||||
let boolean_proto = vm.builtin_proto(ProtoKind::BooleanProto);
|
||||
let is_ctor = if this_val.is_object() {
|
||||
let ptr = this_val.as_js_object_ptr();
|
||||
if ptr.is_null() {
|
||||
|
||||
@@ -38,7 +38,7 @@ pub fn eval<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let code = oxide_kernel::string_forge::source_escape(&units);
|
||||
match vm.create_dynamic_script(&code) {
|
||||
Ok(func) => {
|
||||
let global = JsValue::from_js_object(vm.session().global_object().as_ptr() as *mut JsObject);
|
||||
let global = JsValue::from_js_object(vm.global_object().as_ptr() as *mut JsObject);
|
||||
match vm.call_function_sync(func, global, &[]) {
|
||||
Ok(val) => NativeResult::Ok(val),
|
||||
Err(e) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use oxide_runtime_api::{NativeResult, VmHost};
|
||||
use oxide_runtime_api::{NativeResult, ProtoKind, VmHost};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -114,7 +114,7 @@ pub fn string_value_of<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
/// JS `String()` 构造逻辑:把参数转成字符串(单元保真);new 语义返回
|
||||
/// `[[StringData]]` 包装对象。
|
||||
pub fn string_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let string_proto = vm.session().builtin_world().string_proto.as_ptr() as *mut JsObject;
|
||||
let string_proto = vm.builtin_proto(ProtoKind::StringProto);
|
||||
let this_val = vm.reg(if args.is_empty() { 0 } else { args[0] });
|
||||
let is_ctor = if this_val.is_object() {
|
||||
let ptr = this_val.as_js_object_ptr();
|
||||
|
||||
@@ -4,7 +4,7 @@ use oxide_kernel::shape_forge::EMPTY_SHAPE_ID;
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
use oxide_runtime_api::VmHost;
|
||||
use oxide_runtime_api::{ProtoKind, VmHost};
|
||||
|
||||
macro_rules! try_string {
|
||||
($e:expr) => {
|
||||
@@ -398,7 +398,7 @@ pub(crate) fn split_limit_to_uint32<H: VmHost>(vm: &mut H, limit_val: JsValue) -
|
||||
/// 以已构造的字符串值构建字符串数组(元素零拷贝落地),供逐单元产出路径
|
||||
/// (空分隔 split)复用,跳过 `Vec<String>` 中间层。
|
||||
pub(crate) fn make_string_array_values<H: VmHost>(vm: &mut H, parts: Vec<JsValue>) -> JsValue {
|
||||
let proto = vm.session().builtin_world().array_proto.as_ptr() as *mut JsObject;
|
||||
let proto = vm.builtin_proto(ProtoKind::ArrayProto);
|
||||
let n = parts.len();
|
||||
let arr = vm.alloc_object(JsObject::new_array(EMPTY_SHAPE_ID, JsValue::from_js_object(proto), n));
|
||||
unsafe {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Temporal.Duration:ISO 字符串与 property bag 解析、构造、getter、total/round、
|
||||
//! 加减比较与格式化。
|
||||
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, VmHost};
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, ProtoKind, VmHost};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -265,7 +265,7 @@ pub(crate) fn duration_like_values<H: VmHost>(vm: &mut H, val: JsValue) -> Resul
|
||||
|
||||
/// `Temporal.Duration` 构造器,保存十个整数时长分量。
|
||||
pub fn duration_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let ctor_proto = vm.session().builtin_world().duration_proto.as_ptr();
|
||||
let ctor_proto = vm.builtin_proto(ProtoKind::DurationProto);
|
||||
if !is_ctor_call(vm, args, ctor_proto) {
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use chrono::Utc;
|
||||
use num_traits::ToPrimitive;
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, VmHost};
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, ProtoKind, VmHost};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -300,7 +300,7 @@ pub fn now_time_zone_id<H: VmHost>(vm: &mut H, _args: &[u8]) -> NativeResult {
|
||||
|
||||
/// `Temporal.Instant` 构造器:把参数按 ToBigInt 转换为纪元纳秒。
|
||||
pub fn instant_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let ctor_proto = vm.session().builtin_world().instant_proto.as_ptr();
|
||||
let ctor_proto = vm.builtin_proto(ProtoKind::InstantProto);
|
||||
if !is_ctor_call(vm, args, ctor_proto) {
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Temporal.PlainDate:ISO 日期解析与校验、构造、getter、日历属性与加减/差值。
|
||||
|
||||
use chrono::{Datelike, Days, NaiveDate};
|
||||
use oxide_runtime_api::{to_string, NativeResult, VmHost};
|
||||
use oxide_runtime_api::{to_string, NativeResult, ProtoKind, VmHost};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -138,7 +138,7 @@ pub(crate) fn parse_iso_date(s: &str) -> Result<(i32, u32, u32), String> {
|
||||
|
||||
/// `Temporal.PlainDate` 构造器:`new PlainDate(year, month, day)`。
|
||||
pub fn plain_date_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let ctor_proto = vm.session().builtin_world().plain_date_proto.as_ptr();
|
||||
let ctor_proto = vm.builtin_proto(ProtoKind::PlainDateProto);
|
||||
if !is_ctor_call(vm, args, ctor_proto) {
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Temporal.PlainDateTime:ISO 日期时间解析、构造、getter、日历属性与加减/差值。
|
||||
|
||||
use chrono::{Datelike, NaiveDate};
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, VmHost};
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, ProtoKind, VmHost};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -20,7 +20,7 @@ use super::{
|
||||
|
||||
/// `Temporal.PlainDateTime` 构造器:保存 ISO 日期与午夜后纳秒。
|
||||
pub fn plain_date_time_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let ctor_proto = vm.session().builtin_world().plain_date_time_proto.as_ptr();
|
||||
let ctor_proto = vm.builtin_proto(ProtoKind::PlainDateTimeProto);
|
||||
if !is_ctor_call(vm, args, ctor_proto) {
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Temporal.PlainMonthDay:ISO 月日解析、构造、getter 与 with/toPlainDate。
|
||||
|
||||
use oxide_runtime_api::{to_string, NativeResult, VmHost};
|
||||
use oxide_runtime_api::{to_string, NativeResult, ProtoKind, VmHost};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -60,7 +60,7 @@ pub(crate) fn temporal_constructor_calendar_id<H: VmHost>(vm: &mut H, value: JsV
|
||||
|
||||
/// `Temporal.PlainMonthDay` 构造器:`new PlainMonthDay(month, day[, calendar[, referenceISOYear]])`。
|
||||
pub fn plain_month_day_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let ctor_proto = vm.session().builtin_world().plain_month_day_proto.as_ptr();
|
||||
let ctor_proto = vm.builtin_proto(ProtoKind::PlainMonthDayProto);
|
||||
if !is_ctor_call(vm, args, ctor_proto) {
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Temporal.PlainTime:ISO 时间解析、构造、getter、with/until/since 与加减舍入。
|
||||
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, VmHost};
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, ProtoKind, VmHost};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -272,7 +272,7 @@ pub(crate) fn valid_plain_time(hour: u32, minute: u32, second: u32, ms: u32, us:
|
||||
|
||||
/// `Temporal.PlainTime` 构造器:`new PlainTime(h, m, s, ms, us, ns)`,缺省为 0。
|
||||
pub fn plain_time_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let ctor_proto = vm.session().builtin_world().plain_time_proto.as_ptr();
|
||||
let ctor_proto = vm.builtin_proto(ProtoKind::PlainTimeProto);
|
||||
if !is_ctor_call(vm, args, ctor_proto) {
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Temporal.PlainYearMonth:ISO 年月解析、构造、getter、日历属性与 with/加减差值。
|
||||
|
||||
use oxide_runtime_api::{to_string, NativeResult, VmHost};
|
||||
use oxide_runtime_api::{to_string, NativeResult, ProtoKind, VmHost};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -26,7 +26,7 @@ fn plain_year_month_ymd<H: VmHost>(vm: &mut H, args: &[u8]) -> Result<(f64, f64,
|
||||
|
||||
/// `Temporal.PlainYearMonth` 构造器:`new PlainYearMonth(year, month[, calendar[, referenceISODay]])`。
|
||||
pub fn plain_year_month_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let ctor_proto = vm.session().builtin_world().plain_year_month_proto.as_ptr();
|
||||
let ctor_proto = vm.builtin_proto(ProtoKind::PlainYearMonthProto);
|
||||
if !is_ctor_call(vm, args, ctor_proto) {
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! with/until/since、舍入、加减与格式化。
|
||||
|
||||
use chrono::{Datelike, NaiveDate};
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, VmHost};
|
||||
use oxide_runtime_api::{to_number, to_string, NativeResult, ProtoKind, VmHost};
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
@@ -34,7 +34,7 @@ use super::{
|
||||
|
||||
/// `Temporal.ZonedDateTime` 构造器:保存纪元纳秒、固定偏移或 UTC 时区以及 ISO 日历。
|
||||
pub fn zoned_date_time_constructor<H: VmHost>(vm: &mut H, args: &[u8]) -> NativeResult {
|
||||
let ctor_proto = vm.session().builtin_world().zoned_date_time_proto.as_ptr();
|
||||
let ctor_proto = vm.builtin_proto(ProtoKind::ZonedDateTimeProto);
|
||||
if !is_ctor_call(vm, args, ctor_proto) {
|
||||
return NativeResult::Err(crate::error::create_type_error(
|
||||
vm,
|
||||
|
||||
Reference in New Issue
Block a user