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/+/2946746 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/master@{#75025}
This commit is contained in:
parent
8c2c22fa9c
commit
c563e44a13
@ -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);
|
||||||
}
|
}
|
||||||
|
26
test/intl/regress-11860.js
Normal file
26
test/intl/regress-11860.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// 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']);
|
Loading…
Reference in New Issue
Block a user