You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Properly name Intl.PluralRules functions
* Address issues brought up in the May 2018 and June 2018 Intl call
* Address previously uncaught issue where we failed fast unintentionally
when handling the sign part in ICU > 61.
* Always use null-prototyped property descriptors to avoid Object.prototype.get
tainting.
// ICU has an internal API, uplrules_selectWithFormat, that is equivalent to uplrules_select but will respect digit options of the passed UNumberFormat.
3059
+
// Since its an internal API, we can't use it -- however, we can work around it by creating a UNumberFormat with provided digit options,
3060
+
// formatting the requested number to a string, and then converting the string back to a double which we can pass to uplrules_select.
3061
+
// This workaround was suggested during the May 2018 ECMA-402 discussion.
3062
+
// TODO(jahorto): investigate caching this UNumberFormat on the state as well. This is currently not possible because we are using InternalProperyIds::HiddenObject
3063
+
// for all ICU object caching, but once we move to better names for the cache property IDs, we can cache both the UNumberFormat as well as the UPluralRules.
Copy file name to clipboardExpand all lines: test/Intl/NumberFormat.js
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -190,7 +190,7 @@ const tests = [
190
190
// real formatToParts support was only added with ICU 61
191
191
assert.areEqual(1,actualParts.length,`formatToParts(${n}) stub implementation should return only one part`);
192
192
constliteral=actualParts[0];
193
-
assert.areEqual("literal",literal.type,`formatToParts(${n}) stub implementation should return a literal part`);
193
+
assert.areEqual("unknown",literal.type,`formatToParts(${n}) stub implementation should return an unknown part`);
194
194
assert.areEqual(nf.format(n),literal.value,`formatToParts(${n}) stub implementation should return one part whose value matches the fully formatted number`);
Copy file name to clipboardExpand all lines: test/Intl/PluralRules.js
+38-1Lines changed: 38 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -109,5 +109,42 @@ testRunner.runTests([
109
109
opts1.pluralCategories[0]="changed";
110
110
assert.areNotEqual(opts1.pluralCategories[0],pr1.resolvedOptions().pluralCategories[0],"Changing the pluralCategories from one call to resolvedOptions should not impact future calls");
111
111
}
112
-
}
112
+
},
113
+
{
114
+
name: "Number digit options",
115
+
body(){
116
+
functiontest(options,n,expected){
117
+
constpr=newIntl.PluralRules("en",options);
118
+
assert.areEqual(expected,pr.select(n),`Incorrect result using n = ${n} and options = ${JSON.stringify(options)}`);
0 commit comments