Commit 1f09e468 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Temporal] Change Parser from Maybe to Optional

Bug: v8:11544
Change-Id: I16b1fb2cb4f6f4104b2f972a06b8fe0798ac6835
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3632675
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80435}
parent 1a5c64da
This diff is collapsed.
......@@ -5,6 +5,7 @@
#include "src/temporal/temporal-parser.h"
#include "src/base/bounds.h"
#include "src/base/optional.h"
#include "src/objects/string-inl.h"
#include "src/strings/char-predicates-inl.h"
......@@ -1187,7 +1188,7 @@ SATISIFY(TemporalDurationString, ParsedISO8601Duration)
} // namespace
#define IMPL_PARSE_METHOD(R, NAME) \
Maybe<R> TemporalParser::Parse##NAME(Isolate* isolate, \
base::Optional<R> TemporalParser::Parse##NAME(Isolate* isolate, \
Handle<String> iso_string) { \
bool valid; \
R parsed; \
......@@ -1201,8 +1202,8 @@ SATISIFY(TemporalDurationString, ParsedISO8601Duration)
valid = Satisfy##NAME(str_content.ToUC16Vector(), &parsed); \
} \
} \
if (valid) return Just(parsed); \
return Nothing<R>(); \
if (valid) return parsed; \
return base::nullopt; \
}
IMPL_PARSE_METHOD(ParsedISO8601Result, TemporalDateTimeString)
......
......@@ -5,6 +5,7 @@
#ifndef V8_TEMPORAL_TEMPORAL_PARSER_H_
#define V8_TEMPORAL_TEMPORAL_PARSER_H_
#include "src/base/optional.h"
#include "src/execution/isolate.h"
namespace v8 {
......@@ -127,8 +128,8 @@ struct ParsedISO8601Duration {
class V8_EXPORT_PRIVATE TemporalParser {
public:
#define DEFINE_PARSE_METHOD(R, NAME) \
V8_WARN_UNUSED_RESULT static Maybe<R> Parse##NAME(Isolate* isolate, \
Handle<String> iso_string)
V8_WARN_UNUSED_RESULT static base::Optional<R> Parse##NAME( \
Isolate* isolate, Handle<String> iso_string)
DEFINE_PARSE_METHOD(ParsedISO8601Result, TemporalDateString);
DEFINE_PARSE_METHOD(ParsedISO8601Result, TemporalDateTimeString);
DEFINE_PARSE_METHOD(ParsedISO8601Result, TemporalTimeString);
......
......@@ -59,7 +59,7 @@ void CheckTimeZoneNumericUTCOffset(const ParsedISO8601Result& actual,
int32_t date_month, int32_t date_day, const char* calendar_name) { \
Handle<String> input = CcTest::MakeString(str); \
ParsedISO8601Result actual = \
TemporalParser::ParseTemporal##R##String(isolate, input).ToChecked(); \
*TemporalParser::ParseTemporal##R##String(isolate, input); \
CheckDate(actual, date_year, date_month, date_day); \
CheckCalendar(isolate, input, actual.calendar_name_start, \
actual.calendar_name_length, calendar_name); \
......@@ -78,7 +78,7 @@ IMPL_VERIFY_PARSE_TEMPORAL_DATE_STRING_SUCCESS(RelativeTo)
const char* calendar_name) { \
Handle<String> input = CcTest::MakeString(str); \
ParsedISO8601Result actual = \
TemporalParser::ParseTemporal##R##String(isolate, input).ToChecked(); \
*TemporalParser::ParseTemporal##R##String(isolate, input); \
CheckDate(actual, date_year, date_month, date_day); \
CheckCalendar(isolate, input, actual.calendar_name_start, \
actual.calendar_name_length, calendar_name); \
......@@ -98,7 +98,7 @@ IMPL_VERIFY_PARSE_TEMPORAL_DATE_TIME_STRING_SUCCESS(RelativeTo)
bool utc_designator, const char* tzi_name) { \
Handle<String> input = CcTest::MakeString(str); \
ParsedISO8601Result actual = \
TemporalParser::ParseTemporal##R##String(isolate, input).ToChecked(); \
*TemporalParser::ParseTemporal##R##String(isolate, input); \
CheckDate(actual, date_year, date_month, date_day); \
CheckCalendar(isolate, input, actual.calendar_name_start, \
actual.calendar_name_length, calendar_name); \
......@@ -122,7 +122,7 @@ void VerifyParseTemporalInstantStringSuccess(
int32_t tzuo_nanosecond) {
Handle<String> input = CcTest::MakeString(str);
ParsedISO8601Result actual =
TemporalParser::ParseTemporalInstantString(isolate, input).ToChecked();
*TemporalParser::ParseTemporalInstantString(isolate, input);
CHECK_EQ(utc_designator, actual.utc_designator);
if (!utc_designator) {
CheckTimeZoneNumericUTCOffset(actual, tzuo_sign, tzuo_hour, tzuo_minute,
......@@ -134,7 +134,7 @@ void VerifyParseTemporalCalendarStringSuccess(
Isolate* isolate, const char* str, const std::string& calendar_name) {
Handle<String> input = CcTest::MakeString(str);
ParsedISO8601Result actual =
TemporalParser::ParseTemporalCalendarString(isolate, input).ToChecked();
*TemporalParser::ParseTemporalCalendarString(isolate, input);
CheckCalendar(isolate, input, actual.calendar_name_start,
actual.calendar_name_length, calendar_name);
}
......@@ -142,7 +142,7 @@ void VerifyParseTemporalCalendarStringSuccess(
#define VERIFY_PARSE_FAIL(R, str) \
do { \
Handle<String> input = CcTest::MakeString(str); \
CHECK(TemporalParser::Parse##R(isolate, input).IsNothing()); \
CHECK(!TemporalParser::Parse##R(isolate, input).has_value()); \
} while (false)
void VerifyParseTemporalTimeStringSuccess(
......@@ -150,7 +150,7 @@ void VerifyParseTemporalTimeStringSuccess(
int32_t time_second, int32_t time_nanosecond, const char* calendar_name) {
Handle<String> input = CcTest::MakeString(str);
ParsedISO8601Result actual =
TemporalParser::ParseTemporalTimeString(isolate, input).ToChecked();
*TemporalParser::ParseTemporalTimeString(isolate, input);
CheckTime(actual, time_hour, time_minute, time_second, time_nanosecond);
CheckCalendar(isolate, input, actual.calendar_name_start,
actual.calendar_name_length, calendar_name);
......@@ -1969,10 +1969,10 @@ void VerifyParseDurationSuccess(Isolate* isolate, const char* str, int64_t sign,
int64_t minutes_fraction, int64_t whole_seconds,
int64_t seconds_fraction) {
Handle<String> input = CcTest::MakeString(str);
CheckDuration(
TemporalParser::ParseTemporalDurationString(isolate, input).ToChecked(),
CheckDuration(*TemporalParser::ParseTemporalDurationString(isolate, input),
sign, years, months, weeks, days, whole_hours, hours_fraction,
whole_minutes, minutes_fraction, whole_seconds, seconds_fraction);
whole_minutes, minutes_fraction, whole_seconds,
seconds_fraction);
}
void VerifyParseDurationSuccess(Isolate* isolate, const char* str,
......@@ -1987,7 +1987,7 @@ void VerifyParseDurationSuccess(Isolate* isolate, const char* str,
void VerifyParseDurationWithPositiveSign(Isolate* isolate, const char* str) {
Handle<String> input = CcTest::MakeString(str);
ParsedISO8601Duration expected =
TemporalParser::ParseTemporalDurationString(isolate, input).ToChecked();
*TemporalParser::ParseTemporalDurationString(isolate, input);
std::string with_sign("+");
with_sign += str;
VerifyParseDurationSuccess(isolate, with_sign.c_str(), expected);
......@@ -1998,7 +1998,7 @@ void VerifyParseDurationWithMinusSign(Isolate* isolate, const char* str) {
with_sign += str;
Handle<String> input = CcTest::MakeString(with_sign.c_str());
ParsedISO8601Duration expected =
TemporalParser::ParseTemporalDurationString(isolate, input).ToChecked();
*TemporalParser::ParseTemporalDurationString(isolate, input);
with_sign = "\u2212";
with_sign += str;
VerifyParseDurationSuccess(isolate, with_sign.c_str(), expected);
......@@ -2011,7 +2011,7 @@ char asciitolower(char in) {
void VerifyParseDurationWithLowerCase(Isolate* isolate, const char* str) {
Handle<String> input = CcTest::MakeString(str);
ParsedISO8601Duration expected =
TemporalParser::ParseTemporalDurationString(isolate, input).ToChecked();
*TemporalParser::ParseTemporalDurationString(isolate, input);
std::string lower(str);
std::transform(lower.begin(), lower.end(), lower.begin(), asciitolower);
VerifyParseDurationSuccess(isolate, lower.c_str(), expected);
......@@ -2023,7 +2023,7 @@ void VerifyParseDurationWithComma(Isolate* isolate, const char* str) {
std::transform(period.begin(), period.end(), period.begin(), commatoperiod);
Handle<String> input = CcTest::MakeString(str);
ParsedISO8601Duration expected =
TemporalParser::ParseTemporalDurationString(isolate, input).ToChecked();
*TemporalParser::ParseTemporalDurationString(isolate, input);
VerifyParseDurationSuccess(isolate, str, expected);
}
......@@ -2322,8 +2322,8 @@ void VerifyParseTimeZoneNumericUTCOffsetSuccess(
int32_t tzuo_minute, int32_t tzuo_second, int32_t tzuo_nanosecond) {
Handle<String> input = CcTest::MakeString(str);
CheckTimeZoneNumericUTCOffset(
TemporalParser::ParseTimeZoneNumericUTCOffset(isolate, input).ToChecked(),
tzuo_sign, tzuo_hour, tzuo_minute, tzuo_second, tzuo_nanosecond);
*TemporalParser::ParseTimeZoneNumericUTCOffset(isolate, input), tzuo_sign,
tzuo_hour, tzuo_minute, tzuo_second, tzuo_nanosecond);
}
TEST(TimeZoneNumericUTCOffsetBasic) {
......
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