[Temporal] Add PlainMonthDay.prototype.toJSON
Also add AO: TemporalMonthDayToString Spec Text: https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype.tojson https://tc39.es/proposal-temporal/#sec-temporal-temporalmonthdaytostring Bug: v8:11544 Change-Id: Ibbc5b28a9c73474f7edc1b67c9beabf5bca54dbc Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3437891 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#80624}
This commit is contained in:
parent
852e075639
commit
0b44a86009
@ -268,8 +268,6 @@ TO_BE_IMPLEMENTED(TemporalPlainMonthDayPrototypeWith)
|
||||
TO_BE_IMPLEMENTED(TemporalPlainMonthDayPrototypeEquals)
|
||||
/* Temporal #sec-temporal.plainmonthday.prototype.tostring */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainMonthDayPrototypeToString)
|
||||
/* Temporal #sec-temporal.plainmonthday.tojson */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainMonthDayPrototypeToJSON)
|
||||
/* Temporal #sec-temporal.plainmonthday.prototype.toplaindate */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainMonthDayPrototypeToPlainDate)
|
||||
|
||||
@ -601,6 +599,7 @@ TEMPORAL_GET_BY_FORWARD_CALENDAR(PlainMonthDay, MonthCode, monthCode)
|
||||
TEMPORAL_GET_BY_FORWARD_CALENDAR(PlainMonthDay, Day, day)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainMonthDay, GetISOFields, getISOFields)
|
||||
TEMPORAL_VALUE_OF(PlainMonthDay)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainMonthDay, ToJSON, toJSON)
|
||||
|
||||
// ZonedDateTime
|
||||
|
||||
|
@ -2657,6 +2657,55 @@ MaybeHandle<String> TemporalDateToString(
|
||||
return builder.Finish().ToHandleChecked();
|
||||
}
|
||||
|
||||
// #sec-temporal-temporalmonthdaytostring
|
||||
MaybeHandle<String> TemporalMonthDayToString(
|
||||
Isolate* isolate, Handle<JSTemporalPlainMonthDay> month_day,
|
||||
ShowCalendar show_calendar) {
|
||||
// 1. Assert: Type(monthDay) is Object.
|
||||
// 2. Assert: monthDay has an [[InitializedTemporalMonthDay]] internal slot.
|
||||
IncrementalStringBuilder builder(isolate);
|
||||
// 6. Let calendarID be ? ToString(monthDay.[[Calendar]]).
|
||||
Handle<String> calendar_id;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(
|
||||
isolate, calendar_id,
|
||||
Object::ToString(isolate, handle(month_day->calendar(), isolate)),
|
||||
String);
|
||||
// 7. If showCalendar is "always" or if calendarID is not "iso8601", then
|
||||
if (show_calendar == ShowCalendar::kAlways ||
|
||||
!String::Equals(isolate, calendar_id,
|
||||
isolate->factory()->iso8601_string())) {
|
||||
// a. Let year be ! PadISOYear(monthDay.[[ISOYear]]).
|
||||
PadISOYear(&builder, month_day->iso_year());
|
||||
// b. Set result to the string-concatenation of year, the code unit
|
||||
// 0x002D (HYPHEN-MINUS), and result.
|
||||
builder.AppendCharacter('-');
|
||||
}
|
||||
// 3. Let month be ToZeroPaddedDecimalString(monthDay.[[ISOMonth]], 2).
|
||||
int32_t month = month_day->iso_month();
|
||||
if (month < 10) {
|
||||
builder.AppendCharacter('0');
|
||||
}
|
||||
builder.AppendInt(month);
|
||||
// 5. Let result be the string-concatenation of month, the code unit 0x002D
|
||||
// (HYPHEN-MINUS), and day.
|
||||
builder.AppendCharacter('-');
|
||||
// 4. Let day be ToZeroPaddedDecimalString(monthDay.[[ISODay]], 2).
|
||||
int32_t day = month_day->iso_day();
|
||||
if (day < 10) {
|
||||
builder.AppendCharacter('0');
|
||||
}
|
||||
builder.AppendInt(day);
|
||||
// 8. Let calendarString be ! FormatCalendarAnnotation(calendarID,
|
||||
// showCalendar).
|
||||
Handle<String> calendar_string =
|
||||
FormatCalendarAnnotation(isolate, calendar_id, show_calendar);
|
||||
|
||||
// 9. Set result to the string-concatenation of result and calendarString.
|
||||
builder.AppendString(calendar_string);
|
||||
// 10. Return result.
|
||||
return builder.Finish().ToHandleChecked();
|
||||
}
|
||||
|
||||
// #sec-temporal-builtintimezonegetoffsetstringfor
|
||||
MaybeHandle<String> BuiltinTimeZoneGetOffsetStringFor(
|
||||
Isolate* isolate, Handle<JSReceiver> time_zone,
|
||||
@ -6657,7 +6706,10 @@ MaybeHandle<String> JSTemporalCalendar::MonthCode(
|
||||
Handle<JSTemporalPlainYearMonth>::cast(temporal_date_like)->iso_month();
|
||||
}
|
||||
IncrementalStringBuilder builder(isolate);
|
||||
builder.AppendCString((month < 10) ? "M0" : "M");
|
||||
builder.AppendCharacter('M');
|
||||
if (month < 10) {
|
||||
builder.AppendCharacter('0');
|
||||
}
|
||||
builder.AppendInt(month);
|
||||
|
||||
return builder.Finish();
|
||||
@ -7896,6 +7948,12 @@ MaybeHandle<JSReceiver> JSTemporalPlainMonthDay::GetISOFields(
|
||||
return fields;
|
||||
}
|
||||
|
||||
// #sec-temporal.plainmonthday.prototype.tojson
|
||||
MaybeHandle<String> JSTemporalPlainMonthDay::ToJSON(
|
||||
Isolate* isolate, Handle<JSTemporalPlainMonthDay> month_day) {
|
||||
return TemporalMonthDayToString(isolate, month_day, ShowCalendar::kAuto);
|
||||
}
|
||||
|
||||
MaybeHandle<JSTemporalPlainYearMonth> JSTemporalPlainYearMonth::Constructor(
|
||||
Isolate* isolate, Handle<JSFunction> target, Handle<HeapObject> new_target,
|
||||
Handle<Object> iso_year_obj, Handle<Object> iso_month_obj,
|
||||
|
@ -338,6 +338,10 @@ class JSTemporalPlainMonthDay
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> GetISOFields(
|
||||
Isolate* isolate, Handle<JSTemporalPlainMonthDay> month_day);
|
||||
|
||||
// #sec-temporal.plainmonthday.prototype.tojson
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToJSON(
|
||||
Isolate* isolate, Handle<JSTemporalPlainMonthDay> month_day);
|
||||
|
||||
DECL_PRINTER(JSTemporalPlainMonthDay)
|
||||
|
||||
DEFINE_TORQUE_GENERATED_JS_TEMPORAL_YEAR_MONTH_DAY()
|
||||
|
@ -46,7 +46,6 @@
|
||||
# Temporal tests to be implemented
|
||||
# https://crbug.com/v8/11544
|
||||
'temporal/calendar-date-until': [FAIL],
|
||||
'temporal/calendar-month-day-from-fields': [FAIL],
|
||||
'temporal/calendar-week-of-year': [FAIL],
|
||||
'temporal/calendar-year-month-from-fields': [FAIL],
|
||||
'temporal/duration-add': [FAIL],
|
||||
|
@ -1155,9 +1155,6 @@
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/equals/calendars': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/equals/calendar-temporal-object': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/equals/infinity-throws-rangeerror': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/toJSON/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/toJSON/calendarname': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/toJSON/year-format': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/toLocaleString/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/argument-not-object': [FAIL],
|
||||
'built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/branding': [FAIL],
|
||||
|
Loading…
Reference in New Issue
Block a user