Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add valueOf methods to the Temporal builtins #4079

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions core/engine/src/builtins/temporal/duration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ impl IntrinsicObject for Duration {
.method(Self::total, js_string!("total"), 1)
.method(Self::to_string, js_string!("toString"), 1)
.method(Self::to_json, js_string!("toJSON"), 0)
.method(Self::value_of, js_string!("valueOf"), 0)
.build();
}

Expand Down Expand Up @@ -794,6 +795,12 @@ impl Duration {
.with_message("not yet implemented.")
.into())
}

pub(crate) fn value_of(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("valueOf not implemented for Temporal objects. See 'compare', 'equals', or `toString`")
Copy link
Member

@jedel1043 jedel1043 Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm a bit negative about the "not implemented" phrasing because it seems like we haven't implemented it yet. Maybe something like "valueOf is not supported on Temporal objects".

.into())
}
}

// -- Duration Abstract Operations --
Expand Down
7 changes: 7 additions & 0 deletions core/engine/src/builtins/temporal/instant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl IntrinsicObject for Instant {
.method(Self::round, js_string!("round"), 1)
.method(Self::equals, js_string!("equals"), 1)
.method(Self::to_zoned_date_time, js_string!("toZonedDateTime"), 1)
.method(Self::value_of, js_string!("valueOf"), 0)
.method(
Self::to_zoned_date_time_iso,
js_string!("toZonedDateTimeISO"),
Expand Down Expand Up @@ -474,6 +475,12 @@ impl Instant {
.with_message("not yet implemented.")
.into())
}

pub(crate) fn value_of(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("valueOf not implemented for Temporal objects. See 'compare', 'equals', or `toString`")
.into())
}
}

// -- Instant Abstract Operations --
Expand Down
7 changes: 7 additions & 0 deletions core/engine/src/builtins/temporal/plain_date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ impl IntrinsicObject for PlainDate {
.method(Self::since, js_string!("since"), 1)
.method(Self::equals, js_string!("equals"), 1)
.method(Self::to_plain_datetime, js_string!("toPlainDateTime"), 0)
.method(Self::value_of, js_string!("valueOf"), 0)
.build();
}

Expand Down Expand Up @@ -783,6 +784,12 @@ impl PlainDate {
// 4. Return ? CreateTemporalDateTime(temporalDate.[[ISOYear]], temporalDate.[[ISOMonth]], temporalDate.[[ISODay]], temporalTime.[[ISOHour]], temporalTime.[[ISOMinute]], temporalTime.[[ISOSecond]], temporalTime.[[ISOMillisecond]], temporalTime.[[ISOMicrosecond]], temporalTime.[[ISONanosecond]], temporalDate.[[Calendar]]).
create_temporal_datetime(date.inner.to_date_time(time)?, None, context).map(Into::into)
}

pub(crate) fn value_of(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("valueOf not implemented for Temporal objects. See 'compare', 'equals', or `toString`")
.into())
}
}

// -- `PlainDate` Abstract Operations --
Expand Down
7 changes: 7 additions & 0 deletions core/engine/src/builtins/temporal/plain_date_time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ impl IntrinsicObject for PlainDateTime {
.method(Self::since, js_string!("since"), 1)
.method(Self::round, js_string!("round"), 1)
.method(Self::equals, js_string!("equals"), 1)
.method(Self::value_of, js_string!("valueOf"), 0)
.build();
}

Expand Down Expand Up @@ -904,6 +905,12 @@ impl PlainDateTime {
// 6. Return ? CalendarEquals(dateTime.[[Calendar]], other.[[Calendar]]).
Ok((dt.inner == other).into())
}

pub(crate) fn value_of(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("valueOf not implemented for Temporal objects. See 'compare', 'equals', or `toString`")
.into())
}
}

// ==== `PlainDateTime` Abstract Operations` ====
Expand Down
7 changes: 7 additions & 0 deletions core/engine/src/builtins/temporal/plain_month_day/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ impl PlainMonthDay {

Ok(month_day_to_string(inner, show_calendar))
}

pub(crate) fn value_of(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("valueOf not implemented for Temporal objects. See 'compare', 'equals', or `toString`")
.into())
}
}

impl BuiltInObject for PlainMonthDay {
Expand Down Expand Up @@ -164,6 +170,7 @@ impl IntrinsicObject for PlainMonthDay {
Attribute::CONFIGURABLE,
)
.method(Self::to_string, js_string!("toString"), 1)
.method(Self::value_of, js_string!("valueOf"), 0)
.static_method(Self::from, js_string!("from"), 2)
.build();
}
Expand Down
4 changes: 2 additions & 2 deletions core/engine/src/builtins/temporal/plain_time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,10 @@ impl PlainTime {
}

/// 4.3.22 Temporal.PlainTime.prototype.valueOf ( )
fn value_of(_: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
fn value_of(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
// 1. Throw a TypeError exception.
Err(JsNativeError::typ()
.with_message("valueOf cannot be called on PlainTime.")
.with_message("valueOf not implemented for Temporal objects. See 'compare', 'equals', or `toString`")
.into())
}
}
Expand Down
7 changes: 7 additions & 0 deletions core/engine/src/builtins/temporal/plain_year_month/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl IntrinsicObject for PlainYearMonth {
.method(Self::since, js_string!("since"), 2)
.method(Self::equals, js_string!("equals"), 1)
.method(Self::to_string, js_string!("toString"), 1)
.method(Self::value_of, js_string!("valueOf"), 0)
.build();
}

Expand Down Expand Up @@ -406,6 +407,12 @@ impl PlainYearMonth {

Ok(year_month_to_string(inner, show_calendar))
}

pub(crate) fn value_of(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("valueOf not implemented for Temporal objects. See 'compare', 'equals', or `toString`")
.into())
}
}

// ==== Abstract Operations ====
Expand Down
7 changes: 7 additions & 0 deletions core/engine/src/builtins/temporal/zoneddatetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ impl IntrinsicObject for ZonedDateTime {
.static_method(Self::from, js_string!("from"), 1)
.method(Self::add, js_string!("add"), 1)
.method(Self::subtract, js_string!("subtract"), 1)
.method(Self::value_of, js_string!("valueOf"), 0)
.build();
}

Expand Down Expand Up @@ -838,6 +839,12 @@ impl ZonedDateTime {
)
.map(Into::into)
}

pub(crate) fn value_of(_this: &JsValue, _: &[JsValue], _: &mut Context) -> JsResult<JsValue> {
Err(JsNativeError::typ()
.with_message("valueOf not implemented for Temporal objects. See 'compare', 'equals', or `toString`")
.into())
}
}

// -- ZonedDateTime Abstract Operations --
Expand Down
Loading