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

[Temporal] Use MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE

1. Move the use of MAYBE_RETURN to MAYBE_ASSIGN_RETURN_ON_EXCEPTION_VALUE
if possible.
2. Remove some MYABE_RETURN in the wrong spot and therefore fix some tests.
3. Change Intl::GetTimeZoneIndex() to return Maybe<int32_t> as index and use
< 0 value to indicate not getting index to make the function signature
simpler.

Bug: v8:11544
Change-Id: I685cbff142e9dea69ef316a1bc180730aef5aec8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3625839Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80379}
parent a7f4ca5f
......@@ -2861,18 +2861,16 @@ std::string Intl::TimeZoneIdFromIndex(int32_t index) {
return id;
}
Maybe<bool> Intl::GetTimeZoneIndex(Isolate* isolate, Handle<String> identifier,
int32_t* index) {
int32_t Intl::GetTimeZoneIndex(Isolate* isolate, Handle<String> identifier) {
if (identifier->Equals(*isolate->factory()->UTC_string())) {
*index = 0;
return Just(true);
return 0;
}
std::string identifier_str(identifier->ToCString().get());
std::unique_ptr<icu::TimeZone> tz(
icu::TimeZone::createTimeZone(identifier_str.c_str()));
if (!IsValidTimeZoneName(*tz)) {
return Just(false);
return -1;
}
std::unique_ptr<icu::StringEnumeration> enumeration(
......@@ -2883,11 +2881,10 @@ Maybe<bool> Intl::GetTimeZoneIndex(Isolate* isolate, Handle<String> identifier,
UErrorCode status = U_ZERO_ERROR;
while (U_SUCCESS(status) &&
(id = enumeration->next(nullptr, status)) != nullptr) {
curr++;
if (identifier_str == id) {
*index = curr + 1;
return Just(true);
return curr;
}
curr++;
}
CHECK(U_SUCCESS(status));
// We should not reach here, the !IsValidTimeZoneName should return earlier
......
......@@ -356,8 +356,10 @@ class Intl {
// Function to support Temporal
V8_WARN_UNUSED_RESULT static std::string TimeZoneIdFromIndex(int32_t index);
V8_WARN_UNUSED_RESULT static Maybe<bool> GetTimeZoneIndex(
Isolate* isolate, Handle<String> identifier, int32_t* index);
// Return the index of timezone which later could be used with
// TimeZoneIdFromIndex. Returns -1 while the identifier is not a built-in
// TimeZone name.
static int32_t GetTimeZoneIndex(Isolate* isolate, Handle<String> identifier);
V8_WARN_UNUSED_RESULT static MaybeHandle<String> CanonicalizeTimeZoneName(
Isolate* isolate, Handle<String> identifier);
......
This diff is collapsed.
This diff is collapsed.
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