1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 05:07:35 +00:00

LibJS: Port canonicalize_time_zone_name() to String

This commit is contained in:
Linus Groh 2023-01-26 15:09:59 +00:00
parent 96855d53c4
commit 0f5f9acc9c
6 changed files with 17 additions and 17 deletions

View file

@ -657,7 +657,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeZoneName, *time_zone_name);
// 2. Set timeZoneName to ! CanonicalizeTimeZoneName(timeZoneName).
time_zone_name = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(canonicalize_time_zone_name(time_zone_name->to_deprecated_string())));
time_zone_name = MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, *time_zone_name));
}
// ii. Let timeZone be ! CreateTemporalTimeZone(timeZoneName).

View file

@ -43,7 +43,7 @@ bool is_available_time_zone_name(StringView time_zone)
// 11.1.2 CanonicalizeTimeZoneName ( timeZone ), https://tc39.es/proposal-temporal/#sec-canonicalizetimezonename
// 15.1.2 CanonicalizeTimeZoneName ( timeZone ), https://tc39.es/proposal-temporal/#sup-canonicalizetimezonename
DeprecatedString canonicalize_time_zone_name(DeprecatedString const& time_zone)
ThrowCompletionOr<String> canonicalize_time_zone_name(VM& vm, StringView time_zone)
{
// 1. Let ianaTimeZone be the String value of the Zone or Link name of the IANA Time Zone Database that is an ASCII-case-insensitive match of timeZone as described in 6.1.
// 2. If ianaTimeZone is a Link name, let ianaTimeZone be the String value of the corresponding Zone name as specified in the file backward of the IANA Time Zone Database.
@ -53,7 +53,7 @@ DeprecatedString canonicalize_time_zone_name(DeprecatedString const& time_zone)
// NOTE: This is already done in canonicalize_time_zone().
// 4. Return ianaTimeZone.
return *iana_time_zone;
return TRY_OR_THROW_OOM(vm, String::from_utf8(*iana_time_zone));
}
// 11.6.1 CreateTemporalTimeZone ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporaltimezone
@ -82,7 +82,7 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM& vm, DeprecatedString
// 4. Else,
else {
// a. Assert: ! CanonicalizeTimeZoneName(identifier) is identifier.
VERIFY(canonicalize_time_zone_name(identifier) == identifier);
VERIFY(MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, identifier)) == identifier.view());
// b. Set object.[[Identifier]] to identifier.
object->set_identifier(identifier);
@ -349,7 +349,7 @@ ThrowCompletionOr<Object*> to_temporal_time_zone(VM& vm, Value temporal_time_zon
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeZoneName, name);
// ii. Set name to ! CanonicalizeTimeZoneName(name).
name = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(canonicalize_time_zone_name(name.to_deprecated_string())));
name = MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, name));
}
// c. Return ! CreateTemporalTimeZone(name).

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -37,7 +37,7 @@ private:
};
bool is_available_time_zone_name(StringView time_zone);
DeprecatedString canonicalize_time_zone_name(DeprecatedString const& time_zone);
ThrowCompletionOr<String> canonicalize_time_zone_name(VM&, StringView time_zone);
ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM&, DeprecatedString const& identifier, FunctionObject const* new_target = nullptr);
ISODateTime get_iso_parts_from_epoch(VM&, Crypto::SignedBigInteger const& epoch_nanoseconds);
BigInt* get_named_time_zone_next_transition(VM&, StringView time_zone_identifier, BigInt const& epoch_nanoseconds);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -48,7 +48,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> TimeZoneConstructor::construct(FunctionO
auto& vm = this->vm();
// 2. Set identifier to ? ToString(identifier).
auto identifier = TRY(vm.argument(0).to_deprecated_string(vm));
auto identifier = TRY(vm.argument(0).to_string(vm));
// 3. If IsTimeZoneOffsetString(identifier) is false, then
if (!is_time_zone_offset_string(identifier)) {
@ -59,11 +59,11 @@ ThrowCompletionOr<NonnullGCPtr<Object>> TimeZoneConstructor::construct(FunctionO
}
// b. Set identifier to ! CanonicalizeTimeZoneName(identifier).
identifier = canonicalize_time_zone_name(identifier);
identifier = MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, identifier));
}
// 4. Return ? CreateTemporalTimeZone(identifier, NewTarget).
return *TRY(create_temporal_time_zone(vm, identifier, &new_target));
return *TRY(create_temporal_time_zone(vm, identifier.to_deprecated_string(), &new_target));
}
// 11.3.2 Temporal.TimeZone.from ( item ), https://tc39.es/proposal-temporal/#sec-temporal.timezone.from

View file

@ -203,7 +203,7 @@ ThrowCompletionOr<ZonedDateTime*> to_temporal_zoned_date_time(VM& vm, Value item
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidTimeZoneName, *time_zone_name);
// ii. Set timeZoneName to ! CanonicalizeTimeZoneName(timeZoneName).
time_zone_name = TRY_OR_THROW_OOM(vm, String::from_deprecated_string(canonicalize_time_zone_name(time_zone_name->to_deprecated_string())));
time_zone_name = MUST_OR_THROW_OOM(canonicalize_time_zone_name(vm, *time_zone_name));
}
// g. Let offsetString be result.[[TimeZone]].[[OffsetString]].