@@ -24,6 +24,7 @@ var GlobalIntl = global.Intl;
2424var GlobalIntlDateTimeFormat = GlobalIntl . DateTimeFormat ;
2525var GlobalIntlNumberFormat = GlobalIntl . NumberFormat ;
2626var GlobalIntlCollator = GlobalIntl . Collator ;
27+ var GlobalIntlPluralRules = utils . ImportNow ( "PluralRules" ) ;
2728var GlobalIntlv8BreakIterator = GlobalIntl . v8BreakIterator ;
2829var GlobalNumber = global . Number ;
2930var GlobalRegExp = global . RegExp ;
@@ -32,6 +33,7 @@ var IntlFallbackSymbol = utils.ImportNow("intl_fallback_symbol");
3233var InternalArray = utils . InternalArray ;
3334var MaxSimple ;
3435var ObjectHasOwnProperty = global . Object . prototype . hasOwnProperty ;
36+ var ObjectKeys = global . Object . keys ;
3537var patternSymbol = utils . ImportNow ( "intl_pattern_symbol" ) ;
3638var resolvedSymbol = utils . ImportNow ( "intl_resolved_symbol" ) ;
3739var StringSubstr = GlobalString . prototype . substr ;
@@ -124,7 +126,8 @@ var AVAILABLE_LOCALES = {
124126 'collator' : UNDEFINED ,
125127 'numberformat' : UNDEFINED ,
126128 'dateformat' : UNDEFINED ,
127- 'breakiterator' : UNDEFINED
129+ 'breakiterator' : UNDEFINED ,
130+ 'pluralrules' : UNDEFINED ,
128131} ;
129132
130133/**
@@ -190,7 +193,7 @@ var SERVICE_RE = UNDEFINED;
190193function GetServiceRE ( ) {
191194 if ( IS_UNDEFINED ( SERVICE_RE ) ) {
192195 SERVICE_RE =
193- new GlobalRegExp ( '^(collator|numberformat|dateformat|breakiterator )$' ) ;
196+ new GlobalRegExp ( '^(' + % _Call ( ArrayJoin , ObjectKeys ( AVAILABLE_LOCALES ) , '|' ) + ' )$') ;
194197 }
195198 return SERVICE_RE ;
196199}
@@ -1072,6 +1075,108 @@ function compare(collator, x, y) {
10721075
10731076AddBoundMethod ( GlobalIntlCollator , 'compare' , compare , 2 , 'collator' , false ) ;
10741077
1078+ function PluralRulesConstructor ( ) {
1079+ if ( IS_UNDEFINED ( new . target ) ) {
1080+ throw % make_type_error ( kConstructorNotFunction , "PluralRules" ) ;
1081+ }
1082+
1083+ var locales = arguments [ 0 ] ;
1084+ var options = arguments [ 1 ] ;
1085+
1086+ if ( IS_UNDEFINED ( options ) ) {
1087+ options = { } ;
1088+ }
1089+
1090+ var getOption = getGetOption ( options , 'pluralrules' ) ;
1091+
1092+ var locale = resolveLocale ( 'pluralrules' , locales , options ) ;
1093+
1094+ var internalOptions = { } ;
1095+ defineWEProperty ( internalOptions , 'type' , getOption (
1096+ 'type' , 'string' , [ 'cardinal' , 'ordinal' ] , 'cardinal' ) ) ;
1097+
1098+ SetNumberFormatDigitOptions ( internalOptions , options , 0 , 3 ) ;
1099+
1100+ var requestedLocale = locale . locale ;
1101+ var resolved = % object_define_properties ( { } , {
1102+ type : { value : internalOptions . type , writable : true } ,
1103+ locale : { writable : true } ,
1104+ maximumFractionDigits : { writable : true } ,
1105+ minimumFractionDigits : { writable : true } ,
1106+ minimumIntegerDigits : { writable : true } ,
1107+ requestedLocale : { value : requestedLocale , writable : true } ,
1108+ } ) ;
1109+ if ( HAS_OWN_PROPERTY ( internalOptions , 'minimumSignificantDigits' ) ) {
1110+ defineWEProperty ( resolved , 'minimumSignificantDigits' , UNDEFINED ) ;
1111+ }
1112+ if ( HAS_OWN_PROPERTY ( internalOptions , 'maximumSignificantDigits' ) ) {
1113+ defineWEProperty ( resolved , 'maximumSignificantDigits' , UNDEFINED ) ;
1114+ }
1115+ defineWEProperty ( resolved , 'pluralCategories' , [ ] ) ;
1116+ var pluralRules = % CreatePluralRules ( requestedLocale , internalOptions ,
1117+ resolved ) ;
1118+
1119+ % MarkAsInitializedIntlObjectOfType ( pluralRules , 'pluralrules' ) ;
1120+ pluralRules [ resolvedSymbol ] = resolved ;
1121+
1122+ return pluralRules ;
1123+ }
1124+ % SetCode ( GlobalIntlPluralRules , PluralRulesConstructor ) ;
1125+
1126+ DEFINE_METHOD (
1127+ GlobalIntlPluralRules . prototype ,
1128+ resolvedOptions ( ) {
1129+ if ( ! % IsInitializedIntlObjectOfType ( this , 'pluralrules' ) ) {
1130+ throw % make_type_error ( kIncompatibleMethodReceiver ,
1131+ 'Intl.PluralRules.prototype.resolvedOptions' ,
1132+ this ) ;
1133+ }
1134+
1135+ var result = {
1136+ locale : this [ resolvedSymbol ] . locale ,
1137+ type : this [ resolvedSymbol ] . type ,
1138+ minimumIntegerDigits : this [ resolvedSymbol ] . minimumIntegerDigits ,
1139+ minimumFractionDigits : this [ resolvedSymbol ] . minimumFractionDigits ,
1140+ maximumFractionDigits : this [ resolvedSymbol ] . maximumFractionDigits ,
1141+ } ;
1142+
1143+ if ( HAS_OWN_PROPERTY ( this [ resolvedSymbol ] , 'minimumSignificantDigits' ) ) {
1144+ defineWECProperty ( result , 'minimumSignificantDigits' ,
1145+ this [ resolvedSymbol ] . minimumSignificantDigits ) ;
1146+ }
1147+
1148+ if ( HAS_OWN_PROPERTY ( this [ resolvedSymbol ] , 'maximumSignificantDigits' ) ) {
1149+ defineWECProperty ( result , 'maximumSignificantDigits' ,
1150+ this [ resolvedSymbol ] . maximumSignificantDigits ) ;
1151+ }
1152+
1153+ defineWECProperty ( result , 'pluralCategories' ,
1154+ this [ resolvedSymbol ] . pluralCategories ) ;
1155+
1156+ return result ;
1157+ }
1158+ ) ;
1159+
1160+ DEFINE_METHOD (
1161+ GlobalIntlPluralRules ,
1162+ supportedLocalesOf ( locales ) {
1163+ return supportedLocalesOf ( 'pluralrules' , locales, arguments [ 1 ] ) ;
1164+ }
1165+ ) ;
1166+
1167+ DEFINE_METHOD (
1168+ GlobalIntlPluralRules . prototype ,
1169+ select ( value ) {
1170+ if ( ! % IsInitializedIntlObjectOfType ( this , 'pluralrules' ) ) {
1171+ throw % make_type_error ( kIncompatibleMethodReceiver ,
1172+ 'Intl.PluralRules.prototype.select' ,
1173+ this ) ;
1174+ }
1175+
1176+ return % PluralRulesSelect ( this , TO_NUMBER ( value ) + 0 ) ;
1177+ }
1178+ ) ;
1179+
10751180/**
10761181 * Verifies that the input is a well-formed ISO 4217 currency code.
10771182 * Don't uppercase to test. It could convert invalid code into a valid one.
0 commit comments