From a101b15ad01c1dca00ba6fed2a5f9fc6386ba2b9 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 26 Jan 2023 15:20:00 +0000 Subject: [PATCH] LibJS: Port create_temporal_calendar() to String --- Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp | 10 +++++----- Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h | 8 ++++---- .../LibJS/Runtime/Temporal/CalendarConstructor.cpp | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp index 9650b61423..b4e39d961d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp @@ -27,7 +27,7 @@ namespace JS::Temporal { // 12 Temporal.Calendar Objects, https://tc39.es/proposal-temporal/#sec-temporal-calendar-objects -Calendar::Calendar(DeprecatedString identifier, Object& prototype) +Calendar::Calendar(String identifier, Object& prototype) : Object(ConstructWithPrototypeTag::Tag, prototype) , m_identifier(move(identifier)) { @@ -65,7 +65,7 @@ Span available_calendars() } // 12.2.1 CreateTemporalCalendar ( identifier [ , newTarget ] ), https://tc39.es/proposal-temporal/#sec-temporal-createtemporalcalendar -ThrowCompletionOr create_temporal_calendar(VM& vm, DeprecatedString const& identifier, FunctionObject const* new_target) +ThrowCompletionOr create_temporal_calendar(VM& vm, String const& identifier, FunctionObject const* new_target) { auto& realm = *vm.current_realm(); @@ -78,7 +78,7 @@ ThrowCompletionOr create_temporal_calendar(VM& vm, DeprecatedString c // 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »). // 4. Set object.[[Identifier]] to the ASCII-lowercase of identifier. - auto object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_calendar_prototype, identifier.to_lowercase())); + auto object = TRY(ordinary_create_from_constructor(vm, *new_target, &Intrinsics::temporal_calendar_prototype, TRY_OR_THROW_OOM(vm, identifier.to_lowercase()))); // 5. Return object. return object.ptr(); @@ -92,7 +92,7 @@ ThrowCompletionOr get_builtin_calendar(VM& vm, DeprecatedString const return vm.throw_completion(ErrorType::TemporalInvalidCalendarIdentifier, identifier); // 2. Return ! CreateTemporalCalendar(id). - return MUST(create_temporal_calendar(vm, identifier)); + return MUST_OR_THROW_OOM(create_temporal_calendar(vm, TRY_OR_THROW_OOM(vm, String::from_deprecated_string(identifier)))); } // 12.2.3 GetISO8601Calendar ( ), https://tc39.es/proposal-temporal/#sec-temporal-getiso8601calendar @@ -473,7 +473,7 @@ ThrowCompletionOr to_temporal_calendar(VM& vm, Value temporal_calendar_ return vm.throw_completion(ErrorType::TemporalInvalidCalendarIdentifier, identifier); // 5. Return ! CreateTemporalCalendar(identifier). - return MUST(create_temporal_calendar(vm, identifier.to_deprecated_string())); + return MUST_OR_THROW_OOM(create_temporal_calendar(vm, identifier)); } // 12.2.22 ToTemporalCalendarWithISODefault ( temporalCalendarLike ), https://tc39.es/proposal-temporal/#sec-temporal-totemporalcalendarwithisodefault diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h index 1d1a9480c7..d5a90759b7 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.h @@ -22,13 +22,13 @@ class Calendar final : public Object { public: virtual ~Calendar() override = default; - [[nodiscard]] DeprecatedString const& identifier() const { return m_identifier; } + [[nodiscard]] String const& identifier() const { return m_identifier; } private: - Calendar(DeprecatedString identifier, Object& prototype); + Calendar(String identifier, Object& prototype); // 12.5 Properties of Temporal.Calendar Instances, https://tc39.es/proposal-temporal/#sec-properties-of-temporal-calendar-instances - DeprecatedString m_identifier; // [[Identifier]] + String m_identifier; // [[Identifier]] }; // 14.2 The Year-Week Record Specification Type, https://tc39.es/proposal-temporal/#sec-year-week-record-specification-type @@ -39,7 +39,7 @@ struct YearWeekRecord { bool is_builtin_calendar(StringView identifier); Span available_calendars(); -ThrowCompletionOr create_temporal_calendar(VM&, DeprecatedString const& identifier, FunctionObject const* new_target = nullptr); +ThrowCompletionOr create_temporal_calendar(VM&, String const& identifier, FunctionObject const* new_target = nullptr); ThrowCompletionOr get_builtin_calendar(VM&, DeprecatedString const& identifier); Calendar* get_iso8601_calendar(VM&); ThrowCompletionOr> calendar_fields(VM&, Object& calendar, Vector const& field_names); diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarConstructor.cpp index 1a03ae7c0f..60189b5c21 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarConstructor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, Linus Groh + * Copyright (c) 2021-2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -47,7 +47,7 @@ ThrowCompletionOr> CalendarConstructor::construct(FunctionO auto& vm = this->vm(); // 2. Set id to ? ToString(id). - auto identifier = TRY(vm.argument(0).to_deprecated_string(vm)); + auto identifier = TRY(vm.argument(0).to_string(vm)); // 3. If IsBuiltinCalendar(id) is false, then if (!is_builtin_calendar(identifier)) {