refactor: 收敛 builtin 绑定表驱动并补完数组宏化收尾

This commit is contained in:
爱特每羊队
2026-06-09 00:49:59 +08:00
parent 046b59fa5e
commit 4713b46d5c
10 changed files with 358 additions and 238 deletions
+17 -13
View File
@@ -1,6 +1,6 @@
use std::sync::Arc;
use oxide_kernel::bind_methods;
use crate::bindings::{apply_binding_table, bind_global_value};
use oxide_kernel::kernel::OxideKernel;
use oxide_types::object::JsObject;
use oxide_types::value::JsValue;
@@ -9,20 +9,24 @@ pub fn bind_json(kernel: &Arc<OxideKernel>, global: &mut JsObject) {
let json_ptr = kernel.builtin_world().json_object.as_ptr() as *mut JsObject;
let json = unsafe { &mut *json_ptr };
bind_methods!(
apply_binding_table(
kernel.builtin_world(),
json,
kernel.string_forge().as_ref(),
kernel.shape_forge().as_ref(),
("parse", crate::builtins::json::json_parse, 1),
("stringify", crate::builtins::json::json_stringify, 1),
kernel,
&[
("parse", crate::builtins::json::json_parse as *const (), 1),
(
"stringify",
crate::builtins::json::json_stringify as *const (),
1,
),
],
);
let si_j = kernel.string_forge().intern("JSON").0;
let j_shape = kernel.shape_forge().make_shape(global.shape_id(), si_j);
let j_val =
JsValue::from_js_object(kernel.builtin_world().json_object.as_ptr() as *mut JsObject);
global.set_shape_id(j_shape);
global.ensure_hash_props().push(Box::new(j_val));
global.bump_generation();
bind_global_value(
kernel,
global,
"JSON",
JsValue::from_js_object(kernel.builtin_world().json_object.as_ptr() as *mut JsObject),
);
}