v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-number-format.h
Go to the documentation of this file.
1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_OBJECTS_JS_NUMBER_FORMAT_H_
6#define V8_OBJECTS_JS_NUMBER_FORMAT_H_
7
8#ifndef V8_INTL_SUPPORT
9#error Internationalization is expected to be enabled.
10#endif // V8_INTL_SUPPORT
11
12#include <set>
13#include <string>
14
15#include "src/base/bit-field.h"
17#include "src/heap/factory.h"
19#include "src/objects/managed.h"
20#include "src/objects/objects.h"
21
22// Has to be the last include (doesn't have include guards):
24
25namespace U_ICU_NAMESPACE {
26class Formattable;
27class UnicodeString;
28namespace number {
29class FormattedNumber;
30class FormattedNumberRange;
31class LocalizedNumberFormatter;
32class LocalizedNumberRangeFormatter;
33class UnlocalizedNumberFormatter;
34} // namespace number
35} // namespace U_ICU_NAMESPACE
36
37namespace v8 {
38namespace internal {
39
40#include "torque-generated/src/objects/js-number-format-tq.inc"
41
43 : public TorqueGeneratedJSNumberFormat<JSNumberFormat, JSObject> {
44 public:
45 // ecma402/#sec-initializenumberformat
47 Isolate* isolate, DirectHandle<Map> map, DirectHandle<Object> locales,
48 DirectHandle<Object> options, const char* service);
49
50 // ecma402/#sec-unwrapnumberformat
53
54 // #sec-number-format-functions
56 Isolate* isolate, DirectHandle<JSNumberFormat> number_format,
57 Handle<Object> numeric_obj);
58
59 // ecma402/#sec-intl.numberformat.prototype.resolvedoptions
61 Isolate* isolate, DirectHandle<JSNumberFormat> number_format);
62
64 Isolate* isolate, DirectHandle<JSNumberFormat> number_format,
65 Handle<Object> numeric_obj);
66
67 // ecma402/#sec-formatnumericrange
69 Isolate* isolate, DirectHandle<JSNumberFormat> number_format,
71
72 // ecma402/#sec-formatnumericrangetoparts
75 DirectHandle<JSNumberFormat> number_format,
77
79 Isolate* isolate,
80 const icu::number::LocalizedNumberFormatter& number_format,
81 Handle<Object> numeric_obj);
82
83 V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
84
85 // Helper functions shared with JSPluralRules.
87 const icu::UnicodeString& skeleton);
88 static bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton,
89 int32_t* minimum, int32_t* maximum);
90 static bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton,
91 int32_t* minimum, int32_t* maximum);
92
94 Isolate* isolate, const icu::UnicodeString& skeleton);
96 Isolate* isolate, const icu::UnicodeString& skeleton);
98 Isolate* isolate, const icu::UnicodeString& skeleton);
100 Isolate* isolate, const icu::UnicodeString& skeleton);
101
103
104 static icu::number::UnlocalizedNumberFormatter SetDigitOptionsToFormatter(
105 const icu::number::UnlocalizedNumberFormatter& settings,
106 const Intl::NumberFormatDigitOptions& digit_options);
107
108 static const icu::UnicodeString NumberingSystemFromSkeleton(
109 const icu::UnicodeString& skeleton);
110
113 Isolate* isolate, Tagged<String> locale,
114 const icu::number::LocalizedNumberFormatter& number_formatter);
115
117
120
122};
123
124// IntlMathematicalValue is designed only to be used as part of
125// JSNumberFormat and can only be allocate on the stack. We place this class in
126// the header so we can write unit test code for it. Please do NOT use this
127// class outside JSNumberFormat implementation.
129 public:
130 IntlMathematicalValue() : approx_(0) {}
131 V8_EXPORT_PRIVATE bool IsNaN() const;
132
134 Isolate* isolate, Handle<Object> value);
135
137 Isolate* isolate,
138 const icu::number::LocalizedNumberFormatter& number_format,
139 const IntlMathematicalValue& x);
140
142 Isolate* isolate,
143 const icu::number::LocalizedNumberRangeFormatter& number_range_format,
145
146 private:
147 double approx_;
148 Handle<Object> value_; // Number, BigInt or String
149 Maybe<icu::Formattable> ToFormattable(Isolate* isolate) const;
150 MaybeHandle<String> ToString(Isolate* isolate) const;
151};
152
153} // namespace internal
154} // namespace v8
155
157
158#endif // V8_OBJECTS_JS_NUMBER_FORMAT_H_
static V8_EXPORT_PRIVATE const std::set< std::string > & GetAvailableLocales()
static int32_t MinimumIntegerDigitsFromSkeleton(const icu::UnicodeString &skeleton)
static DirectHandle< String > TrailingZeroDisplayString(Isolate *isolate, const icu::UnicodeString &skeleton)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< String > NumberFormatFunction(Isolate *isolate, DirectHandle< JSNumberFormat > number_format, Handle< Object > numeric_obj)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< String > FormatNumeric(Isolate *isolate, const icu::number::LocalizedNumberFormatter &number_format, Handle< Object > numeric_obj)
static DirectHandle< Object > RoundingIncrement(Isolate *isolate, const icu::UnicodeString &skeleton)
static DirectHandle< JSObject > ResolvedOptions(Isolate *isolate, DirectHandle< JSNumberFormat > number_format)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSNumberFormat > New(Isolate *isolate, DirectHandle< Map > map, DirectHandle< Object > locales, DirectHandle< Object > options, const char *service)
static const icu::UnicodeString NumberingSystemFromSkeleton(const icu::UnicodeString &skeleton)
static V8_WARN_UNUSED_RESULT Maybe< icu::number::LocalizedNumberRangeFormatter > GetRangeFormatter(Isolate *isolate, Tagged< String > locale, const icu::number::LocalizedNumberFormatter &number_formatter)
static icu::number::UnlocalizedNumberFormatter SetDigitOptionsToFormatter(const icu::number::UnlocalizedNumberFormatter &settings, const Intl::NumberFormatDigitOptions &digit_options)
static DirectHandle< String > RoundingPriorityString(Isolate *isolate, const icu::UnicodeString &skeleton)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSNumberFormat > UnwrapNumberFormat(Isolate *isolate, DirectHandle< JSReceiver > format_holder)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSArray > FormatToParts(Isolate *isolate, DirectHandle< JSNumberFormat > number_format, Handle< Object > numeric_obj)
static bool SignificantDigitsFromSkeleton(const icu::UnicodeString &skeleton, int32_t *minimum, int32_t *maximum)
static bool FractionDigitsFromSkeleton(const icu::UnicodeString &skeleton, int32_t *minimum, int32_t *maximum)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSArray > FormatNumericRangeToParts(Isolate *isolate, DirectHandle< JSNumberFormat > number_format, Handle< Object > x, Handle< Object > y)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< String > FormatNumericRange(Isolate *isolate, DirectHandle< JSNumberFormat > number_format, Handle< Object > x, Handle< Object > y)
static DirectHandle< String > RoundingModeString(Isolate *isolate, const icu::UnicodeString &skeleton)
int x
constexpr const char * ToString(DeoptimizeKind kind)
Definition globals.h:880
bool IsNaN(Tagged< Object > obj)
#define DECL_ACCESSORS(name,...)
#define DECL_PRINTER(Name)
#define TQ_OBJECT_CONSTRUCTORS(Type)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:671
#define V8_NODISCARD
Definition v8config.h:693