From 12f41d2ce4a5152ab81eaa1bd8c1bf957d6bdc16 Mon Sep 17 00:00:00 2001 From: nekevss Date: Sat, 3 Feb 2024 11:01:13 -0500 Subject: [PATCH] fix ToTemporalCalendarSlot on to differentiate builtins --- core/engine/src/builtins/temporal/calendar/mod.rs | 12 ++++++------ .../src/builtins/temporal/plain_date_time/mod.rs | 3 +++ .../src/builtins/temporal/plain_date_time/tests.rs | 10 ++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 core/engine/src/builtins/temporal/plain_date_time/tests.rs diff --git a/core/engine/src/builtins/temporal/calendar/mod.rs b/core/engine/src/builtins/temporal/calendar/mod.rs index 132af2cd1cd..4cb31160e8a 100644 --- a/core/engine/src/builtins/temporal/calendar/mod.rs +++ b/core/engine/src/builtins/temporal/calendar/mod.rs @@ -33,11 +33,6 @@ use boa_temporal::{ mod object; -/* -#[doc(inline)] -pub(crate) use object::JsObject; -*/ - #[cfg(test)] mod tests; /// The `Temporal.Calendar` object. @@ -1075,7 +1070,12 @@ pub(crate) fn to_temporal_calendar_slot_value( } // c. Return temporalCalendarLike. - return Ok(CalendarSlot::Protocol(calendar_like.clone())); + match calendar_like.clone().downcast::() { + Ok(cal) => return Ok(cal.borrow().data().slot.clone()), + Err(custom) => { + return Ok(CalendarSlot::Protocol(custom.clone())); + } + } } // 3. If temporalCalendarLike is not a String, throw a TypeError exception. diff --git a/core/engine/src/builtins/temporal/plain_date_time/mod.rs b/core/engine/src/builtins/temporal/plain_date_time/mod.rs index c643adfdd1f..64b830e2205 100644 --- a/core/engine/src/builtins/temporal/plain_date_time/mod.rs +++ b/core/engine/src/builtins/temporal/plain_date_time/mod.rs @@ -17,6 +17,9 @@ use crate::{ use boa_gc::{Finalize, Trace}; use boa_profiler::Profiler; +#[cfg(test)] +mod tests; + use boa_temporal::{ components::{ calendar::{CalendarSlot, GetCalendarSlot}, diff --git a/core/engine/src/builtins/temporal/plain_date_time/tests.rs b/core/engine/src/builtins/temporal/plain_date_time/tests.rs new file mode 100644 index 00000000000..4cf106bcfc0 --- /dev/null +++ b/core/engine/src/builtins/temporal/plain_date_time/tests.rs @@ -0,0 +1,10 @@ +use crate::{run_test_actions, TestAction}; + +#[test] +fn pdt_year_of_week_basic() { + run_test_actions([ + TestAction::run("let calendar = Temporal.Calendar.from('iso8601')"), + TestAction::run("let pdt = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar)"), + TestAction::assert_eq("pdt.yearOfWeek", 1976), + ]); +}