mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 11:11:11 +08:00
feat: PlainMonthDay/PlainYearMonth toLocaleString(默认形串)与 valueOf(TypeError)绑定
This commit is contained in:
@@ -1005,6 +1005,16 @@ pub fn bind_temporal(core: &Arc<KernelCore>, session: &KernelSession, global: &m
|
||||
oxide_builtins::temporal::plain_month_day_to_json::<crate::vm::Vm> as *const (),
|
||||
0,
|
||||
),
|
||||
(
|
||||
"toLocaleString",
|
||||
oxide_builtins::temporal::plain_month_day_to_locale_string::<crate::vm::Vm> as *const (),
|
||||
0,
|
||||
),
|
||||
(
|
||||
"valueOf",
|
||||
oxide_builtins::temporal::plain_month_day_value_of::<crate::vm::Vm> as *const (),
|
||||
0,
|
||||
),
|
||||
],
|
||||
);
|
||||
bind_well_known_data_property(
|
||||
@@ -1088,6 +1098,16 @@ pub fn bind_temporal(core: &Arc<KernelCore>, session: &KernelSession, global: &m
|
||||
oxide_builtins::temporal::plain_year_month_to_json::<crate::vm::Vm> as *const (),
|
||||
0,
|
||||
),
|
||||
(
|
||||
"toLocaleString",
|
||||
oxide_builtins::temporal::plain_year_month_to_locale_string::<crate::vm::Vm> as *const (),
|
||||
0,
|
||||
),
|
||||
(
|
||||
"valueOf",
|
||||
oxide_builtins::temporal::plain_year_month_value_of::<crate::vm::Vm> as *const (),
|
||||
0,
|
||||
),
|
||||
],
|
||||
);
|
||||
bind_well_known_data_property(
|
||||
|
||||
@@ -2797,3 +2797,32 @@ fn plain_month_day_and_year_month_branding() {
|
||||
.unwrap();
|
||||
assert_eq!(str_val(&vm, r), "TypeError|TypeError|TypeError|TypeError");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_month_day_and_year_month_to_locale_string_value_of_to_string_tag() {
|
||||
let mut vm = Vm::new();
|
||||
// toLocaleString 忽略 locale/options,恒默认形串;valueOf 恒 TypeError
|
||||
// (`<` 走 ToPrimitive→valueOf 同抛);toStringTag 经 Object.prototype.toString 读回。
|
||||
let r = eval(
|
||||
&mut vm,
|
||||
"(() => {
|
||||
const pmd = new Temporal.PlainMonthDay(5, 2);
|
||||
const pym = new Temporal.PlainYearMonth(2021, 2);
|
||||
const kind = (fn) => { try { fn(); return 'no'; } catch (e) { return e.constructor.name; } };
|
||||
return [
|
||||
pmd.toLocaleString('en-US', {calendar: 'iso8601'}),
|
||||
pym.toLocaleString(),
|
||||
kind(() => pmd.valueOf()),
|
||||
kind(() => pym.valueOf()),
|
||||
kind(() => pmd < pym),
|
||||
Object.prototype.toString.call(pmd),
|
||||
Object.prototype.toString.call(pym),
|
||||
].join('|');
|
||||
})()",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
str_val(&vm, r),
|
||||
"05-02|2021-02|TypeError|TypeError|TypeError|[object Temporal.PlainMonthDay]|[object Temporal.PlainYearMonth]"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user