Skip to content

Commit

Permalink
Bug 1930465: Sort plural categories in Intl.PluralRules.prototype.res…
Browse files Browse the repository at this point in the history
…olvedOptions. r=spidermonkey-reviewers,dminor

Sort plural categories per <tc39/ecma402#918>.

Tests are in <tc39/test262#4275>.

Differential Revision: https://phabricator.services.mozilla.com/D228569
  • Loading branch information
anba committed Nov 26, 2024
1 parent 502d37f commit 1755f74
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions js/src/builtin/intl/PluralRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,20 @@ bool js::intl_GetPluralCategories(JSContext* cx, unsigned argc, Value* vp) {
res->setDenseInitializedLength(categories.size());

size_t index = 0;
for (PluralRules::Keyword keyword : categories) {
JSString* str = KeywordToString(keyword, cx);
MOZ_ASSERT(str);

res->initDenseElement(index++, StringValue(str));
for (auto keyword : {
PluralRules::Keyword::Zero,
PluralRules::Keyword::One,
PluralRules::Keyword::Two,
PluralRules::Keyword::Few,
PluralRules::Keyword::Many,
PluralRules::Keyword::Other,
}) {
if (categories.contains(keyword)) {
JSString* str = KeywordToString(keyword, cx);
MOZ_ASSERT(str);

res->initDenseElement(index++, StringValue(str));
}
}
MOZ_ASSERT(index == categories.size());

Expand Down

0 comments on commit 1755f74

Please sign in to comment.