11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_INTL_SUPPORT
61cb0ef41Sopenharmony_ci#error Internationalization is expected to be enabled.
71cb0ef41Sopenharmony_ci#endif  // V8_INTL_SUPPORT
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci#ifndef V8_OBJECTS_JS_NUMBER_FORMAT_H_
101cb0ef41Sopenharmony_ci#define V8_OBJECTS_JS_NUMBER_FORMAT_H_
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci#include <set>
131cb0ef41Sopenharmony_ci#include <string>
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci#include "src/base/bit-field.h"
161cb0ef41Sopenharmony_ci#include "src/execution/isolate.h"
171cb0ef41Sopenharmony_ci#include "src/heap/factory.h"
181cb0ef41Sopenharmony_ci#include "src/objects/intl-objects.h"
191cb0ef41Sopenharmony_ci#include "src/objects/managed.h"
201cb0ef41Sopenharmony_ci#include "src/objects/objects.h"
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci// Has to be the last include (doesn't have include guards):
231cb0ef41Sopenharmony_ci#include "src/objects/object-macros.h"
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_cinamespace U_ICU_NAMESPACE {
261cb0ef41Sopenharmony_ciclass UnicodeString;
271cb0ef41Sopenharmony_cinamespace number {
281cb0ef41Sopenharmony_ciclass LocalizedNumberFormatter;
291cb0ef41Sopenharmony_ciclass UnlocalizedNumberFormatter;
301cb0ef41Sopenharmony_ciclass LocalizedNumberRangeFormatter;
311cb0ef41Sopenharmony_ci}  //  namespace number
321cb0ef41Sopenharmony_ci}  //  namespace U_ICU_NAMESPACE
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_cinamespace v8 {
351cb0ef41Sopenharmony_cinamespace internal {
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci#include "torque-generated/src/objects/js-number-format-tq.inc"
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciclass JSNumberFormat
401cb0ef41Sopenharmony_ci    : public TorqueGeneratedJSNumberFormat<JSNumberFormat, JSObject> {
411cb0ef41Sopenharmony_ci public:
421cb0ef41Sopenharmony_ci  // ecma402/#sec-initializenumberformat
431cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<JSNumberFormat> New(
441cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<Map> map, Handle<Object> locales,
451cb0ef41Sopenharmony_ci      Handle<Object> options, const char* service);
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci  // ecma402/#sec-unwrapnumberformat
481cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<JSNumberFormat> UnwrapNumberFormat(
491cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSReceiver> format_holder);
501cb0ef41Sopenharmony_ci
511cb0ef41Sopenharmony_ci  // ecma402/#sec-intl.numberformat.prototype.resolvedoptions
521cb0ef41Sopenharmony_ci  static Handle<JSObject> ResolvedOptions(Isolate* isolate,
531cb0ef41Sopenharmony_ci                                          Handle<JSNumberFormat> number_format);
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> FormatToParts(
561cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSNumberFormat> number_format,
571cb0ef41Sopenharmony_ci      Handle<Object> numeric_obj);
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  // ecma402/#sec-formatnumericrange
601cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatNumericRange(
611cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSNumberFormat> number_format, Handle<Object> x,
621cb0ef41Sopenharmony_ci      Handle<Object> y);
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci  // ecma402/#sec-formatnumericrangetoparts
651cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<JSArray> FormatNumericRangeToParts(
661cb0ef41Sopenharmony_ci      Isolate* isolate, Handle<JSNumberFormat> number_format, Handle<Object> x,
671cb0ef41Sopenharmony_ci      Handle<Object> y);
681cb0ef41Sopenharmony_ci
691cb0ef41Sopenharmony_ci  V8_WARN_UNUSED_RESULT static MaybeHandle<String> FormatNumeric(
701cb0ef41Sopenharmony_ci      Isolate* isolate,
711cb0ef41Sopenharmony_ci      const icu::number::LocalizedNumberFormatter& number_format,
721cb0ef41Sopenharmony_ci      Handle<Object> numeric_obj);
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci  V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ci  // Helper functions shared with JSPluralRules.
771cb0ef41Sopenharmony_ci  static int32_t MinimumIntegerDigitsFromSkeleton(
781cb0ef41Sopenharmony_ci      const icu::UnicodeString& skeleton);
791cb0ef41Sopenharmony_ci  static bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton,
801cb0ef41Sopenharmony_ci                                         int32_t* minimum, int32_t* maximum);
811cb0ef41Sopenharmony_ci  static bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton,
821cb0ef41Sopenharmony_ci                                            int32_t* minimum, int32_t* maximum);
831cb0ef41Sopenharmony_ci
841cb0ef41Sopenharmony_ci  enum class ShowTrailingZeros { kShow, kHide };
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci  static icu::number::UnlocalizedNumberFormatter SetDigitOptionsToFormatter(
871cb0ef41Sopenharmony_ci      const icu::number::UnlocalizedNumberFormatter& settings,
881cb0ef41Sopenharmony_ci      const Intl::NumberFormatDigitOptions& digit_options,
891cb0ef41Sopenharmony_ci      int rounding_increment, ShowTrailingZeros show);
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci  DECL_PRINTER(JSNumberFormat)
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ci  DECL_ACCESSORS(icu_number_formatter,
941cb0ef41Sopenharmony_ci                 Managed<icu::number::LocalizedNumberFormatter>)
951cb0ef41Sopenharmony_ci  DECL_ACCESSORS(icu_number_range_formatter,
961cb0ef41Sopenharmony_ci                 Managed<icu::number::LocalizedNumberRangeFormatter>)
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ci  TQ_OBJECT_CONSTRUCTORS(JSNumberFormat)
991cb0ef41Sopenharmony_ci};
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ci}  // namespace internal
1021cb0ef41Sopenharmony_ci}  // namespace v8
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci#include "src/objects/object-macros-undef.h"
1051cb0ef41Sopenharmony_ci
1061cb0ef41Sopenharmony_ci#endif  // V8_OBJECTS_JS_NUMBER_FORMAT_H_
107