diff options
author | Linus Groh <mail@linusgroh.de> | 2023-01-26 15:09:59 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-26 20:20:54 +0000 |
commit | 0f5f9acc9cca34b4d8626c5172b2baa4d503d3e7 (patch) | |
tree | 4c11bdb86f3b22632b09b790182e813d90c7c58f /Userland/Libraries/LibJS/Runtime | |
parent | 96855d53c4eaa579a5e8357078fa4a0de4294591 (diff) | |
download | serenity-0f5f9acc9cca34b4d8626c5172b2baa4d503d3e7.zip |
LibJS: Port canonicalize_time_zone_name() to String
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
6 files changed, 17 insertions, 17 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp index b67e35f8c9..14e8914beb 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DateTimeFormatConstructor.cpp @@ -214,17 +214,17 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF // 29. Let timeZone be ? Get(options, "timeZone"). auto time_zone_value = TRY(options->get(vm.names.timeZone)); - DeprecatedString time_zone; + String time_zone; // 30. If timeZone is undefined, then if (time_zone_value.is_undefined()) { // a. Set timeZone to DefaultTimeZone(). - time_zone = default_time_zone(); + time_zone = TRY_OR_THROW_OOM(vm, String::from_utf8(default_time_zone())); } // 31. Else, else { // a. Set timeZone to ? ToString(timeZone). - time_zone = TRY(time_zone_value.to_deprecated_string(vm)); + time_zone = TRY(time_zone_value.to_string(vm)); // b. If IsAvailableTimeZoneName(timeZone) is false, then if (!Temporal::is_available_time_zone_name(time_zone)) { @@ -233,11 +233,11 @@ ThrowCompletionOr<DateTimeFormat*> initialize_date_time_format(VM& vm, DateTimeF } // c. Set timeZone to ! CanonicalizeTimeZoneName(timeZone). - time_zone = Temporal::canonicalize_time_zone_name(time_zone); + time_zone = MUST_OR_THROW_OOM(Temporal::canonicalize_time_zone_name(vm, time_zone)); } // 32. Set dateTimeFormat.[[TimeZone]] to timeZone. - date_time_format.set_time_zone(move(time_zone)); + date_time_format.set_time_zone(time_zone.to_deprecated_string()); // 33. Let formatOptions be a new Record. ::Locale::CalendarPattern format_options {}; diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index 801ee97ac9..4e1d87d427 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -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). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp index 53759cf099..4fa0acf21d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp @@ -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). diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h index 1892196bd5..e37f268a20 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.h @@ -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); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp index ea44f7e143..633a45c480 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZoneConstructor.cpp @@ -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 diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp index 11112877c2..07de939c23 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ZonedDateTime.cpp @@ -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]]. |