diff --git a/BUILD.bazel b/BUILD.bazel index f4a21f2fb9..1c84b2fe49 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -981,7 +981,6 @@ filegroup( "src/objects/js-collator.tq", "src/objects/js-date-time-format.tq", "src/objects/js-display-names.tq", - "src/objects/js-duration-format.tq", "src/objects/js-list-format.tq", "src/objects/js-locale.tq", "src/objects/js-number-format.tq", @@ -2606,9 +2605,6 @@ filegroup( "src/objects/js-display-names.cc", "src/objects/js-display-names.h", "src/objects/js-display-names-inl.h", - "src/objects/js-duration-format.cc", - "src/objects/js-duration-format.h", - "src/objects/js-duration-format-inl.h", "src/objects/js-list-format.cc", "src/objects/js-list-format.h", "src/objects/js-list-format-inl.h", diff --git a/BUILD.gn b/BUILD.gn index ec4f80daee..2c228ee628 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1856,7 +1856,6 @@ if (v8_enable_i18n_support) { "src/objects/js-collator.tq", "src/objects/js-date-time-format.tq", "src/objects/js-display-names.tq", - "src/objects/js-duration-format.tq", "src/objects/js-list-format.tq", "src/objects/js-locale.tq", "src/objects/js-number-format.tq", @@ -3670,8 +3669,6 @@ v8_header_set("v8_internal_headers") { "src/objects/js-date-time-format.h", "src/objects/js-display-names-inl.h", "src/objects/js-display-names.h", - "src/objects/js-duration-format-inl.h", - "src/objects/js-duration-format.h", "src/objects/js-list-format-inl.h", "src/objects/js-list-format.h", "src/objects/js-locale-inl.h", @@ -4533,7 +4530,6 @@ v8_source_set("v8_base_without_compiler") { "src/objects/js-collator.cc", "src/objects/js-date-time-format.cc", "src/objects/js-display-names.cc", - "src/objects/js-duration-format.cc", "src/objects/js-function.cc", "src/objects/js-list-format.cc", "src/objects/js-locale.cc", @@ -5122,7 +5118,6 @@ v8_source_set("v8_base_without_compiler") { "src/objects/js-collator.cc", "src/objects/js-date-time-format.cc", "src/objects/js-display-names.cc", - "src/objects/js-duration-format.cc", "src/objects/js-list-format.cc", "src/objects/js-locale.cc", "src/objects/js-number-format.cc", diff --git a/include/v8-isolate.h b/include/v8-isolate.h index 2f8acc8868..4f31d8c7a8 100644 --- a/include/v8-isolate.h +++ b/include/v8-isolate.h @@ -536,7 +536,6 @@ class V8_EXPORT Isolate { kFunctionPrototypeCaller = 114, kTurboFanOsrCompileStarted = 115, kAsyncStackTaggingCreateTaskCall = 116, - kDurationFormat = 117, // If you add new values here, you'll also need to update Chromium's: // web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to diff --git a/src/builtins/builtins-definitions.h b/src/builtins/builtins-definitions.h index 99a3c35c45..175acbd495 100644 --- a/src/builtins/builtins-definitions.h +++ b/src/builtins/builtins-definitions.h @@ -1750,16 +1750,6 @@ namespace internal { CPP(DisplayNamesPrototypeResolvedOptions) \ /* ecma402 #sec-Intl.DisplayNames.supportedLocalesOf */ \ CPP(DisplayNamesSupportedLocalesOf) \ - /* ecma402 #sec-intl-durationformat-constructor */ \ - CPP(DurationFormatConstructor) \ - /* ecma402 #sec-Intl.DurationFormat.prototype.format */ \ - CPP(DurationFormatPrototypeFormat) \ - /* ecma402 #sec-Intl.DurationFormat.prototype.formatToParts */ \ - CPP(DurationFormatPrototypeFormatToParts) \ - /* ecma402 #sec-Intl.DurationFormat.prototype.resolvedOptions */ \ - CPP(DurationFormatPrototypeResolvedOptions) \ - /* ecma402 #sec-Intl.DurationFormat.supportedLocalesOf */ \ - CPP(DurationFormatSupportedLocalesOf) \ /* ecma402 #sec-intl.getcanonicallocales */ \ CPP(IntlGetCanonicalLocales) \ /* ecma402 #sec-intl.supportedvaluesof */ \ diff --git a/src/builtins/builtins-intl.cc b/src/builtins/builtins-intl.cc index 0410c3ef91..452e551207 100644 --- a/src/builtins/builtins-intl.cc +++ b/src/builtins/builtins-intl.cc @@ -21,7 +21,6 @@ #include "src/objects/js-collator-inl.h" #include "src/objects/js-date-time-format-inl.h" #include "src/objects/js-display-names-inl.h" -#include "src/objects/js-duration-format-inl.h" #include "src/objects/js-list-format-inl.h" #include "src/objects/js-locale-inl.h" #include "src/objects/js-number-format-inl.h" @@ -384,51 +383,6 @@ BUILTIN(DisplayNamesPrototypeOf) { JSDisplayNames::Of(isolate, holder, code_obj)); } -// Intl.DurationFormat -BUILTIN(DurationFormatConstructor) { - HandleScope scope(isolate); - - return DisallowCallConstructor( - args, isolate, v8::Isolate::UseCounterFeature::kDurationFormat, - "Intl.DurationFormat"); -} - -BUILTIN(DurationFormatPrototypeResolvedOptions) { - HandleScope scope(isolate); - CHECK_RECEIVER(JSDurationFormat, holder, - "Intl.DurationFormat.prototype.resolvedOptions"); - return *JSDurationFormat::ResolvedOptions(isolate, holder); -} - -BUILTIN(DurationFormatSupportedLocalesOf) { - HandleScope scope(isolate); - Handle locales = args.atOrUndefined(isolate, 1); - Handle options = args.atOrUndefined(isolate, 2); - - RETURN_RESULT_OR_FAILURE( - isolate, Intl::SupportedLocalesOf( - isolate, "Intl.DurationFormat.supportedLocalesOf", - JSDurationFormat::GetAvailableLocales(), locales, options)); -} - -BUILTIN(DurationFormatPrototypeFormat) { - HandleScope scope(isolate); - CHECK_RECEIVER(JSDurationFormat, holder, - "Intl.DurationFormat.prototype.format"); - Handle value = args.atOrUndefined(isolate, 1); - RETURN_RESULT_OR_FAILURE(isolate, - JSDurationFormat::Format(isolate, holder, value)); -} - -BUILTIN(DurationFormatPrototypeFormatToParts) { - HandleScope scope(isolate); - CHECK_RECEIVER(JSDurationFormat, holder, - "Intl.DurationFormat.prototype.formatToParts"); - Handle value = args.atOrUndefined(isolate, 1); - RETURN_RESULT_OR_FAILURE( - isolate, JSDurationFormat::FormatToParts(isolate, holder, value)); -} - // Intl.NumberFormat BUILTIN(NumberFormatConstructor) { diff --git a/src/compiler/code-assembler.h b/src/compiler/code-assembler.h index 36a73dc37f..3c4a392616 100644 --- a/src/compiler/code-assembler.h +++ b/src/compiler/code-assembler.h @@ -47,7 +47,6 @@ class JSCollator; class JSCollection; class JSDateTimeFormat; class JSDisplayNames; -class JSDurationFormat; class JSListFormat; class JSLocale; class JSNumberFormat; diff --git a/src/compiler/types.cc b/src/compiler/types.cc index b8fcd6b2b7..004495a286 100644 --- a/src/compiler/types.cc +++ b/src/compiler/types.cc @@ -227,7 +227,6 @@ Type::bitset BitsetType::Lub(const MapRefLike& map) { case JS_COLLATOR_TYPE: case JS_DATE_TIME_FORMAT_TYPE: case JS_DISPLAY_NAMES_TYPE: - case JS_DURATION_FORMAT_TYPE: case JS_LIST_FORMAT_TYPE: case JS_LOCALE_TYPE: case JS_NUMBER_FORMAT_TYPE: diff --git a/src/diagnostics/objects-debug.cc b/src/diagnostics/objects-debug.cc index 0f91a0fc81..441b2b08e9 100644 --- a/src/diagnostics/objects-debug.cc +++ b/src/diagnostics/objects-debug.cc @@ -46,7 +46,6 @@ #ifdef V8_INTL_SUPPORT #include "src/objects/js-date-time-format-inl.h" #include "src/objects/js-display-names-inl.h" -#include "src/objects/js-duration-format-inl.h" #endif // V8_INTL_SUPPORT #include "src/objects/js-generator-inl.h" #ifdef V8_INTL_SUPPORT diff --git a/src/diagnostics/objects-printer.cc b/src/diagnostics/objects-printer.cc index 87b501fd1d..e2ebabde3a 100644 --- a/src/diagnostics/objects-printer.cc +++ b/src/diagnostics/objects-printer.cc @@ -2452,15 +2452,6 @@ void JSDisplayNames::JSDisplayNamesPrint(std::ostream& os) { JSObjectPrintBody(os, *this); } -void JSDurationFormat::JSDurationFormatPrint(std::ostream& os) { - JSObjectPrintHeader(os, *this, "JSDurationFormat"); - os << "\n - style_flags: " << style_flags(); - os << "\n - display_flags: " << display_flags(); - os << "\n - icu locale: " << Brief(icu_locale()); - os << "\n - icu number formatter: " << Brief(icu_number_formatter()); - JSObjectPrintBody(os, *this); -} - void JSListFormat::JSListFormatPrint(std::ostream& os) { JSObjectPrintHeader(os, *this, "JSListFormat"); os << "\n - locale: " << Brief(locale()); diff --git a/src/flags/flag-definitions.h b/src/flags/flag-definitions.h index 84c3570153..32cf3e4c13 100644 --- a/src/flags/flag-definitions.h +++ b/src/flags/flag-definitions.h @@ -231,10 +231,9 @@ DEFINE_BOOL(harmony_shipping, true, "enable all shipped harmony features") V(harmony_regexp_unicode_sets, "harmony RegExp Unicode Sets") #ifdef V8_INTL_SUPPORT -#define HARMONY_INPROGRESS(V) \ - HARMONY_INPROGRESS_BASE(V) \ - V(harmony_intl_best_fit_matcher, "Intl BestFitMatcher") \ - V(harmony_intl_duration_format, "Intl DurationFormat API") +#define HARMONY_INPROGRESS(V) \ + HARMONY_INPROGRESS_BASE(V) \ + V(harmony_intl_best_fit_matcher, "Intl BestFitMatcher") #else #define HARMONY_INPROGRESS(V) HARMONY_INPROGRESS_BASE(V) #endif diff --git a/src/init/bootstrapper.cc b/src/init/bootstrapper.cc index 732c6a632c..6dc7f88a6d 100644 --- a/src/init/bootstrapper.cc +++ b/src/init/bootstrapper.cc @@ -47,7 +47,6 @@ #include "src/objects/js-collator.h" #include "src/objects/js-date-time-format.h" #include "src/objects/js-display-names.h" -#include "src/objects/js-duration-format.h" #include "src/objects/js-list-format.h" #include "src/objects/js-locale.h" #include "src/objects/js-number-format.h" @@ -5555,46 +5554,6 @@ void Genesis::InitializeGlobal_experimental_web_snapshots() { Builtin::kWebSnapshotDeserialize, 2, false); } -#ifdef V8_INTL_SUPPORT -void Genesis::InitializeGlobal_harmony_intl_duration_format() { - if (!FLAG_harmony_intl_duration_format) return; - Handle intl = Handle::cast( - JSReceiver::GetProperty( - isolate(), - Handle(native_context()->global_object(), isolate()), - factory()->InternalizeUtf8String("Intl")) - .ToHandleChecked()); - - Handle duration_format_fun = InstallFunction( - isolate(), intl, "DurationFormat", JS_DURATION_FORMAT_TYPE, - JSDurationFormat::kHeaderSize, 0, factory()->the_hole_value(), - Builtin::kDurationFormatConstructor); - duration_format_fun->shared().set_length(0); - duration_format_fun->shared().DontAdaptArguments(); - InstallWithIntrinsicDefaultProto( - isolate(), duration_format_fun, - Context::INTL_DURATION_FORMAT_FUNCTION_INDEX); - - SimpleInstallFunction(isolate(), duration_format_fun, "supportedLocalesOf", - Builtin::kDurationFormatSupportedLocalesOf, 1, false); - - Handle prototype( - JSObject::cast(duration_format_fun->instance_prototype()), isolate()); - - InstallToStringTag(isolate(), prototype, "Intl.DurationFormat"); - - SimpleInstallFunction(isolate(), prototype, "resolvedOptions", - Builtin::kDurationFormatPrototypeResolvedOptions, 0, - false); - - SimpleInstallFunction(isolate(), prototype, "format", - Builtin::kDurationFormatPrototypeFormat, 1, false); - SimpleInstallFunction(isolate(), prototype, "formatToParts", - Builtin::kDurationFormatPrototypeFormatToParts, 1, - false); -} -#endif // V8_INTL_SUPPORT - Handle Genesis::CreateArrayBuffer( Handle name, ArrayBufferKind array_buffer_kind) { // Create the %ArrayBufferPrototype% diff --git a/src/init/heap-symbols.h b/src/init/heap-symbols.h index 89039d0f75..38c0c7d722 100644 --- a/src/init/heap-symbols.h +++ b/src/init/heap-symbols.h @@ -27,10 +27,8 @@ V(_, dateStyle_string, "dateStyle") \ V(_, dateTimeField_string, "dateTimeField") \ V(_, dayPeriod_string, "dayPeriod") \ - V(_, daysDisplay_string, "daysDisplay") \ V(_, decimal_string, "decimal") \ V(_, dialect_string, "dialect") \ - V(_, digital_string, "digital") \ V(_, direction_string, "direction") \ V(_, endRange_string, "endRange") \ V(_, engineering_string, "engineering") \ @@ -45,7 +43,6 @@ V(_, floor_string, "floor") \ V(_, format_string, "format") \ V(_, fraction_string, "fraction") \ - V(_, fractionalDigits_string, "fractionalDigits") \ V(_, fractionalSecond_string, "fractionalSecond") \ V(_, full_string, "full") \ V(_, granularity_string, "granularity") \ @@ -63,7 +60,6 @@ V(_, hour12_string, "hour12") \ V(_, hourCycle_string, "hourCycle") \ V(_, hourCycles_string, "hourCycles") \ - V(_, hoursDisplay_string, "hoursDisplay") \ V(_, ideo_string, "ideo") \ V(_, ignorePunctuation_string, "ignorePunctuation") \ V(_, Invalid_Date_string, "Invalid Date") \ @@ -82,8 +78,6 @@ V(_, ltr_string, "ltr") \ V(_, maximumFractionDigits_string, "maximumFractionDigits") \ V(_, maximumSignificantDigits_string, "maximumSignificantDigits") \ - V(_, microsecondsDisplay_string, "microsecondsDisplay") \ - V(_, millisecondsDisplay_string, "millisecondsDisplay") \ V(_, min2_string, "min2") \ V(_, minimalDays_string, "minimalDays") \ V(_, minimumFractionDigits_string, "minimumFractionDigits") \ @@ -91,11 +85,8 @@ V(_, minimumSignificantDigits_string, "minimumSignificantDigits") \ V(_, minus_0, "-0") \ V(_, minusSign_string, "minusSign") \ - V(_, minutesDisplay_string, "minutesDisplay") \ - V(_, monthsDisplay_string, "monthsDisplay") \ V(_, morePrecision_string, "morePrecision") \ V(_, nan_string, "nan") \ - V(_, nanosecondsDisplay_string, "nanosecondsDisplay") \ V(_, narrowSymbol_string, "narrowSymbol") \ V(_, negative_string, "negative") \ V(_, never_string, "never") \ @@ -115,7 +106,6 @@ V(_, roundingPriority_string, "roundingPriority") \ V(_, rtl_string, "rtl") \ V(_, scientific_string, "scientific") \ - V(_, secondsDisplay_string, "secondsDisplay") \ V(_, segment_string, "segment") \ V(_, SegmentIterator_string, "Segment Iterator") \ V(_, Segments_string, "Segments") \ @@ -135,7 +125,6 @@ V(_, timeZoneName_string, "timeZoneName") \ V(_, trailingZeroDisplay_string, "trailingZeroDisplay") \ V(_, trunc_string, "trunc") \ - V(_, two_digit_string, "2-digit") \ V(_, type_string, "type") \ V(_, unknown_string, "unknown") \ V(_, upper_string, "upper") \ @@ -144,10 +133,8 @@ V(_, unitDisplay_string, "unitDisplay") \ V(_, weekday_string, "weekday") \ V(_, weekend_string, "weekend") \ - V(_, weeksDisplay_string, "weeksDisplay") \ V(_, weekInfo_string, "weekInfo") \ - V(_, yearName_string, "yearName") \ - V(_, yearsDisplay_string, "yearsDisplay") + V(_, yearName_string, "yearName") #else // V8_INTL_SUPPORT #define INTERNALIZED_STRING_LIST_GENERATOR_INTL(V, _) #endif // V8_INTL_SUPPORT diff --git a/src/objects/all-objects-inl.h b/src/objects/all-objects-inl.h index 3b513bba32..568f731f0c 100644 --- a/src/objects/all-objects-inl.h +++ b/src/objects/all-objects-inl.h @@ -97,7 +97,6 @@ #include "src/objects/js-collator-inl.h" #include "src/objects/js-date-time-format-inl.h" #include "src/objects/js-display-names-inl.h" -#include "src/objects/js-duration-format-inl.h" #include "src/objects/js-list-format-inl.h" #include "src/objects/js-locale-inl.h" #include "src/objects/js-number-format-inl.h" diff --git a/src/objects/contexts.h b/src/objects/contexts.h index d1deebadba..cd9196f0d7 100644 --- a/src/objects/contexts.h +++ b/src/objects/contexts.h @@ -157,8 +157,6 @@ enum ContextLookupFlags { intl_date_time_format_function) \ V(INTL_DISPLAY_NAMES_FUNCTION_INDEX, JSFunction, \ intl_display_names_function) \ - V(INTL_DURATION_FORMAT_FUNCTION_INDEX, JSFunction, \ - intl_duration_format_function) \ V(INTL_NUMBER_FORMAT_FUNCTION_INDEX, JSFunction, \ intl_number_format_function) \ V(INTL_LOCALE_FUNCTION_INDEX, JSFunction, intl_locale_function) \ diff --git a/src/objects/js-duration-format-inl.h b/src/objects/js-duration-format-inl.h deleted file mode 100644 index 024e1ed7b2..0000000000 --- a/src/objects/js-duration-format-inl.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2022 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef V8_INTL_SUPPORT -#error Internationalization is expected to be enabled. -#endif // V8_INTL_SUPPORT - -#ifndef V8_OBJECTS_JS_DURATION_FORMAT_INL_H_ -#define V8_OBJECTS_JS_DURATION_FORMAT_INL_H_ - -#include "src/objects/js-duration-format.h" -#include "src/objects/objects-inl.h" - -// Has to be the last include (doesn't have include guards): -#include "src/objects/object-macros.h" - -namespace v8 { -namespace internal { - -#include "torque-generated/src/objects/js-duration-format-tq-inl.inc" - -TQ_OBJECT_CONSTRUCTORS_IMPL(JSDurationFormat) - -ACCESSORS(JSDurationFormat, icu_locale, Managed, kIcuLocaleOffset) - -#define IMPL_INLINE_SETTER_GETTER(T, n, B, f, M) \ - inline void JSDurationFormat::set_##n(T value) { \ - DCHECK_GE(B::kMax, value); \ - DCHECK_GE(T::M, value); \ - set_##f(B::update(f(), value)); \ - } \ - inline JSDurationFormat::T JSDurationFormat::n() const { \ - return B::decode(f()); \ - } - -#define IMPL_INLINE_DISPLAY_SETTER_GETTER(f, R) \ - IMPL_INLINE_SETTER_GETTER(Display, f##_display, R##DisplayBit, \ - display_flags, kAlways) - -#define IMPL_INLINE_FIELD_STYLE3_SETTER_GETTER(f, R) \ - IMPL_INLINE_SETTER_GETTER(FieldStyle, f##_style, R##StyleBits, style_flags, \ - kNarrow) - -#define IMPL_INLINE_FIELD_STYLE4_SETTER_GETTER(f, R) \ - IMPL_INLINE_SETTER_GETTER(FieldStyle, f##_style, R##StyleBits, style_flags, \ - kNumeric) - -#define IMPL_INLINE_FIELD_STYLE5_SETTER_GETTER(f, R) \ - IMPL_INLINE_SETTER_GETTER(FieldStyle, f##_style, R##StyleBits, style_flags, \ - k2Digit) - -IMPL_INLINE_DISPLAY_SETTER_GETTER(years, Years) -IMPL_INLINE_DISPLAY_SETTER_GETTER(months, Months) -IMPL_INLINE_DISPLAY_SETTER_GETTER(weeks, Weeks) -IMPL_INLINE_DISPLAY_SETTER_GETTER(days, Days) -IMPL_INLINE_DISPLAY_SETTER_GETTER(hours, Hours) -IMPL_INLINE_DISPLAY_SETTER_GETTER(minutes, Minutes) -IMPL_INLINE_DISPLAY_SETTER_GETTER(seconds, Seconds) -IMPL_INLINE_DISPLAY_SETTER_GETTER(milliseconds, Milliseconds) -IMPL_INLINE_DISPLAY_SETTER_GETTER(microseconds, Microseconds) -IMPL_INLINE_DISPLAY_SETTER_GETTER(nanoseconds, Nanoseconds) - -IMPL_INLINE_SETTER_GETTER(Style, style, StyleBits, style_flags, kDigital) - -IMPL_INLINE_FIELD_STYLE3_SETTER_GETTER(years, Years) -IMPL_INLINE_FIELD_STYLE3_SETTER_GETTER(months, Months) -IMPL_INLINE_FIELD_STYLE3_SETTER_GETTER(weeks, Weeks) -IMPL_INLINE_FIELD_STYLE3_SETTER_GETTER(days, Days) -IMPL_INLINE_FIELD_STYLE5_SETTER_GETTER(hours, Hours) -IMPL_INLINE_FIELD_STYLE5_SETTER_GETTER(minutes, Minutes) -IMPL_INLINE_FIELD_STYLE5_SETTER_GETTER(seconds, Seconds) -IMPL_INLINE_FIELD_STYLE4_SETTER_GETTER(milliseconds, Milliseconds) -IMPL_INLINE_FIELD_STYLE4_SETTER_GETTER(microseconds, Microseconds) -IMPL_INLINE_FIELD_STYLE4_SETTER_GETTER(nanoseconds, Nanoseconds) - -#undef IMPL_INLINE_SETTER_GETTER -#undef IMPL_INLINE_DISPLAY_SETTER_GETTER -#undef IMPL_INLINE_FIELD_STYLE3_SETTER_GETTER -#undef IMPL_INLINE_FIELD_STYLE5_SETTER_GETTER - -inline void JSDurationFormat::set_fractional_digits(int32_t digits) { - DCHECK_GE(9, digits); - DCHECK_LE(0, digits); - int hints = display_flags(); - hints = FractionalDigitsBits::update(hints, digits); - set_display_flags(hints); -} -inline int32_t JSDurationFormat::fractional_digits() const { - int32_t v = FractionalDigitsBits::decode(display_flags()); - DCHECK_GE(9, v); - DCHECK_LE(0, v); - return v; -} - -ACCESSORS(JSDurationFormat, icu_number_formatter, - Managed, - kIcuNumberFormatterOffset) -} // namespace internal -} // namespace v8 - -#include "src/objects/object-macros-undef.h" - -#endif // V8_OBJECTS_JS_DURATION_FORMAT_INL_H_ diff --git a/src/objects/js-duration-format.cc b/src/objects/js-duration-format.cc deleted file mode 100644 index 12946f580e..0000000000 --- a/src/objects/js-duration-format.cc +++ /dev/null @@ -1,772 +0,0 @@ -// Copyright 2022 the V8 project authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef V8_INTL_SUPPORT -#error Internationalization is expected to be enabled. -#endif // V8_INTL_SUPPORT - -#include "src/objects/js-duration-format.h" - -#include -#include -#include -#include - -#include "src/execution/isolate.h" -#include "src/heap/factory.h" -#include "src/objects/intl-objects.h" -#include "src/objects/js-duration-format-inl.h" -#include "src/objects/js-number-format.h" -#include "src/objects/js-temporal-objects.h" -#include "src/objects/option-utils.h" -#include "unicode/listformatter.h" -#include "unicode/locid.h" -#include "unicode/numberformatter.h" -#include "unicode/ulistformatter.h" -#include "unicode/unumberformatter.h" - -namespace v8 { -namespace internal { - -using temporal::DurationRecord; - -namespace { - -// #sec-getdurationunitoptions -enum class StylesList { k3Styles, k4Styles, k5Styles }; -enum class UnitKind { kMinutesOrSeconds, kOthers }; -struct DurationUnitOptions { - JSDurationFormat::FieldStyle style; - JSDurationFormat::Display display; -}; -Maybe GetDurationUnitOptions( - Isolate* isolate, const char* unit, const char* display_field, - Handle options, JSDurationFormat::Style base_style, - StylesList styles_list, JSDurationFormat::FieldStyle prev_style, - UnitKind unit_kind, const char* method_name) { - JSDurationFormat::FieldStyle style; - JSDurationFormat::FieldStyle digital_base; - // 1. Let style be ? GetOption(options, unit, "string", stylesList, - // undefined). - switch (styles_list) { - case StylesList::k3Styles: - // For years, months, weeks, days - MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, style, - GetStringOption( - isolate, options, unit, method_name, {"long", "short", "narrow"}, - {JSDurationFormat::FieldStyle::kLong, - JSDurationFormat::FieldStyle::kShort, - JSDurationFormat::FieldStyle::kNarrow}, - JSDurationFormat::FieldStyle::kUndefined), - Nothing()); - digital_base = JSDurationFormat::FieldStyle::kShort; - break; - case StylesList::k4Styles: - // For milliseconds, microseconds, nanoseconds - MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, style, - GetStringOption( - isolate, options, unit, method_name, - {"long", "short", "narrow", "numeric"}, - {JSDurationFormat::FieldStyle::kLong, - JSDurationFormat::FieldStyle::kShort, - JSDurationFormat::FieldStyle::kNarrow, - JSDurationFormat::FieldStyle::kNumeric}, - JSDurationFormat::FieldStyle::kUndefined), - Nothing()); - digital_base = JSDurationFormat::FieldStyle::kNumeric; - break; - case StylesList::k5Styles: - // For hours, minutes, seconds - MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, style, - GetStringOption( - isolate, options, unit, method_name, - {"long", "short", "narrow", "numeric", "2-digit"}, - {JSDurationFormat::FieldStyle::kLong, - JSDurationFormat::FieldStyle::kShort, - JSDurationFormat::FieldStyle::kNarrow, - JSDurationFormat::FieldStyle::kNumeric, - JSDurationFormat::FieldStyle::k2Digit}, - JSDurationFormat::FieldStyle::kUndefined), - Nothing()); - digital_base = JSDurationFormat::FieldStyle::kNumeric; - break; - } - - // 2. Let displayDefault be "always". - JSDurationFormat::Display display_default = - JSDurationFormat::Display::kAlways; - // 3. If style is undefined, then - if (style == JSDurationFormat::FieldStyle::kUndefined) { - // a. If baseStyle is "digital", then - if (base_style == JSDurationFormat::Style::kDigital) { - // i. If unit is not one of "hours", "minutes", or "seconds", then - if (styles_list != StylesList::k5Styles) { - DCHECK_NE(0, strcmp(unit, "hours")); - DCHECK_NE(0, strcmp(unit, "minutes")); - DCHECK_NE(0, strcmp(unit, "seconds")); - // a. Set displayDefault to "auto". - display_default = JSDurationFormat::Display::kAuto; - } - // ii. Set style to digitalBase. - style = digital_base; - // b. Else - } else { - // i. Set displayDefault to "auto". - display_default = JSDurationFormat::Display::kAuto; - // ii. if prevStyle is "numeric" or "2-digit", then - if (prev_style == JSDurationFormat::FieldStyle::kNumeric || - prev_style == JSDurationFormat::FieldStyle::k2Digit) { - // 1. Set style to "numeric". - style = JSDurationFormat::FieldStyle::kNumeric; - // iii. Else, - } else { - // 1. Set style to baseStyle. - switch (base_style) { - case JSDurationFormat::Style::kLong: - style = JSDurationFormat::FieldStyle::kLong; - break; - case JSDurationFormat::Style::kShort: - style = JSDurationFormat::FieldStyle::kShort; - break; - case JSDurationFormat::Style::kNarrow: - style = JSDurationFormat::FieldStyle::kNarrow; - break; - default: - UNREACHABLE(); - } - } - } - } - // 4. Let displayField be the string-concatenation of unit and "Display". - // 5. Let display be ? GetOption(options, displayField, "string", « "auto", - // "always" », displayDefault). - JSDurationFormat::Display display; - MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, display, - GetStringOption( - isolate, options, display_field, method_name, {"auto", "always"}, - {JSDurationFormat::Display::kAuto, - JSDurationFormat::Display::kAlways}, - display_default), - Nothing()); - // 6. If prevStyle is "numeric" or "2-digit", then - if (prev_style == JSDurationFormat::FieldStyle::kNumeric || - prev_style == JSDurationFormat::FieldStyle::k2Digit) { - // a. If style is not "numeric" or "2-digit", then - if (style != JSDurationFormat::FieldStyle::kNumeric && - style != JSDurationFormat::FieldStyle::k2Digit) { - // i. Throw a RangeError exception. - // b. Else if unit is "minutes" or "seconds", then - } else if (unit_kind == UnitKind::kMinutesOrSeconds) { - CHECK(strcmp(unit, "minutes") == 0 || strcmp(unit, "seconds") == 0); - // i. Set style to "2-digit". - style = JSDurationFormat::FieldStyle::k2Digit; - } - } - // 7. Return the Record { [[Style]]: style, [[Display]]: display }. - return Just(DurationUnitOptions({style, display})); -} - -} // namespace -MaybeHandle JSDurationFormat::New( - Isolate* isolate, Handle map, Handle locales, - Handle input_options) { - Factory* factory = isolate->factory(); - const char* method_name = "Intl.DurationFormat"; - - // 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). - std::vector requested_locales; - MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, requested_locales, - Intl::CanonicalizeLocaleList(isolate, locales), - Handle()); - - // 4. Let options be ? GetOptionsObject(options). - Handle options; - ASSIGN_RETURN_ON_EXCEPTION( - isolate, options, GetOptionsObject(isolate, input_options, method_name), - JSDurationFormat); - - // 5. Let matcher be ? GetOption(options, "localeMatcher", "string", « - // "lookup", "best fit" », "best fit"). - Intl::MatcherOption matcher; - MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, matcher, Intl::GetLocaleMatcher(isolate, options, method_name), - Handle()); - - // 6. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", - // undefined, undefined). - // - // 7. If numberingSystem is not undefined, then - // - // a. If numberingSystem does not match the Unicode Locale Identifier type - // nonterminal, throw a RangeError exception. - // Note: The matching test and throw in Step 7-a is throw inside - // Intl::GetNumberingSystem. - std::unique_ptr numbering_system_str = nullptr; - bool get; - MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, get, - Intl::GetNumberingSystem(isolate, options, method_name, - &numbering_system_str), - Handle()); - - // 8. Let opt be the Record { [[localeMatcher]]: matcher, [[nu]]: - // numberingSystem }. - // 9. Let r be ResolveLocale(%DurationFormat%.[[AvailableLocales]], - // requestedLocales, opt, %DurationFormat%.[[RelevantExtensionKeys]], - // %DurationFormat%.[[LocaleData]]). - std::set relevant_extension_keys{"nu"}; - Intl::ResolvedLocale r; - MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, r, - Intl::ResolveLocale(isolate, JSDurationFormat::GetAvailableLocales(), - requested_locales, matcher, relevant_extension_keys), - Handle()); - - // 10. Let locale be r.[[locale]]. - icu::Locale r_locale = r.icu_locale; - UErrorCode status = U_ZERO_ERROR; - // 11. Set durationFormat.[[Locale]] to locale. - // 12. Set durationFormat.[[NumberingSystem]] to r.[[nu]]. - if (numbering_system_str != nullptr) { - auto nu_extension_it = r.extensions.find("nu"); - if (nu_extension_it != r.extensions.end() && - nu_extension_it->second != numbering_system_str.get()) { - r_locale.setUnicodeKeywordValue("nu", nullptr, status); - DCHECK(U_SUCCESS(status)); - } - } - icu::Locale icu_locale = r_locale; - if (numbering_system_str != nullptr && - Intl::IsValidNumberingSystem(numbering_system_str.get())) { - r_locale.setUnicodeKeywordValue("nu", numbering_system_str.get(), status); - DCHECK(U_SUCCESS(status)); - } - std::string numbering_system = Intl::GetNumberingSystem(r_locale); - - // 13. Let style be ? GetOption(options, "style", "string", « "long", "short", - // "narrow", "digital" », "long"). - Style style; - MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, style, - GetStringOption