mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 10:27:36 +00:00
Everywhere: Use _{short_,}string to create Strings from literals
This commit is contained in:
parent
85414d9338
commit
09d40bfbb2
92 changed files with 334 additions and 310 deletions
|
@ -159,7 +159,7 @@ ThrowCompletionOr<String> to_temporal_overflow(VM& vm, Object const* options)
|
|||
{
|
||||
// 1. If options is undefined, return "constrain".
|
||||
if (options == nullptr)
|
||||
return TRY_OR_THROW_OOM(vm, String::from_utf8("constrain"sv));
|
||||
return TRY_OR_THROW_OOM(vm, "constrain"_string);
|
||||
|
||||
// 2. Return ? GetOption(options, "overflow", "string", « "constrain", "reject" », "constrain").
|
||||
auto option = TRY(get_option(vm, *options, vm.names.overflow, OptionType::String, { "constrain"sv, "reject"sv }, "constrain"sv));
|
||||
|
@ -173,7 +173,7 @@ ThrowCompletionOr<String> to_temporal_disambiguation(VM& vm, Object const* optio
|
|||
{
|
||||
// 1. If options is undefined, return "compatible".
|
||||
if (options == nullptr)
|
||||
return TRY_OR_THROW_OOM(vm, String::from_utf8("compatible"sv));
|
||||
return TRY_OR_THROW_OOM(vm, "compatible"_string);
|
||||
|
||||
// 2. Return ? GetOption(options, "disambiguation", "string", « "compatible", "earlier", "later", "reject" », "compatible").
|
||||
auto option = TRY(get_option(vm, *options, vm.names.disambiguation, OptionType::String, { "compatible"sv, "earlier"sv, "later"sv, "reject"sv }, "compatible"sv));
|
||||
|
@ -1269,7 +1269,7 @@ ThrowCompletionOr<ISODateTime> parse_iso_date_time(VM& vm, ParseResult const& pa
|
|||
}
|
||||
|
||||
// 7. Let yearMV be ! ToIntegerOrInfinity(CodePointsToString(year)).
|
||||
auto year_mv = *normalized_year.value_or(String::from_utf8_short_string("0"sv)).to_number<i32>();
|
||||
auto year_mv = *normalized_year.value_or("0"_short_string).to_number<i32>();
|
||||
|
||||
// 8. If month is empty, then
|
||||
// a. Let monthMV be 1.
|
||||
|
@ -1425,7 +1425,7 @@ ThrowCompletionOr<TemporalInstant> parse_temporal_instant_string(VM& vm, StringV
|
|||
// 4. If result.[[TimeZone]].[[Z]] is true, then
|
||||
if (result.time_zone.z) {
|
||||
// a. Set offsetString to "+00:00".
|
||||
offset_string = TRY_OR_THROW_OOM(vm, String::from_utf8("+00:00"sv));
|
||||
offset_string = TRY_OR_THROW_OOM(vm, "+00:00"_string);
|
||||
}
|
||||
|
||||
// 6. Assert: offsetString is not undefined.
|
||||
|
@ -1460,7 +1460,7 @@ ThrowCompletionOr<String> parse_temporal_calendar_string(VM& vm, StringView iso_
|
|||
|
||||
// b. If calendar is undefined, return "iso8601".
|
||||
if (!calendar.has_value())
|
||||
return TRY_OR_THROW_OOM(vm, String::from_utf8("iso8601"sv));
|
||||
return TRY_OR_THROW_OOM(vm, "iso8601"_string);
|
||||
// c. Else, return calendar.
|
||||
else
|
||||
return calendar.release_value();
|
||||
|
|
|
@ -99,7 +99,7 @@ ThrowCompletionOr<Calendar*> get_builtin_calendar(VM& vm, String const& identifi
|
|||
Calendar* get_iso8601_calendar(VM& vm)
|
||||
{
|
||||
// 1. Return ! GetBuiltinCalendar("iso8601").
|
||||
return MUST(get_builtin_calendar(vm, String::from_utf8("iso8601"sv).release_value_but_fixme_should_propagate_errors()));
|
||||
return MUST(get_builtin_calendar(vm, "iso8601"_string.release_value_but_fixme_should_propagate_errors()));
|
||||
}
|
||||
|
||||
// 12.2.4 CalendarFields ( calendar, fieldNames ), https://tc39.es/proposal-temporal/#sec-temporal-calendarfields
|
||||
|
@ -824,10 +824,10 @@ ThrowCompletionOr<ISODateRecord> iso_date_from_fields(VM& vm, Object const& fiel
|
|||
|
||||
// 2. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "year", "day" »).
|
||||
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields,
|
||||
{ String::from_utf8_short_string("day"sv),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("month"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("monthCode"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("year"sv)) },
|
||||
{ "day"_short_string,
|
||||
TRY_OR_THROW_OOM(vm, "month"_string),
|
||||
TRY_OR_THROW_OOM(vm, "monthCode"_string),
|
||||
TRY_OR_THROW_OOM(vm, "year"_string) },
|
||||
Vector<StringView> { "year"sv, "day"sv }));
|
||||
|
||||
// 3. Let overflow be ? ToTemporalOverflow(options).
|
||||
|
@ -859,9 +859,9 @@ ThrowCompletionOr<ISOYearMonth> iso_year_month_from_fields(VM& vm, Object const&
|
|||
|
||||
// 2. Set fields to ? PrepareTemporalFields(fields, « "month", "monthCode", "year" », « "year" »).
|
||||
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields,
|
||||
{ TRY_OR_THROW_OOM(vm, String::from_utf8("month"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("monthCode"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("year"sv)) },
|
||||
{ TRY_OR_THROW_OOM(vm, "month"_string),
|
||||
TRY_OR_THROW_OOM(vm, "monthCode"_string),
|
||||
TRY_OR_THROW_OOM(vm, "year"_string) },
|
||||
Vector<StringView> { "year"sv }));
|
||||
|
||||
// 3. Let overflow be ? ToTemporalOverflow(options).
|
||||
|
@ -890,10 +890,10 @@ ThrowCompletionOr<ISOMonthDay> iso_month_day_from_fields(VM& vm, Object const& f
|
|||
|
||||
// 2. Set fields to ? PrepareTemporalFields(fields, « "day", "month", "monthCode", "year" », « "day" »).
|
||||
auto* prepared_fields = TRY(prepare_temporal_fields(vm, fields,
|
||||
{ String::from_utf8_short_string("day"sv),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("month"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("monthCode"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("year"sv)) },
|
||||
{ "day"_short_string,
|
||||
TRY_OR_THROW_OOM(vm, "month"_string),
|
||||
TRY_OR_THROW_OOM(vm, "monthCode"_string),
|
||||
TRY_OR_THROW_OOM(vm, "year"_string) },
|
||||
Vector<StringView> { "day"sv }));
|
||||
|
||||
// 3. Let overflow be ? ToTemporalOverflow(options).
|
||||
|
|
|
@ -216,7 +216,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::date_until)
|
|||
|
||||
// 8. If largestUnit is "auto", set largestUnit to "day".
|
||||
if (largest_unit == "auto")
|
||||
largest_unit = String::from_utf8_short_string("day"sv);
|
||||
largest_unit = "day"_short_string;
|
||||
|
||||
// 9. Let result be DifferenceISODate(one.[[ISOYear]], one.[[ISOMonth]], one.[[ISODay]], two.[[ISOYear]], two.[[ISOMonth]], two.[[ISODay]], largestUnit).
|
||||
auto result = difference_iso_date(vm, one->iso_year(), one->iso_month(), one->iso_day(), two->iso_year(), two->iso_month(), two->iso_day(), *largest_unit);
|
||||
|
|
|
@ -369,7 +369,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round)
|
|||
smallest_unit_present = false;
|
||||
|
||||
// b. Set smallestUnit to "nanosecond".
|
||||
smallest_unit = TRY_OR_THROW_OOM(vm, String::from_utf8("nanosecond"sv));
|
||||
smallest_unit = TRY_OR_THROW_OOM(vm, "nanosecond"_string);
|
||||
}
|
||||
|
||||
// 10. Let defaultLargestUnit be ! DefaultTemporalLargestUnit(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]]).
|
||||
|
|
|
@ -267,7 +267,7 @@ ThrowCompletionOr<String> temporal_instant_to_string(VM& vm, Instant& instant, V
|
|||
// 8. If timeZone is undefined, then
|
||||
if (time_zone.is_undefined()) {
|
||||
// a. Let timeZoneString be "Z".
|
||||
time_zone_string = String::from_utf8_short_string("Z"sv);
|
||||
time_zone_string = "Z"_short_string;
|
||||
}
|
||||
// 9. Else,
|
||||
else {
|
||||
|
|
|
@ -344,12 +344,12 @@ ThrowCompletionOr<TemporalTimeLikeRecord> to_temporal_time_record(VM& vm, Object
|
|||
|
||||
// 2. Let partial be ? PrepareTemporalFields(temporalTimeLike, « "hour", "microsecond", "millisecond", "minute", "nanosecond", "second" », partial).
|
||||
auto* partial = TRY(prepare_temporal_fields(vm, temporal_time_like,
|
||||
{ TRY_OR_THROW_OOM(vm, String::from_utf8("hour"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("microsecond"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("millisecond"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("minute"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("nanosecond"sv)),
|
||||
TRY_OR_THROW_OOM(vm, String::from_utf8("second"sv)) },
|
||||
{ TRY_OR_THROW_OOM(vm, "hour"_string),
|
||||
TRY_OR_THROW_OOM(vm, "microsecond"_string),
|
||||
TRY_OR_THROW_OOM(vm, "millisecond"_string),
|
||||
TRY_OR_THROW_OOM(vm, "minute"_string),
|
||||
TRY_OR_THROW_OOM(vm, "nanosecond"_string),
|
||||
TRY_OR_THROW_OOM(vm, "second"_string) },
|
||||
PrepareTemporalFieldsPartial {}));
|
||||
|
||||
TemporalTimeLikeRecord result;
|
||||
|
|
|
@ -150,10 +150,10 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
|
|||
auto field_names = TRY(calendar_fields(vm, *calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
|
||||
|
||||
// d. Append "timeZone" to fieldNames.
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, String::from_utf8("timeZone"sv)));
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, "timeZone"_string));
|
||||
|
||||
// e. Append "offset" to fieldNames.
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, String::from_utf8("offset"sv)));
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, "offset"_string));
|
||||
|
||||
// f. Let fields be ? PrepareTemporalFields(item, fieldNames, « "timeZone" »).
|
||||
auto* fields = TRY(prepare_temporal_fields(vm, item_object, field_names, Vector<StringView> { "timeZone"sv }));
|
||||
|
|
|
@ -769,7 +769,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
|
|||
auto field_names = TRY(calendar_fields(vm, calendar, { "day"sv, "hour"sv, "microsecond"sv, "millisecond"sv, "minute"sv, "month"sv, "monthCode"sv, "nanosecond"sv, "second"sv, "year"sv }));
|
||||
|
||||
// 7. Append "offset" to fieldNames.
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, String::from_utf8("offset"sv)));
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, "offset"_string));
|
||||
|
||||
// 8. Let partialZonedDateTime be ? PrepareTemporalFields(temporalZonedDateTimeLike, fieldNames, partial).
|
||||
auto* partial_zoned_date_time = TRY(prepare_temporal_fields(vm, temporal_zoned_date_time_like.as_object(), field_names, PrepareTemporalFieldsPartial {}));
|
||||
|
@ -787,7 +787,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::with)
|
|||
auto& time_zone = zoned_date_time->time_zone();
|
||||
|
||||
// 13. Append "timeZone" to fieldNames.
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, String::from_utf8("timeZone"sv)));
|
||||
field_names.append(TRY_OR_THROW_OOM(vm, "timeZone"_string));
|
||||
|
||||
// 14. Let fields be ? PrepareTemporalFields(zonedDateTime, fieldNames, « "timeZone", "offset" »).
|
||||
auto* fields = TRY(prepare_temporal_fields(vm, *zoned_date_time, field_names, Vector<StringView> { "timeZone"sv, "offset"sv }));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue