Commit c563e44a authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

Fix supportedLocalesOf of "best fit" matcher

Only return "subset of" the requested Locales.


Bug: v8:11860
Change-Id: I917753c6f0f5dfc7a52d071febbe03abfab45b04
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2946746Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75025}
parent 8c2c22fa
...@@ -1564,8 +1564,13 @@ std::vector<std::string> BestFitSupportedLocales( ...@@ -1564,8 +1564,13 @@ std::vector<std::string> BestFitSupportedLocales(
matcher.getBestMatchResult(desired, status); matcher.getBestMatchResult(desired, status);
if (U_FAILURE(status)) continue; if (U_FAILURE(status)) continue;
if (matched.getSupportedIndex() < 0) continue; if (matched.getSupportedIndex() < 0) continue;
std::string bestfit =
matched.makeResolvedLocale(status).toLanguageTag<std::string>(status); // The BestFitSupportedLocales abstract operation returns the *SUBSET* of
// the provided BCP 47 language priority list requestedLocales for which
// availableLocales has a matching locale when using the Best Fit Matcher
// algorithm. Locales appear in the same order in the returned list as in
// requestedLocales. The steps taken are implementation dependent.
std::string bestfit = desired.toLanguageTag<std::string>(status);
if (U_FAILURE(status)) continue; if (U_FAILURE(status)) continue;
result.push_back(bestfit); result.push_back(bestfit);
} }
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony_intl_best_fit_matcher
//
// Test the return list is subset of the request list.
// https://tc39.es/ecma402/#sec-bestfitsupportedlocales
// 9.2.9 BestFitSupportedLocales ( availableLocales, requestedLocales )
// The BestFitSupportedLocales abstract operation returns the SUBSET of the
// provided BCP 47 language priority list requestedLocales for which
// availableLocales has a matching locale when using the Best Fit Matcher
// algorithm. Locales appear in the same order in the returned list as in
// requestedLocales. The steps taken are implementation dependent.
function assertSubarray(a, b) {
assertTrue(a.every(val => b.includes(val)), ['returns:', a, 'requested:', b]);
}
function verifySupportedLocalesAreSubarray(f, ll) {
assertSubarray(f(ll), ll);
}
verifySupportedLocalesAreSubarray(Intl.DateTimeFormat.supportedLocalesOf, ['en', 'ceb']);
verifySupportedLocalesAreSubarray(Intl.DateTimeFormat.supportedLocalesOf, ['en', 'ceb', 'fil']);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment