@@ -48,48 +48,67 @@ using namespace PlatformAgnostic::ICUHelpers;
48
48
49
49
#endif // INTL_ICU
50
50
51
- // NOTE(jahorto): Keep these enums in sync with those by the same name in Intl.js
52
- // These enums are used by both WinGlob- and ICU-backed Intl
53
- enum class NumberFormatStyle
54
- {
55
- Decimal, // Intl.NumberFormat(locale, { style: "decimal" }); // aka in our code as "number"
56
- Percent, // Intl.NumberFormat(locale, { style: "percent" });
57
- Currency, // Intl.NumberFormat(locale, { style: "currency", ... });
58
-
59
- Max,
60
- Default = Decimal,
61
- };
62
-
63
- enum class NumberFormatCurrencyDisplay
64
- {
65
- Symbol, // Intl.NumberFormat(locale, { style: "currency", currencyDisplay: "symbol" }); // e.g. "$" or "US$" depeding on locale
66
- Code, // Intl.NumberFormat(locale, { style: "currency", currencyDisplay: "code" }); // e.g. "USD"
67
- Name, // Intl.NumberFormat(locale, { style: "currency", currencyDisplay: "name" }); // e.g. "US dollar"
68
-
69
- Max,
70
- Default = Symbol,
51
+ // The following macros allow the key-value pairs to be C++ enums as well as JS objects
52
+ // in Intl.js. When adding a new macro, follow the same format as the _VALUES macros below,
53
+ // and add your new _VALUES macro to PROJECTED_ENUMS along with the name of the enum.
54
+ // NOTE: make sure the last VALUE macro has the highest integer value, since the C++ enum's ::Max
55
+ // value is added to the end of the C++ enum definition as an increment of the previous value.
56
+ // The ::Max value is used in a defensive assert, and we want to make sure its always 1 greater
57
+ // than the highest valid value.
58
+
59
+ #define NUMBERFORMATSTYLE_VALUES (VALUE ) \
60
+ VALUE (Default, default_, 0 ) \
61
+ VALUE(Decimal, decimal, 0 ) \
62
+ VALUE(Percent, percent, 1 ) \
63
+ VALUE(Currency, currency, 2 )
64
+
65
+ #define NUMBERFORMATCURRENCYDISPLAY_VALUES (VALUE ) \
66
+ VALUE (Default, default_, 0 ) \
67
+ VALUE(Symbol, symbol, 0 ) \
68
+ VALUE(Code, code, 1 ) \
69
+ VALUE(Name, name, 2 )
70
+
71
+ #define COLLATORSENSITIVITY_VALUES (VALUE ) \
72
+ VALUE (Default, default_, 3 ) \
73
+ VALUE(Base, base, 0 ) \
74
+ VALUE(Accent, accent, 1 ) \
75
+ VALUE(Case, case_, 2 ) \
76
+ VALUE(Variant, variant, 3 )
77
+
78
+ #define COLLATORCASEFIRST_VALUES (VALUE ) \
79
+ VALUE (Default, default_, 2 ) \
80
+ VALUE(Upper, upper, 0 ) \
81
+ VALUE(Lower, lower, 1 ) \
82
+ VALUE(False, false_, 2 )
83
+
84
+ // LocaleDataKind intentionally has no Default value
85
+ #define LOCALEDATAKIND_VALUES (VALUE ) \
86
+ VALUE (Collation, co, 0 ) \
87
+ VALUE(CaseFirst, kf, 1 ) \
88
+ VALUE(Numeric, kn, 2 ) \
89
+ VALUE(Calendar, ca, 3 ) \
90
+ VALUE(NumberingSystem, nu, 4 ) \
91
+ VALUE(HourCycle, hc, 5 )
92
+
93
+ #define ENUM_VALUE (enumName, propId, value ) enumName = value,
94
+ #define PROJECTED_ENUM (ClassName, VALUES ) \
95
+ enum class ClassName \
96
+ { \
97
+ VALUES (ENUM_VALUE) \
98
+ Max \
71
99
};
72
100
73
- enum class CollatorSensitivity
74
- {
75
- Base,
76
- Accent,
77
- Case,
78
- Variant,
101
+ # define PROJECTED_ENUMS ( PROJECT ) \
102
+ PROJECT (LocaleDataKind, LOCALEDATAKIND_VALUES) \
103
+ PROJECT(CollatorCaseFirst, COLLATORCASEFIRST_VALUES) \
104
+ PROJECT(CollatorSensitivity, COLLATORSENSITIVITY_VALUES) \
105
+ PROJECT(NumberFormatCurrencyDisplay, NUMBERFORMATCURRENCYDISPLAY_VALUES) \
106
+ PROJECT(NumberFormatStyle, NUMBERFORMATSTYLE_VALUES)
79
107
80
- Max,
81
- Default = Variant,
82
- };
108
+ PROJECTED_ENUMS(PROJECTED_ENUM)
83
109
84
- enum class CollatorCaseFirst
85
- {
86
- Upper,
87
- Lower,
88
- False,
89
-
90
- Max,
91
- Default = False,
92
- };
110
+ #undef PROJECTED_ENUM
111
+ #undef ENUM_VALUE
93
112
94
113
#pragma warning(push)
95
114
#pragma warning(disable:4309) // truncation of constant value
@@ -549,6 +568,20 @@ namespace Js
549
568
550
569
library->AddMember (intlNativeInterfaces, PropertyIds::FallbackSymbol, library->CreateSymbol (BuiltInPropertyRecords::_intlFallbackSymbol));
551
570
571
+ DynamicObject * enumObj = nullptr ;
572
+
573
+ // Projects the exact layout of our C++ enums into Intl.js so that we dont have to remember to keep them in sync
574
+ #define ENUM_VALUE (enumName, unicodeKey, value ) library->AddMember (enumObj, PropertyIds::##unicodeKey, JavascriptNumber::ToVar(value, scriptContext));
575
+ #define PROJECTED_ENUM (ClassName, VALUES ) \
576
+ enumObj = library->CreateObject (); \
577
+ VALUES (ENUM_VALUE) \
578
+ library->AddMember (intlNativeInterfaces, PropertyIds::##ClassName, enumObj); \
579
+
580
+ PROJECTED_ENUMS (PROJECTED_ENUM)
581
+
582
+ #undef PROJECTED_ENUM
583
+ #undef ENUM_VALUE
584
+
552
585
#if INTL_WINGLOB
553
586
library->AddMember (intlNativeInterfaces, Js::PropertyIds::winglob, library->GetTrue ());
554
587
#else
@@ -1049,15 +1082,8 @@ DEFINE_ISXLOCALEAVAILABLE(DTF, udat)
1049
1082
DEFINE_ISXLOCALEAVAILABLE(PR, uloc)
1050
1083
1051
1084
#ifdef INTL_ICU
1052
- enum class LocaleDataKind
1053
- {
1054
- Collation,
1055
- CaseFirst,
1056
- Numeric,
1057
- Calendar,
1058
- NumberingSystem,
1059
- HourCycle
1060
- };
1085
+
1086
+
1061
1087
#endif
1062
1088
1063
1089
Var IntlEngineInterfaceExtensionObject::EntryIntl_GetLocaleData (RecyclableObject* function, CallInfo callInfo, ...)
0 commit comments