feat: 注入 harness 并补齐关键全局内建
This commit is contained in:
@@ -7,6 +7,7 @@ use oxide_types::object::JsObject;
|
||||
|
||||
pub fn bind_array(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
|
||||
let _array_methods = ArrayMethods {
|
||||
is_array: crate::builtins::array::array_is_array as *const (),
|
||||
push: crate::builtins::array::array_push as *const (),
|
||||
pop: crate::builtins::array::array_pop as *const (),
|
||||
slice: crate::builtins::array::array_slice as *const (),
|
||||
|
||||
@@ -10,6 +10,7 @@ pub fn bind_object(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
|
||||
keys: crate::builtins::object::object_keys as *const (),
|
||||
create: crate::builtins::object::object_create as *const (),
|
||||
assign: crate::builtins::object::object_assign as *const (),
|
||||
is: crate::builtins::object::object_is as *const (),
|
||||
define_property: crate::builtins::object::object_define_property as *const (),
|
||||
get_own_property_descriptor: crate::builtins::object::object_get_own_property_descriptor as *const (),
|
||||
freeze: crate::builtins::object::object_freeze as *const (),
|
||||
|
||||
@@ -90,4 +90,6 @@ pub fn init_kernel_builtins(kernel: &Arc<OxideKernel>) {
|
||||
bind_function::bind_function(kernel);
|
||||
bind_regexp::bind_regexp(kernel, global);
|
||||
bind_symbol::bind_symbol(kernel, global);
|
||||
|
||||
bind_global_value(kernel, global, "globalThis", JsValue::from_js_object(global_ptr));
|
||||
}
|
||||
|
||||
@@ -105,6 +105,21 @@ pub fn array_constructor(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
||||
Ok(JsValue::from_js_object(arr))
|
||||
}
|
||||
|
||||
pub fn array_is_array(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
||||
if args.len() < 2 {
|
||||
return Ok(JsValue::bool(false));
|
||||
}
|
||||
let val = vm.reg(args[1]);
|
||||
if !val.is_object() {
|
||||
return Ok(JsValue::bool(false));
|
||||
}
|
||||
let ptr = val.as_js_object_ptr();
|
||||
if ptr.is_null() {
|
||||
return Ok(JsValue::bool(false));
|
||||
}
|
||||
Ok(JsValue::bool(unsafe { &*ptr }.is_array()))
|
||||
}
|
||||
|
||||
pub fn array_push(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
||||
let arr_ptr = array_ptr!(vm, args);
|
||||
let arr = unsafe { &mut *arr_ptr };
|
||||
|
||||
@@ -131,6 +131,12 @@ pub fn object_assign(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
||||
Ok(target_val)
|
||||
}
|
||||
|
||||
pub fn object_is(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
||||
let lhs = if args.len() > 1 { vm.reg(args[1]) } else { JsValue::undefined() };
|
||||
let rhs = if args.len() > 2 { vm.reg(args[2]) } else { JsValue::undefined() };
|
||||
Ok(JsValue::bool(coercion::same_value(lhs, rhs)))
|
||||
}
|
||||
|
||||
pub fn object_define_property(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
||||
if args.len() < 4 {
|
||||
return Err(JsValue::undefined());
|
||||
|
||||
Reference in New Issue
Block a user