feat: 支持 to_string 与错误栈

This commit is contained in:
爱特每羊队
2026-06-08 14:52:44 +08:00
parent 3880882fda
commit a6e448e326
12 changed files with 233 additions and 0 deletions
@@ -1,5 +1,6 @@
use std::sync::Arc;
use crate::bind_constructor_hash;
use oxide_kernel::builtin::ErrorMethods;
use oxide_kernel::kernel::OxideKernel;
use oxide_types::object::JsObject;
@@ -14,6 +15,8 @@ pub fn bind_error(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
syntax_error: crate::builtins::error::syntax_error_constructor as *const (),
uri_error: crate::builtins::error::uri_error_constructor as *const (),
eval_error: crate::builtins::error::eval_error_constructor as *const (),
to_string: crate::builtins::error::error_to_string as *const (),
stack: crate::builtins::error::error_stack_getter as *const (),
};
kernel.builtin_world().bind_error_methods(
&error_methods,
@@ -29,6 +32,13 @@ pub fn bind_error(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
global.ensure_hash_props().push(Box::new(err_val));
global.bump_generation();
bind_constructor_hash!(kernel, global, "TypeError", kernel.builtin_world().type_error_proto.as_ptr() as *mut JsObject, crate::builtins::error::type_error_constructor, 1);
bind_constructor_hash!(kernel, global, "ReferenceError", kernel.builtin_world().reference_error_proto.as_ptr() as *mut JsObject, crate::builtins::error::reference_error_constructor, 1);
bind_constructor_hash!(kernel, global, "RangeError", kernel.builtin_world().range_error_proto.as_ptr() as *mut JsObject, crate::builtins::error::range_error_constructor, 1);
bind_constructor_hash!(kernel, global, "SyntaxError", kernel.builtin_world().syntax_error_proto.as_ptr() as *mut JsObject, crate::builtins::error::syntax_error_constructor, 1);
bind_constructor_hash!(kernel, global, "URIError", kernel.builtin_world().uri_error_proto.as_ptr() as *mut JsObject, crate::builtins::error::uri_error_constructor, 1);
bind_constructor_hash!(kernel, global, "EvalError", kernel.builtin_world().eval_error_proto.as_ptr() as *mut JsObject, crate::builtins::error::eval_error_constructor, 1);
{
let err_ctor_ptr = kernel.builtin_world().error_constructor.as_ptr() as *mut JsObject;
let err_ctor = unsafe { &mut *err_ctor_ptr };
@@ -8,6 +8,7 @@ pub fn bind_function(kernel: &Arc<OxideKernel>) {
call: crate::builtins::function::function_call as *const (),
apply: crate::builtins::function::function_apply as *const (),
bind: crate::builtins::function::function_bind as *const (),
to_string: crate::builtins::function::function_to_string as *const (),
};
kernel.builtin_world().bind_function_methods(
&function_methods,
@@ -14,6 +14,11 @@ pub fn bind_number(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
parse_float: crate::builtins::number::number_parse_float as *const (),
to_string: crate::builtins::number::number_to_string as *const (),
to_fixed: crate::builtins::number::number_to_fixed as *const (),
is_integer: crate::builtins::number::number_is_integer as *const (),
is_safe_integer: crate::builtins::number::number_is_safe_integer as *const (),
to_exponential: crate::builtins::number::number_to_exponential as *const (),
to_precision: crate::builtins::number::number_to_precision as *const (),
value_of: crate::builtins::number::number_value_of as *const (),
};
kernel.builtin_world().bind_number_methods(
&number_methods,
@@ -37,6 +42,46 @@ pub fn bind_number(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
crate::builtins::number::number_constructor as *const (),
));
num_ctor.set_native_arg_count(1);
num_ctor.ensure_hash_props().push(Box::new(JsValue::float(2.220446049250313e-16)));
let eps_si = kernel.string_forge().intern("EPSILON").0;
let _shape1 = kernel.shape_forge().make_shape(num_ctor.shape_id(), eps_si);
num_ctor.set_shape_id(_shape1);
num_ctor.ensure_hash_props().push(Box::new(JsValue::float(9007199254740991f64)));
let max_safe_si = kernel.string_forge().intern("MAX_SAFE_INTEGER").0;
let _shape2 = kernel.shape_forge().make_shape(num_ctor.shape_id(), max_safe_si);
num_ctor.set_shape_id(_shape2);
num_ctor.ensure_hash_props().push(Box::new(JsValue::float(-9007199254740991f64)));
let min_safe_si = kernel.string_forge().intern("MIN_SAFE_INTEGER").0;
let _shape3 = kernel.shape_forge().make_shape(num_ctor.shape_id(), min_safe_si);
num_ctor.set_shape_id(_shape3);
num_ctor.ensure_hash_props().push(Box::new(JsValue::float(1.7976931348623157e308)));
let max_val_si = kernel.string_forge().intern("MAX_VALUE").0;
let _shape4 = kernel.shape_forge().make_shape(num_ctor.shape_id(), max_val_si);
num_ctor.set_shape_id(_shape4);
num_ctor.ensure_hash_props().push(Box::new(JsValue::float(5e-324)));
let min_val_si = kernel.string_forge().intern("MIN_VALUE").0;
let _shape5 = kernel.shape_forge().make_shape(num_ctor.shape_id(), min_val_si);
num_ctor.set_shape_id(_shape5);
num_ctor.ensure_hash_props().push(Box::new(JsValue::float(f64::NAN)));
let nan_si = kernel.string_forge().intern("NaN").0;
let _shape6 = kernel.shape_forge().make_shape(num_ctor.shape_id(), nan_si);
num_ctor.set_shape_id(_shape6);
num_ctor.ensure_hash_props().push(Box::new(JsValue::float(f64::NEG_INFINITY)));
let neg_inf_si = kernel.string_forge().intern("NEGATIVE_INFINITY").0;
let _shape7 = kernel.shape_forge().make_shape(num_ctor.shape_id(), neg_inf_si);
num_ctor.set_shape_id(_shape7);
num_ctor.ensure_hash_props().push(Box::new(JsValue::float(f64::INFINITY)));
let pos_inf_si = kernel.string_forge().intern("POSITIVE_INFINITY").0;
let _shape8 = kernel.shape_forge().make_shape(num_ctor.shape_id(), pos_inf_si);
num_ctor.set_shape_id(_shape8);
}
let pi_fn = crate::builtins::number::number_parse_int as *const ();