Commit afe71f39 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Add Temporal.PlainDate.from

Bug: v8:11544
Change-Id: I781119561db5ec05b12b9bca31c98403355e35ac
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3378882Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79396}
parent e7b7a3df
......@@ -1661,6 +1661,7 @@ namespace internal {
CPP(TemporalCalendarPrototypeToJSON) \
\
/* "Private" (created but not exposed) Bulitins needed by Temporal */ \
TFJ(StringFixedArrayFromIterable, kJSArgcReceiverSlots, kIterable) \
TFJ(TemporalInstantFixedArrayFromIterable, kJSArgcReceiverSlots, kIterable)
#define BUILTIN_LIST_BASE(CPP, TFJ, TFC, TFS, TFH, ASM) \
......
......@@ -218,7 +218,7 @@ TF_BUILTIN(IterableToFixedArrayForWasm, IteratorBuiltinsAssembler) {
}
#endif // V8_ENABLE_WEBASSEMBLY
TNode<JSArray> IteratorBuiltinsAssembler::StringListFromIterable(
TNode<FixedArray> IteratorBuiltinsAssembler::StringListFromIterable(
TNode<Context> context, TNode<Object> iterable) {
Label done(this);
GrowableFixedArray list(state());
......@@ -279,7 +279,7 @@ TNode<JSArray> IteratorBuiltinsAssembler::StringListFromIterable(
BIND(&done);
// 6. Return list.
return list.ToJSArray(context);
return list.ToFixedArray();
}
TF_BUILTIN(StringListFromIterable, IteratorBuiltinsAssembler) {
......@@ -289,6 +289,13 @@ TF_BUILTIN(StringListFromIterable, IteratorBuiltinsAssembler) {
Return(StringListFromIterable(context, iterable));
}
TF_BUILTIN(StringFixedArrayFromIterable, IteratorBuiltinsAssembler) {
auto context = Parameter<Context>(Descriptor::kContext);
auto iterable = Parameter<Object>(Descriptor::kIterable);
Return(StringListFromIterable(context, iterable));
}
// This builtin always returns a new JSArray and is thus safe to use even in the
// presence of code that may call back into user-JS. This builtin will take the
// fast path if the iterable is a fast array and the Array prototype and the
......
......@@ -67,8 +67,8 @@ class IteratorBuiltinsAssembler : public CodeStubAssembler {
// Currently at https://tc39.github.io/proposal-intl-list-format/
// #sec-createstringlistfromiterable
TNode<JSArray> StringListFromIterable(TNode<Context> context,
TNode<Object> iterable);
TNode<FixedArray> StringListFromIterable(TNode<Context> context,
TNode<Object> iterable);
void FastIterableToList(TNode<Context> context, TNode<Object> iterable,
TVariable<JSArray>* var_result, Label* slow);
......
......@@ -38,8 +38,6 @@ namespace internal {
JSTemporal##T::NowISO(isolate, args.atOrUndefined(isolate, 1))); \
}
/* Temporal #sec-temporal.plaindate.from */
TO_BE_IMPLEMENTED(TemporalPlainDateFrom)
/* Temporal #sec-temporal.plaindate.compare */
TO_BE_IMPLEMENTED(TemporalPlainDateCompare)
/* Temporal #sec-temporal.plaindate.prototype.toplainyearmonth */
......@@ -454,6 +452,15 @@ TO_BE_IMPLEMENTED(TemporalZonedDateTimePrototypeToLocaleString)
args.atOrUndefined(isolate, 3))); \
}
#define TEMPORAL_METHOD2(T, METHOD) \
BUILTIN(Temporal##T##METHOD) { \
HandleScope scope(isolate); \
RETURN_RESULT_OR_FAILURE( \
isolate, \
JSTemporal##T ::METHOD(isolate, args.atOrUndefined(isolate, 1), \
args.atOrUndefined(isolate, 2))); \
}
#define TEMPORAL_VALUE_OF(T) \
BUILTIN(Temporal##T##PrototypeValueOf) { \
HandleScope scope(isolate); \
......@@ -561,6 +568,7 @@ BUILTIN(TemporalPlainDateConstructor) {
args.atOrUndefined(isolate, 3), // iso_day
args.atOrUndefined(isolate, 4))); // calendar_like
}
TEMPORAL_METHOD2(PlainDate, From)
TEMPORAL_GET(PlainDate, Calendar, calendar)
TEMPORAL_GET_BY_FORWARD_CALENDAR(PlainDate, Year, year)
TEMPORAL_GET_BY_FORWARD_CALENDAR(PlainDate, Month, month)
......
......@@ -5298,6 +5298,15 @@ void Genesis::InitializeGlobal_harmony_temporal() {
#undef INSTALL_TEMPORAL_CTOR_AND_PROTOTYPE
#undef INSTALL_TEMPORAL_FUNC
// The StringListFromIterable functions is created but not
// exposed, as it is used internally by CalendarFields.
{
Handle<JSFunction> func = SimpleCreateFunction(
isolate_,
factory()->InternalizeUtf8String("StringFixedArrayFromIterable"),
Builtin::kStringFixedArrayFromIterable, 1, false);
native_context()->set_string_fixed_array_from_iterable(*func);
}
// The TemporalInsantFixedArrayFromIterable functions is created but not
// exposed, as it is used internally by GetPossibleInstantsFor.
{
......
......@@ -31,8 +31,6 @@
V(_, direction_string, "direction") \
V(_, endRange_string, "endRange") \
V(_, engineering_string, "engineering") \
V(_, era_string, "era") \
V(_, eraYear_string, "eraYear") \
V(_, exceptZero_string, "exceptZero") \
V(_, expand_string, "expand") \
V(_, exponentInteger_string, "exponentInteger") \
......@@ -228,6 +226,8 @@
V(_, epochMilliseconds_string, "epochMilliseconds") \
V(_, epochNanoseconds_string, "epochNanoseconds") \
V(_, epochSeconds_string, "epochSeconds") \
V(_, era_string, "era") \
V(_, eraYear_string, "eraYear") \
V(_, errors_string, "errors") \
V(_, error_to_string, "[object Error]") \
V(_, eval_string, "eval") \
......
......@@ -210,6 +210,8 @@ enum ContextLookupFlags {
temporal_zoned_date_time_function) \
V(TEMPORAL_INSTANT_FIXED_ARRAY_FROM_ITERABLE_FUNCTION_INDEX, JSFunction, \
temporal_instant_fixed_array_from_iterable) \
V(STRING_FIXED_ARRAY_FROM_ITERABLE_FUNCTION_INDEX, JSFunction, \
string_fixed_array_from_iterable) \
/* Context maps */ \
V(NATIVE_CONTEXT_MAP_INDEX, Map, native_context_map) \
V(FUNCTION_CONTEXT_MAP_INDEX, Map, function_context_map) \
......
......@@ -197,19 +197,13 @@ Handle<String> JSListFormat::TypeAsString() const {
namespace {
// Extract String from JSArray into array of UnicodeString
// Extract String from FixedArray into array of UnicodeString
Maybe<std::vector<icu::UnicodeString>> ToUnicodeStringArray(
Isolate* isolate, Handle<JSArray> array) {
// Thanks to iterable-to-list preprocessing, we never see dictionary-mode
// arrays here, so the loop below can construct an entry from the index.
DCHECK(array->HasFastElements(isolate));
auto* accessor = array->GetElementsAccessor();
size_t length = accessor->NumberOfElements(*array);
Isolate* isolate, Handle<FixedArray> array) {
int length = array->length();
std::vector<icu::UnicodeString> result;
for (InternalIndex entry : InternalIndex::Range(length)) {
DCHECK(accessor->HasEntry(*array, entry));
Handle<Object> item = accessor->Get(array, entry);
for (int i = 0; i < length; i++) {
Handle<Object> item = FixedArray::get(*array, i, isolate);
DCHECK(item->IsString());
Handle<String> item_str = Handle<String>::cast(item);
if (!item_str->IsFlat()) item_str = String::Flatten(isolate, item_str);
......@@ -220,7 +214,7 @@ Maybe<std::vector<icu::UnicodeString>> ToUnicodeStringArray(
template <typename T>
MaybeHandle<T> FormatListCommon(
Isolate* isolate, Handle<JSListFormat> format, Handle<JSArray> list,
Isolate* isolate, Handle<JSListFormat> format, Handle<FixedArray> list,
const std::function<MaybeHandle<T>(Isolate*, const icu::FormattedValue&)>&
formatToResult) {
DCHECK(!list->IsUndefined());
......@@ -283,14 +277,14 @@ MaybeHandle<JSArray> FormattedListToJSArray(
// ecma402 #sec-formatlist
MaybeHandle<String> JSListFormat::FormatList(Isolate* isolate,
Handle<JSListFormat> format,
Handle<JSArray> list) {
Handle<FixedArray> list) {
return FormatListCommon<String>(isolate, format, list,
Intl::FormattedToString);
}
// ecma42 #sec-formatlisttoparts
MaybeHandle<JSArray> JSListFormat::FormatListToParts(
Isolate* isolate, Handle<JSListFormat> format, Handle<JSArray> list) {
Isolate* isolate, Handle<JSListFormat> format, Handle<FixedArray> list) {
return FormatListCommon<JSArray>(isolate, format, list,
FormattedListToJSArray);
}
......
......@@ -46,12 +46,12 @@ class JSListFormat
// ecma402 #sec-formatlist
V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatList(
Isolate* isolate, Handle<JSListFormat> format_holder,
Handle<JSArray> list);
Handle<FixedArray> list);
// ecma42 #sec-formatlisttoparts
V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> FormatListToParts(
Isolate* isolate, Handle<JSListFormat> format_holder,
Handle<JSArray> list);
Handle<FixedArray> list);
V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
......
This diff is collapsed.
......@@ -123,6 +123,10 @@ class JSTemporalPlainDate
Isolate* isolate, Handle<JSTemporalPlainDate> plain_date,
Handle<Object> calendar_like);
// #sec-temporal.plaindate.from
V8_WARN_UNUSED_RESULT static MaybeHandle<JSTemporalPlainDate> From(
Isolate* isolate, Handle<Object> item, Handle<Object> options);
// #sec-temporal.plaindate.prototype.getisofields
V8_WARN_UNUSED_RESULT static MaybeHandle<JSReceiver> GetISOFields(
Isolate* isolate, Handle<JSTemporalPlainDate> plain_date);
......
......@@ -37,7 +37,7 @@ RUNTIME_FUNCTION(Runtime_FormatList) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSListFormat, list_format, 0);
CONVERT_ARG_HANDLE_CHECKED(JSArray, list, 1);
CONVERT_ARG_HANDLE_CHECKED(FixedArray, list, 1);
RETURN_RESULT_OR_FAILURE(
isolate, JSListFormat::FormatList(isolate, list_format, list));
}
......@@ -47,7 +47,7 @@ RUNTIME_FUNCTION(Runtime_FormatListToParts) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSListFormat, list_format, 0);
CONVERT_ARG_HANDLE_CHECKED(JSArray, list, 1);
CONVERT_ARG_HANDLE_CHECKED(FixedArray, list, 1);
RETURN_RESULT_OR_FAILURE(
isolate, JSListFormat::FormatListToParts(isolate, list_format, list));
}
......
......@@ -986,17 +986,10 @@
'built-ins/Temporal/PlainDate/from/argument-plaindate': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-plaindatetime': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-string': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-string-invalid': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-string-with-utc-designator': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/from/calendar-fields-iterable': [FAIL],
'built-ins/Temporal/PlainDate/from/calendar-temporal-object': [FAIL],
'built-ins/Temporal/PlainDate/from/infinity-throws-rangeerror': [FAIL],
'built-ins/Temporal/PlainDate/from/limits': [FAIL],
'built-ins/Temporal/PlainDate/from/options-invalid': [FAIL],
'built-ins/Temporal/PlainDate/from/options-undefined': [FAIL],
'built-ins/Temporal/PlainDate/from/order-of-operations': [FAIL],
'built-ins/Temporal/PlainDate/from/overflow-invalid-string': [FAIL],
......@@ -1175,7 +1168,6 @@
'built-ins/Temporal/PlainDate/prototype/until/smallestunit-undefined': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/smallestunit-wrong-type': [FAIL],
'built-ins/Temporal/PlainDate/prototype/until/weeks-months': [FAIL],
'built-ins/Temporal/PlainDate/prototype/valueOf/basic': [FAIL],
'built-ins/Temporal/PlainDate/prototype/weekOfYear/basic': [FAIL],
'built-ins/Temporal/PlainDate/prototype/with/basic': [FAIL],
'built-ins/Temporal/PlainDate/prototype/with/branding': [FAIL],
......@@ -2492,7 +2484,6 @@
'built-ins/Temporal/PlainDate/from/argument-object-invalid': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-object-valid': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-string-overflow': [FAIL],
'built-ins/Temporal/PlainDate/from/argument-string-trailing-junk': [FAIL],
'built-ins/Temporal/PlainDate/from/year-zero': [FAIL],
'built-ins/Temporal/PlainDate/prototype/add/argument-invalid-duration': [FAIL],
'built-ins/Temporal/PlainDate/prototype/add/argument-missing-properties': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment