Commit a6d2fe40 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Remove GetDefaultLocale

Simplified test for default locale under test/intl
Remove GetDefaultLocale from runtime
Move Intl::DefaultLocale from intl-object.h to
internal function inside intl-object.cc

Bug: v8:5751
Change-Id: I885abf30ff33d5213ee99c07ac1e92d3c5065d8b
Reviewed-on: https://chromium-review.googlesource.com/c/1358022Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarJungshik Shin <jshin@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58081}
parent 29684ef0
...@@ -537,7 +537,8 @@ std::set<std::string> Intl::BuildLocaleSet( ...@@ -537,7 +537,8 @@ std::set<std::string> Intl::BuildLocaleSet(
return locales; return locales;
} }
std::string Intl::DefaultLocale(Isolate* isolate) { namespace {
std::string DefaultLocale(Isolate* isolate) {
if (isolate->default_locale().empty()) { if (isolate->default_locale().empty()) {
icu::Locale default_locale; icu::Locale default_locale;
// Translate ICU's fallback locale to a well-known locale. // Translate ICU's fallback locale to a well-known locale.
...@@ -557,6 +558,7 @@ std::string Intl::DefaultLocale(Isolate* isolate) { ...@@ -557,6 +558,7 @@ std::string Intl::DefaultLocale(Isolate* isolate) {
} }
return isolate->default_locale(); return isolate->default_locale();
} }
} // namespace
// See ecma402/#legacy-constructor. // See ecma402/#legacy-constructor.
MaybeHandle<Object> Intl::LegacyUnwrapReceiver(Isolate* isolate, MaybeHandle<Object> Intl::LegacyUnwrapReceiver(Isolate* isolate,
...@@ -876,7 +878,7 @@ MaybeHandle<String> Intl::StringLocaleConvertCase(Isolate* isolate, ...@@ -876,7 +878,7 @@ MaybeHandle<String> Intl::StringLocaleConvertCase(Isolate* isolate,
return MaybeHandle<String>(); return MaybeHandle<String>();
} }
std::string requested_locale = requested_locales.size() == 0 std::string requested_locale = requested_locales.size() == 0
? Intl::DefaultLocale(isolate) ? DefaultLocale(isolate)
: requested_locales[0]; : requested_locales[0];
size_t dash = requested_locale.find('-'); size_t dash = requested_locale.find('-');
if (dash != std::string::npos) { if (dash != std::string::npos) {
...@@ -1548,7 +1550,7 @@ std::string LookupMatcher(Isolate* isolate, ...@@ -1548,7 +1550,7 @@ std::string LookupMatcher(Isolate* isolate,
// 3. Let defLocale be DefaultLocale(); // 3. Let defLocale be DefaultLocale();
// 4. Set result.[[locale]] to defLocale. // 4. Set result.[[locale]] to defLocale.
// 5. Return result. // 5. Return result.
return Intl::DefaultLocale(isolate); return DefaultLocale(isolate);
} }
} // namespace } // namespace
......
...@@ -62,8 +62,6 @@ class Intl { ...@@ -62,8 +62,6 @@ class Intl {
const std::set<std::string>& available_locales, Handle<Object> locales_in, const std::set<std::string>& available_locales, Handle<Object> locales_in,
Handle<Object> options_in); Handle<Object> options_in);
static std::string DefaultLocale(Isolate* isolate);
// ECMA402 9.2.10. GetOption( options, property, type, values, fallback) // ECMA402 9.2.10. GetOption( options, property, type, values, fallback)
// ecma402/#sec-getoption // ecma402/#sec-getoption
// //
......
...@@ -52,14 +52,6 @@ RUNTIME_FUNCTION(Runtime_FormatListToParts) { ...@@ -52,14 +52,6 @@ RUNTIME_FUNCTION(Runtime_FormatListToParts) {
isolate, JSListFormat::FormatListToParts(isolate, list_format, list)); isolate, JSListFormat::FormatListToParts(isolate, list_format, list));
} }
RUNTIME_FUNCTION(Runtime_GetDefaultICULocale) {
HandleScope scope(isolate);
DCHECK_EQ(0, args.length());
return *isolate->factory()->NewStringFromAsciiChecked(
Intl::DefaultLocale(isolate).c_str());
}
RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) { RUNTIME_FUNCTION(Runtime_StringToLowerCaseIntl) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK_EQ(args.length(), 1); DCHECK_EQ(args.length(), 1);
......
...@@ -200,7 +200,6 @@ namespace internal { ...@@ -200,7 +200,6 @@ namespace internal {
#define FOR_EACH_INTRINSIC_INTL(F, I) \ #define FOR_EACH_INTRINSIC_INTL(F, I) \
F(FormatList, 2, 1) \ F(FormatList, 2, 1) \
F(FormatListToParts, 2, 1) \ F(FormatListToParts, 2, 1) \
F(GetDefaultICULocale, 0, 1) \
F(StringToLowerCaseIntl, 1, 1) \ F(StringToLowerCaseIntl, 1, 1) \
F(StringToUpperCaseIntl, 1, 1) // End of macro. F(StringToUpperCaseIntl, 1, 1) // End of macro.
#else #else
......
...@@ -37,9 +37,6 @@ assertFalse(options.locale === 'und'); ...@@ -37,9 +37,6 @@ assertFalse(options.locale === 'und');
assertFalse(options.locale === ''); assertFalse(options.locale === '');
assertFalse(options.locale === undefined); assertFalse(options.locale === undefined);
// Then check for legitimacy.
assertLanguageTag(%GetDefaultICULocale(), options.locale);
var iteratorNone = new Intl.v8BreakIterator(); var iteratorNone = new Intl.v8BreakIterator();
assertEquals(options.locale, iteratorNone.resolvedOptions().locale); assertEquals(options.locale, iteratorNone.resolvedOptions().locale);
......
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Passing a well formed but unsupported locale falls back to default.
var iterator = Intl.v8BreakIterator(['xx']);
assertLanguageTag(%GetDefaultICULocale(), iterator.resolvedOptions().locale);
...@@ -37,9 +37,6 @@ assertFalse(options.locale === 'und'); ...@@ -37,9 +37,6 @@ assertFalse(options.locale === 'und');
assertFalse(options.locale === ''); assertFalse(options.locale === '');
assertFalse(options.locale === undefined); assertFalse(options.locale === undefined);
// Then check for legitimacy.
assertLanguageTag(%GetDefaultICULocale(), options.locale);
var collatorNone = new Intl.Collator(); var collatorNone = new Intl.Collator();
assertEquals(options.locale, collatorNone.resolvedOptions().locale); assertEquals(options.locale, collatorNone.resolvedOptions().locale);
...@@ -49,5 +46,4 @@ assertEquals(options.locale, collatorBraket.resolvedOptions().locale); ...@@ -49,5 +46,4 @@ assertEquals(options.locale, collatorBraket.resolvedOptions().locale);
var collatorWithOptions = new Intl.Collator(undefined, {usage: 'search'}); var collatorWithOptions = new Intl.Collator(undefined, {usage: 'search'});
var locale = collatorWithOptions.resolvedOptions().locale; var locale = collatorWithOptions.resolvedOptions().locale;
assertLanguageTag(%GetDefaultICULocale(), locale);
assertEquals(locale.indexOf('-co-search'), -1); assertEquals(locale.indexOf('-co-search'), -1);
...@@ -5,14 +5,12 @@ ...@@ -5,14 +5,12 @@
// No locale // No locale
var collatorWithOptions = new Intl.Collator(undefined); var collatorWithOptions = new Intl.Collator(undefined);
var { locale, usage, collation } = collatorWithOptions.resolvedOptions(); var { locale, usage, collation } = collatorWithOptions.resolvedOptions();
assertLanguageTag(%GetDefaultICULocale(), locale);
assertEquals('sort', usage); assertEquals('sort', usage);
assertEquals('default', collation); assertEquals('default', collation);
assertEquals(locale.indexOf('-co-search'), -1); assertEquals(locale.indexOf('-co-search'), -1);
collatorWithOptions = new Intl.Collator(undefined, {usage: 'sort'}); collatorWithOptions = new Intl.Collator(undefined, {usage: 'sort'});
var { locale, usage, collation } = collatorWithOptions.resolvedOptions(); var { locale, usage, collation } = collatorWithOptions.resolvedOptions();
assertLanguageTag(%GetDefaultICULocale(), locale);
assertEquals('sort', usage); assertEquals('sort', usage);
assertEquals('default', collation); assertEquals('default', collation);
assertEquals(locale.indexOf('-co-search'), -1); assertEquals(locale.indexOf('-co-search'), -1);
...@@ -21,12 +19,10 @@ collatorWithOptions = new Intl.Collator(undefined, {usage: 'search'}); ...@@ -21,12 +19,10 @@ collatorWithOptions = new Intl.Collator(undefined, {usage: 'search'});
var { locale, usage, collation } = collatorWithOptions.resolvedOptions(); var { locale, usage, collation } = collatorWithOptions.resolvedOptions();
assertEquals('search', usage); assertEquals('search', usage);
assertEquals('default', collation); assertEquals('default', collation);
assertLanguageTag(%GetDefaultICULocale(), locale);
assertEquals(locale.indexOf('-co-search'), -1); assertEquals(locale.indexOf('-co-search'), -1);
collatorWithOptions = new Intl.Collator(locale); collatorWithOptions = new Intl.Collator(locale);
var { locale, usage, collation } = collatorWithOptions.resolvedOptions(); var { locale, usage, collation } = collatorWithOptions.resolvedOptions();
assertLanguageTag(%GetDefaultICULocale(), locale);
assertEquals('sort', usage); assertEquals('sort', usage);
assertEquals('default', collation); assertEquals('default', collation);
assertEquals(locale.indexOf('-co-search'), -1); assertEquals(locale.indexOf('-co-search'), -1);
......
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Passing a well formed but unsupported locale falls back to default.
var collator = Intl.Collator(['xx']);
assertLanguageTag(%GetDefaultICULocale(), collator.resolvedOptions().locale);
...@@ -37,8 +37,5 @@ assertFalse(options.locale === 'und'); ...@@ -37,8 +37,5 @@ assertFalse(options.locale === 'und');
assertFalse(options.locale === ''); assertFalse(options.locale === '');
assertFalse(options.locale === undefined); assertFalse(options.locale === undefined);
// Then check for legitimacy.
assertLanguageTag(%GetDefaultICULocale(), options.locale);
var dtfNone = new Intl.DateTimeFormat(); var dtfNone = new Intl.DateTimeFormat();
assertEquals(options.locale, dtfNone.resolvedOptions().locale); assertEquals(options.locale, dtfNone.resolvedOptions().locale);
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Passing a well formed but unsupported locale falls back to default.
var dtf = Intl.DateTimeFormat(['xx']);
assertLanguageTag(%GetDefaultICULocale(), dtf.resolvedOptions().locale);
// Copyright 2018 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.
// Environment Variables: LC_ALL=de
assertEquals("de", (new Intl.Collator([])).resolvedOptions().locale);
assertEquals("de", (new Intl.Collator(['xx'])).resolvedOptions().locale);
assertEquals("de", (new Intl.Collator(undefined)).resolvedOptions().locale);
assertEquals("de", (new Intl.Collator(undefined, {usage: 'sort'})).resolvedOptions().locale);
assertEquals("de", (new Intl.Collator(undefined, {usage: 'search'})).resolvedOptions().locale);
assertEquals("de", (new Intl.DateTimeFormat([])).resolvedOptions().locale);
assertEquals("de", (new Intl.DateTimeFormat(['xx'])).resolvedOptions().locale);
assertEquals("de", (new Intl.NumberFormat([])).resolvedOptions().locale);
assertEquals("de", (new Intl.NumberFormat(['xx'])).resolvedOptions().locale);
assertEquals("de", (new Intl.v8BreakIterator([])).resolvedOptions().locale);
assertEquals("de", (new Intl.v8BreakIterator(['xx'])).resolvedOptions().locale);
...@@ -42,14 +42,18 @@ ...@@ -42,14 +42,18 @@
# noi18n cannot turn on ICU backend for Date # noi18n cannot turn on ICU backend for Date
'relative-time-format/default-locale-fr-CA': [SKIP], 'relative-time-format/default-locale-fr-CA': [SKIP],
'relative-time-format/default-locale-pt-BR': [SKIP], 'relative-time-format/default-locale-pt-BR': [SKIP],
# Unable to change locale on Windows:
'default_locale': [SKIP],
}], # system == windows' }], # system == windows'
['system == android', { ['system == android', {
# Android's ICU data file does not have the Chinese/Japanese dictionary # Android's ICU data file does not have the Chinese/Japanese dictionary
# required for the test to pass. # required for the test to pass.
'break-iterator/zh-break': [FAIL], 'break-iterator/zh-break': [SKIP],
# Unable to change locale on Android: # Unable to change locale on Android:
'relative-time-format/default-locale-fr-CA': [FAIL], 'relative-time-format/default-locale-fr-CA': [SKIP],
'relative-time-format/default-locale-pt-BR': [FAIL], 'relative-time-format/default-locale-pt-BR': [SKIP],
'default_locale': [SKIP],
}], # 'system == android' }], # 'system == android'
] ]
...@@ -37,8 +37,5 @@ assertFalse(options.locale === 'und'); ...@@ -37,8 +37,5 @@ assertFalse(options.locale === 'und');
assertFalse(options.locale === ''); assertFalse(options.locale === '');
assertFalse(options.locale === undefined); assertFalse(options.locale === undefined);
// Then check for legitimacy.
assertLanguageTag(%GetDefaultICULocale(), options.locale);
var nfNone = new Intl.NumberFormat(); var nfNone = new Intl.NumberFormat();
assertEquals(options.locale, nfNone.resolvedOptions().locale); assertEquals(options.locale, nfNone.resolvedOptions().locale);
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Passing a well formed but unsupported locale falls back to default.
var nf = Intl.NumberFormat(['xx']);
assertLanguageTag(%GetDefaultICULocale(), nf.resolvedOptions().locale);
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