Commit 7701af03 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Allow Intl.Locale to create "und"

Bug: v8:8657, v8:8236, v8:7684
Change-Id: I369a3b302ef70e3fa37208e5c7d1e2fcea1fa390
Reviewed-on: https://chromium-review.googlesource.com/c/1400852Reviewed-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@{#58807}
parent 102e2265
......@@ -30,23 +30,6 @@ namespace internal {
namespace {
// Helper function to check a language tag is valid. It will return false if
// the parsing is not the same as the tag. For example, it will return false if
// the tag is too long.
bool IsValidLanguageTag(const char* tag, int length) {
// icu::Locale::forLanguageTag won't return U_STRING_NOT_TERMINATED_WARNING
// for incorrect locale yet. So we still need the following
// uloc_forLanguageTag
// TODO(ftang): Remove once icu::Locale::forLanguageTag indicate error.
char result[ULOC_FULLNAME_CAPACITY];
UErrorCode status = U_ZERO_ERROR;
int parsed_length = 0;
int icu_length = uloc_forLanguageTag(tag, result, ULOC_FULLNAME_CAPACITY,
&parsed_length, &status);
return U_SUCCESS(status) && parsed_length == length &&
status != U_STRING_NOT_TERMINATED_WARNING && icu_length != 0;
}
// Helper function to check a locale is valid. It will return false if
// the length of the extension fields are incorrect. For example, en-u-a or
// en-u-co-b will return false.
......@@ -218,14 +201,10 @@ Maybe<icu::Locale> ApplyOptionsToTag(Isolate* isolate, Handle<String> tag,
CHECK_NOT_NULL(*bcp47_tag);
// 2. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError
// exception.
if (!IsValidLanguageTag(*bcp47_tag, bcp47_tag.length())) {
THROW_NEW_ERROR_RETURN_VALUE(
isolate, NewRangeError(MessageTemplate::kLocaleBadParameters),
Nothing<icu::Locale>());
}
UErrorCode status = U_ZERO_ERROR;
icu::Locale icu_locale = icu::Locale::forLanguageTag(*bcp47_tag, status);
if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING) {
icu::Locale icu_locale =
icu::Locale::forLanguageTag({*bcp47_tag, bcp47_tag.length()}, status);
if (U_FAILURE(status)) {
THROW_NEW_ERROR_RETURN_VALUE(
isolate, NewRangeError(MessageTemplate::kLocaleBadParameters),
Nothing<icu::Locale>());
......
// Copyright 2019 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-locale
assertDoesNotThrow(() => new Intl.Locale('und'));
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