mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 03:01:12 +08:00
feat: 绑定全局 escape/unescape 与缺失全局桩函数
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use oxide_kernel::kernel::{KernelCore, KernelSession};
|
||||
use oxide_types::object::JsObject;
|
||||
|
||||
use crate::bindings::apply_binding_table;
|
||||
|
||||
pub fn bind_global(core: &Arc<KernelCore>, session: &KernelSession, global: &mut JsObject) {
|
||||
apply_binding_table(
|
||||
session.builtin_world(),
|
||||
global,
|
||||
core,
|
||||
&[
|
||||
("escape", crate::builtins::global::js_escape as *const (), 1),
|
||||
("unescape", crate::builtins::global::js_unescape as *const (), 1),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use oxide_kernel::kernel::{KernelCore, KernelSession};
|
||||
use oxide_kernel::shape_forge::EMPTY_SHAPE_ID;
|
||||
use oxide_types::mem::P;
|
||||
use oxide_types::object::JsObject;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
use crate::bindings::{bind_global_value, configure_native_constructor};
|
||||
|
||||
const STUBS: [(&str, *const (), u8); 8] = [
|
||||
("Proxy", crate::builtins::stubs::proxy_stub as *const (), 2),
|
||||
("BigInt", crate::builtins::stubs::bigint_stub as *const (), 1),
|
||||
("WeakMap", crate::builtins::stubs::weakmap_stub as *const (), 0),
|
||||
("WeakSet", crate::builtins::stubs::weakset_stub as *const (), 0),
|
||||
("WeakRef", crate::builtins::stubs::weakref_stub as *const (), 1),
|
||||
("FinalizationRegistry", crate::builtins::stubs::finalization_registry_stub as *const (), 1),
|
||||
("SharedArrayBuffer", crate::builtins::stubs::shared_array_buffer_stub as *const (), 1),
|
||||
("Atomics", crate::builtins::stubs::atomics_stub as *const (), 0),
|
||||
];
|
||||
|
||||
pub fn bind_stubs(core: &Arc<KernelCore>, session: &mut KernelSession, global: &mut JsObject) {
|
||||
let builtin_world = Arc::get_mut(&mut session.builtin_world)
|
||||
.expect("BuiltinWorld must be uniquely owned during init_kernel_builtins");
|
||||
|
||||
for (name, native_fn, arg_count) in STUBS {
|
||||
let mut stub = JsObject::new_empty(
|
||||
EMPTY_SHAPE_ID,
|
||||
JsValue::from_js_object(builtin_world.function_proto.as_ptr() as *mut JsObject),
|
||||
);
|
||||
stub.set_function(true);
|
||||
configure_native_constructor(&mut stub, native_fn, arg_count);
|
||||
|
||||
let stub = P::new(stub);
|
||||
let stub_ptr = stub.as_ptr() as *mut JsObject;
|
||||
bind_global_value(core, global, name, JsValue::from_js_object(stub_ptr));
|
||||
builtin_world.stub_objects.push(stub);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ pub mod bind_boolean;
|
||||
pub mod bind_date;
|
||||
pub mod bind_error;
|
||||
pub mod bind_function;
|
||||
pub mod bind_global;
|
||||
pub mod bind_json;
|
||||
pub mod bind_map;
|
||||
pub mod bind_math;
|
||||
@@ -11,6 +12,7 @@ pub mod bind_object;
|
||||
pub mod bind_regexp;
|
||||
pub mod bind_set;
|
||||
pub mod bind_string;
|
||||
pub mod bind_stubs;
|
||||
pub mod bind_symbol;
|
||||
|
||||
use std::sync::Arc;
|
||||
@@ -77,7 +79,7 @@ pub(crate) fn bind_global_value(core: &Arc<KernelCore>, global: &mut JsObject, n
|
||||
global.bump_generation();
|
||||
}
|
||||
|
||||
pub fn init_kernel_builtins(core: &Arc<KernelCore>, session: &KernelSession) {
|
||||
pub fn init_kernel_builtins(core: &Arc<KernelCore>, session: &mut KernelSession) {
|
||||
let global_ptr = session.global_object().as_ptr() as *mut oxide_types::object::JsObject;
|
||||
let global = unsafe { &mut *global_ptr };
|
||||
|
||||
@@ -95,6 +97,8 @@ pub fn init_kernel_builtins(core: &Arc<KernelCore>, session: &KernelSession) {
|
||||
bind_function::bind_function(core, session, global);
|
||||
bind_regexp::bind_regexp(core, session, global);
|
||||
bind_symbol::bind_symbol(core, session, global);
|
||||
bind_global::bind_global(core, session, global);
|
||||
bind_stubs::bind_stubs(core, session, global);
|
||||
|
||||
bind_global_value(core, global, "globalThis", JsValue::from_js_object(global_ptr));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user