Commit 770eafd4 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

Reland "[Intl] Fix legacy error handling"

This is a reland of 1f5ab936

Tests started passing before this was reverted so this isn't
culprit.

Original change's description:
> [Intl] Fix legacy error handling
>
> Bug: v8:5751
> Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
> Change-Id: I382404f4c59c1e997ea0fb58f3a995b653c0d6bc
> Reviewed-on: https://chromium-review.googlesource.com/1148031
> Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#54625}

TBR: jgruber@chromium.org
Bug: v8:5751
Change-Id: I546b10e5cbbbac3aa947ca55cea1f7cc4ae77270
Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Reviewed-on: https://chromium-review.googlesource.com/1148660Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54672}
parent f320738f
...@@ -804,14 +804,7 @@ function canonicalizeLanguageTag(localeID) { ...@@ -804,14 +804,7 @@ function canonicalizeLanguageTag(localeID) {
} }
// ECMA 402 6.2.3 // ECMA 402 6.2.3
var tag = %CanonicalizeLanguageTag(localeString); return %CanonicalizeLanguageTag(localeString);
// TODO(jshin): This should not happen because the structural validity
// is already checked. If that's the case, remove this.
if (tag === 'invalid-tag') {
throw %make_range_error(kInvalidLanguageTag, localeString);
}
return tag;
} }
......
...@@ -55,13 +55,14 @@ namespace internal { ...@@ -55,13 +55,14 @@ namespace internal {
// ECMA 402 6.2.3 // ECMA 402 6.2.3
RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) { RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) {
HandleScope scope(isolate); HandleScope scope(isolate);
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
Factory* factory = isolate->factory();
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(String, locale_id_str, 0); CONVERT_ARG_HANDLE_CHECKED(String, locale_id_str, 0);
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate);
Factory* factory = isolate->factory();
v8::String::Utf8Value locale_id(v8_isolate, v8::String::Utf8Value locale_id(v8_isolate,
v8::Utils::ToLocal(locale_id_str)); v8::Utils::ToLocal(locale_id_str));
...@@ -72,15 +73,14 @@ RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) { ...@@ -72,15 +73,14 @@ RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) {
// handle long locale names better. See // handle long locale names better. See
// https://ssl.icu-project.org/trac/ticket/13417 . // https://ssl.icu-project.org/trac/ticket/13417 .
// Return value which denotes invalid language tag.
const char* const kInvalidTag = "invalid-tag";
UErrorCode error = U_ZERO_ERROR; UErrorCode error = U_ZERO_ERROR;
char icu_result[ULOC_FULLNAME_CAPACITY]; char icu_result[ULOC_FULLNAME_CAPACITY];
uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY, nullptr, uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY, nullptr,
&error); &error);
if (U_FAILURE(error) || error == U_STRING_NOT_TERMINATED_WARNING) { if (U_FAILURE(error) || error == U_STRING_NOT_TERMINATED_WARNING) {
return *factory->NewStringFromAsciiChecked(kInvalidTag); THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
NewRangeError(MessageTemplate::kInvalidLanguageTag, locale_id_str));
} }
char result[ULOC_FULLNAME_CAPACITY]; char result[ULOC_FULLNAME_CAPACITY];
...@@ -89,9 +89,12 @@ RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) { ...@@ -89,9 +89,12 @@ RUNTIME_FUNCTION(Runtime_CanonicalizeLanguageTag) {
uloc_toLanguageTag(icu_result, result, ULOC_FULLNAME_CAPACITY, TRUE, &error); uloc_toLanguageTag(icu_result, result, ULOC_FULLNAME_CAPACITY, TRUE, &error);
if (U_FAILURE(error) || error == U_STRING_NOT_TERMINATED_WARNING) { if (U_FAILURE(error) || error == U_STRING_NOT_TERMINATED_WARNING) {
return *factory->NewStringFromAsciiChecked(kInvalidTag); THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
NewRangeError(MessageTemplate::kInvalidLanguageTag, locale_id_str));
} }
DCHECK_NOT_NULL(result);
return *factory->NewStringFromAsciiChecked(result); return *factory->NewStringFromAsciiChecked(result);
} }
......
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