Browse Source

Temporal: attribute/property and custom calendar fixes (#3639)

* Fix accessor attribute and toStringTag property

* Fix calendar methods and custom extends calendar calling

* Complete attribute update

* run cargo fmt
pull/3642/head
Kevin 10 months ago committed by GitHub
parent
commit
8f7028d112
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 62
      core/engine/src/builtins/temporal/calendar/mod.rs
  2. 36
      core/engine/src/builtins/temporal/calendar/object.rs
  3. 56
      core/engine/src/builtins/temporal/duration/mod.rs
  4. 10
      core/engine/src/builtins/temporal/instant/mod.rs
  5. 40
      core/engine/src/builtins/temporal/plain_date/mod.rs
  6. 2
      core/engine/src/builtins/temporal/plain_date_time/mod.rs
  7. 2
      core/engine/src/builtins/temporal/plain_month_day/mod.rs
  8. 12
      core/engine/src/builtins/temporal/plain_time/mod.rs
  9. 28
      core/engine/src/builtins/temporal/plain_year_month/mod.rs
  10. 2
      core/engine/src/builtins/temporal/time_zone/mod.rs
  11. 2
      core/engine/src/builtins/temporal/zoned_date_time/mod.rs
  12. 4
      core/temporal/src/components/date.rs
  13. 4
      core/temporal/src/components/datetime.rs

62
core/engine/src/builtins/temporal/calendar/mod.rs

@ -73,12 +73,12 @@ impl IntrinsicObject for Calendar {
.build(); .build();
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::CONFIGURABLE, Attribute::CONFIGURABLE,
) )
.accessor(utf16!("id"), Some(get_id), None, Attribute::default()) .accessor(utf16!("id"), Some(get_id), None, Attribute::CONFIGURABLE)
.static_method(Self::from, js_string!("from"), 1) .static_method(Self::from, js_string!("from"), 1)
.method(Self::date_from_fields, js_string!("dateFromFields"), 2) .method(Self::date_from_fields, js_string!("dateFromFields"), 2)
.method( .method(
@ -174,8 +174,9 @@ impl Calendar {
.as_object() .as_object()
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ().with_message(
.with_message("the this value of Calendar must be a Calendar object.") "the this value of Calendar.prototype.id must be a Calendar object.",
)
})?; })?;
Ok(JsString::from(calendar.slot.identifier(context)?.as_str()).into()) Ok(JsString::from(calendar.slot.identifier(context)?.as_str()).into())
@ -193,8 +194,9 @@ impl Calendar {
.as_object() .as_object()
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ().with_message(
.with_message("this value of Calendar must be a Calendar object.") "this value of Calendar dateFromFields must be a Calendar object.",
)
})?; })?;
// 3. If Type(fields) is not Object, throw a TypeError exception. // 3. If Type(fields) is not Object, throw a TypeError exception.
@ -273,8 +275,9 @@ impl Calendar {
.as_object() .as_object()
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ().with_message(
.with_message("this value of Calendar must be a Calendar object.") "this value of Calendar yearMonthFromFields must be a Calendar object.",
)
})?; })?;
let fields = args.get_or_undefined(0); let fields = args.get_or_undefined(0);
@ -349,8 +352,9 @@ impl Calendar {
.as_object() .as_object()
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ().with_message(
.with_message("this value of Calendar must be a Calendar object.") "this value of Calendar monthDayFromFields must be a Calendar object.",
)
})?; })?;
// 3. If Type(fields) is not Object, throw a TypeError exception. // 3. If Type(fields) is not Object, throw a TypeError exception.
@ -422,7 +426,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar dateAdd must be a Calendar object.")
})?; })?;
// 4. Set date to ? ToTemporalDate(date). // 4. Set date to ? ToTemporalDate(date).
@ -461,7 +465,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar dateUntil must be a Calendar object.")
})?; })?;
// 4. Set one to ? ToTemporalDate(one). // 4. Set one to ? ToTemporalDate(one).
@ -497,7 +501,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar era must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -517,7 +521,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar eraYear must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -537,7 +541,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar year must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -554,7 +558,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar month must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -576,7 +580,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar monthCode must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -593,7 +597,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar day must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -612,7 +616,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar dayOfWeek must be a Calendar object.")
})?; })?;
// 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike).
@ -632,7 +636,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar dayOfYear must be a Calendar object.")
})?; })?;
// 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike).
@ -652,7 +656,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar weekOfYear must be a Calendar object.")
})?; })?;
// 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike).
@ -672,7 +676,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar yearOfWeek must be a Calendar object.")
})?; })?;
// 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike).
@ -692,7 +696,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar daysInWeek must be a Calendar object.")
})?; })?;
// 3. Let temporalDate be ? ToTemporalDate(temporalDateLike). // 3. Let temporalDate be ? ToTemporalDate(temporalDateLike).
@ -712,7 +716,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar daysInMonth must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -729,7 +733,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar daysInYear must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -749,7 +753,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar monthsInYear must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -766,7 +770,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar inLeapYear must be a Calendar object.")
})?; })?;
let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?; let date_like = to_calendar_date_like(args.get_or_undefined(0), context)?;
@ -785,7 +789,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar Fields must be a Calendar object.")
})?; })?;
// Custom Calendars override the `fields` method. // Custom Calendars override the `fields` method.
@ -902,7 +906,7 @@ impl Calendar {
.and_then(JsObject::downcast_ref::<Self>) .and_then(JsObject::downcast_ref::<Self>)
.ok_or_else(|| { .ok_or_else(|| {
JsNativeError::typ() JsNativeError::typ()
.with_message("this value of Calendar must be a Calendar object.") .with_message("this value of Calendar mergeFields must be a Calendar object.")
})?; })?;
let fields = args.get_or_undefined(0).to_object(context)?; let fields = args.get_or_undefined(0).to_object(context)?;

36
core/engine/src/builtins/temporal/calendar/object.rs

@ -267,7 +267,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -314,7 +314,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -361,7 +361,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
let JsValue::String(result) = val else { let JsValue::String(result) = val else {
@ -393,7 +393,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -440,7 +440,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -489,7 +489,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -538,7 +538,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -587,7 +587,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -629,7 +629,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -677,7 +677,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -728,7 +728,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -777,7 +777,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
// Validate the return value. // Validate the return value.
@ -828,7 +828,7 @@ impl CalendarProtocol for JsCustomCalendar {
let val = method let val = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[date_like], context) .call(&self.calendar.clone().into(), &[date_like], context)
.map_err(|err| TemporalError::general(err.to_string()))?; .map_err(|err| TemporalError::general(err.to_string()))?;
let JsValue::Boolean(result) = val else { let JsValue::Boolean(result) = val else {
@ -858,7 +858,7 @@ impl CalendarProtocol for JsCustomCalendar {
let result = method let result = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[fields_js.into()], context) .call(&self.calendar.clone().into(), &[fields_js.into()], context)
.map_err(|e| TemporalError::general(e.to_string()))?; .map_err(|e| TemporalError::general(e.to_string()))?;
// validate result and map to a `Vec<String>` // validate result and map to a `Vec<String>`
@ -909,7 +909,11 @@ impl CalendarProtocol for JsCustomCalendar {
let value = method let value = method
.as_callable() .as_callable()
.expect("is method") .expect("is method")
.call(&method, &[fields.into(), add_fields.into()], context) .call(
&self.calendar.clone().into(),
&[fields.into(), add_fields.into()],
context,
)
.map_err(|e| TemporalError::general(e.to_string()))?; .map_err(|e| TemporalError::general(e.to_string()))?;
let JsValue::Object(o) = value else { let JsValue::Object(o) = value else {
@ -930,7 +934,7 @@ impl CalendarProtocol for JsCustomCalendar {
.calendar .calendar
.__get__( .__get__(
&PropertyKey::from(utf16!("id")), &PropertyKey::from(utf16!("id")),
JsValue::undefined(), self.calendar.clone().into(),
&mut context.into(), &mut context.into(),
) )
.expect("method must exist on a object that implements the CalendarProtocol."); .expect("method must exist on a object that implements the CalendarProtocol.");

56
core/engine/src/builtins/temporal/duration/mod.rs

@ -101,53 +101,83 @@ impl IntrinsicObject for Duration {
.build(); .build();
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,
) )
.accessor(utf16!("years"), Some(get_years), None, Attribute::default()) .accessor(
utf16!("years"),
Some(get_years),
None,
Attribute::CONFIGURABLE,
)
.accessor( .accessor(
utf16!("months"), utf16!("months"),
Some(get_months), Some(get_months),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
)
.accessor(
utf16!("weeks"),
Some(get_weeks),
None,
Attribute::CONFIGURABLE,
)
.accessor(
utf16!("days"),
Some(get_days),
None,
Attribute::CONFIGURABLE,
)
.accessor(
utf16!("hours"),
Some(get_hours),
None,
Attribute::CONFIGURABLE,
) )
.accessor(utf16!("weeks"), Some(get_weeks), None, Attribute::default())
.accessor(utf16!("days"), Some(get_days), None, Attribute::default())
.accessor(utf16!("hours"), Some(get_hours), None, Attribute::default())
.accessor( .accessor(
utf16!("minutes"), utf16!("minutes"),
Some(get_minutes), Some(get_minutes),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("seconds"), utf16!("seconds"),
Some(get_seconds), Some(get_seconds),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("milliseconds"), utf16!("milliseconds"),
Some(get_milliseconds), Some(get_milliseconds),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("microseconds"), utf16!("microseconds"),
Some(get_microseconds), Some(get_microseconds),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("nanoseconds"), utf16!("nanoseconds"),
Some(get_nanoseconds), Some(get_nanoseconds),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
)
.accessor(
utf16!("sign"),
Some(get_sign),
None,
Attribute::CONFIGURABLE,
)
.accessor(
utf16!("blank"),
Some(is_blank),
None,
Attribute::CONFIGURABLE,
) )
.accessor(utf16!("sign"), Some(get_sign), None, Attribute::default())
.accessor(utf16!("blank"), Some(is_blank), None, Attribute::default())
.method(Self::with, js_string!("with"), 1) .method(Self::with, js_string!("with"), 1)
.method(Self::negated, js_string!("negated"), 0) .method(Self::negated, js_string!("negated"), 0)
.method(Self::abs, js_string!("abs"), 0) .method(Self::abs, js_string!("abs"), 0)

10
core/engine/src/builtins/temporal/instant/mod.rs

@ -58,7 +58,7 @@ impl IntrinsicObject for Instant {
.build(); .build();
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::CONFIGURABLE, Attribute::CONFIGURABLE,
@ -67,25 +67,25 @@ impl IntrinsicObject for Instant {
utf16!("epochSeconds"), utf16!("epochSeconds"),
Some(get_seconds), Some(get_seconds),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("epochMilliseconds"), utf16!("epochMilliseconds"),
Some(get_millis), Some(get_millis),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("epochMicroseconds"), utf16!("epochMicroseconds"),
Some(get_micros), Some(get_micros),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("epochNanoseconds"), utf16!("epochNanoseconds"),
Some(get_nanos), Some(get_nanos),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.method(Self::add, js_string!("add"), 1) .method(Self::add, js_string!("add"), 1)
.method(Self::subtract, js_string!("subtract"), 1) .method(Self::subtract, js_string!("subtract"), 1)

40
core/engine/src/builtins/temporal/plain_date/mod.rs

@ -103,7 +103,7 @@ impl IntrinsicObject for PlainDate {
.build(); .build();
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::CONFIGURABLE, Attribute::CONFIGURABLE,
@ -112,70 +112,80 @@ impl IntrinsicObject for PlainDate {
utf16!("calendarId"), utf16!("calendarId"),
Some(get_calendar_id), Some(get_calendar_id),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
)
.accessor(
utf16!("year"),
Some(get_year),
None,
Attribute::CONFIGURABLE,
)
.accessor(
utf16!("month"),
Some(get_month),
None,
Attribute::CONFIGURABLE,
) )
.accessor(utf16!("year"), Some(get_year), None, Attribute::default())
.accessor(utf16!("month"), Some(get_month), None, Attribute::default())
.accessor( .accessor(
utf16!("monthCode"), utf16!("monthCode"),
Some(get_month_code), Some(get_month_code),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor(utf16!("day"), Some(get_day), None, Attribute::default()) .accessor(utf16!("day"), Some(get_day), None, Attribute::CONFIGURABLE)
.accessor( .accessor(
utf16!("dayOfWeek"), utf16!("dayOfWeek"),
Some(get_day_of_week), Some(get_day_of_week),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("dayOfYear"), utf16!("dayOfYear"),
Some(get_day_of_year), Some(get_day_of_year),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("weekOfYear"), utf16!("weekOfYear"),
Some(get_week_of_year), Some(get_week_of_year),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("yearOfWeek"), utf16!("yearOfWeek"),
Some(get_year_of_week), Some(get_year_of_week),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("daysInWeek"), utf16!("daysInWeek"),
Some(get_days_in_week), Some(get_days_in_week),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("daysInMonth"), utf16!("daysInMonth"),
Some(get_days_in_month), Some(get_days_in_month),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("daysInYear"), utf16!("daysInYear"),
Some(get_days_in_year), Some(get_days_in_year),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("monthsInYear"), utf16!("monthsInYear"),
Some(get_months_in_year), Some(get_months_in_year),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("inLeapYear"), utf16!("inLeapYear"),
Some(get_in_leap_year), Some(get_in_leap_year),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.method(Self::to_plain_year_month, js_string!("toPlainYearMonth"), 0) .method(Self::to_plain_year_month, js_string!("toPlainYearMonth"), 0)
.method(Self::to_plain_month_day, js_string!("toPlainMonthDay"), 0) .method(Self::to_plain_month_day, js_string!("toPlainMonthDay"), 0)

2
core/engine/src/builtins/temporal/plain_date_time/mod.rs

@ -127,7 +127,7 @@ impl IntrinsicObject for PlainDateTime {
.build(); .build();
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::CONFIGURABLE, Attribute::CONFIGURABLE,

2
core/engine/src/builtins/temporal/plain_month_day/mod.rs

@ -38,7 +38,7 @@ impl IntrinsicObject for PlainMonthDay {
let _timer = Profiler::global().start_event(std::any::type_name::<Self>(), "init"); let _timer = Profiler::global().start_event(std::any::type_name::<Self>(), "init");
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::CONFIGURABLE, Attribute::CONFIGURABLE,

12
core/engine/src/builtins/temporal/plain_time/mod.rs

@ -66,7 +66,7 @@ impl IntrinsicObject for PlainTime {
.build(); .build();
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::CONFIGURABLE, Attribute::CONFIGURABLE,
@ -76,31 +76,31 @@ impl IntrinsicObject for PlainTime {
utf16!("minute"), utf16!("minute"),
Some(get_minute), Some(get_minute),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("second"), utf16!("second"),
Some(get_second), Some(get_second),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("millisecond"), utf16!("millisecond"),
Some(get_millisecond), Some(get_millisecond),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("microsecond"), utf16!("microsecond"),
Some(get_microsecond), Some(get_microsecond),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("nanosecond"), utf16!("nanosecond"),
Some(get_nanosecond), Some(get_nanosecond),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.method(Self::add, js_string!("add"), 1) .method(Self::add, js_string!("add"), 1)
.method(Self::subtract, js_string!("subtract"), 1) .method(Self::subtract, js_string!("subtract"), 1)

28
core/engine/src/builtins/temporal/plain_year_month/mod.rs

@ -70,7 +70,7 @@ impl IntrinsicObject for PlainYearMonth {
.build(); .build();
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::CONFIGURABLE, Attribute::CONFIGURABLE,
@ -79,39 +79,49 @@ impl IntrinsicObject for PlainYearMonth {
utf16!("calendarId"), utf16!("calendarId"),
Some(get_calendar_id), Some(get_calendar_id),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
)
.accessor(
utf16!("year"),
Some(get_year),
None,
Attribute::CONFIGURABLE,
)
.accessor(
utf16!("month"),
Some(get_month),
None,
Attribute::CONFIGURABLE,
) )
.accessor(utf16!("year"), Some(get_year), None, Attribute::default())
.accessor(utf16!("month"), Some(get_month), None, Attribute::default())
.accessor( .accessor(
utf16!("monthCode"), utf16!("monthCode"),
Some(get_month_code), Some(get_month_code),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("daysInMonth"), utf16!("daysInMonth"),
Some(get_days_in_month), Some(get_days_in_month),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("daysInYear"), utf16!("daysInYear"),
Some(get_days_in_year), Some(get_days_in_year),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("monthsInYear"), utf16!("monthsInYear"),
Some(get_months_in_year), Some(get_months_in_year),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.accessor( .accessor(
utf16!("inLeapYear"), utf16!("inLeapYear"),
Some(get_in_leap_year), Some(get_in_leap_year),
None, None,
Attribute::default(), Attribute::CONFIGURABLE,
) )
.method(Self::with, js_string!("with"), 2) .method(Self::with, js_string!("with"), 2)
.method(Self::add, js_string!("add"), 2) .method(Self::add, js_string!("add"), 2)

2
core/engine/src/builtins/temporal/time_zone/mod.rs

@ -85,7 +85,7 @@ impl IntrinsicObject for TimeZone {
) )
.method(Self::to_string, js_string!("toString"), 0) .method(Self::to_string, js_string!("toString"), 0)
.method(Self::to_string, js_string!("toJSON"), 0) .method(Self::to_string, js_string!("toJSON"), 0)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE, Attribute::READONLY | Attribute::NON_ENUMERABLE | Attribute::CONFIGURABLE,

2
core/engine/src/builtins/temporal/zoned_date_time/mod.rs

@ -44,7 +44,7 @@ impl IntrinsicObject for ZonedDateTime {
let _timer = Profiler::global().start_event(std::any::type_name::<Self>(), "init"); let _timer = Profiler::global().start_event(std::any::type_name::<Self>(), "init");
BuiltInBuilder::from_standard_constructor::<Self>(realm) BuiltInBuilder::from_standard_constructor::<Self>(realm)
.static_property( .property(
JsSymbol::to_string_tag(), JsSymbol::to_string_tag(),
Self::NAME, Self::NAME,
Attribute::CONFIGURABLE, Attribute::CONFIGURABLE,

4
core/temporal/src/components/date.rs

@ -195,7 +195,7 @@ impl<C: CalendarProtocol> Date<C> {
/// Returns the calendar day of year value with provided context. /// Returns the calendar day of year value with provided context.
pub fn contextual_day_of_year(&self, context: &mut dyn Any) -> TemporalResult<u16> { pub fn contextual_day_of_year(&self, context: &mut dyn Any) -> TemporalResult<u16> {
self.calendar.day_of_week( self.calendar.day_of_year(
&super::calendar::CalendarDateLike::Date(self.clone()), &super::calendar::CalendarDateLike::Date(self.clone()),
context, context,
) )
@ -203,7 +203,7 @@ impl<C: CalendarProtocol> Date<C> {
/// Returns the calendar day of year value. /// Returns the calendar day of year value.
pub fn day_of_year(&self) -> TemporalResult<u16> { pub fn day_of_year(&self) -> TemporalResult<u16> {
self.contextual_day_of_week(&mut ()) self.contextual_day_of_year(&mut ())
} }
/// Returns the calendar week of year value with provided context. /// Returns the calendar week of year value with provided context.

4
core/temporal/src/components/datetime.rs

@ -238,7 +238,7 @@ impl<C: CalendarProtocol> DateTime<C> {
/// Returns the calendar day of year value with provided context. /// Returns the calendar day of year value with provided context.
pub fn contextual_day_of_year(&self, context: &mut dyn Any) -> TemporalResult<u16> { pub fn contextual_day_of_year(&self, context: &mut dyn Any) -> TemporalResult<u16> {
self.calendar.day_of_week( self.calendar.day_of_year(
&super::calendar::CalendarDateLike::DateTime(self.clone()), &super::calendar::CalendarDateLike::DateTime(self.clone()),
context, context,
) )
@ -246,7 +246,7 @@ impl<C: CalendarProtocol> DateTime<C> {
/// Returns the calendar day of year value. /// Returns the calendar day of year value.
pub fn day_of_year(&self) -> TemporalResult<u16> { pub fn day_of_year(&self) -> TemporalResult<u16> {
self.contextual_day_of_week(&mut ()) self.contextual_day_of_year(&mut ())
} }
/// Returns the calendar week of year value with provided context. /// Returns the calendar week of year value with provided context.

Loading…
Cancel
Save