[Temporal] Add toJSON and non-intl version ot toLocaleString to PlainDateTime
Implement AO: TemporalDateTimeToString Spec Text: https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.tojson https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype.tolocalestring https://tc39.es/proposal-temporal/#sec-temporal-temporaldatetimetostring Bug: v8:11544 Change-Id: I170fa13822d87cfd668bd4cd8df50476f00c86f8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3672001 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#80793}
This commit is contained in:
parent
8ea33c9f54
commit
c61c73ad0d
@ -70,12 +70,8 @@ TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeUntil)
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeSince)
|
||||
/* Temporal #sec-temporal.plaindatetime.prototype.round */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeRound)
|
||||
/* Temporal #sec-temporal.plaindatetime.prototype.tolocalestring */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeToLocaleString)
|
||||
/* Temporal #sec-temporal.plaindatetime.prototype.tostring */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeToString)
|
||||
/* Temporal #sec-temporal.plainddatetimeprototype.tojson */
|
||||
TO_BE_IMPLEMENTED(TemporalPlainDateTimePrototypeToJSON)
|
||||
|
||||
/* Temporal.ZonedDateTime */
|
||||
/* Temporal #sec-temporal.zoneddatetime.from */
|
||||
@ -458,6 +454,8 @@ TEMPORAL_PROTOTYPE_METHOD2(PlainDateTime, With, with)
|
||||
TEMPORAL_VALUE_OF(PlainDateTime)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainDateTime, ToPlainDate, toPlainDate)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainDateTime, ToPlainTime, toPlainTime)
|
||||
TEMPORAL_PROTOTYPE_METHOD0(PlainDateTime, ToJSON, toJSON)
|
||||
TEMPORAL_PROTOTYPE_METHOD2(PlainDateTime, ToLocaleString, toLocaleString)
|
||||
|
||||
// PlainYearMonth
|
||||
BUILTIN(TemporalPlainYearMonthConstructor) {
|
||||
|
@ -9190,6 +9190,83 @@ MaybeHandle<JSTemporalPlainDateTime> JSTemporalPlainDateTime::WithPlainDate(
|
||||
calendar);
|
||||
}
|
||||
|
||||
namespace {
|
||||
MaybeHandle<String> TemporalDateTimeToString(
|
||||
Isolate* isolate, const DateTimeRecordCommon& date_time,
|
||||
Handle<JSReceiver> calendar, Precision precision,
|
||||
ShowCalendar show_calendar) {
|
||||
IncrementalStringBuilder builder(isolate);
|
||||
// 1. Assert: isoYear, isoMonth, isoDay, hour, minute, second, millisecond,
|
||||
// microsecond, and nanosecond are integers.
|
||||
// 2. Let year be ! PadISOYear(isoYear).
|
||||
PadISOYear(&builder, date_time.date.year);
|
||||
|
||||
// 3. Let month be ToZeroPaddedDecimalString(isoMonth, 2).
|
||||
builder.AppendCharacter('-');
|
||||
ToZeroPaddedDecimalString(&builder, date_time.date.month, 2);
|
||||
|
||||
// 4. Let day be ToZeroPaddedDecimalString(isoDay, 2).
|
||||
builder.AppendCharacter('-');
|
||||
ToZeroPaddedDecimalString(&builder, date_time.date.day, 2);
|
||||
// 5. Let hour be ToZeroPaddedDecimalString(hour, 2).
|
||||
builder.AppendCharacter('T');
|
||||
ToZeroPaddedDecimalString(&builder, date_time.time.hour, 2);
|
||||
|
||||
// 6. Let minute be ToZeroPaddedDecimalString(minute, 2).
|
||||
builder.AppendCharacter(':');
|
||||
ToZeroPaddedDecimalString(&builder, date_time.time.minute, 2);
|
||||
|
||||
// 7. Let seconds be ! FormatSecondsStringPart(second, millisecond,
|
||||
// microsecond, nanosecond, precision).
|
||||
FormatSecondsStringPart(
|
||||
&builder, date_time.time.second, date_time.time.millisecond,
|
||||
date_time.time.microsecond, date_time.time.nanosecond, precision);
|
||||
// 8. Let calendarID be ? ToString(calendar).
|
||||
Handle<String> calendar_id;
|
||||
ASSIGN_RETURN_ON_EXCEPTION(isolate, calendar_id,
|
||||
Object::ToString(isolate, calendar), String);
|
||||
|
||||
// 9. Let calendarString be ! FormatCalendarAnnotation(calendarID,
|
||||
// showCalendar).
|
||||
Handle<String> calendar_string =
|
||||
FormatCalendarAnnotation(isolate, calendar_id, show_calendar);
|
||||
|
||||
// 10. Return the string-concatenation of year, the code unit 0x002D
|
||||
// (HYPHEN-MINUS), month, the code unit 0x002D (HYPHEN-MINUS), day, 0x0054
|
||||
// (LATIN CAPITAL LETTER T), hour, the code unit 0x003A (COLON), minute,
|
||||
builder.AppendString(calendar_string);
|
||||
return builder.Finish().ToHandleChecked();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// #sec-temporal.plaindatetime.prototype.tojson
|
||||
MaybeHandle<String> JSTemporalPlainDateTime::ToJSON(
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time) {
|
||||
return TemporalDateTimeToString(
|
||||
isolate,
|
||||
{{date_time->iso_year(), date_time->iso_month(), date_time->iso_day()},
|
||||
{date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(),
|
||||
date_time->iso_millisecond(), date_time->iso_microsecond(),
|
||||
date_time->iso_nanosecond()}},
|
||||
Handle<JSReceiver>(date_time->calendar(), isolate), Precision::kAuto,
|
||||
ShowCalendar::kAuto);
|
||||
}
|
||||
|
||||
// #sec-temporal.plaindatetime.prototype.tolocalestring
|
||||
MaybeHandle<String> JSTemporalPlainDateTime::ToLocaleString(
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time,
|
||||
Handle<Object> locales, Handle<Object> options) {
|
||||
// TODO(ftang) Implement #sup-temporal.plaindatetime.prototype.tolocalestring
|
||||
return TemporalDateTimeToString(
|
||||
isolate,
|
||||
{{date_time->iso_year(), date_time->iso_month(), date_time->iso_day()},
|
||||
{date_time->iso_hour(), date_time->iso_minute(), date_time->iso_second(),
|
||||
date_time->iso_millisecond(), date_time->iso_microsecond(),
|
||||
date_time->iso_nanosecond()}},
|
||||
Handle<JSReceiver>(date_time->calendar(), isolate), Precision::kAuto,
|
||||
ShowCalendar::kAuto);
|
||||
}
|
||||
|
||||
// #sec-temporal.now.plaindatetime
|
||||
MaybeHandle<JSTemporalPlainDateTime> JSTemporalPlainDateTime::Now(
|
||||
Isolate* isolate, Handle<Object> calendar_like,
|
||||
|
@ -404,6 +404,15 @@ class JSTemporalPlainDateTime
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time,
|
||||
Handle<Object> temporal_date_time_like, Handle<Object> options);
|
||||
|
||||
// #sec-temporal.plaindatetime.prototype.tojson
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToJSON(
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time);
|
||||
|
||||
// #sec-temporal.plaindatetime.prototype.tolocalestring
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<String> ToLocaleString(
|
||||
Isolate* isolate, Handle<JSTemporalPlainDateTime> date_time,
|
||||
Handle<Object> locales, Handle<Object> options);
|
||||
|
||||
// #sec-temporal.now.plaindatetime
|
||||
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainDateTime> Now(
|
||||
Isolate* isolate, Handle<Object> calendar_like,
|
||||
|
@ -868,10 +868,6 @@
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/overflow-undefined': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/overflow-wrong-type': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/subtract/subclassing-ignored': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toJSON/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toJSON/year-format': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toLocaleString/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toLocaleString/return-string': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toPlainDate/limits': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toString/branding': [FAIL],
|
||||
'built-ins/Temporal/PlainDateTime/prototype/toString/calendarname-invalid-string': [FAIL],
|
||||
|
Loading…
Reference in New Issue
Block a user