mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 03:01:12 +08:00
feat: 九原型新增 toSource 遗留扩展方法
This commit is contained in:
@@ -67,7 +67,10 @@ pub fn bind_array(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
|
||||
session.builtin_world(),
|
||||
array_proto,
|
||||
core,
|
||||
&[("toString", oxide_builtins::array::array_to_string::<crate::vm::Vm> as *const (), 0)],
|
||||
&[
|
||||
("toString", oxide_builtins::array::array_to_string::<crate::vm::Vm> as *const (), 0),
|
||||
("toSource", oxide_builtins::to_source::to_source_array::<crate::vm::Vm> as *const (), 0),
|
||||
],
|
||||
);
|
||||
// 内置原型方法不可枚举(否则会泄漏进 for-in)。
|
||||
let si = core.perm_interner().intern("toString").0;
|
||||
|
||||
@@ -29,6 +29,7 @@ pub fn bind_boolean(core: &Arc<KernelCore>, session: &KernelSession, global: &mu
|
||||
oxide_builtins::boolean::boolean_prototype_to_string::<crate::vm::Vm> as *const (),
|
||||
0,
|
||||
),
|
||||
("toSource", oxide_builtins::to_source::to_source_boolean::<crate::vm::Vm> as *const (), 0),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ pub fn bind_date(core: &Arc<KernelCore>, session: &KernelSession, global: &mut J
|
||||
0,
|
||||
),
|
||||
("valueOf", oxide_builtins::date::date_value_of::<crate::vm::Vm> as *const (), 0),
|
||||
("toSource", oxide_builtins::to_source::to_source_date::<crate::vm::Vm> as *const (), 0),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -135,6 +135,20 @@ pub fn bind_error(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
|
||||
);
|
||||
}
|
||||
|
||||
// toSource 遗留扩展(Error 原型方法不走 kernel 侧 bind_error_methods,
|
||||
// 此处独立经 apply_binding_table 安装,描述符非枚举由绑定器内置)。
|
||||
{
|
||||
let proto_ptr = session.builtin_world().error_proto.as_ptr() as *mut JsObject;
|
||||
// SAFETY: error_proto 由 session 持有,存活整个 session;本块内只改其 shape/属性区,无 reset。
|
||||
let proto = unsafe { &mut *proto_ptr };
|
||||
super::apply_binding_table(
|
||||
session.builtin_world(),
|
||||
proto,
|
||||
core,
|
||||
&[("toSource", oxide_builtins::to_source::to_source_error::<crate::vm::Vm> as *const (), 0)],
|
||||
);
|
||||
}
|
||||
|
||||
// 全局 Error 槽位既有槽原位更新(旧家族构造器指针不得滞留在属性 vec),
|
||||
// 无槽时开新槽;描述符非枚举(规范 { writable:true, enumerable:false, configurable:true })。
|
||||
let si_err = core.perm_interner().intern("Error").0;
|
||||
|
||||
@@ -6,6 +6,7 @@ use oxide_kernel::shape_forge::EMPTY_SHAPE_ID;
|
||||
use oxide_types::object::{JsObject, NativeFnPtr, PropAttributes};
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
use super::apply_binding_table;
|
||||
use super::bind_global_value;
|
||||
use super::configure_native_constructor;
|
||||
|
||||
@@ -66,6 +67,15 @@ pub fn bind_function(core: &Arc<KernelCore>, session: &KernelSession, global: &m
|
||||
// 函数对象,任何访问抛 TypeError(AddRestrictedFunctionProperties 语义)。
|
||||
bind_function_proto_restricted(core, session, proto);
|
||||
|
||||
// toSource 遗留扩展(Function 原型方法不走 kernel 侧 bind_function_methods,
|
||||
// 此处独立经 apply_binding_table 安装,描述符非枚举由绑定器内置)。
|
||||
apply_binding_table(
|
||||
session.builtin_world(),
|
||||
proto,
|
||||
core,
|
||||
&[("toSource", oxide_builtins::to_source::to_source_function::<crate::vm::Vm> as *const (), 0)],
|
||||
);
|
||||
|
||||
bind_global_value(core, global, "Function", JsValue::from_js_object(function_ctor));
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ pub fn bind_number(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
|
||||
0,
|
||||
),
|
||||
("valueOf", oxide_builtins::number::number_value_of::<crate::vm::Vm> as *const (), 0),
|
||||
("toSource", oxide_builtins::to_source::to_source_number::<crate::vm::Vm> as *const (), 0),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ pub fn bind_object(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
|
||||
oxide_builtins::object::object_proto_lookup_setter::<crate::vm::Vm> as *const (),
|
||||
1,
|
||||
),
|
||||
("toSource", oxide_builtins::to_source::to_source_object::<crate::vm::Vm> as *const (), 0),
|
||||
],
|
||||
);
|
||||
// 内置原型方法不可枚举(否则会泄漏进 for-in)。
|
||||
@@ -98,6 +99,7 @@ pub fn bind_object(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
|
||||
"__defineSetter__",
|
||||
"__lookupGetter__",
|
||||
"__lookupSetter__",
|
||||
"toSource",
|
||||
] {
|
||||
let si = core.perm_interner().intern(name).0;
|
||||
if let Some(pos) = core.shape_forge().lookup_position(object_proto.shape_id(), si) {
|
||||
|
||||
@@ -38,6 +38,7 @@ pub fn bind_regexp(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
|
||||
("test", oxide_builtins::regexp::regexp_test::<crate::vm::Vm> as *const (), 1),
|
||||
("toString", oxide_builtins::regexp::regexp_to_string::<crate::vm::Vm> as *const (), 0),
|
||||
("compile", oxide_builtins::regexp::regexp_compile::<crate::vm::Vm> as *const (), 2),
|
||||
("toSource", oxide_builtins::to_source::to_source_regexp::<crate::vm::Vm> as *const (), 0),
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -86,7 +86,10 @@ pub fn bind_string(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
|
||||
session.builtin_world(),
|
||||
proto,
|
||||
core,
|
||||
&[("toString", oxide_builtins::string::string_to_string::<crate::vm::Vm> as *const (), 0)],
|
||||
&[
|
||||
("toString", oxide_builtins::string::string_to_string::<crate::vm::Vm> as *const (), 0),
|
||||
("toSource", oxide_builtins::to_source::to_source_string::<crate::vm::Vm> as *const (), 0),
|
||||
],
|
||||
);
|
||||
// String.prototype[@@iterator]:逐 code point 迭代字符;name 属性按规范
|
||||
// 落 "[Symbol.iterator]"。
|
||||
|
||||
Reference in New Issue
Block a user