feat: 注册 Symbol.toPrimitive well-known symbol
This commit is contained in:
@@ -217,6 +217,7 @@ pub struct BuiltinWorld {
|
||||
pub sym_search: P<JsObject>,
|
||||
pub sym_split: P<JsObject>,
|
||||
pub sym_iterator: P<JsObject>,
|
||||
pub sym_to_primitive: P<JsObject>,
|
||||
pub stub_objects: Vec<P<JsObject>>,
|
||||
}
|
||||
|
||||
@@ -539,6 +540,7 @@ impl BuiltinWorld {
|
||||
BuiltinId::SymSearch => &self.sym_search,
|
||||
BuiltinId::SymSplit => &self.sym_split,
|
||||
BuiltinId::SymIterator => &self.sym_iterator,
|
||||
BuiltinId::SymToPrimitive => &self.sym_to_primitive,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,6 +576,7 @@ impl BuiltinWorld {
|
||||
let sym_search = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
|
||||
let sym_split = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
|
||||
let sym_iterator = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
|
||||
let sym_to_primitive = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null()));
|
||||
let stub_objects = Vec::new();
|
||||
|
||||
let world = Self {
|
||||
@@ -641,6 +644,7 @@ impl BuiltinWorld {
|
||||
sym_search,
|
||||
sym_split,
|
||||
sym_iterator,
|
||||
sym_to_primitive,
|
||||
stub_objects,
|
||||
};
|
||||
wire_builtin_world_links(&world);
|
||||
@@ -701,8 +705,16 @@ impl BuiltinWorld {
|
||||
},
|
||||
)
|
||||
};
|
||||
let (symbol_proto, symbol_constructor, sym_match, sym_replace, sym_search, sym_split, sym_iterator) =
|
||||
if dirty.symbol_family {
|
||||
let (
|
||||
symbol_proto,
|
||||
symbol_constructor,
|
||||
sym_match,
|
||||
sym_replace,
|
||||
sym_search,
|
||||
sym_split,
|
||||
sym_iterator,
|
||||
sym_to_primitive,
|
||||
) = if dirty.symbol_family {
|
||||
let (symbol_proto, symbol_constructor) = make_named_pair(string_forge, shape_forge, labels, "Symbol");
|
||||
(
|
||||
symbol_proto,
|
||||
@@ -712,6 +724,7 @@ impl BuiltinWorld {
|
||||
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
|
||||
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
|
||||
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
|
||||
P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
@@ -722,6 +735,7 @@ impl BuiltinWorld {
|
||||
current.sym_search.clone(),
|
||||
current.sym_split.clone(),
|
||||
current.sym_iterator.clone(),
|
||||
current.sym_to_primitive.clone(),
|
||||
)
|
||||
};
|
||||
|
||||
@@ -861,6 +875,7 @@ impl BuiltinWorld {
|
||||
sym_search,
|
||||
sym_split,
|
||||
sym_iterator,
|
||||
sym_to_primitive,
|
||||
stub_objects,
|
||||
};
|
||||
wire_builtin_world_links(&world);
|
||||
|
||||
@@ -201,7 +201,7 @@ pub struct KernelSession {
|
||||
/// Maintenance: every new `BuiltinWorld` object field must be added here and to
|
||||
/// `KernelSession::dirty_since_snapshot()` so selective reset can rebuild the
|
||||
/// correct builtin family.
|
||||
pub const NUM_BUILTINS: usize = 64;
|
||||
pub const NUM_BUILTINS: usize = 65;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
@@ -270,6 +270,7 @@ pub enum BuiltinId {
|
||||
SymSearch = 61,
|
||||
SymSplit = 62,
|
||||
SymIterator = 63,
|
||||
SymToPrimitive = 64,
|
||||
}
|
||||
|
||||
impl BuiltinId {
|
||||
@@ -338,6 +339,7 @@ impl BuiltinId {
|
||||
BuiltinId::SymSearch,
|
||||
BuiltinId::SymSplit,
|
||||
BuiltinId::SymIterator,
|
||||
BuiltinId::SymToPrimitive,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -506,7 +508,8 @@ impl KernelSession {
|
||||
|| gen(BuiltinId::SymReplace) != snap(BuiltinId::SymReplace)
|
||||
|| gen(BuiltinId::SymSearch) != snap(BuiltinId::SymSearch)
|
||||
|| gen(BuiltinId::SymSplit) != snap(BuiltinId::SymSplit)
|
||||
|| gen(BuiltinId::SymIterator) != snap(BuiltinId::SymIterator),
|
||||
|| gen(BuiltinId::SymIterator) != snap(BuiltinId::SymIterator)
|
||||
|| gen(BuiltinId::SymToPrimitive) != snap(BuiltinId::SymToPrimitive),
|
||||
math: gen(BuiltinId::MathObject) != snap(BuiltinId::MathObject),
|
||||
json: gen(BuiltinId::JsonObject) != snap(BuiltinId::JsonObject),
|
||||
date: gen(BuiltinId::DateConstructor) != snap(BuiltinId::DateConstructor)
|
||||
|
||||
@@ -53,6 +53,10 @@ pub fn bind_symbol(core: &Arc<KernelCore>, session: &KernelSession, global: &mut
|
||||
"iterator",
|
||||
JsValue::from_js_object(session.builtin_world().sym_iterator.as_ptr() as *mut JsObject),
|
||||
),
|
||||
(
|
||||
"toPrimitive",
|
||||
JsValue::from_js_object(session.builtin_world().sym_to_primitive.as_ptr() as *mut JsObject),
|
||||
),
|
||||
] {
|
||||
bind_well_known_symbol(core, ctor, name, val);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user